diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..ef002c5 --- /dev/null +++ b/Makefile @@ -0,0 +1,35 @@ +IMAGES=$(shell ls -1 */Dockerfile | sed -e s:/Dockerfile::) +COPY=sim2c_1.0-3_all.deb + +DATA=data +WORKDIR=/root +HUBU=rodalvas + +all: cplint + +.PHONY: prolog logtalk cplint clean sim2c + +prolog: + docker build $@ --tag $@:latest + docker tag $@:latest $(HUBU)/$@:latest + +sim2c: + cp $(COPY) $@/sim2c.deb + docker build $@ --tag $@:latest + docker tag $@:latest $(HUBU)/$@:latest + + +run-%:: + docker run -ti \ + -v $(PWD)/$(DATA):$(WORKDIR)/$(DATA) \ + $(subst run-,,$@):latest + +logtalk.deb:: + [ -e $(LGTDEB) ] || wget -q https://logtalk.org/files/$(LGTDEB) + ln -sf $(LGTDEB) logtalk.deb + +clean: + rm -f $(DATA)/* + docker container prune -f + docker image prune -f + docker image rm -f $(IMAGES) diff --git a/sim2c-1.0/defs.m4 b/sim2c-1.0/defs.m4 index e782ea0..6011e07 100644 --- a/sim2c-1.0/defs.m4 +++ b/sim2c-1.0/defs.m4 @@ -72,12 +72,12 @@ _define_(`store', `_np_ M[M[SP]] = M[SP+1]; SP += 2; // STORE') _define_(`skipz', `_np_ if (! M[SP++]) goto _pc_at_(2); // SKIPZ') _define_(`jump', `_np_ goto * ((void *) M[SP++]); // JUMP') -_define_(`call', `_np_ { void *C = (void *) M[SP]; M[SP]=(int)&&_pc_at_(1); goto *C; } // CALL') +_define_(`call', `_np_ { void *C = (void *) M[SP]; M[SP]=(long)&&_pc_at_(1); goto *C; } // CALL') _define_(`local', `_np_ M[SP] = M[SP] + FP; // LOCAL') _define_(`stack', `_np_ M[SP] = M[SP] + SP; // STACK') -_define_(`link', `_np_ { int N = M[SP]; M[SP]= FP; FP=SP+1; SP -= N; } // LINK') +_define_(`link', `_np_ { long N = M[SP]; M[SP]= FP; FP=SP+1; SP -= N; } // LINK') _define_(`unlink', `_np_ SP=FP; FP=M[SP-1]; // UNLINK') _define_(`dup_sr', `_np_ SR = M[SP]; // DUP_SR') @@ -90,27 +90,27 @@ _ifelse_(_regexp_($1,`^[-0-9]'), 0, `_dnl_ $1', `_dnl_ -- Numbers go untouched ------------ _ifdef_(`_DATA_'$1,_dnl_ _DATA_`'$1,_dnl_ -- (known) data labels ------------- -(int) &&$1`'_dnl_ -- code labels --------------------- +(long) &&$1`'_dnl_ -- code labels --------------------- )')') _define_(`label', `_dnl_ _ifelse_(_data_text_,__data__,_dnl_ -` int m_`'$1[0]; // data `label' for "$1"_dnl_ +` long m_`'$1[0]; // data `label' for "$1"_dnl_ _define_(`_DATA_'$1,`GV_'$1)_global_var_($1)',_dnl_ `$1:')') _define_(`_ac_',0) _define_(`_anon_', `_define_(`_ac_',_incr_(_ac_))_format_(`a_%04.4d',_ac_)') -_define_(`_word_',` int _anon_;_divert_(4)_dnl_ +_define_(`_word_',` long _anon_;_divert_(4)_dnl_ global.named._format_(`a_%04.4d',_ac_) = _initializer_($1); _divert_(1)') -_define_(`_def_word_', ` int m_$1;_dnl_ +_define_(`_def_word_', ` long m_$1;_dnl_ _divert_(4) global.named.m_$1 = _initializer_($2); _define_(`_DATA_'$1,`GV_'$1)_global_var_($1)') -_define_(`_def_space_', ` int m_$1[$2];_dnl_ +_define_(`_def_space_', ` long m_$1[$2];_dnl_ _divert_(4) for (i=0; i<$2; ++i) global.named.m_$1[i] = 0; _define_(`_DATA_'$1,`GV_'$1)_global_var_($1)') @@ -118,7 +118,7 @@ _define_(`_initializer_',`_dnl_ _ifelse_(_regexp_($1,`^[-0-9]'), 0, `$1', `GV_`'$1')') _define_(`_global_var_',`_divert_(3)_dnl_ -#define GV_$1 ((int *) &global.named.m_$1 - (int *) &global.named) +#define GV_$1 ((long *) &global.named.m_$1 - (long *) &global.named) _divert_(1)') _define_(`_data_', `_divert_(1)_define_(`_data_text_', __data__)') @@ -138,14 +138,14 @@ _define_(`_dumpdata_', ` #define MEM_SZ ((DATA_SZ) + (HEAP_SZ) + (STACK_SZ)) union { - int mem[0]; + long mem[0]; struct {_dnl_ _undivert_(1)_dnl_ } named; struct { - int z_data[DATA_SZ]; - int z_heap[HEAP_SZ]; - int z_stack[STACK_SZ]; + long z_data[DATA_SZ]; + long z_heap[HEAP_SZ]; + long z_stack[STACK_SZ]; } zone; } global; @@ -154,9 +154,9 @@ _undivert_(1)_dnl_ #define HEAP global.zone.z_heap #define STACK global.zone.z_stack -int SP = MEM_SZ; -int FP = 0; -int SR; +long SP = MEM_SZ; +long FP = 0; +long SR; void *PC; // (unused) // -- Names for global variables ---------------------------------------------- @@ -168,7 +168,7 @@ _define_(`_dumptext_', `_dnl_ int main (int argc, char *argv[]) { - int i; + long i; // -- Initialization ---------------------------------------------------------- _undivert_(4)_dnl_ @@ -178,7 +178,7 @@ _undivert_(4)_dnl_ _include_(LIBDIR/library.m4)_dnl_ // -- Start execution --------------------------------------------------------- - M[--SP] = (int) &&L_exit_program; // Save return address for main program + M[--SP] = (long) &&L_exit_program; // Save return address for main program goto program; // start kicking... L_exit_program: // Return here, and... exit (0); // quit. diff --git a/sim2c-1.0/library.m4 b/sim2c-1.0/library.m4 index 3250a3b..ba8d197 100644 --- a/sim2c-1.0/library.m4 +++ b/sim2c-1.0/library.m4 @@ -9,7 +9,7 @@ _divert_(0)_dnl_ goto lib_init; // skip library code! print_int: // print_int (int) -> () - printf ("%d\n", M[SP+1]); + printf ("%ld\n", M[SP+1]); goto * ((void *) M[SP++]); print_char: // print_char (int) -> () @@ -17,7 +17,7 @@ print_char: // print_char (int) -> () goto * ((void *) M[SP++]); read_int: // read_int () -> int - scanf ("%d", &M[SP+1]); + scanf ("%ld", &M[SP+1]); goto * ((void *) M[SP++]); read_char: // read_char () -> int @@ -30,9 +30,9 @@ halt: // halt () -> () dump_regs: // dump_regs () -> () { printf ("-- Register dump --\n"); - printf ("SP = 0x%x (%d)\n", (int) SP, (int) SP); - printf ("FP = 0x%x (%d)\n", (int) FP, (int) FP); - printf ("SR = 0x%x (%d)\n", (int) SR, (int) SR); + printf ("SP = 0x%lx (%ld)\n", (long) SP, (long) SP); + printf ("FP = 0x%lx (%ld)\n", (long) FP, (long) FP); + printf ("SR = 0x%lx (%ld)\n", (long) SR, (long) SR); printf ("PC = (unused)\n"); } goto * ((void *) M[SP++]); diff --git a/sim2c-1.0/test3.c b/sim2c-1.0/test3.c index 4a8e0a3..e9f54cd 100644 --- a/sim2c-1.0/test3.c +++ b/sim2c-1.0/test3.c @@ -1,4 +1,5 @@ #include +#include // == Global data ============================================================= @@ -13,15 +14,15 @@ #define MEM_SZ ((DATA_SZ) + (HEAP_SZ) + (STACK_SZ)) union { - int mem[0]; + long mem[0]; struct { - int m_x; - int m_xpto[20]; + long m_x; + long m_xpto[20]; } named; struct { - int z_data[DATA_SZ]; - int z_heap[HEAP_SZ]; - int z_stack[STACK_SZ]; + long z_data[DATA_SZ]; + long z_heap[HEAP_SZ]; + long z_stack[STACK_SZ]; } zone; } global; @@ -30,21 +31,21 @@ union { #define HEAP global.zone.z_heap #define STACK global.zone.z_stack -int SP = MEM_SZ; -int FP = 0; -int SR; +long SP = MEM_SZ; +long FP = 0; +long SR; void *PC; // (unused) // -- Names for global variables ---------------------------------------------- -#define GV_x ((int *) &global.named.m_x - (int *) &global.named) -#define GV_xpto ((int *) &global.named.m_xpto - (int *) &global.named) +#define GV_x ((long *) &global.named.m_x - (long *) &global.named) +#define GV_xpto ((long *) &global.named.m_xpto - (long *) &global.named) // == Program ================================================================= int main (int argc, char *argv[]) { - int i; + long i; // -- Initialization ---------------------------------------------------------- global.named.m_x = 123; @@ -55,7 +56,7 @@ int main (int argc, char *argv[]) goto lib_init; // skip library code! print_int: // print_int (int) -> () - printf ("%d\n", M[SP+1]); + printf ("%ld\n", M[SP+1]); goto * ((void *) M[SP++]); print_char: // print_char (int) -> () @@ -63,7 +64,7 @@ print_char: // print_char (int) -> () goto * ((void *) M[SP++]); read_int: // read_int () -> int - scanf ("%d", &M[SP+1]); + scanf ("%ld", &M[SP+1]); goto * ((void *) M[SP++]); read_char: // read_char () -> int @@ -76,9 +77,9 @@ halt: // halt () -> () dump_regs: // dump_regs () -> () { printf ("-- Register dump --\n"); - printf ("SP = 0x%x (%d)\n", (int) SP, (int) SP); - printf ("FP = 0x%x (%d)\n", (int) FP, (int) FP); - printf ("SR = 0x%x (%d)\n", (int) SR, (int) SR); + printf ("SP = 0x%lx (%ld)\n", (long) SP, (long) SP); + printf ("FP = 0x%lx (%ld)\n", (long) FP, (long) FP); + printf ("SR = 0x%lx (%ld)\n", (long) SR, (long) SR); printf ("PC = (unused)\n"); } goto * ((void *) M[SP++]); @@ -108,7 +109,7 @@ lib_init: } // -- Start execution --------------------------------------------------------- - M[--SP] = (int) &&L_exit_program; // Save return address for main program + M[--SP] = (long) &&L_exit_program; // Save return address for main program goto program; // start kicking... L_exit_program: // Return here, and... exit (0); // quit. @@ -117,10 +118,10 @@ L_exit_program: // Return here, and... // -- Instructions ------------------------------------------------------------ program: M[--SP] = 0; // PUSH 0 - { int N = M[SP]; M[SP]= FP; FP=SP+1; SP -= N; } // LINK + { long N = M[SP]; M[SP]= FP; FP=SP+1; SP -= N; } // LINK M[--SP] = 12; // PUSH 12 - M[--SP] = (int) &&print_int; // PUSH print_int - { void *C = (void *) M[SP]; M[SP]=(int)&&P_6; goto *C; } // CALL + M[--SP] = (long) &&print_int; // PUSH print_int + { void *C = (void *) M[SP]; M[SP]=(long)&&P_6; goto *C; } // CALL P_6: SP=FP; FP=M[SP-1]; // UNLINK goto * ((void *) M[SP++]); // JUMP -- libgit2 0.21.2