name = "__func#{$lifted.length}".to_sym
$lifted[name] = func
func = ANF::Var.new(0, func.type, name)
+ freevars = env[:$free].keys.map {|v| ANF::Var.new(0, nil, v) }
+ func = ANF::Apply.new(0, func.type, :__mkclosure, [func] + freevars)
end
func
end
else
patch_vars($parser.syms.clone, e, true)
end
-# pp e
-# puts ""
e
end
ANF::Var.new(0, nil, name),
value,
nil)
- ANF.check(let)
+# ANF.check(let)
ANF.pp(let)
puts ""
end
$toplevel.each do |e|
ANF.pp(e)
- ANF.check(e)
+# ANF.check(e)
puts ""
end
Const = Struct.new(:loc, :type, :value)
Var = Struct.new(:loc, :type, :name)
EnvRef = Struct.new(:loc, :type, :index)
- Env = Struct.new(:loc, :type, :index)
Let = Struct.new(:loc, :type, :var, :expr, :body)
If = Struct.new(:loc, :type, :cond, :then, :else)
Set = Struct.new(:loc, :type, :var, :expr)
elsif expr.is_a? Env
print("ENV_CREATE\n", indent)
elsif expr.is_a? EnvRef
- print("ENV_REF\n", indent)
+ print("(env-ref #{expr.index}\n", indent)
else
raise "unexpected form: #{expr.class}"
end
elsif a.is_a? Var
"#{a.name}"
elsif a.is_a? EnvRef
- "ENV_REF"
+ "(env-ref #{a.index})"
else
raise "argument to apply is not atomic"
end