From cfee75b21b307b5d57c215cad5b1c089c91182fc Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Wed, 3 Jan 2018 00:52:01 -0800 Subject: Reworked {} a bit and added dicts to the core language. Did some more testing on string interpolations too. --- lib/operators.nom | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'lib/operators.nom') diff --git a/lib/operators.nom b/lib/operators.nom index 1fcb42a..198a8ff 100644 --- a/lib/operators.nom +++ b/lib/operators.nom @@ -32,7 +32,17 @@ compile [..] compile [%obj'%key, %obj's %key, %obj -> %key] to: "(\(%obj as lua))[\(%key as lua)]" # Variable assignment operator, and += type versions -compile [%var = %val] to code: "\(%var as lua) = \(%val as lua);" +compile [%var = %val] to code: + lua> ".." + if \%var.type == 'List' and \%val.type == 'List' then + local lhs = {}; + for i,x in ipairs(\%var.value) do lhs[i] = nomsu:tree_to_lua(x); end + local rhs = {}; + for i,x in ipairs(\%val.value) do rhs[i] = nomsu:tree_to_lua(x); end + return table.concat(lhs, ", ").." = "..table.concat(rhs, ", ")..";"; + else + return \(%var as lua).." = "..\(%val as lua)..";"; + end compile [%var += %val] to code: "\(%var as lua) = \(%var as lua) + \(%val as lua);" compile [%var -= %val] to code: "\(%var as lua) = \(%var as lua) - \(%val as lua);" compile [%var *= %val] to code: "\(%var as lua) = \(%var as lua) * \(%val as lua);" @@ -53,7 +63,7 @@ lua do> ".." end nomsu:defmacro("%a "..nomsu_alias.." %b", (function(nomsu, vars) return "("..nomsu:tree_to_lua(vars.a).." "..op.." "..nomsu:tree_to_lua(vars.b)..")"; - end), [["(\\(%a) ]]..op..[[ \\(%b))"]]); + end), [["(\\%a ]]..op..[[ \\(%b))"]]); end # TODO: implement OR, XOR, AND for multiple operands -- cgit v1.2.3