]> git.mdlowis.com Git - proto/sclpl-rb.git/commitdiff
debugging free variable detection. It is still very broken. I do not know why
authorMichael D. Lowis <mike.lowis@gentex.com>
Fri, 7 Aug 2020 20:46:07 +0000 (16:46 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Fri, 7 Aug 2020 20:46:07 +0000 (16:46 -0400)
dyn.src
lib/dyn.rb

diff --git a/dyn.src b/dyn.src
index d082790967565e42511fbb2ec489031b4c7bd29d..e8d96d8dc40543b788fcbb9f5f1fb0c9e06d048a 100644 (file)
--- a/dyn.src
+++ b/dyn.src
@@ -35,6 +35,8 @@
 #  42
 #}
 
+a = 1
+
 add : int -> int
 add = fun(a, b) {
   a + b
index 5f568ca89d1be4f4dcf5f2ae8ecd9dec6b43cc1c..2529218193980ea83361b942fc05120c09e63272 100755 (executable)
@@ -94,6 +94,11 @@ class SymTable < Hash
   def annotation(key)
     (method(:[]).super_method.call(key) || {})[:ann]
   end
+
+  def stack()
+    parent = (@parent.is_a?(SymTable) ? @parent.stack : [])
+    ([self] + parent).flatten
+  end
 end
 
 class Lexer
@@ -640,6 +645,7 @@ module TypeChecker
     end
     env.freevars = (env.freevars + newenv.freevars).uniq
     pp "free", env.freevars
+    pp env.stack
     types.last
   end
 
@@ -827,11 +833,16 @@ a = 123
 
 foo : int -> int
 foo = fun(b){
+  d = 123
   bar : int -> int
   bar = fun(c){
     a + b + c
   }
   bar(1)
+  d
+  e = 1
+  e
+  d
 }
 
 eos