diff --git a/TODO b/TODO index b384016c..62f2b02c 100644 --- a/TODO +++ b/TODO @@ -1,7 +1,5 @@ Working TODO list: - - Add an (exit) primitive in the compiler and interpreter - - Issues with detecting cycles: - (equal?) loops forever when comparing two different circular lists - printing *global-environment* in the repl still loops forever diff --git a/cgen.scm b/cgen.scm index f1c31104..8f4db262 100644 --- a/cgen.scm +++ b/cgen.scm @@ -433,6 +433,7 @@ ((eq? p '<=) "__num_lte") ((eq? p 'apply) "apply") ((eq? p '%halt) "__halt") + ((eq? p 'exit) "__halt") ((eq? p 'error) "Cyc_error") ((eq? p 'current-input-port) "Cyc_io_current_input_port") ((eq? p 'open-input-file) "Cyc_io_open_input_file") diff --git a/eval.scm b/eval.scm index 2e92833c..919c14ab 100644 --- a/eval.scm +++ b/eval.scm @@ -199,6 +199,7 @@ (list '<= <=) (list 'apply apply) (list '%halt %halt) + (list 'exit exit) (list 'error error) (list 'cons cons) (list 'cell-get cell-get) diff --git a/runtime.h b/runtime.h index d8a527eb..a8272bd8 100644 --- a/runtime.h +++ b/runtime.h @@ -1171,6 +1171,10 @@ static void _Cyc_91get_91cvar(object cont, object args) { printf("not implemented\n"); exit(1); } static void _Cyc_91set_91cvar_67(object cont, object args) { printf("not implemented\n"); exit(1); } +/* Note we cannot use _exit (per convention) because it is reserved by C */ +static void _cyc_exit(object cont, object args) { + __halt(car(args)); +} static void __75halt(object cont, object args) { printf("not implemented\n"); exit(1); } static void _cell_91get(object cont, object args) { @@ -1263,6 +1267,7 @@ defprimitive(_125_123, >=, &__125_123); /* >= */ defprimitive(_121_123, <=, &__121_123); /* <= */ defprimitive(apply, apply, &_apply); /* apply */ defprimitive(_75halt, %halt, &__75halt); /* %halt */ +defprimitive(exit, exit, &_cyc_exit); /* exit */ defprimitive(error, error, &_error); /* error */ defprimitive(cons, cons, &_cons); /* cons */ defprimitive(cell_91get, cell-get, &_cell_91get); /* cell-get */ diff --git a/trans.scm b/trans.scm index 524a145a..ae794446 100644 --- a/trans.scm +++ b/trans.scm @@ -517,6 +517,7 @@ apply %halt error + exit cons cell-get set-global!