summaryrefslogtreecommitdiffstats
path: root/parser.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2018-04-04 20:01:02 -0700
committerKaz Kylheku <kaz@kylheku.com>2018-04-04 20:01:02 -0700
commit274cb70971d6a2cebcd887350b4b8602b32743d7 (patch)
tree07344e7330788fa23d35ad34b0a6bf48dcd97661 /parser.c
parent5484325557ee4201fd04772049145ad95ff7dbc4 (diff)
downloadtxr-274cb70971d6a2cebcd887350b4b8602b32743d7.tar.gz
txr-274cb70971d6a2cebcd887350b4b8602b32743d7.tar.bz2
txr-274cb70971d6a2cebcd887350b4b8602b32743d7.zip
Implement compiled file loading.
* eval.c (load): If open_txr_file indicates compiled file by setting txr_lisp_p to character #\o, use read_compiled_file. * match.c (v_load): Likewise. * parser.c (open_txr_file): Recognize the .tlo suffix, and also try to open a .tlo version of an unsuffixed file before trying it as .tl. Indicate a .tlo file by setting txr_lisp_p to the character #\o rather than t. (read_file_common): New static function, made from contents of read_eval_stream. Will either evaluate forms or load compiled code by instantiating virtual machine descriptions and performing their top-level execution. (read_eval_stream): Now a wrapper for read_file_common. (read_compiled_file): New function. * parser.h (read_compiled_file): Declared. * txr.c (help): List new --compiled option. (txr_main): If --compiled is specified, set txr_lisp_p to #\o to load as compiled code. Update error message that -c is not compatible with --lisp or --compiled. If txr_lisp_p is #\o, then use read_compiled_file.
Diffstat (limited to 'parser.c')
-rw-r--r--parser.c48
1 files changed, 41 insertions, 7 deletions
diff --git a/parser.c b/parser.c
index 0d0151d5..a5109a18 100644
--- a/parser.c
+++ b/parser.c
@@ -55,6 +55,7 @@
#include "cadr.h"
#include "struct.h"
#include "parser.h"
+#include "vm.h"
#include "txr.h"
#if HAVE_TERMIOS
#include "linenoise/linenoise.h"
@@ -411,12 +412,14 @@ val parser_circ_ref(parser_t *p, val num)
void open_txr_file(val spec_file, val *txr_lisp_p, val *name, val *stream)
{
- enum { none, tl, txr } suffix;
+ enum { none, tl, tlo, txr } suffix;
if (match_str(spec_file, lit(".txr"), negone))
suffix = txr;
else if (match_str(spec_file, lit(".tl"), negone))
suffix = tl;
+ else if (match_str(spec_file, lit(".tlo"), negone))
+ suffix = tlo;
else
suffix = none;
@@ -431,6 +434,9 @@ void open_txr_file(val spec_file, val *txr_lisp_p, val *name, val *stream)
case tl:
*txr_lisp_p = t;
break;
+ case tlo:
+ *txr_lisp_p = chr('o');
+ break;
case txr:
*txr_lisp_p = nil;
break;
@@ -456,10 +462,17 @@ void open_txr_file(val spec_file, val *txr_lisp_p, val *name, val *stream)
}
- if (suffix == none && in == 0) {
- spec_file_try = scat(lit("."), spec_file, lit("tl"), nao);
- in = w_fopen(c_str(spec_file_try), L"r");
- *txr_lisp_p = t;
+ if (suffix == none) {
+ if (in == 0) {
+ spec_file_try = scat(lit("."), spec_file, lit("tlo"), nao);
+ in = w_fopen(c_str(spec_file_try), L"r");
+ *txr_lisp_p = chr('o');
+ }
+ if (in == 0) {
+ spec_file_try = scat(lit("."), spec_file, lit("tl"), nao);
+ in = w_fopen(c_str(spec_file_try), L"r");
+ *txr_lisp_p = t;
+ }
}
if (in == 0) {
@@ -592,7 +605,7 @@ val iread(val source_in, val error_stream, val error_return_val,
name_in, lineno);
}
-val read_eval_stream(val stream, val error_stream)
+static val read_file_common(val stream, val error_stream, val compiled)
{
val error_val = gensym(nil);
val name = stream_get_prop(stream, name_k);
@@ -609,7 +622,18 @@ val read_eval_stream(val stream, val error_stream)
continue;
}
- (void) eval_intrinsic(form, nil);
+ if (compiled) {
+ val nlevels = pop(&form);
+ val nregs = pop(&form);
+ val bytecode = pop(&form);
+ val dv_raw = pop(&form);
+ val datavec = if3(consp(dv_raw), vec_list(cadr(dv_raw)), dv_raw);
+ val funvec = car(form);
+ val desc = vm_make_desc(nlevels, nregs, bytecode, datavec, funvec);
+ (void) vm_execute_toplevel(desc);
+ } else {
+ (void) eval_intrinsic(form, nil);
+ }
if (parser_eof(parser))
break;
@@ -618,6 +642,16 @@ val read_eval_stream(val stream, val error_stream)
return t;
}
+val read_eval_stream(val stream, val error_stream)
+{
+ return read_file_common(stream, error_stream, nil);
+}
+
+val read_compiled_file(val stream, val error_stream)
+{
+ return read_file_common(stream, error_stream, t);
+}
+
#if HAVE_TERMIOS
static void load_rcfile(val name)