|
@@ -7,15 +7,26 @@
|
|
|
generalize the AST format. This makes context analysis easier, since
|
|
generalize the AST format. This makes context analysis easier, since
|
|
|
initialisations need not be considered. The assignments are placed in the
|
|
initialisations need not be considered. The assignments are placed in the
|
|
|
function body, after local fuction declarations (which are not in the
|
|
function body, after local fuction declarations (which are not in the
|
|
|
- example):
|
|
|
|
|
-
|
|
|
|
|
-{v int foo = 0;
|
|
|
|
|
-int bar = foo; v}
|
|
|
|
|
|
|
+ example below). Initialisations fo global variables are moved to a new
|
|
|
|
|
+ function called "__init", which is a reserved function that is called by the
|
|
|
|
|
+ VM before the main function is called.
|
|
|
|
|
+
|
|
|
|
|
+{v int glob = 1;
|
|
|
|
|
+export int main() \{
|
|
|
|
|
+ int foo = 0;
|
|
|
|
|
+ int bar = foo;
|
|
|
|
|
+\} v}
|
|
|
becomes:
|
|
becomes:
|
|
|
-{v int foo;
|
|
|
|
|
-int bar;
|
|
|
|
|
-foo = 0;
|
|
|
|
|
-bar = foo; v}
|
|
|
|
|
|
|
+{v export void __init() \{
|
|
|
|
|
+ glob = 1;
|
|
|
|
|
+\}
|
|
|
|
|
+int glob;
|
|
|
|
|
+export int main() \{
|
|
|
|
|
+ int foo;
|
|
|
|
|
+ int bar;
|
|
|
|
|
+ foo = 0;
|
|
|
|
|
+ bar = foo;
|
|
|
|
|
+\} v}
|
|
|
|
|
|
|
|
{3 Array initialisations}
|
|
{3 Array initialisations}
|
|
|
|
|
|