5 #include "../include/oberon.h"
7 static char source_test
[] =
11 " Packed = ARRAY 16, 32 OF RECORD a : INTEGER; r : RECORD x : INTEGER; END; END;"
12 " IArray = ARRAY 16, 32, 666 OF INTEGER;"
14 " k : POINTER TO Packed;"
15 " ii : POINTER TO IArray;"
19 " k[5, 2].r.x := 456;"
24 static char source_out
[] =
26 // "(* Interface to outer program ;) *)"
28 // " Open- : PROCEDURE;"
29 // " Char- : PROCEDURE(ch : CHAR);"
30 // " String- : PROCEDURE(str : ARRAY OF CHAR)"
31 // " Int- : PROCEDURE(i, n : LONGINT);"
32 // " Int- : PROCEDURE(i, n : INTEGER);"
33 // " Real- : PROCEDURE(x : REAL; n : INTEGER);"
34 // " LongReal- : PROCEDURE(x : LONGREAL; n : INTEGER);"
35 // " Ln- : PROCEDURE;"
39 static oberon_context_t
* ctx
;
40 static oberon_module_t
* mod
;
43 import_module(const char * name
)
45 if(strcmp(name
, "Test") == 0)
49 else if(strcmp(name
, "Out") == 0)
59 typedef void (*TOutOpen
)();
60 static TOutOpen
* OutOpenPtr
;
65 typedef void (*TOutInt
)(int, int);
66 static TOutInt
* OutIntPtr
;
67 void ImplOutInt(int i
, int n
)
70 snprintf(number
, 22, "%d", i
);
71 int len
= strlen(number
);
72 for(int i
= 0; i
< n
- len
; i
++)
79 typedef void (*TOutReal
)(float, int);
80 static TOutReal
* OutRealPtr
;
81 void ImplOutReal(float i
, int n
)
84 snprintf(number
, 32, "%F", i
);
85 int len
= strlen(number
);
86 for(int i
= 0; i
< n
- len
; i
++)
93 typedef void (*TOutLn
)();
94 static TOutLn
* OutLnPtr
;
100 void init_system_modules()
102 OutOpenPtr
= oberon_generator_get_var(ctx
, "Out_Open");
103 *OutOpenPtr
= ImplOutOpen
;
104 OutIntPtr
= oberon_generator_get_var(ctx
, "Out_Int");
105 *OutIntPtr
= ImplOutInt
;
106 OutRealPtr
= oberon_generator_get_var(ctx
, "Out_Real");
107 *OutRealPtr
= ImplOutReal
;
108 OutLnPtr
= oberon_generator_get_var(ctx
, "Out_Ln");
109 *OutLnPtr
= ImplOutLn
;
114 void (*begin
)() = oberon_generator_get_procedure(ctx
, "Test_BEGIN");
119 main(int argc
, char ** argv
)
121 ctx
= oberon_create_context(import_module
);
122 mod
= oberon_compile_module(ctx
, source_test
);
124 oberon_generate_code(ctx
);
126 // init_system_modules();
128 // oberon_generator_dump(ctx, "dump.txt");
132 oberon_destroy_context(ctx
);