~tim/malcc

e58cf4099679e8e522edb28747fc507d1542a3bd — Tim Morgan 5 years ago e65ada2 fix-compile-mal
Fix bug compiling mal inside malcc

Also add tests!

    make mal-in-mal
    make test-mal-in-mal
3 files changed, 26 insertions(+), 5 deletions(-)

M .gitignore
M Makefile
M malcc.c
M .gitignore => .gitignore +2 -0
@@ 10,5 10,7 @@ step8_macros
step9_try
stepA_mal
malcc
mal-in-mal
mal-in-mal.c
*.o
history.txt

M Makefile => Makefile +15 -1
@@ 29,7 29,10 @@ clean:
	rm -f $(ALL_STEPS) *.o
	cd tinycc && make clean

test: test0 test1 test2 test3 test4 test5 test6 test7 test8 test9 testA test-malcc test-self-hosted test-supplemental
mal-in-mal: all
	cd mal/mal && ../../malcc --compile stepA_mal.mal ../../mal-in-mal

test: test0 test1 test2 test3 test4 test5 test6 test7 test8 test9 testA test-malcc test-self-hosted test-supplemental test-mal-in-mal

RUN_TEST_CMD=mal/runtest.py --rundir mal/tests --hard --deferrable --optional --start-timeout 1 --test-timeout 1



@@ 100,6 103,17 @@ test-self-hosted: all
test-supplemental: all
	$(RUN_TEST_CMD) --test-timeout 30 ../../tests/utf-8.mal ../../malcc

test-mal-in-mal: mal-in-mal
	$(RUN_TEST_CMD) --test-timeout 30 step2_eval.mal ../../mal-in-mal
	$(RUN_TEST_CMD) --test-timeout 30 step3_env.mal ../../mal-in-mal
	$(RUN_TEST_CMD) --test-timeout 30 step4_if_fn_do.mal ../../mal-in-mal
	$(RUN_TEST_CMD) --test-timeout 30 step5_tco.mal ../../mal-in-mal
	$(RUN_TEST_CMD) --test-timeout 30 step6_file.mal ../../mal-in-mal
	$(RUN_TEST_CMD) --test-timeout 30 step7_quote.mal ../../mal-in-mal
	$(RUN_TEST_CMD) --test-timeout 30 step8_macros.mal ../../mal-in-mal
	$(RUN_TEST_CMD) --test-timeout 30 step9_try.mal ../../mal-in-mal
	$(RUN_TEST_CMD) --test-timeout 30 stepA_mal.mal ../../mal-in-mal

perf: all
	cd mal/tests && ../../malcc perf1.mal && ../../malcc perf2.mal && ../../malcc perf3.mal


M malcc.c => malcc.c +9 -4
@@ 240,6 240,9 @@ int gen_code(MalType *node, MalEnv *env, struct codegen *code, int ret, int *var
      return 1;
    case MAL_VECTOR_TYPE:
      return gen_vector_code(node, env, code, ret, var_num);
    case MAL_ERROR_TYPE:
      printf("unhandled error during code gen: %s\n", pr_str(node->error_val, 1));
      return 0;
    default:
      printf("unknown node type in code gen type=%d\n", node->type);
      return 0;


@@ 967,6 970,8 @@ void aot_compile(MalType *arg_vec) {
    exit(1);
  }
  MalEnv *env = build_top_env();
  add_core_ns_to_env(env);
  rep(builtin_defs, env);
  MalType *filename = mal_vector_ref(arg_vec, 1);
  MalType *out_filename = mal_vector_ref(arg_vec, 2);
  MalType *contents = read_file(filename->str);


@@ 983,10 988,10 @@ void aot_compile(MalType *arg_vec) {
    fprintf(f, "%s\n", out->str);
    fclose(f);
    char *cmd = mal_sprintf(
      "gcc -g -I tinycc -o %S %S.c reader.c printer.c hashmap.c types.c util.c env.c core.c " \
      "tinycc/libtcc.a -ledit -lgc -lpcre -ldl",
      out_filename,
      out_filename
      "gcc -g -I %s/tinycc -I %s -o %S %S.c %s/reader.c %s/printer.c %s/hashmap.c %s/types.c %s/util.c %s/env.c %s/core.c " \
      "%s/tinycc/libtcc.a -ledit -lgc -lpcre -ldl",
      PATH, PATH, out_filename, out_filename, PATH, PATH, PATH, PATH, PATH, PATH, PATH,
      PATH
    )->str;
    fprintf(stderr, "%s\n", cmd);
    int result = system(cmd);