OSDN Git Service

Add: if-expression
authorMIZUNO Hiroki <mzpppp@gmail.com>
Sun, 18 May 2008 00:27:28 +0000 (09:27 +0900)
committerMIZUNO Hiroki <mzpppp@gmail.com>
Sun, 18 May 2008 00:27:28 +0000 (09:27 +0900)
- fix: label create position

example/bool.scm
src/asm.ml
util/instruction.ml
util/instruction.txt

index 7e84a79..a599637 100644 (file)
@@ -1 +1,4 @@
-(if 1 2 3)
\ No newline at end of file
+(if (< 1 42)
+    (print "big")
+    (print "small"))
+
index 4b2513d..97aeaf9 100644 (file)
@@ -36,9 +36,12 @@ let method_asm cmap index m =
     List.fold_left
       (fun 
         (stack,scope,count,bytes) 
-        {op=op;args=args;stack=st;scope=sc;count=c} -> 
+        {op=op;prefix=prefix;args=args;stack=st;scope=sc;count=c} -> 
           let by =
-            (Bytes.u8 op)::args cmap in
+            List.concat [
+              prefix cmap;
+              [Bytes.u8 op];
+              args cmap] in
             add stack st,add scope sc,count+c,by::bytes)
       (init,init,1,[]) configs in
   let info =
index 0552158..926e474 100644 (file)
@@ -57,6 +57,7 @@ let output_match decls =
     Printf.printf "type config = {
   op:int;
   args: Cpool.cmap -> Bytes.t list;
+  prefix: Cpool.cmap -> Bytes.t list;
   const:  Cpool.clist;
   stack: int;
   scope: int;
@@ -67,6 +68,7 @@ let const x _ = x
 let default = {
   op=0;
   args=const [];
+  prefix=const [];
   const= Cpool.empty;
   stack=0;
   scope=0;
index a668855..1f65d30 100644 (file)
@@ -13,7 +13,7 @@ GreaterThan: op=0xaf; stack= ~-1
 GreaterEquals: op=0xb0; stack= ~-1
 
 # if
-Label of Label.t: op=0x09; args=const [label arg0]
+Label of Label.t: op=0x09; prefix=const [label arg0]
 IfNlt of Label.t: op=0x0c; stack= ~-1; args=const [label_ref arg0]
 IfNle of Label.t: op=0x0d; stack= ~-1; args=const [label_ref arg0]
 IfNgt of Label.t: op=0x0e; stack= ~-1; args=const [label_ref arg0]