aboutsummaryrefslogtreecommitdiff
path: root/lib/operators.nom
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2018-01-03 00:52:01 -0800
committerBruce Hill <bitbucket@bruce-hill.com>2018-01-03 00:52:01 -0800
commitcfee75b21b307b5d57c215cad5b1c089c91182fc (patch)
treee6d605892aced717a4519f7860c0b143d11819a6 /lib/operators.nom
parent3bd12b5331f7e5ec939cb8130350ea68fcbd6ceb (diff)
Reworked {} a bit and added dicts to the core language. Did some more
testing on string interpolations too.
Diffstat (limited to 'lib/operators.nom')
-rw-r--r--lib/operators.nom14
1 files changed, 12 insertions, 2 deletions
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