diff --git a/src/wren_core.c b/src/wren_core.c index 85dbb493..d79f0539 100644 --- a/src/wren_core.c +++ b/src/wren_core.c @@ -358,6 +358,11 @@ DEF_NATIVE(fn_toString) RETURN_VAL(wrenNewString(vm, "", 4)); } +DEF_NATIVE(list_instantiate) +{ + RETURN_OBJ(wrenNewList(vm, 0)); +} + DEF_NATIVE(list_add) { ObjList* list = AS_LIST(args[0]); @@ -936,8 +941,6 @@ void wrenInitializeCore(WrenVM* vm) // Define the methods specific to Class after wiring up its superclass to // prevent the inherited ones from overwriting them. - // TODO: Now that instantiation is controlled by the class, implement "new" - // for List. NATIVE(vm->classClass, " instantiate", class_instantiate); NATIVE(vm->classClass, "name", class_name); @@ -1041,6 +1044,7 @@ void wrenInitializeCore(WrenVM* vm) wrenInterpret(vm, "Wren core library", libSource); vm->listClass = AS_CLASS(findGlobal(vm, "List")); + NATIVE(vm->listClass->metaclass, " instantiate", list_instantiate); NATIVE(vm->listClass, "add ", list_add); NATIVE(vm->listClass, "clear", list_clear); NATIVE(vm->listClass, "count", list_count); diff --git a/src/wren_value.h b/src/wren_value.h index 7db13d04..2423e06b 100644 --- a/src/wren_value.h +++ b/src/wren_value.h @@ -616,7 +616,7 @@ void wrenPrintValue(Value value); // Returns true if [value] is a bool. Do not call this directly, instead use // [IS_BOOL]. -inline bool wrenIsBool(Value value) +static inline bool wrenIsBool(Value value) { #if WREN_NAN_TAGGING return value.bits == TRUE_VAL.bits || value.bits == FALSE_VAL.bits; @@ -627,13 +627,13 @@ inline bool wrenIsBool(Value value) // Returns true if [value] is an object of type [type]. Do not call this // directly, instead use the [IS___] macro for the type in question. -inline bool wrenIsObjType(Value value, ObjType type) +static inline bool wrenIsObjType(Value value, ObjType type) { return IS_OBJ(value) && AS_OBJ(value)->type == type; } // Converts the raw object pointer [obj] to a [Value]. -inline Value wrenObjectToValue(Obj* obj) +static inline Value wrenObjectToValue(Obj* obj) { #if WREN_NAN_TAGGING return (Value)(SIGN_BIT | QNAN | (uint64_t)(obj)); diff --git a/test/list/new.wren b/test/list/new.wren new file mode 100644 index 00000000..0db068c7 --- /dev/null +++ b/test/list/new.wren @@ -0,0 +1,6 @@ +var list = new List + +IO.print(list.count) // expect: 0 +IO.print(list) // expect: [] +list.add(1) +IO.print(list) // expect: [1]