Tweaks and adjustments.

This commit is contained in:
Bruce Hill 2017-09-22 00:51:53 -07:00
parent 861d5accc0
commit d3a5fc73bc
2 changed files with 23 additions and 28 deletions

View File

@ -30,13 +30,8 @@ local parsetree_mt = {
end
}
local ParseTree
ParseTree = function(type, src, value, errors)
return setmetatable({
type = type,
src = src,
value = value,
errors = errors
}, parsetree_mt)
ParseTree = function(x)
return setmetatable(x, parsetree_mt)
end
local functiondef_mt = {
__tostring = function(self)
@ -184,12 +179,20 @@ local defs = {
}
setmetatable(defs, {
__index = function(t, key)
local fn
fn = function(src, value, errors)
return ParseTree(key, src, value, errors)
do
local _with_0
_with_0 = function(src, value, errors)
return {
type = key,
src = src,
value = value,
errors = errors
}
end
t[key] = _with_0
local _ = nil
return _with_0
end
t[key] = fn
return fn
end
})
nomsu = re.compile(nomsu, defs)
@ -209,7 +212,7 @@ do
aliases = self:get_aliases(aliases)
end
if self.debug then
self:writeln("Defining rule: " .. tostring(aliases))
self:writeln("Defining rule: " .. tostring(repr(aliases)))
end
local fn_def = FunctionDef(fn, { }, src, is_macro)
return self:add_aliases(aliases, fn_def)
@ -287,7 +290,7 @@ do
args = _tbl_0
end
if self.debug then
self:writeln("Calling " .. tostring(alias) .. " with args: " .. tostring(repr(args)))
self:writeln("Calling " .. tostring(repr(alias)) .. " with args: " .. tostring(repr(args)))
end
insert(self.callstack, alias)
local rets = {
@ -560,10 +563,6 @@ do
end
end,
get_aliases = function(self, x)
if self.value then
print(self)
error("WTF")
end
if not x then
self:error("Nothing to get aliases from")
end

View File

@ -23,8 +23,7 @@ STRING_ESCAPES = n:"\n", t:"\t", b:"\b", a:"\a", v:"\v", f:"\f", r:"\r"
-- Helper "classes"
parsetree_mt = {__tostring:=> "#{@type}(#{repr(@value)})"}
ParseTree = (type, src, value, errors)->
setmetatable({:type, :src, :value, :errors}, parsetree_mt)
ParseTree = (x)-> setmetatable(x, parsetree_mt)
functiondef_mt = {__tostring:=> "FunctionDef(#{repr(@aliases)}"}
FunctionDef = (fn, aliases, src, is_macro)->
@ -151,9 +150,9 @@ defs =
setmetatable(defs, {
__index: (t,key)->
fn = (src, value, errors)-> ParseTree(key, src, value, errors)
t[key] = fn
return fn
-- Disabled for performance
--with t[key] = (src, value, errors)-> ParseTree({type: key, :src, :value, :errors}) do nil
with t[key] = (src, value, errors)-> {type: key, :src, :value, :errors} do nil
})
nomsu = re.compile(nomsu, defs)
@ -176,7 +175,7 @@ class NomsuCompiler
if type(aliases) == 'string'
aliases = @get_aliases aliases
if @debug
@writeln "Defining rule: #{aliases}"
@writeln "Defining rule: #{repr aliases}"
fn_def = FunctionDef(fn, {}, src, is_macro)
@add_aliases aliases, fn_def
@ -221,7 +220,7 @@ class NomsuCompiler
{:fn, :aliases} = fn_def
args = {name, select(i,...) for i,name in ipairs(aliases[alias])}
if @debug
@writeln "Calling #{alias} with args: #{repr(args)}"
@writeln "Calling #{repr alias} with args: #{repr(args)}"
insert @callstack, alias
-- TODO: optimize, but still allow multiple return values?
rets = {fn(self,args)}
@ -430,9 +429,6 @@ class NomsuCompiler
return concat(alias," "), args
get_aliases:(x)=>
if self.value
print self
error "WTF"
if not x then @error "Nothing to get aliases from"
if type(x) == 'string'
alias, args = @get_alias(x)