new built-in keysof and rewrote the json parser

This commit is contained in:
cozis
2022-12-06 22:43:13 +01:00
parent 7e3eb6364a
commit 380b8a8917
11 changed files with 521 additions and 219 deletions
+15
View File
@@ -317,6 +317,20 @@ static int bin_istypeof(Runtime *runtime, Object **argv, unsigned int argc, Obje
return 1;
}
static int bin_keysof(Runtime *runtime, Object **argv, unsigned int argc, Object *rets[static MAX_RETS], Error *error)
{
UNUSED(argc);
UNUSED(rets);
UNUSED(runtime);
ASSERT(argc == 1);
Heap *heap = Runtime_GetHeap(runtime);
Object *keys = Object_KeysOf(argv[0], heap, error);
if (keys == NULL)
return -1;
rets[0] = keys;
return 1;
}
void bins_basic_init(StaticMapSlot slots[])
{
slots[0].as_type = Object_GetTypeType();
@@ -361,5 +375,6 @@ StaticMapSlot bins_basic[] = {
{ "error", SM_FUNCT, .as_funct = bin_error, .argc = 1 },
{ "assert", SM_FUNCT, .as_funct = bin_assert, .argc = -1 },
{ "istypeof", SM_FUNCT, .as_funct = bin_istypeof, .argc = 2, },
{ "keysof", SM_FUNCT, .as_funct = bin_keysof, .argc = 1, },
{ NULL, SM_END, {}, {} },
};