Taddeus Kroes 12 лет назад
Родитель
Сommit
c47c1c0ee2
1 измененных файлов с 36 добавлено и 28 удалено
  1. 36 28
      phases/desug.mli

+ 36 - 28
phases/desug.mli

@@ -12,7 +12,7 @@
     VM before the main function is called.
     VM before the main function is called.
 
 
 {v int glob = 1;
 {v int glob = 1;
-export int main() \{
+void foo() \{
   int foo = 0;
   int foo = 0;
   int bar = foo;
   int bar = foo;
 \} v}
 \} v}
@@ -21,7 +21,7 @@ export int main() \{
     glob = 1;
     glob = 1;
 \}
 \}
 int glob;
 int glob;
-export int main() \{
+void foo() \{
   int foo;
   int foo;
   int bar;
   int bar;
   foo = 0;
   foo = 0;
@@ -36,28 +36,32 @@ export int main() \{
     generated for each array index. For scalar values and aray constants that
     generated for each array index. For scalar values and aray constants that
     have a lower nesting level than the number of array dimensions, for-loops
     have a lower nesting level than the number of array dimensions, for-loops
     are generated. The following example shows all situation:
     are generated. The following example shows all situation:
-{v int[3] a = [1, 2, 3];
-int[3] b = 4;
-int[2, 2] c = [[3, 4], 5]; v}
+{v void foo() \{
+    int[3] a = [1, 2, 3];
+    int[3] b = 4;
+    int[2, 2] c = [[3, 4], 5];
+\} v}
 
 
     The snippet above is transformed to code equivalent to the following:
     The snippet above is transformed to code equivalent to the following:
 
 
-{v int[] a;
-int[] b;
-int[] c;
-a = __allocate(3);
-a[0] = 1;
-a[1] = 2;
-a[2] = 3;
-b = __allocate(3);
-for (int i = 0, 3) \{
-    b[i] = 4;
-\}
-c = __allocate(4);
-c[0] = 3;
-c[1] = 4;
-for (int i = 0, 2) \{
-    c[1, i] = 5;
+{v void foo() \{
+    int[] a;
+    int[] b;
+    int[] c;
+    a = __allocate(3);
+    a[0] = 1;
+    a[1] = 2;
+    a[2] = 3;
+    b = __allocate(3);
+    for (int i = 0, 3) \{
+        b[i] = 4;
+    \}
+    c = __allocate(4);
+    c[0] = 3;
+    c[1] = 4;
+    for (int i = 0, 2) \{
+        c[1, i] = 5;
+    \}
 \} v}
 \} v}
 
 
     {2 Prevent incorrect double evaluation}
     {2 Prevent incorrect double evaluation}
@@ -92,10 +96,13 @@ void foo() \{
     and constant propagation):
     and constant propagation):
 {v ...
 {v ...
 void foo() \{
 void foo() \{
-  int a$dim$$2 = two();
-  int const$$1 = two();
-  int const$$2 = two();
+  int a$dim$$2;
+  int const$$1;
+  int const$$2;
   int[2, a$dim$$2] a;
   int[2, a$dim$$2] a;
+  a$dim$$2 = two();
+  const$$1 = two();
+  const$$2 = two();
   a = __allocate(2 * a$dim$$2);
   a = __allocate(2 * a$dim$$2);
   a[0] = 1;
   a[0] = 1;
   a[1] = const$$1;
   a[1] = const$$1;
@@ -108,7 +115,7 @@ void foo() \{
 
 
     {2 Transforming for-loops to while-loops}
     {2 Transforming for-loops to while-loops}
 
 
-{v for(int i = <start>,<stop>,<step>) \{
+{v for (int i = <start>, <stop>, <step>) \{
     <body>
     <body>
 \} v}
 \} v}
 
 
@@ -117,16 +124,17 @@ void foo() \{
 {v i$1 = <start>;
 {v i$1 = <start>;
 step$2 = <step>;
 step$2 = <step>;
 stop$3 = <stop>;
 stop$3 = <stop>;
-while((step$2 > 0) ? (i$1 < stop$3) : (i$1 > stop$3)) \{
+while ((step$2 > 0) ? (i$1 < stop$3) : (i$1 > stop$3)) \{
     <body>
     <body>
     i$1 = i$1 + step$2;
     i$1 = i$1 + step$2;
 \} v}
 \} v}
 
 
-    Where [i$1], [step$2] and [stop$3] are fresh variables. Definitions of these
+    Here, [i$1], [step$2] and [stop$3] are fresh variables. Definitions of these
     new variables are added to the scope of the current function. Every
     new variables are added to the scope of the current function. Every
     occurrence of [i] in [<body>] is replaced with the fresh variable [i$1],
     occurrence of [i] in [<body>] is replaced with the fresh variable [i$1],
     this prevents problems with nested for-loops that use the same induction
     this prevents problems with nested for-loops that use the same induction
-    variable .*)
+    variable.
+    *)
 
 
 (** Main phase function, called by {!Main}. *)
 (** Main phase function, called by {!Main}. *)
 val phase : Main.phase_func
 val phase : Main.phase_func