immediate-hash, '#&box constants serialized

This commit is contained in:
ESL 2023-04-20 11:03:14 -04:00
parent 7cc993e16b
commit e95b05135b
4 changed files with 1410 additions and 1352 deletions

21
i.c
View file

@ -3426,6 +3426,15 @@ define_instruction(igco) {
gonexti(); gonexti();
} }
define_instruction(hshim) {
unsigned long long v = (unsigned long long)ac, base = 0; obj b = spop();
if (v && isaptr(v)) failtype(v, "immediate value");
if (b) { ckk(b); base = get_fixnum(b); }
if (!base) base = 1 + (unsigned long long)FIXNUM_MAX;
ac = fixnum_obj((fixnum_t)(v % base));
gonexti();
}
define_instruction(rdsx) { define_instruction(rdsx) {
cks(ac); cks(ac);
unload_ac(); /* ac->ra (string) */ unload_ac(); /* ac->ra (string) */
@ -3448,6 +3457,7 @@ define_instruction(rdsc) {
gonexti(); gonexti();
} }
define_instruction(litf) { ac = bool_obj(0); gonexti(); } define_instruction(litf) { ac = bool_obj(0); gonexti(); }
define_instruction(litt) { ac = bool_obj(1); gonexti(); } define_instruction(litt) { ac = bool_obj(1); gonexti(); }
define_instruction(litn) { ac = null_obj(); gonexti(); } define_instruction(litn) { ac = null_obj(); gonexti(); }
@ -4097,7 +4107,16 @@ static obj *rds_sexp(obj *r, obj *sp, obj *hp)
} }
ra = hpushu8v(sp-r, newbytevector((unsigned char *)cbdata(pcb), (int)cblen(pcb))); ra = hpushu8v(sp-r, newbytevector((unsigned char *)cbdata(pcb), (int)cblen(pcb)));
freecb(pcb); freecb(pcb);
} } break;
case 'z': {
spush(port);
ra = sref(0); hp = rds_elt(r, sp, hp);
if (iseof(ra)) { sdrop(1); return hp; } else spush(ra);
hreserve(boxbsz(), sp-r);
*--hp = sref(0);
ra = hend_box();
sdrop(2);
} break;
} }
return hp; return hp;
} }

3
i.h
View file

@ -523,7 +523,7 @@ declare_instruction(panic, "Z7", 0, "%panic",
declare_instruction(abort, "Z8\0t", 0, "%abort", 'u', AUTOGL) declare_instruction(abort, "Z8\0t", 0, "%abort", 'u', AUTOGL)
declare_instruction(exit, "Z9\0t", 0, "%exit", 'u', AUTOGL) declare_instruction(exit, "Z9\0t", 0, "%exit", 'u', AUTOGL)
/* serialization and deserialization instructions */ /* serialization, deserialization, compilation-related instructions */
declare_instruction(igp, "U0", 0, "integrable?", '1', AUTOGL) declare_instruction(igp, "U0", 0, "integrable?", '1', AUTOGL)
declare_instruction(itrs, "U1", 0, "initial-transformers", '0', AUTOGL) declare_instruction(itrs, "U1", 0, "initial-transformers", '0', AUTOGL)
declare_instruction(rdsx, "U3", 0, "deserialize-sexp", '1', AUTOGL) declare_instruction(rdsx, "U3", 0, "deserialize-sexp", '1', AUTOGL)
@ -532,6 +532,7 @@ declare_instruction(iglk, "U5", 0, "lookup-integrable",
declare_instruction(igty, "U6", 0, "integrable-type", '1', AUTOGL) declare_instruction(igty, "U6", 0, "integrable-type", '1', AUTOGL)
declare_instruction(iggl, "U7", 0, "integrable-global", '1', AUTOGL) declare_instruction(iggl, "U7", 0, "integrable-global", '1', AUTOGL)
declare_instruction(igco, "U8", 0, "integrable-code", '2', AUTOGL) declare_instruction(igco, "U8", 0, "integrable-code", '2', AUTOGL)
declare_instruction(hshim, "H2\0f", 0, "immediate-hash", 'b', AUTOGL)
/* inlined integrables (no custom instructions) */ /* inlined integrables (no custom instructions) */
declare_integrable(NULL, "N0", 0, "complex?", '1', AUTOGL) declare_integrable(NULL, "N0", 0, "complex?", '1', AUTOGL)

2735
k.c

File diff suppressed because it is too large Load diff

View file

@ -793,6 +793,9 @@
(write-serialized-size (string-length x) port) (write-serialized-size (string-length x) port)
(do ([i 0 (fx+ i 1)]) [(fx=? i (string-length x))] (do ([i 0 (fx+ i 1)]) [(fx=? i (string-length x))]
(write-serialized-char (string-ref x i) port)))] (write-serialized-char (string-ref x i) port)))]
[(box? x)
(write-char #\z port)
(write-serialized-element (unbox x) port)]
[else (c-error "cannot encode literal" x)])) [else (c-error "cannot encode literal" x)]))
(define (write-serialized-arg arg port) (define (write-serialized-arg arg port)