diff options
| author | Camil Staps | 2016-07-03 14:42:27 +0200 | 
|---|---|---|
| committer | Camil Staps | 2016-07-03 14:42:27 +0200 | 
| commit | 6025a6637dae924ec87e10d94b0b49ea81592eea (patch) | |
| tree | 6e18a288cedd5adaa84ceb7737900440166202da | |
| parent | Moved to directory, added test program (diff) | |
Added ABC.Code
| -rw-r--r-- | ABC/Code.dcl | 4 | ||||
| -rw-r--r-- | ABC/Code.icl | 1 | ||||
| -rw-r--r-- | ABC/Code/RTS.dcl | 5 | ||||
| -rw-r--r-- | ABC/Code/RTS.icl | 60 | ||||
| -rw-r--r-- | ABC/GraphStore.icl | 2 | ||||
| -rw-r--r-- | ABC/IO.icl | 3 | ||||
| -rw-r--r-- | ABC/Nodes.icl | 4 | 
7 files changed, 74 insertions, 5 deletions
| diff --git a/ABC/Code.dcl b/ABC/Code.dcl new file mode 100644 index 0000000..faf4aa9 --- /dev/null +++ b/ABC/Code.dcl @@ -0,0 +1,4 @@ +definition module ABC.Code + +import +	ABC.Code.RTS diff --git a/ABC/Code.icl b/ABC/Code.icl new file mode 100644 index 0000000..618fd08 --- /dev/null +++ b/ABC/Code.icl @@ -0,0 +1 @@ +implementation module ABC.Code diff --git a/ABC/Code/RTS.dcl b/ABC/Code/RTS.dcl new file mode 100644 index 0000000..03e1759 --- /dev/null +++ b/ABC/Code/RTS.dcl @@ -0,0 +1,5 @@ +definition module ABC.Code.RTS + +from ABC.Assembler import ::Statement, ::Assembler + +rts :: Assembler diff --git a/ABC/Code/RTS.icl b/ABC/Code/RTS.icl new file mode 100644 index 0000000..f28f4d8 --- /dev/null +++ b/ABC/Code/RTS.icl @@ -0,0 +1,60 @@ +implementation module ABC.Code.RTS + +import ABC.Machine + +rts :: Assembler +rts +	= [       Descriptor      "INT"  "_rnf" 0 "integer" +	  ,       Descriptor      "BOOL" "_rnf" 0 "boolean" +	  ,       Jmp             "init_graph" +	  , Label "init_graph" +	  ,       Create +	  ,       Fill            "Start" 0 "n_Start" 0 +	  ,       Jsr             "_driver" +	  ,       Print           "\n" +	  ,       Halt +	  , Label "_driver" +	  ,       PushI           0 +	  , Label "_print" +	  ,       JsrEval +	  ,       GetNodeArity    0 +	  ,       EqI_b           0 0 +	  ,       JmpFalse        "_args" +	  , Label "_print_last"    +	  ,       PrintSymbol     0 +	  ,       Pop_a           1 +	  ,       Pop_b           1 +	  , Label "_brackets" +	  ,       EqI_b           0 0 +	  ,       JmpTrue         "_exit" +	  ,       Print           ")" +	  ,       DecI +	  ,       Jmp             "_brackets" +	  , Label "_exit" +	  ,       Rtn +	  , Label "_args" +	  ,       Print           "(" +	  ,       PrintSymbol     0 +	  ,       GetDescArity    0 +	  ,       ReplArgs_b +	  ,       Pop_b           1 +	  , Label "_arg_loop" +	  ,       Print           " " +	  ,       EqI_b           1 0 +	  ,       JmpFalse        "_next_arg" +	  ,       Pop_b           1 +	  ,       IncI +	  ,       Jmp             "_print" +	  , Label "_next_arg" +	  ,       Jsr             "_driver" +	  ,       DecI +	  ,       Jmp             "_arg_loop" +	  , Label "_rnf" +	  ,       Rtn +	  , Label "_cycle" +	  ,       Print           "cycle in spine\n" +	  ,       Halt +	  , Label "_type_error"    +	  ,       Print           "type error\n" +	  ,       Halt +	  ] diff --git a/ABC/GraphStore.icl b/ABC/GraphStore.icl index 0f32994..fd41517 100644 --- a/ABC/GraphStore.icl +++ b/ABC/GraphStore.icl @@ -36,7 +36,7 @@ where  	show_nds :: Int [Node] [Desc] -> String  	show_nds i [] ds = ""  	show_nds i [n:ns] ds -		= i <+ " : " <+ show_nd n ds <+ "\n" <+ show_nds (i+1) ns ds +		= "    " <+ i <+ " : " <+ show_nd n ds <+ "\n" <+ show_nds (i+1) ns ds  	show_nd :: Node [Desc] -> String  	show_nd (Basic _ e b) _  = e <+ " " <+ b @@ -22,8 +22,7 @@ show_node (Node _ _ _) (Desc _ _ n) = n  instance toString State  where  	toString {astack,bstack,cstack,graphstore,descstore,pc,program,io} -		= "output  : " <+ io <+ "\n" <+ -		  "pc      : " <+ pc <+ "\n" <+ +		= "pc      : " <+ pc <+ "\n" <+  		  "A-stack : " <+ astack <+ "\n" <+  		  "B-stack : " <+ bstack <+ "\n" <+  		  "C-stack : " <+ cstack <+ "\n" <+ diff --git a/ABC/Nodes.icl b/ABC/Nodes.icl index fa29cb4..55be090 100644 --- a/ABC/Nodes.icl +++ b/ABC/Nodes.icl @@ -11,9 +11,9 @@ n_arg n i a  | otherwise = abortn "n_arg: index greater than arity"  n_args      :: Node Arity -> [NodeId] -n_args (Node _ _ args) a +n_args (Node d e args) a  | a == length args = args -| otherwise        = abortn "n_args: incorrect arity" +| otherwise        = abortn ("n_args: incorrect arity " <+ a <+ " for node " <+ d <+ ":" <++ (",", args))  n_args _ _         = abortn "n_args: no arguments in node"  n_arity     :: Node -> Arity | 
