]> git.lizzy.rs Git - metalua.git/commitdiff
H: fixed the creation of H.alpha
authorFabien Fleutot <fabien@macfabien.local>
Sun, 3 Feb 2008 12:41:14 +0000 (13:41 +0100)
committerFabien Fleutot <fabien@macfabien.local>
Sun, 3 Feb 2008 12:41:14 +0000 (13:41 +0100)
src/lib/extension/H-runtime.mlua
src/samples/h_test2.mlua

index 9f82a944ad8e6cddc3d702dbe2b7513faa75e4fb..0546b992a3e76737ccee5c3fcf79c08d3d9611c6 100644 (file)
@@ -31,7 +31,7 @@ require 'walk.id'
 
 H = { } --setmetatable(H, H)
 H.__index=H
-H.template = { }
+H.template = { alpha = { } }
 
 --------------------------------------------------------------------------------
 --
@@ -89,7 +89,8 @@ function H:__call (ast)
 
       -- free_vars is an old_name -> new_name dictionary computed from alpha:
       -- self.alpha is not an efficient representation for searching.
-      if not alpha or #alpha==0 then alpha = `Local{ { }, { } }; self.alpha=alpha end
+      if not alpha then alpha = { }; self.alpha = alpha end
+      if #alpha==0 then alpha <- `Local{ { }, { } } end
       local new, old = unpack(alpha) 
       local free_vars  = { }
 
index dd24376c508f5e65377c40d92133ee8ecc11d59c..751794b53b278c8bf41aa52636a77edb3981c3e1 100644 (file)
@@ -1,18 +1,25 @@
 -{ block:
    -{ extension 'log' }
    -{ extension 'H' }
+
    require 'dollar'
+
+   local H = H:new{alpha={ }}
+   print("initial H.alpha", H.alpha)
+
+
    function dollar.Q(cond, iftrue, iffalse)
       local b = +{ block: 
                    local v 
-                   print("ternary cond")
-                   if -{!cond} then v = -{!iftrue} 
+                   if -{!cond} then v = -{!iftrue}
                    else v = -{!iffalse} end }
       local r = `Stat{ b, +{v} }
-      $log('before hygiene:', H.alpha)
       H(r)
-      $log('after hygiene:', H.alpha)
       return r
-   end }
+   end 
+
+   $log(H)
+   return H.alpha }
 
-y=$Q(x==1, a, b)
\ No newline at end of file
+x=1 ; y=$Q(x==1, 'one', 'two') ; print(y)
+x=2 ; y=$Q(x==1, 'one', 'two') ; print(y)
\ No newline at end of file