diff --git a/Makefile b/Makefile index 97ada6b6..8353fad8 100644 --- a/Makefile +++ b/Makefile @@ -32,6 +32,7 @@ BINDIR=$(PREFIX)/bin # TODO - when api is finalized, only export public symbols instead of using rdynamic # which exports all symbols. Saves a few KB in binary. +#CFLAGS=-std=c99 -Wall -Wextra -Isrc/include -fpic -g CFLAGS=-std=c99 -Wall -Wextra -Isrc/include -fpic -O2 -fvisibility=hidden CLIBS=-lm -ldl PREFIX=/usr/local @@ -117,10 +118,12 @@ valgrind: $(DST_TARGET) test: $(DST_TARGET) ./$(DST_TARGET) test/suite0.dst ./$(DST_TARGET) test/suite1.dst + ./$(DST_TARGET) test/suite2.dst valtest: $(DST_TARGET) valgrind --leak-check=full -v ./$(DST_TARGET) test/suite0.dst valgrind --leak-check=full -v ./$(DST_TARGET) test/suite1.dst + valgrind --leak-check=full -v ./$(DST_TARGET) test/suite2.dst ################### ##### Natives ##### diff --git a/src/core/core.dst b/src/core/core.dst index 3dbef6a5..d9c7f08c 100644 --- a/src/core/core.dst +++ b/src/core/core.dst @@ -362,7 +362,7 @@ accum) (defmacro coro - "A wrapper for making fibers. Same as (fiber (fn [] ...body))." + "A wrapper for making fibers. Same as (fiber.new (fn @[] ...body))." [& body] (tuple fiber.new (apply tuple 'fn @[] body))) @@ -1266,7 +1266,7 @@ get a chunk of source code. Should return nil for end of file." @[getchunk onvalue onerr] (def newenv (make-env)) - (default getchunk (fn [buf] + (default getchunk (fn @[buf] (file.read stdin :line buf))) (default onvalue (fn [x] (put newenv '_ @{:value x}) diff --git a/src/core/marsh.c b/src/core/marsh.c index de0d89c6..353f9c8f 100644 --- a/src/core/marsh.c +++ b/src/core/marsh.c @@ -454,6 +454,7 @@ static const uint8_t *unmarshal_one_env( const uint8_t *end = st->end; if (data >= end) longjmp(st->err, UMR_EOS); if (*data == LB_FUNCENV_REF) { + data++; int32_t index = readint(st, &data); if (index < 0 || index >= dst_v_count(st->lookup_envs)) longjmp(st->err, UMR_INVALID_REFERENCE); @@ -479,6 +480,8 @@ static const uint8_t *unmarshal_one_env( data = unmarshal_one(st, data, env->as.values + i, flags); } } + /* Set out */ + *out = env; } return data; } @@ -492,6 +495,7 @@ static const uint8_t *unmarshal_one_def( const uint8_t *end = st->end; if (data >= end) longjmp(st->err, UMR_EOS); if (*data == LB_FUNCDEF_REF) { + data++; int32_t index = readint(st, &data); if (index < 0 || index >= dst_v_count(st->lookup_defs)) longjmp(st->err, UMR_INVALID_REFERENCE); @@ -552,6 +556,7 @@ static const uint8_t *unmarshal_one_def( ((uint32_t)(data[1]) << 8) | ((uint32_t)(data[2]) << 16) | ((uint32_t)(data[3]) << 24); + data += 4; } /* Unmarshal environments */ @@ -596,6 +601,9 @@ static const uint8_t *unmarshal_one_def( /* Validate */ if (dst_verify(def)) longjmp(st->err, UMR_INVALID_BYTECODE); + + /* Set def */ + *out = def; } return data; } @@ -696,7 +704,7 @@ static const uint8_t *unmarshal_one( *out = dst_wrap_function(func); dst_array_push(&st->lookup, *out); for (int32_t i = 0; i < def->environments_length; i++) { - data = unmarshal_one_env(st, data, func->envs + i, flags + 1); + data = unmarshal_one_env(st, data, &(func->envs[i]), flags + 1); } return data; }