DEADSOFTWARE

JVM: Исправлено сравнение LongInt, Real и LongReal
[dsw-obn.git] / src / test.c
index d2950b968189c70a5f4b743c5131cd9682498959..d2501611eee396c8c7f2e4036d115937e967eec3 100644 (file)
@@ -4,53 +4,96 @@
 
 #include "../include/oberon.h"
 
+/*
 static char source_test[] =
        "(* Main module *)"
        "MODULE Test;"
        "IMPORT Out;"
-       "CONST"
-       "  null = 0X;"
-       "  space = 020X;"
-       "  bang = 021X;"
-       "  h = 048X;"
-       "  e = 045X;"
-       "  l = 04CX;"
-       "  o = 04FX;"
-       "  w = 057X;"
-       "  r = 052X;"
-       "  d = 044X;"
        ""
        "TYPE"
-       "  Ident = ARRAY 20 OF CHAR;"
-       "  PrintString = PROCEDURE (str : ARRAY OF CHAR);"
+       "  R = LONGINT;"
        ""
-       "VAR"
-       "  hello : Ident;"
-       "  print : PrintString;"
+       "PROCEDURE Factorial(n : R) : R;"
+       "BEGIN"
+       "  IF n <= 1 THEN"
+       "    RETURN 1;"
+       "  ELSE"
+       "    RETURN n * Factorial(n - 1);"
+       "  END;"
+       "  RETURN 0; (* Детектор ретурнов - дерьмо *)"
+       "END Factorial;"
        ""
        "BEGIN"
-       "  print := Out.String;"
-       "  hello[0] := h;"
-       "  hello[1] := e;"
-       "  hello[2] := l;"
-       "  hello[3] := l;"
-       "  hello[4] := o;"
-       "  hello[5] := space;"
-       "  hello[6] := w;"
-       "  hello[7] := o;"
-       "  hello[8] := r;"
-       "  hello[9] := l;"
-       "  hello[10] := d;"
-       "  hello[11] := bang;"
-       "  hello[12] := null;"
-       "  Out.Open;"
-       "  print(hello);"
-       "  Out.Ln;"
+       "  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."
 ;
+*/
 
-// PROCEDURE Char* (ch : CHAR);
-// PROCEDURE String* (str : ARRAY OF CHAR);
+static char source_test[] =
+       "(* Main module *)"
+       "MODULE Test;"
+       "IMPORT Out;"
+       ""
+       "TYPE"
+       "  R = LONGREAL;"
+       ""
+       "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;"