index 2247eac4b7f42e6c463a01918e822d2adf45915e..297da8de9a9c9d21c05fe7db43989753f35613cb 100644 (file)
--- a/test.c
+++ b/test.c
#include "oberon.h"
-#include <assert.h>
+#include "generator.h"
-static oberon_type_t integer = { "INTEGER", OBERON_TYPE_INTEGER, sizeof(int) };
-static oberon_type_t boolean = { "BOOLEAN", OBERON_TYPE_BOOLEAN, sizeof(int) };
+#include <string.h>
+#include <assert.h>
-static const char source[] =
+static char source_test[] =
"MODULE Test;"
+ "IMPORT I := Imported;"
+ "TYPE"
+ " Callback = PROCEDURE() : INTEGER;"
+ ""
"VAR"
+ " cb : Callback;"
" i : INTEGER;"
- " b : BOOLEAN;"
+ " r : I.Rider;"
+ ""
+ "PROCEDURE RelBack;"
"BEGIN"
- " i := 10;"
+ " i := 666;"
+ "END RelBack;"
+ ""
+ "BEGIN;"
+ " 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();
- oberon_register_global_type(ctx, &integer);
- oberon_register_global_type(ctx, &boolean);
- mod = oberon_compile_module(ctx, source);
+ 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;
}