summaryrefslogtreecommitdiffstats
path: root/parser.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2018-04-05 06:23:21 -0700
committerKaz Kylheku <kaz@kylheku.com>2018-04-05 06:23:21 -0700
commit4561d4e6be6ffa6ef7b282b9a72ce966625382c3 (patch)
tree8c830b7100447c7d73351c2863d789ea00126aa4 /parser.c
parent999d8e65b03023d1af7b9d5654c4f0477673d112 (diff)
downloadtxr-4561d4e6be6ffa6ef7b282b9a72ce966625382c3.tar.gz
txr-4561d4e6be6ffa6ef7b282b9a72ce966625382c3.tar.bz2
txr-4561d4e6be6ffa6ef7b282b9a72ce966625382c3.zip
compile-file/load: add version to files.
* parser.c (read_file_common): Treat first form in file as a version number of the form (major minor), where major nad minor are non-negative integers. If the major number is greater than zero, reject the file as incompatible. * share/txr/stdlib/compiler.tl (usr:compile-file): Emit version number (0 0) as the first item in a compiled file.
Diffstat (limited to 'parser.c')
-rw-r--r--parser.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/parser.c b/parser.c
index 081b8137..f39293ee 100644
--- a/parser.c
+++ b/parser.c
@@ -610,6 +610,7 @@ 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);
+ val first = t;
for (;;) {
val form = lisp_parse(stream, error_stream, error_val, name, colon_k);
@@ -623,7 +624,14 @@ static val read_file_common(val stream, val error_stream, val compiled)
continue;
}
- if (compiled) {
+ if (compiled && first) {
+ val major = pop(&form);
+ if (gt(major, zero))
+ uw_throwf(error_s,
+ lit("cannot load ~s; it was compiled by a newer implementation"),
+ stream, nao);
+ first = nil;
+ } else if (compiled) {
val nlevels = pop(&form);
val nregs = pop(&form);
val bytecode = pop(&form);