diff --git a/Makefile b/Makefile index 77dad1b..7a5e23e 100644 --- a/Makefile +++ b/Makefile @@ -1,34 +1,34 @@ -default: tokenize.c closures.c tokenize.h RTS.h - $(CC) -DNDEBUG -Wall -Wextra -pedantic -Wpointer-arith -Wmissing-prototypes -Werror -std=c99 -O3 ./tokenize.c -lmaa; - $(CC) -DNDEBUG -Wall -Wextra -pedantic -Wpointer-arith -Wmissing-prototypes -Werror -std=c99 -O3 ./closures.c; +default: tokenize.c RTS.c tokenize.h RTS.h + $(CC) -DNDEBUG -Wall -Wextra -pedantic -Wpointer-arith -Wmissing-prototypes -Werror -std=c99 -O3 ./tokenize.c -lmaa -o tokenize_test; + $(CC) -DNDEBUG -Wall -Wextra -pedantic -Wpointer-arith -Wmissing-prototypes -Werror -std=c99 -O3 ./RTS.c -o rts_test; -unsafe: tokenize.c closures.c tokenize.h RTS.h +unsafe: tokenize.c RTS.c tokenize.h RTS.h $(CC) -DNDEBUG -std=c99 -O3 ./tokenize.c -lmaa; - $(CC) -DNDEBUG -std=c99 -O3 ./closures.c; + $(CC) -DNDEBUG -std=c99 -O3 ./RTS.c; -unsafelib: tokenize.c closures.c tokenize.h RTS.h +unsafelib: tokenize.c RTS.c tokenize.h RTS.h $(CC) -DLIB -DNDEBUG -c -fpic -std=c99 -O3 ./tokenize.c; $(CC) -shared -o tokenize.so tokenize.o -lmaa; - $(CC) -DLIB -DNDEBUG -c -fpic -std=c99 -O3 ./closures.c; - $(CC) -shared -o closures.so closures.o; + $(CC) -DLIB -DNDEBUG -c -fpic -std=c99 -O3 ./RTS.c; + $(CC) -shared -o RTS.so RTS.o; -lib: tokenize.c closures.c tokenize.h RTS.h +lib: tokenize.c RTS.c tokenize.h RTS.h $(CC) -DLIB -DNDEBUG -c -fpic -Wall -Wextra -pedantic -Wpointer-arith -Werror -std=c99 -O3 ./tokenize.c $(CC) -shared -o tokenize.so tokenize.o -lmaa; - $(CC) -DLIB -DNDEBUG -c -fpic -Wall -Wextra -pedantic -Wpointer-arith -Werror -std=c99 -O3 ./closures.c; - $(CC) -shared -o closures.so closures.o; + $(CC) -DLIB -DNDEBUG -c -fpic -Wall -Wextra -pedantic -Wpointer-arith -Werror -std=c99 -O3 ./RTS.c; + $(CC) -shared -o RTS.so RTS.o; -debug: tokenize.c closures.c tokenize.h RTS.h - $(CC) -Wall -Wextra -pedantic -Wpointer-arith -Wmissing-prototypes -Werror -std=c99 ./tokenize.c -lmaa; - $(CC) -Wall -Wextra -pedantic -Wpointer-arith -Wmissing-prototypes -Werror -std=c99 ./closures.c; +debug: tokenize.c RTS.c tokenize.h RTS.h + $(CC) -Wall -Wextra -pedantic -Wpointer-arith -Wmissing-prototypes -Werror -std=c99 ./tokenize.c -lmaa -o tokenize_debug; + $(CC) -Wall -Wextra -pedantic -Wpointer-arith -Wmissing-prototypes -Werror -std=c99 ./RTS.c; -debuglib: tokenize.c closures.c tokenize.h RTS.h +debuglib: tokenize.c RTS.c tokenize.h RTS.h $(CC) -g -c -fpic -Wall -Wextra -pedantic -Wpointer-arith -Wmissing-prototypes -Werror -std=c99 ./tokenize.c; $(CC) -shared -o tokenize.so tokenize.o -lmaa; - $(CC) -g -c -fpic -Wall -Wextra -pedantic -Wpointer-arith -Wmissing-prototypes -Werror -std=c99 ./closures.c; - $(CC) -shared -o closures.so closures.o; + $(CC) -g -c -fpic -Wall -Wextra -pedantic -Wpointer-arith -Wmissing-prototypes -Werror -std=c99 ./RTS.c; + $(CC) -shared -o RTS.so RTS.o; diff --git a/RTS.c b/RTS.c index e4328f7..356da7a 100644 --- a/RTS.c +++ b/RTS.c @@ -145,6 +145,21 @@ invoke(svalue_t *closure, svalue_t **arguments) { return closure->value.closure->func(arguments, closure->value.closure->fvars); } +/* Special case where there is only on argument + * this might end up only being used for testing + * since the code generator will construct singleton + * arrays most likely, anyway + */ +inline svalue_t* +invoke1(svalue_t *closure, svalue_t *arg) { + svalue_t **args = malloc(sizeof (svalue_t *)); + CHECK(args); + args[0] = arg; + svalue_t* result = invoke(closure, args); + free(args); + return result; +} + /* * The process for closure conversion basically involves finding all of the free variables * This will give the number of variables the environment must hold in total @@ -189,9 +204,9 @@ main(void) { /* Get the final closure */ svalue_t *closure1 = make_closure(make_doubleadder, env); /* Invoke the closure that the closure returns */ - svalue_t *c1 = invoke(closure1, &box_int(23)); - svalue_t *c2 = invoke(c1, &box_int(5)); - svalue_t *result = invoke(c2, &box_int(334)); + svalue_t *c1 = invoke1(closure1, box_int(23)); + svalue_t *c2 = invoke1(c1, box_int(5)); + svalue_t *result = invoke1(c2, box_int(334)); /* The final result */ printf("print 23 + 5 + 334 == %d\n", result->value.integer); svalue_t *a = box_int(123); diff --git a/RTS.h b/RTS.h index 6d7e2df..3121e5e 100644 --- a/RTS.h +++ b/RTS.h @@ -69,6 +69,10 @@ make_closure(svalue_t *(*func)(svalue_t**, svalue_t**), svalue_t * invoke(svalue_t*, svalue_t**); +svalue_t * +invoke1(svalue_t*, svalue_t*); + + svalue_t * box_int(int x); diff --git a/RTS.o b/RTS.o new file mode 100644 index 0000000..abb0337 Binary files /dev/null and b/RTS.o differ diff --git a/RTS.so b/RTS.so new file mode 100755 index 0000000..eb58ec6 Binary files /dev/null and b/RTS.so differ diff --git a/rts_test b/rts_test new file mode 100755 index 0000000..192a1c6 Binary files /dev/null and b/rts_test differ diff --git a/tokenize.o b/tokenize.o new file mode 100644 index 0000000..df298b8 Binary files /dev/null and b/tokenize.o differ diff --git a/tokenize.so b/tokenize.so new file mode 100755 index 0000000..5fdcd6c Binary files /dev/null and b/tokenize.so differ diff --git a/tokenize_debug b/tokenize_debug new file mode 100755 index 0000000..2841c63 Binary files /dev/null and b/tokenize_debug differ diff --git a/tokenize_test b/tokenize_test new file mode 100755 index 0000000..d82cac4 Binary files /dev/null and b/tokenize_test differ