DEADSOFTWARE

JVM: Исправлено сравнение LongInt, Real и LongReal
[dsw-obn.git] / src / test.c
index 1c3c8e39347533eb9db1d0b2e289f0348f77b693..d2501611eee396c8c7f2e4036d115937e967eec3 100644 (file)
 
 #include "../include/oberon.h"
 
+/*
 static char source_test[] =
        "(* Main module *)"
        "MODULE Test;"
        "IMPORT Out;"
-       "TYPE Ar = ARRAY OF ARRAY OF INTEGER;"
-       "VAR a : POINTER TO Ar;"
        ""
-       "PROCEDURE Ax(VAR x : POINTER TO Ar);"
+       "TYPE"
+       "  R = LONGINT;"
+       ""
+       "PROCEDURE Factorial(n : R) : R;"
+       "BEGIN"
+       "  IF n <= 1 THEN"
+       "    RETURN 1;"
+       "  ELSE"
+       "    RETURN n * Factorial(n - 1);"
+       "  END;"
+       "  RETURN 0; (* Детектор ретурнов - дерьмо *)"
+       "END Factorial;"
+       ""
        "BEGIN"
-       "  x[0, 0] := 777;"
-       "END Ax;"
+       "  Out.Open();"
+       "  Out.Int(Factorial(0), 0); Out.Ln;"
+       "  Out.Int(Factorial(1), 0); Out.Ln;"
+       "  Out.Int(Factorial(2), 0); Out.Ln;"
+       "  Out.Int(Factorial(3), 0); Out.Ln;"
+       "  Out.Int(Factorial(4), 0); Out.Ln;"
+       "  Out.Int(Factorial(5), 0); Out.Ln;"
+       "  Out.Int(Factorial(6), 0); Out.Ln;"
+       "  Out.Int(Factorial(7), 0); Out.Ln;"
+       "  Out.Int(Factorial(8), 0); Out.Ln;"
+       "  Out.Int(Factorial(9), 0); Out.Ln;"
+       "  Out.Int(Factorial(10), 0); Out.Ln;"
+       "  Out.Int(Factorial(11), 0); Out.Ln;"
+       "  Out.Int(Factorial(12), 0); Out.Ln;"
+       "  Out.Int(Factorial(13), 0); Out.Ln;"
+       "  Out.Int(Factorial(14), 0); Out.Ln;"
+       "  Out.Int(Factorial(15), 0); Out.Ln;"
+       "  Out.Int(Factorial(16), 0); Out.Ln;"
+       "  Out.Int(Factorial(17), 0); Out.Ln;"
+       "  Out.Int(Factorial(18), 0); Out.Ln;"
+       "  Out.Int(Factorial(19), 0); Out.Ln;"
+       "  Out.Int(Factorial(20), 0); Out.Ln;"
+       "END Test."
+;
+*/
+
+static char source_test[] =
+       "(* Main module *)"
+       "MODULE Test;"
+       "IMPORT Out;"
        ""
-       "BEGIN;"
-       "  NEW(a, 2, 2);"
-       "  a[0, 0] := 666;"
-       "  Out.Open;"
-       "  Out.Int(a[0, 0], 0);"
-       "  Out.Ln;"
+       "TYPE"
+       "  R = LONGREAL;"
        ""
-       "  Ax(a);"
-//     "  Out.Int(a[0, 0], 0);"
-//     "  Out.Ln;"
+       "PROCEDURE Factorial(n : R) : R;"
+       "BEGIN"
+       "  IF n <= 1 THEN"
+       "    RETURN 1;"
+       "  ELSE"
+       "    RETURN n * Factorial(n - 1);"
+       "  END;"
+       "  RETURN 0; (* Детектор ретурнов - дерьмо *)"
+       "END Factorial;"
+       ""
+       "BEGIN"
+       "  Out.Open();"
+       "  Out.LongReal(Factorial(0), 0); Out.Ln;"
+       "  Out.LongReal(Factorial(1), 0); Out.Ln;"
+       "  Out.LongReal(Factorial(2), 0); Out.Ln;"
+       "  Out.LongReal(Factorial(3), 0); Out.Ln;"
+       "  Out.LongReal(Factorial(4), 0); Out.Ln;"
+       "  Out.LongReal(Factorial(5), 0); Out.Ln;"
+       "  Out.LongReal(Factorial(6), 0); Out.Ln;"
+       "  Out.LongReal(Factorial(7), 0); Out.Ln;"
+       "  Out.LongReal(Factorial(8), 0); Out.Ln;"
+       "  Out.LongReal(Factorial(9), 0); Out.Ln;"
+       "  Out.LongReal(Factorial(10), 0); Out.Ln;"
+       "  Out.LongReal(Factorial(11), 0); Out.Ln;"
+       "  Out.LongReal(Factorial(12), 0); Out.Ln;"
+       "  Out.LongReal(Factorial(13), 0); Out.Ln;"
+       "  Out.LongReal(Factorial(14), 0); Out.Ln;"
+       "  Out.LongReal(Factorial(15), 0); Out.Ln;"
+       "  Out.LongReal(Factorial(16), 0); Out.Ln;"
+       "  Out.LongReal(Factorial(17), 0); Out.Ln;"
+       "  Out.LongReal(Factorial(18), 0); Out.Ln;"
+       "  Out.LongReal(Factorial(19), 0); Out.Ln;"
+       "  Out.LongReal(Factorial(20), 0); Out.Ln;"
+       "  Out.LongReal(Factorial(170), 0); Out.Ln;"
        "END Test."
 ;
 
 static char source_out[] =
        "MODULE Out;"
-       "(* Interface to outer program ;) *)"
-       "VAR"
-       "  Open-     : PROCEDURE;"
-//     "  Char-     : PROCEDURE(ch : CHAR);"
-//     "  String-   : PROCEDURE(str : ARRAY OF CHAR)"
-//     "  Int-      : PROCEDURE(i, n : LONGINT);"
-       "  Int-      : PROCEDURE(i, n : INTEGER);"
-       "  Real-     : PROCEDURE(x : REAL; n : INTEGER);"
-//     "  LongReal- : PROCEDURE(x : LONGREAL; n : INTEGER);"
-       "  Ln-       : PROCEDURE;"
+       "  PROCEDURE Open*;"
+       "  END Open;"
+       ""
+       "  PROCEDURE Char* (ch : CHAR);"
+       "  END Char;"
+       ""
+       "  PROCEDURE String* (str : ARRAY OF CHAR);"
+       "  END String;"
+       ""
+       "  PROCEDURE Int*(i, n : LONGINT);"
+       "  END Int;"
+       ""
+       "  PROCEDURE Real*(x : REAL; n : INTEGER);"
+       "  END Real;"
+       ""
+       "  PROCEDURE LongReal*(x : LONGREAL; n : INTEGER);"
+       "  END LongReal;"
+       ""
+       "  PROCEDURE Ln*;"
+       "  END Ln;"
+       ""
        "END Out."
 ;
 
@@ -131,11 +208,11 @@ main(int argc, char ** argv)
 
        oberon_generate_code(ctx);
 
-       init_system_modules();
+//     init_system_modules();
 
-       oberon_generator_dump(ctx, "dump.txt");
+//     oberon_generator_dump(ctx, "dump.txt");
 
-       start_module();
+//     start_module();
 
        oberon_destroy_context(ctx);
        return 0;