mirror of
https://github.com/janet-lang/janet
synced 2025-06-27 07:32:51 +00:00
Merge branch 'master' into asyncio
This commit is contained in:
commit
c10d9b9d9d
@ -122,6 +122,13 @@ gmake repl
|
|||||||
3. Run `build_win` to compile janet.
|
3. Run `build_win` to compile janet.
|
||||||
4. Run `build_win test` to make sure everything is working.
|
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
|
### Meson
|
||||||
|
|
||||||
Janet also has a build file for [Meson](https://mesonbuild.com/), a cross platform build
|
Janet also has a build file for [Meson](https://mesonbuild.com/), a cross platform build
|
||||||
|
@ -23,7 +23,7 @@ static int num_array_gc(void *p, size_t s) {
|
|||||||
return 0;
|
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);
|
void num_array_put(void *p, Janet key, Janet value);
|
||||||
|
|
||||||
static const JanetAbstractType num_array_type = {
|
static const JanetAbstractType num_array_type = {
|
||||||
@ -31,7 +31,8 @@ static const JanetAbstractType num_array_type = {
|
|||||||
num_array_gc,
|
num_array_gc,
|
||||||
NULL,
|
NULL,
|
||||||
num_array_get,
|
num_array_get,
|
||||||
num_array_put
|
num_array_put,
|
||||||
|
JANET_ATEND_PUT
|
||||||
};
|
};
|
||||||
|
|
||||||
static Janet num_array_new(int32_t argc, Janet *argv) {
|
static Janet num_array_new(int32_t argc, Janet *argv) {
|
||||||
@ -81,21 +82,20 @@ static const JanetMethod methods[] = {
|
|||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
Janet num_array_get(void *p, Janet key) {
|
int num_array_get(void *p, Janet key, Janet *out) {
|
||||||
size_t index;
|
size_t index;
|
||||||
Janet value;
|
|
||||||
num_array *array = (num_array *)p;
|
num_array *array = (num_array *)p;
|
||||||
if (janet_checktype(key, JANET_KEYWORD))
|
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))
|
if (!janet_checkint(key))
|
||||||
janet_panic("expected integer key");
|
janet_panic("expected integer key");
|
||||||
index = (size_t)janet_unwrap_integer(key);
|
index = (size_t)janet_unwrap_integer(key);
|
||||||
if (index >= array->size) {
|
if (index >= array->size) {
|
||||||
value = janet_wrap_nil();
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
value = janet_wrap_number(array->data[index]);
|
*out = janet_wrap_number(array->data[index]);
|
||||||
}
|
}
|
||||||
return value;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const JanetReg cfuns[] = {
|
static const JanetReg cfuns[] = {
|
||||||
|
7
examples/numarray/project.janet
Normal file
7
examples/numarray/project.janet
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
(declare-project
|
||||||
|
:name "numarray"
|
||||||
|
:description "Example c lib with abstract type")
|
||||||
|
|
||||||
|
(declare-native
|
||||||
|
:name "numarray"
|
||||||
|
:source @["numarray.c"])
|
@ -1,10 +1,4 @@
|
|||||||
(import cook)
|
(import build/numarray)
|
||||||
|
|
||||||
(cook/make-native
|
|
||||||
:name "numarray"
|
|
||||||
:source @["numarray.c"])
|
|
||||||
|
|
||||||
(import build/numarray :as numarray)
|
|
||||||
|
|
||||||
(def a (numarray/new 30))
|
(def a (numarray/new 30))
|
||||||
(print (get a 20))
|
(print (get a 20))
|
@ -750,12 +750,14 @@ JanetFuncDef *janetc_pop_funcdef(JanetCompiler *c) {
|
|||||||
/* Copy upvalue bitset */
|
/* Copy upvalue bitset */
|
||||||
if (scope->ua.count) {
|
if (scope->ua.count) {
|
||||||
/* Number of u32s we need to create a bitmask for all slots */
|
/* Number of u32s we need to create a bitmask for all slots */
|
||||||
int32_t numchunks = (def->slotcount + 31) >> 5;
|
int32_t slotchunks = (def->slotcount + 31) >> 5;
|
||||||
uint32_t *chunks = calloc(sizeof(uint32_t), numchunks);
|
/* 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) {
|
if (NULL == chunks) {
|
||||||
JANET_OUT_OF_MEMORY;
|
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. */
|
/* 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;
|
if (scope->ua.count > 7) chunks[7] &= 0xFFFFU;
|
||||||
def->closure_bitset = chunks;
|
def->closure_bitset = chunks;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user