From 6ed1b44439ae838ae4ed60f3c8b62792050d0411 Mon Sep 17 00:00:00 2001 From: Dmitry Boulytchev Date: Tue, 1 Sep 2020 20:31:34 +0300 Subject: [PATCH] Fixed bug with unbox tag in Bsexp --- runtime/runtime.c | 29 ++++++++++++++++++----------- src/X86.ml | 2 +- src/version.ml | 2 +- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/runtime/runtime.c b/runtime/runtime.c index f938356e3..9f5157205 100644 --- a/runtime/runtime.c +++ b/runtime/runtime.c @@ -169,8 +169,9 @@ typedef struct { data contents; } sexp; -extern void* alloc (size_t); -extern void* Bsexp (int n, ...); +extern void* alloc (size_t); +extern void* Bsexp (int n, ...); +extern int LtagHash (char*); void *global_sysargs; @@ -212,7 +213,7 @@ void* Ls__Infix_58 (void *p, void *q) { push_extra_root(&p); push_extra_root(&q); - res = Bsexp (BOX(3), p, q, 848787); + res = Bsexp (BOX(3), p, q, LtagHash ("cons")); //BOX(848787)); pop_extra_root(&q); pop_extra_root(&p); @@ -336,16 +337,18 @@ extern int Blength (void *p) { static char* chars = "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'"; +extern char* de_hash (int); + extern int LtagHash (char *s) { char *p; - int h = 0, limit = 0, pos = 0; - - ASSERT_STRING("tagHash: 1", s); + int h = 0, limit = 0; p = s; while (*p && limit++ < 4) { - char *q = chars; + char *q = chars; + int pos = 0; + for (; *q && *q != *p; q++, pos++); if (*q) h = (h << 6) | pos; @@ -354,6 +357,10 @@ extern int LtagHash (char *s) { p++; } + if (strcmp (s, de_hash (h)) != 0) { + failure ("%s <-> %s\n", s, de_hash(h)); + } + return BOX(h); } @@ -1041,7 +1048,7 @@ extern void* Barray (int bn, ...) { r->tag = ARRAY_TAG | (n << 3); - va_start(args, n); + va_start(args, bn); for (i = 0; itag = SEXP_TAG | ((n-1) << 3); - va_start(args, n); + va_start(args, bn); for (i=0; icontents)[i] = ai; } - r->tag = va_arg(args, int); + r->tag = UNBOX(va_arg(args, int)); #ifdef DEBUG_PRINT r->tag = SEXP_TAG | ((r->tag) << 3); diff --git a/src/X86.ml b/src/X86.ml index c77862fa5..4310b420a 100644 --- a/src/X86.ml +++ b/src/X86.ml @@ -452,7 +452,7 @@ let compile cmd env imports code = | SEXP (t, n) -> let s, env = env#allocate in let env, code = call env ".sexp" (n+1) false in - env, [Mov (L env#hash t, s)] @ code + env, [Mov (L (box (env#hash t)), s)] @ code | DROP -> snd env#pop, [] diff --git a/src/version.ml b/src/version.ml index d23afd346..dc311332b 100644 --- a/src/version.ml +++ b/src/version.ml @@ -1 +1 @@ -let version = "Version 1.00, 81be668d4, Tue Sep 1 06:20:39 2020 +0300" +let version = "Version 1.00, f16f695ed, Tue Sep 1 17:23:36 2020 +0300"