OSDN Git Service

Rename Ast.Method to Ast.Lambda,and remove method-name.
authorMIZUNO Hiroki <mzpppp@gmail.com>
Fri, 30 May 2008 13:14:47 +0000 (22:14 +0900)
committerMIZUNO Hiroki <mzpppp@gmail.com>
Fri, 30 May 2008 13:14:47 +0000 (22:14 +0900)
- Change lambda to represent only anoymous-function.

src/ast.ml
src/ast.mli
src/lisp.ml
test/test_ast.ml
test/test_lisp.ml

index a695ef1..707cfbe 100644 (file)
@@ -2,7 +2,7 @@ open Base
 open Asm
 
 type ast = 
-    Method of string * string list * ast
+    Lambda of string list * ast
   | Call of string * ast list
   | String of string
   | Int of int
@@ -85,13 +85,13 @@ let rec generate_expr ast env =
     | Lt (l,r)  -> binary_op LessThan l r
     | Leq (l,r) -> binary_op LessEquals l r
     (* syntax *)
-    | Method (name,args,body) ->
+    | Lambda (args,body) ->
        let env' =
          add_register args env in
        let args' =
          List.map (const 0) args in
        let m = 
-         make_meth ~args:args' name @@ generate_expr body env' in
+         make_meth ~args:args' "" @@ generate_expr body env' in
          [NewFunction m]
     | Block xs ->
        List.concat @@ interperse [Pop] @@ (List.map expr xs)
index bf942d4..08becf0 100644 (file)
@@ -1,5 +1,5 @@
 type ast = 
-    Method of string * string list * ast
+    Lambda of string list * ast
   | Call of string * ast list
   | String of string
   | Int of int
index 3822f87..a015ce8 100644 (file)
@@ -40,7 +40,7 @@ let rec make_ast =
          | Symbol "lambda"::List args::body ->
              let body' =
                List.map make_ast body in
-             Ast.Method ("",List.map (fun (Symbol x)->x) args,Ast.Block body')
+             Ast.Lambda (List.map (fun (Symbol x)->x) args,Ast.Block body')
          | ((Symbol name)::args) ->
              Ast.Call (name,List.map make_ast args)
          | _ ->
index 7707969..af5a6b1 100644 (file)
@@ -69,11 +69,11 @@ test let_ =
 test call =
   assert_equal 
     (result [NewFunction (result [PushInt 42]) ])
-    (compile (Method ("",[],Block [Int 42])))
+    (compile (Lambda ([],Block [Int 42])))
 
 test call_with_args =
   assert_equal 
     (result [NewFunction (result ~args:[0;0] [GetLocal 2])])
-    (compile (Method ("",["x";"y"],Block [Var "y"])))
+    (compile (Lambda (["x";"y"],Block [Var "y"])))
 
 
index 4269ed4..f948a67 100644 (file)
@@ -46,9 +46,9 @@ test begin_ =
       compile_string "(begin 1 2)"
       
 test lammda =
-    assert_equal [Method ("",[],Block [Int 42])] @@
+    assert_equal [Lambda ([],Block [Int 42])] @@
       compile_string "(lambda () 42)"
 
 test lammda_with_args =
-    assert_equal [Method ("",["a";"b";"c"],Block [Int 42])] @@
+    assert_equal [Lambda (["a";"b";"c"],Block [Int 42])] @@
       compile_string "(lambda (a b c) 42)"