DEADSOFTWARE

Добавлены модули
[dsw-obn.git] / test.c
diff --git a/test.c b/test.c
index b934af876ca2bde9d44397015f95c7ce70953bd5..297da8de9a9c9d21c05fe7db43989753f35613cb 100644 (file)
--- a/test.c
+++ b/test.c
@@ -1,31 +1,71 @@
 #include "oberon.h"
 #include "generator.h"
+
+#include <string.h>
 #include <assert.h>
 
-static const char source[] =
+static char source_test[] =
        "MODULE Test;"
+       "IMPORT I := Imported;"
        "TYPE"
-       "       MyRec = POINTER TO MyRecDesc;"
-       "       MyRecDesc = RECORD"
-       "               a : INTEGER;"
-       "       END;"
+       "       Callback = PROCEDURE() : INTEGER;"
+       ""
        "VAR"
-       "       r : MyRec;"
+       "       cb : Callback;"
+       "       i : INTEGER;"
+       "       r : I.Rider;"
+       ""
+       "PROCEDURE RelBack;"
+       "BEGIN"
+       "       i := 666;"
+       "END RelBack;"
+       ""
        "BEGIN;"
-       "       r := NIL;"
-       "       r.a := 1;"
+       "       i := ABS(-1);"
+       "       i := cb();"
+       "       RelBack;"
+       "       I.Ln;"
        "END Test."
 ;
 
+static char source_imported[] =
+       "MODULE Imported;"
+       "TYPE"
+       "       Rider = RECORD i : INTEGER; END;"
+       ""
+       "PROCEDURE Ln;"
+       "END Ln;"
+       ""
+       "BEGIN;"
+       "END Imported."
+;
+
 static oberon_context_t * ctx;
 static oberon_module_t * mod;
 
+static const char *
+import_module(const char * name)
+{
+       if(strcmp(name, "Test") == 0)
+       {
+               return source_test;
+       }
+       else if(strcmp(name, "Imported") == 0)
+       {
+               return source_imported;
+       }
+       else
+       {
+               return NULL;
+       }
+}
+
 int
 main(int argc, char ** argv)
 {
-       ctx = oberon_create_context();
-       mod = oberon_compile_module(ctx, source);
-       //mod -> begin();
+       ctx = oberon_create_context(import_module);
+       mod = oberon_compile_module(ctx, source_test);
+       oberon_generate_code(ctx);
        oberon_generator_dump(ctx, "dump.txt");
        oberon_destroy_context(ctx);
        return 0;