95b8253
Branches > main > 95b8253 > files
Munge symbol names in eval
Commit: 95b82533f6b5c1399b21900f01af99d4fa14355a
Parent: 4e63b62
2 changed files:
org/faddle/lang/eval.lua view file
@@ -9,6 +9,7 @@ local symbol = require("org.faddle.lang.symbol") local is_symbol = symbol.is_symbol local intern = symbol.intern+local munge = symbol.munge local compiler = require("org.faddle.lang.compile") local compile = compiler.compile@@ -23,15 +24,16 @@ -- So this should add both to a registry of vars, as well as the munged names mapping to the values in the module return table -- And re-defining updates the var and calls its handler or whatever, or calls an update_var() idk, and it also updates the module table-local function def(var_name, args, env)- assert(is_symbol(var_name), "def must be called with a symbol")+local function def(sym, args, env)+ assert(is_symbol(sym), "def must be called with a symbol") assert(modules[env.current_module] ~= nil, "Cannot define var in non-existent module '" .. env.current_module .. "'") local val = eval(first(args), env) -- Doesn't add to the return table right now -- Probably want to munge names so they're easier to use from Lua. -- I'm not sure whether like 'foo?' and 'is_foo' should be the same symbol or just munged to produce the same thing.+ local var_name = munge(sym) modules[env.current_module][var_name] = val- return var_name+ return sym end local function module(mod_name, env)@@ -76,7 +78,8 @@ -- Perhaps special forms should be looked up like anything else, and be shadowable? -- If you lookup say 'def', it returns nil which is strange local function lookup(sym, env)- return temp_vars[sym] or modules[env.current_module][sym]+ -- Should fail if you're looking up a non-existent local, but not otherwise+ return temp_vars[sym] or modules[env.current_module][munge(sym)] end -- Not quite sure how to do this...org/faddle/lang/symbol.lua view file
@@ -74,7 +74,18 @@ return symbol_registry[id] end --- local function munge(sym) end--- local function demunge(sym) end ?+--- Munges a simple symbol to produce a valid Lua identifier+local function munge(simple_sym)+ assert(not module(simple_sym), "Cannot munge a symbol with a module.", 2)+ -- Right now the identifier spaces are identical+ -- If they're ever made to not be, then this would have to change of course+ return name(simple_sym)+end -return {is_symbol = is_symbol, intern = intern, is_valid_symbol = is_valid_symbol, name = name, module = module, str = str}+return {is_symbol = is_symbol,+ intern = intern,+ is_valid_symbol = is_valid_symbol,+ name = name,+ module = module,+ str = str,+ munge = munge}