X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=test.c;h=c3a4b1467f51256bbec89e210374cb69d90a44d8;hb=d1b4e7fdab92589146e19cf4b8b402edf4d6b33d;hp=b934af876ca2bde9d44397015f95c7ce70953bd5;hpb=338eeae16495bbdcbd8c4f3dad4996346e26139b;p=dsw-obn.git diff --git a/test.c b/test.c index b934af8..c3a4b14 100644 --- a/test.c +++ b/test.c @@ -1,32 +1,104 @@ #include "oberon.h" #include "generator.h" + +#include #include -static const char source[] = +static char source_test[] = + "(* Main module *)" "MODULE Test;" - "TYPE" - " MyRec = POINTER TO MyRecDesc;" - " MyRecDesc = RECORD" - " a : INTEGER;" - " END;" - "VAR" - " r : MyRec;" + "IMPORT Out;" "BEGIN;" - " r := NIL;" - " r.a := 1;" + " Out.Open;" + " Out.Int(666, 0);" + " Out.Ln;" "END Test." ; +static char source_out[] = + "MODULE Out;" + "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;" + "END Out." +; + 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, "Out") == 0) + { + return source_out; + } + else + { + return NULL; + } +} + +typedef void (*TOutOpen)(); +static TOutOpen * OutOpenPtr; +void ImplOutOpen() +{ +} + +typedef void (*TOutInt)(int, int); +static TOutInt * OutIntPtr; +void ImplOutInt(int i, int n) +{ + printf("%i", i); +} + +typedef void (*TOutLn)(); +static TOutLn * OutLnPtr; +void ImplOutLn() +{ + printf("\n"); +} + +void init_system_modules() +{ + OutOpenPtr = oberon_generator_get_var(ctx, "Out_Open"); + *OutOpenPtr = ImplOutOpen; + OutIntPtr = oberon_generator_get_var(ctx, "Out_Int"); + *OutIntPtr = ImplOutInt; + OutLnPtr = oberon_generator_get_var(ctx, "Out_Ln"); + *OutLnPtr = ImplOutLn; +} + +void start_module() +{ + void (*begin)() = oberon_generator_get_procedure(ctx, "Test_BEGIN"); + begin(); +} + 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); + + init_system_modules(); + oberon_generator_dump(ctx, "dump.txt"); + + start_module(); + oberon_destroy_context(ctx); return 0; }