]> git.mdlowis.com Git - proto/sclpl-rb.git/commitdiff
added single-level closures master
authorMichael D. Lowis <mike.lowis@gentex.com>
Thu, 26 Jan 2023 21:19:52 +0000 (16:19 -0500)
committerMichael D. Lowis <mike.lowis@gentex.com>
Thu, 26 Jan 2023 21:19:52 +0000 (16:19 -0500)
lib/cerise.rb
lib/utils/anf.rb

index d93ebc7baefb79234491b05d2b7536d13c61a81f..a4d6698268c4790e4bfca61380b36e2af679d7d0 100755 (executable)
@@ -648,6 +648,8 @@ def close_func(env, func, close_funcs = true)
     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
@@ -658,8 +660,6 @@ $toplevel = $parser.exprs.map do |e|
     else
       patch_vars($parser.syms.clone, e, true)
     end
-#    pp e
-#    puts ""
     e
 end
 
@@ -671,13 +671,13 @@ $lifted.each do |name, value|
     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
index 0865c58eb4ccbad00348b2e980802332b3fb931a..c77523a5052259830bf3e16cd7c36612a733d81c 100644 (file)
@@ -25,7 +25,6 @@ module ANF
   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)
@@ -107,7 +106,7 @@ module ANF
     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
@@ -143,7 +142,7 @@ module ANF
       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