1
0
mirror of https://github.com/janet-lang/janet synced 2025-01-12 16:40:27 +00:00

added symbolslots to asm

This commit is contained in:
Jona Ekenberg 2023-02-01 21:12:42 +01:00
parent b685bf3026
commit c0c8ab25e6
3 changed files with 54 additions and 10 deletions

View File

@ -721,6 +721,46 @@ static JanetAssembleResult janet_asm1(JanetAssembler *parent, Janet source, int
} }
} }
/* Set symbolslots */
def->symbolslots = NULL;
def->symbolslots_length = 0;
x = janet_get1(s, janet_ckeywordv("symbolslots"));
if (janet_indexed_view(x, &arr, &count)) {
def->symbolslots_length = count;
def->symbolslots = janet_malloc(sizeof(JanetSymbolSlot) * (size_t) count);
if (NULL == def->symbolslots) {
JANET_OUT_OF_MEMORY;
}
for (i = 0; i < count; i++) {
const Janet *tup;
Janet entry = arr[i];
JanetSymbolSlot ss;
if (!janet_checktype(entry, JANET_TUPLE)) {
janet_asm_error(&a, "expected tuple");
}
tup = janet_unwrap_tuple(entry);
if (!janet_checkint(tup[0])) {
janet_asm_error(&a, "expected integer");
}
if (!janet_checkint(tup[1])) {
janet_asm_error(&a, "expected integer");
}
if (!janet_checkint(tup[2])) {
janet_asm_error(&a, "expected integer");
}
if (!janet_checktype(tup[3], JANET_STRING)) {
janet_asm_error(&a, "expected string");
}
ss.birth_pc = janet_unwrap_integer(tup[0]);
ss.death_pc = janet_unwrap_integer(tup[1]);
ss.slot_index = janet_unwrap_integer(tup[2]);
ss.symbol = janet_unwrap_string(tup[3]);
def->symbolslots[i] = ss;
}
}
/* Set environments */ /* Set environments */
def->environments = janet_realloc(def->environments, def->environments_length * sizeof(int32_t)); def->environments = janet_realloc(def->environments, def->environments_length * sizeof(int32_t));
x = janet_get1(s, janet_ckeywordv("environments")); x = janet_get1(s, janet_ckeywordv("environments"));

View File

@ -998,8 +998,8 @@ static void janetc_init(JanetCompiler *c, JanetTable *env, const uint8_t *where,
static void janetc_deinit(JanetCompiler *c) { static void janetc_deinit(JanetCompiler *c) {
janet_v_free(c->buffer); janet_v_free(c->buffer);
janet_v_free(c->mapbuffer); janet_v_free(c->mapbuffer);
c->env = NULL;
janet_v_free(c->local_symbols); janet_v_free(c->local_symbols);
c->env = NULL;
} }
/* Compile a form. */ /* Compile a form. */

View File

@ -12,15 +12,19 @@
"symbolslots when *debug* is true") "symbolslots when *debug* is true")
(setdyn *debug* false) (setdyn *debug* false)
# need to fix assembling functions (setdyn *debug* true)
(comment (defn a [arg]
(setdyn *debug* true) (def x 10)
(def f (asm (disasm (fn [x] (fn [y] (+ x y)))))) (do
(assert (deep= (in (disasm f) :symbolslots) (def y 20)
@[[0 2147483647 0 "a"] [1 2147483647 1 "x"]]) (def z 30)
"symbolslots survive disasm/asm") (+ x y z)))
(setdyn *debug* false) (def symbolslots (in (disasm a) :symbolslots))
) (def f (asm (disasm a)))
(assert (deep= (in (disasm f) :symbolslots)
symbolslots)
"symbolslots survive disasm/asm")
(setdyn *debug* false)
(setdyn *debug* true) (setdyn *debug* true)
(assert (deep= (in (disasm (defn a [arg] (assert (deep= (in (disasm (defn a [arg]