|
@@ -46,9 +46,11 @@ let assemble program =
|
|
|
[Export (name, ret_type, param_types, label)]
|
|
[Export (name, ret_type, param_types, label)]
|
|
|
else []
|
|
else []
|
|
|
end @
|
|
end @
|
|
|
- [Comment (sprintf "fun \"%s\" with %d local vars" label (indexof node));
|
|
|
|
|
|
|
+ [Comment (sprintf "function \"%s\" with %d parameters and %d local vars"
|
|
|
|
|
+ label (List.length params) (indexof node));
|
|
|
Label label;
|
|
Label label;
|
|
|
RtnEnter (indexof node)] @
|
|
RtnEnter (indexof node)] @
|
|
|
|
|
+ (trav_all params) @
|
|
|
(trav body) @
|
|
(trav body) @
|
|
|
(match ret_type with Void -> [Ret Void] | _ -> []) @
|
|
(match ret_type with Void -> [Ret Void] | _ -> []) @
|
|
|
[EmptyLine] @
|
|
[EmptyLine] @
|
|
@@ -57,6 +59,9 @@ let assemble program =
|
|
|
| VarDec (_, name, _, _) ->
|
|
| VarDec (_, name, _, _) ->
|
|
|
[comline (sprintf "local var \"%s\" at index %d" name (indexof node))]
|
|
[comline (sprintf "local var \"%s\" at index %d" name (indexof node))]
|
|
|
|
|
|
|
|
|
|
+ | Param (_, name, _) ->
|
|
|
|
|
+ [comline (sprintf "parameter \"%s\" at index %d" name (indexof node))]
|
|
|
|
|
+
|
|
|
| LocalFuns _ -> []
|
|
| LocalFuns _ -> []
|
|
|
|
|
|
|
|
| Block body | VarDecs body -> trav_all body
|
|
| Block body | VarDecs body -> trav_all body
|
|
@@ -122,8 +127,8 @@ let assemble program =
|
|
|
* stack, if any *)
|
|
* stack, if any *)
|
|
|
| Expr value ->
|
|
| Expr value ->
|
|
|
let pop = match typeof value with
|
|
let pop = match typeof value with
|
|
|
- | Void -> [comline (node2str node)]
|
|
|
|
|
- | ctype -> [InlineComment (Pop ctype, node2str node)]
|
|
|
|
|
|
|
+ | Void -> []
|
|
|
|
|
+ | ctype -> [InlineComment (Pop ctype, "disregard return value")]
|
|
|
in
|
|
in
|
|
|
trav value @ pop
|
|
trav value @ pop
|
|
|
|
|
|
|
@@ -183,7 +188,9 @@ let assemble program =
|
|
|
| FunDef _ -> RtnJmp (LocalFun (List.length args, labelof dec))
|
|
| FunDef _ -> RtnJmp (LocalFun (List.length args, labelof dec))
|
|
|
| _ -> raise InvalidNode
|
|
| _ -> raise InvalidNode
|
|
|
in
|
|
in
|
|
|
- init :: (trav_all args) @ [jmp]
|
|
|
|
|
|
|
+ InlineComment (init, nameof dec) ::
|
|
|
|
|
+ (trav_all args) @
|
|
|
|
|
+ [InlineComment (jmp, node2str node)]
|
|
|
|
|
|
|
|
| Arg value -> trav value
|
|
| Arg value -> trav value
|
|
|
|
|
|