lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


It's not difficult to add support for and/or operators in the translator, but as I understood, Vlad only needs to support a limited subset of Lua, and quite sensibly didn't focus on things he didn't need.

A version that supports and/or the Lua way would look roughly like this:

function cfg.down.expr (ast)
   match ast with
   | `Op{ 'and', a, b } -> handle_andthen_op (opname, a, b)
   | `Op{ 'or', a, b } -> handle_orelse_op (opname, a, b)
   | `Op{ 'not', `Op{ 'eq', a, b } } -> handle_bin_op.neq (a, b)
   | `Op{ opname, a, b } -> handle_bin_op[opname] (a, b) -- all other binary ops
   | `Op{ opname, a } -> handle_unary_op [opname] (a)
   ... other cases of expressions ...
   end
end

Again, nothing complicated, but there no point handling it if you know you won't need it.

Actually, if you plan to write a translator that converges toward full Lua support, some architectural choices made by Vlad would be seriously unoptimal, although they made sense in his case.

-- Fabien.