|
|
@@ -30,20 +30,28 @@ let assemble program =
|
|
|
| Program (decls, _) ->
|
|
|
trav_all decls
|
|
|
|
|
|
- | GlobalDef (_, ctype, name, _, _) ->
|
|
|
+ | GlobalDef (false, ctype, name, _, _) ->
|
|
|
[Comment (sprintf "global var \"%s\" at index %d" name (indexof node));
|
|
|
Global ctype]
|
|
|
|
|
|
+ | GlobalDef (true, ctype, name, _, _) ->
|
|
|
+ [Comment (sprintf "exported var \"%s\" at index %d" name (indexof node));
|
|
|
+ Global ctype;
|
|
|
+ ExportVar (name, indexof node)]
|
|
|
+
|
|
|
+ | GlobalDec (ctype, name, _) ->
|
|
|
+ [Comment (sprintf "imported var \"%s\" at index %d" name (indexof node));
|
|
|
+ ImportVar (name, ctype)]
|
|
|
+
|
|
|
| FunDec (ret_type, name, params, _) ->
|
|
|
- [Comment (sprintf "extern fun \"%s\" at index %d" name (indexof node));
|
|
|
- Import (name, ret_type, List.map typeof params)]
|
|
|
+ [Comment (sprintf "imported fun \"%s\" at index %d" name (indexof node));
|
|
|
+ ImportFun (name, ret_type, List.map typeof params)]
|
|
|
|
|
|
| FunDef (export, ret_type, name, params, body, _) ->
|
|
|
let label = labelof node in
|
|
|
begin
|
|
|
- if export then
|
|
|
- let param_types = List.map typeof params in
|
|
|
- [Export (name, ret_type, param_types, label)]
|
|
|
+ if export
|
|
|
+ then [ExportFun (name, ret_type, List.map typeof params, label)]
|
|
|
else []
|
|
|
end @
|
|
|
[Comment (sprintf "function \"%s\" with %d parameters and %d local vars"
|
|
|
@@ -146,6 +154,10 @@ let assemble program =
|
|
|
let load = LoadConst (typeof node, indexof node) in
|
|
|
[InlineComment (load, node2str node)]
|
|
|
|
|
|
+ | VarUse (GlobalDec (ctype, _, _) as dec, None, _) ->
|
|
|
+ let load = Load (ctype, Extern, indexof dec) in
|
|
|
+ [InlineComment (load, node2str node)]
|
|
|
+
|
|
|
| VarUse (dec, None, _) ->
|
|
|
let load = match (depthof dec, depthof node) with
|
|
|
| (0, _) -> Load (typeof dec, Glob, indexof dec)
|