OSDN Git Service

change invoke style
authormzp <mzpppp@gmail.com>
Wed, 29 Oct 2008 08:36:23 +0000 (17:36 +0900)
committermzp <mzpppp@gmail.com>
Wed, 29 Oct 2008 08:36:23 +0000 (17:36 +0900)
OMakefile
example/class.scm
src/ast.mli
src/lexer.ml
src/lisp.ml
test/OMakefile
test/test_codegen.ml
test/test_lexer.ml
test/test_lisp.ml
test/test_sexp.ml

index 29c5e7e..ce4b920 100644 (file)
--- a/OMakefile
+++ b/OMakefile
@@ -2,6 +2,6 @@
 .SUBDIRS: test src util camlp4
 
 clean:
-       rm *~ *.omc
+       rm -f *~ *.omc
 
 .DEFAULT: src/aosh
index 4ee2f26..cff377c 100644 (file)
@@ -1,12 +1,14 @@
 ;; Example for class definition
 ;;; 12
 ;;; [object Foo]
+;;; 10
 
 (define-class Foo Object
-  ((init x) (let ((t 10)) 
+  ([init x] (let ((t 10)) 
              (let ((t 12))
                (print t))))
-  ((f    x) (print x)))
+  ([f    x] (print x)))
 
 (define foo (new Foo 42))
-(print foo)
\ No newline at end of file
+(print foo)
+(. foo (f 10))
\ No newline at end of file
index 557d140..8e9be3e 100644 (file)
@@ -17,7 +17,7 @@ type expr =
   | LetRec of (string*expr) list * expr
   | Block  of expr list
   | New    of name * expr list
-  | Invoke of expr   * string * expr list (* (invoke <object> <method-name> <arg1> <arg2>...)*)
+  | Invoke of expr   * string * expr list (* Invoke (<object>,<method-name>, [<arg1>; <arg2>; ...]) *)
 
 (** A type of statement. Statement has side-effect *)
 type stmt = 
index 6cdced5..4efa1aa 100644 (file)
@@ -107,7 +107,7 @@ let scheme = {
   string  = parse_string '"';
   number  = parse_number;
   keyword = parse_keyword ["(";")";"[";"]";"'"];
-  ident   = parse_ident "!$%&*/:<=>?^_~+-*" "+-.@" <|> (fun s-> Genlex.Ident (Char.escaped @@ one_of "/" s));
+  ident   = parse_ident "!$%&*/:<=>?^_~+-*." "+-.@" <|> (fun s-> Genlex.Ident (Char.escaped @@ one_of "/" s));
   comment = parse_comment ";";
   bool    = scheme_bool
 }
index af1c98f..2c2fd78 100644 (file)
@@ -49,7 +49,7 @@ let rec make_expr =
              Ast.Lambda (List.map ensure_symbol args,Ast.Block body')
          | Symbol "new"::Symbol name::args ->
              Ast.New (split_ns name,List.map make_expr args)
-         | Symbol "invoke"::obj::Symbol name::args ->
+         | [Symbol "."; obj; List (Symbol name::args)] ->
              Ast.Invoke ((make_expr obj),name,(List.map make_expr args))
          | _ ->
              Ast.Call (List.map make_expr xs)
index aeb6923..0260196 100644 (file)
@@ -37,7 +37,8 @@ BYTE_ENABLED = true
 #
 # Various options
 #
-OCAMLCFLAGS    += -thread aosh.cma
+OCAMLOPTFLAGS    += -thread
+OCAMLCFLAGS    += -thread
 OCAMLPPFLAGS += -pp "camlp4o ../camlp4/TestCaseCollector.cmo"
 OCAMLDEPFLAGS += $(OCAMLPPFLAGS)
 
@@ -66,7 +67,7 @@ OCAML_LIBS += ../src/aosh
 
 OCAML_OTHER_LIBS += threads
 
-OCamlProgram($(PROGRAM), runner $(FILES))
+OCamlProgram($(PROGRAM), $(FILES) runner)
 
 .DEFAULT: check
 
index df17d37..16d6459 100644 (file)
@@ -183,7 +183,7 @@ test new_ =
 test invoke =
   assert_equal
     (expr [GetLex (make_qname "x");PushByte 10;CallProperty (make_qname "foo",1)])
-    (generate_method @@ Lisp.compile_string "(invoke x foo 10)")
+    (generate_method @@ Lisp.compile_string "(. x (foo 10))")
 
 
 let new_class klass = 
index 6c784e1..7ce74c1 100644 (file)
@@ -12,6 +12,9 @@ test symbol =
   assert_equal (Ident "+.") @@ Stream.next (lex "+.");
   assert_equal (Ident "foo.bar") @@ Stream.next (lex "foo.bar")
 
+test dot =
+  assert_equal (Ident ".") @@ Stream.next (lex ".")
+
 test bool =
   assert_equal (Kwd "true")  @@ Stream.next (lex "#t");
   assert_equal (Kwd "false") @@ Stream.next (lex "#f")
index cbf826a..560dd1e 100644 (file)
@@ -99,7 +99,7 @@ test new_klass_args =
 
 test invoke =
   assert_equal (result (Invoke (Var "foo","baz",[Int 1;Int 2]))) @@
-    compile_string "(invoke foo baz 1 2)"
+    compile_string "(. foo (baz 1 2))"
 
 test define =
   assert_equal [Define ("x",Block [Int 42])] @@
index d85bc71..0b90c47 100644 (file)
@@ -32,7 +32,8 @@ test string =
 
 test symbol =
     assert_equal [(String "foo")]  "\"foo\"";
-    assert_equal [(String "+")]    "\"+\""
+    assert_equal [(String "+")]    "\"+\"";
+    assert_equal [(Symbol ".")]    "."
 
 test add =
     assert_equal [List [Symbol "+";Int 1; Int 2]] "(+ 1 2)"