Commits

yoshihiro503  committed 44e24fd

version 0.51

  • Participants
  • Parent commits 42144f2

Comments (0)

Files changed (2)

   set_fun ctx "to_s" ([], Literal (LString cname));
   let cls = { class_name="Class"; ctx=ctx } in
   let init0 = { class_name=cname; ctx=snd @@ eval cls body } in
-  let init = match get_initializer body with
+  let init = match get_initializer init0.ctx body with
   | Some (init_argnames, init_body) ->
       init_argnames, External (fun self ->
 	let args = List.map (fun a -> get_var self.ctx a) init_argnames in
   in
   set_fun ctx "new" init;
   cls
-and get_initializer expr =
-  let ctx' = snd @@ eval {class_name="Eval.get_initializer"; ctx=empty_ctx} expr in
-  try Some (get_fun ctx' "initialize") with
+and get_initializer ctx expr =
+  let ctx' = copy_ctx ctx in
+  let ctx'' = snd @@ eval {class_name="Eval.get_initializer"; ctx=ctx'} expr in
+  try Some (get_fun ctx'' "initialize") with
   | UnboundValue -> None
 
 and call self (argnames, body) args fname =

File samples/test.rb

 (* (* nested comment *)
 *)
 
+def fff () ggg() + ggg() end
+def ggg() 99 end
+puts (fff()) 
 
 
-(*
-f = lambda { | x | x }
-puts (f.call(3))
-*)
+
+id = lambda {|x| x }
+puts (id.call(3))
+
 
 puts(3+8)
 
   puts(x+3)
 end.call(5)
 
-(*
+
 class CCC
   def initialize()
     @hoge = 3
 puts(c.to_s())
 puts(c)
 
-*)
 
-(*
+
+
 puts (10 == x)
 c.setx(5)
 puts (10 == x)
 puts(5 == c.getx())
 y = c.getx()
 puts(5 == y)
-*)
 
 
 
 
 
 
-(*
+
+
 puts ("hello, world")
 
 class C
   def h ()
     3
   end
-  puts("hoge")
 end
 
-C.new()
+
 
 def hoge()
   def huga(x)
       x + 5
     end
   end.new()
-*)
-(*puts (d.foo(3))*)
+
+puts (d.foo(3))