diff --git a/README.md b/README.md index ed1302d8..3ffc0f1b 100644 --- a/README.md +++ b/README.md @@ -122,6 +122,13 @@ gmake repl 3. Run `build_win` to compile janet. 4. Run `build_win test` to make sure everything is working. +To build an `.msi` installer executable, in addition to the above steps, you will have to: + +5. Install, or otherwise add to your PATH the [WiX 3.11 Toolset](https://github.com/wixtoolset/wix3/releases) +6. run `build_win dist` + +Now you should have an `.msi`. You can run `build_win install` to install the `.msi`, or execute the file itself. + ### Meson Janet also has a build file for [Meson](https://mesonbuild.com/), a cross platform build diff --git a/examples/numarray/numarray.c b/examples/numarray/numarray.c index ac411fad..0c3153a4 100644 --- a/examples/numarray/numarray.c +++ b/examples/numarray/numarray.c @@ -23,7 +23,7 @@ static int num_array_gc(void *p, size_t s) { return 0; } -Janet num_array_get(void *p, Janet key); +int num_array_get(void *p, Janet key, Janet *out); void num_array_put(void *p, Janet key, Janet value); static const JanetAbstractType num_array_type = { @@ -31,7 +31,8 @@ static const JanetAbstractType num_array_type = { num_array_gc, NULL, num_array_get, - num_array_put + num_array_put, + JANET_ATEND_PUT }; static Janet num_array_new(int32_t argc, Janet *argv) { @@ -81,21 +82,20 @@ static const JanetMethod methods[] = { {NULL, NULL} }; -Janet num_array_get(void *p, Janet key) { +int num_array_get(void *p, Janet key, Janet *out) { size_t index; - Janet value; num_array *array = (num_array *)p; if (janet_checktype(key, JANET_KEYWORD)) - return janet_getmethod(janet_unwrap_keyword(key), methods); + return janet_getmethod(janet_unwrap_keyword(key), methods, out); if (!janet_checkint(key)) janet_panic("expected integer key"); index = (size_t)janet_unwrap_integer(key); if (index >= array->size) { - value = janet_wrap_nil(); + return 0; } else { - value = janet_wrap_number(array->data[index]); + *out = janet_wrap_number(array->data[index]); } - return value; + return 1; } static const JanetReg cfuns[] = { diff --git a/examples/numarray/project.janet b/examples/numarray/project.janet new file mode 100644 index 00000000..6cf5f327 --- /dev/null +++ b/examples/numarray/project.janet @@ -0,0 +1,7 @@ +(declare-project + :name "numarray" + :description "Example c lib with abstract type") + +(declare-native + :name "numarray" + :source @["numarray.c"]) diff --git a/examples/numarray/build.janet b/examples/numarray/test/numarray_tests.janet similarity index 65% rename from examples/numarray/build.janet rename to examples/numarray/test/numarray_tests.janet index 2e682568..5ae34bba 100644 --- a/examples/numarray/build.janet +++ b/examples/numarray/test/numarray_tests.janet @@ -1,10 +1,4 @@ -(import cook) - -(cook/make-native - :name "numarray" - :source @["numarray.c"]) - -(import build/numarray :as numarray) +(import build/numarray) (def a (numarray/new 30)) (print (get a 20)) diff --git a/src/core/compile.c b/src/core/compile.c index 88d9b7a3..dd802b3e 100644 --- a/src/core/compile.c +++ b/src/core/compile.c @@ -750,12 +750,14 @@ JanetFuncDef *janetc_pop_funcdef(JanetCompiler *c) { /* Copy upvalue bitset */ if (scope->ua.count) { /* Number of u32s we need to create a bitmask for all slots */ - int32_t numchunks = (def->slotcount + 31) >> 5; - uint32_t *chunks = calloc(sizeof(uint32_t), numchunks); + int32_t slotchunks = (def->slotcount + 31) >> 5; + /* numchunks is min of slotchunks and scope->ua.count */ + int32_t numchunks = slotchunks > scope->ua.count ? scope->ua.count : slotchunks; + uint32_t *chunks = calloc(sizeof(uint32_t), slotchunks); if (NULL == chunks) { JANET_OUT_OF_MEMORY; } - memcpy(chunks, scope->ua.chunks, sizeof(uint32_t) * scope->ua.count); + memcpy(chunks, scope->ua.chunks, sizeof(uint32_t) * numchunks); /* Register allocator preallocates some registers [240-255, high 16 bits of chunk index 7], we can ignore those. */ if (scope->ua.count > 7) chunks[7] &= 0xFFFFU; def->closure_bitset = chunks;