Skip to content

Commit bb25afa

Browse files
committed
feat: Add JSON parsing benchmark and expand standard library with new modules and core natives.
1 parent fa6f0dc commit bb25afa

2 files changed

Lines changed: 27 additions & 3 deletions

File tree

benchmarks/macro/json_bench.prox

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
// Simulated JSON Parsing Benchmark
33

44
class JsonParser {
5-
init(input) {
6-
this.input = input;
5+
init(inp) {
6+
this.input = inp;
77
this.pos = 0;
8-
this.len = len(input);
8+
this.len = len(inp);
99
}
1010

1111
peek() {

src/stdlib/stdlib_core.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,28 @@ static void registerModule(VM* vm, const char* name, ObjModule* module) {
4545
pop(vm);
4646
}
4747

48+
static Value native_push(int argCount, Value* args) {
49+
if (argCount < 2) return NIL_VAL;
50+
if (!IS_LIST(args[0])) return NIL_VAL;
51+
ObjList* list = AS_LIST(args[0]);
52+
Value item = args[1];
53+
if (list->capacity < list->count + 1) {
54+
int oldCapacity = list->capacity;
55+
list->capacity = GROW_CAPACITY(oldCapacity);
56+
list->items = GROW_ARRAY(Value, list->items, oldCapacity, list->capacity);
57+
}
58+
list->items[list->count++] = item;
59+
return item; // Return pushed item or nil? JS returns new length
60+
}
61+
62+
static Value native_pop(int argCount, Value* args) {
63+
if (argCount < 1) return NIL_VAL;
64+
if (!IS_LIST(args[0])) return NIL_VAL;
65+
ObjList* list = AS_LIST(args[0]);
66+
if (list->count == 0) return NIL_VAL;
67+
return list->items[--list->count];
68+
}
69+
4870
/*
4971
* Register all standard library modules
5072
* Called during VM initialization
@@ -191,4 +213,6 @@ void registerStdLib(VM* vm) {
191213
// Register simple globals for convenience
192214
defineNative(vm, "clock", native_clock);
193215
defineNative(vm, "len", native_len);
216+
defineNative(vm, "push", native_push);
217+
defineNative(vm, "pop", native_pop);
194218
}

0 commit comments

Comments
 (0)