diff --git a/src/README.md b/src/README.md index b6c105a9..321df348 100644 --- a/src/README.md +++ b/src/README.md @@ -1,7 +1,7 @@ This contains the Wren source code. It is organized like so: -* `aux`: the Wren and C source code for the auxiliary modules. These are built - in to the VM and can be used even when you embed the VM in your own +* `optional`: the Wren and C source code for the optional modules. These are + built in to the VM and can be used even when you embed the VM in your own application. But they are also optional and can be compiled out by setting defines. diff --git a/src/aux/wren_aux_meta.c b/src/optional/wren_opt_meta.c similarity index 94% rename from src/aux/wren_aux_meta.c rename to src/optional/wren_opt_meta.c index ddad1073..c40677a0 100644 --- a/src/aux/wren_aux_meta.c +++ b/src/optional/wren_opt_meta.c @@ -1,11 +1,11 @@ -#include "wren_aux_meta.h" +#include "wren_opt_meta.h" -#if WREN_AUX_META +#if WREN_OPT_META #include #include "wren_vm.h" -#include "wren_aux_meta.wren.inc" +#include "wren_opt_meta.wren.inc" void metaCompile(WrenVM* vm) { @@ -16,11 +16,11 @@ void metaCompile(WrenVM* vm) ObjModule* module = IS_FN(callingFn) ? AS_FN(callingFn)->module : AS_CLOSURE(callingFn)->fn->module; - + // Compile it. ObjFn* fn = wrenCompile(vm, module, wrenGetArgumentString(vm, 1), false); if (fn == NULL) return; - + // Return the result. We can't use the public API for this since we have a // bare ObjFn. *vm->foreignCallSlot = OBJ_VAL(fn); @@ -38,7 +38,7 @@ static WrenForeignMethodFn bindMetaForeignMethods(WrenVM* vm, ASSERT(strcmp(className, "Meta") == 0, "Should be in Meta class."); ASSERT(isStatic, "Should be static."); ASSERT(strcmp(signature, "compile_(_)") == 0, "Should be compile method."); - + return metaCompile; } @@ -46,7 +46,7 @@ void wrenLoadMetaModule(WrenVM* vm) { WrenBindForeignMethodFn previousBindFn = vm->config.bindForeignMethodFn; vm->config.bindForeignMethodFn = bindMetaForeignMethods; - + wrenInterpretInModule(vm, "meta", metaModuleSource); vm->config.bindForeignMethodFn = previousBindFn; diff --git a/src/aux/wren_aux_meta.h b/src/optional/wren_opt_meta.h similarity index 71% rename from src/aux/wren_aux_meta.h rename to src/optional/wren_opt_meta.h index c5cafc57..891b3b03 100644 --- a/src/aux/wren_aux_meta.h +++ b/src/optional/wren_opt_meta.h @@ -1,11 +1,11 @@ -#ifndef wren_aux_meta_h -#define wren_aux_meta_h +#ifndef wren_opt_meta_h +#define wren_opt_meta_h #include "wren_common.h" #include "wren.h" // This module defines the Meta class and its associated methods. -#if WREN_AUX_META +#if WREN_OPT_META void wrenLoadMetaModule(WrenVM* vm); diff --git a/src/aux/wren_aux_meta.wren b/src/optional/wren_opt_meta.wren similarity index 100% rename from src/aux/wren_aux_meta.wren rename to src/optional/wren_opt_meta.wren diff --git a/src/aux/wren_aux_meta.wren.inc b/src/optional/wren_opt_meta.wren.inc similarity index 83% rename from src/aux/wren_aux_meta.wren.inc rename to src/optional/wren_opt_meta.wren.inc index b80076df..9ac2e106 100644 --- a/src/aux/wren_aux_meta.wren.inc +++ b/src/optional/wren_opt_meta.wren.inc @@ -1,4 +1,4 @@ -// Generated automatically from src/aux/wren_aux_meta.wren. Do not edit. +// Generated automatically from src/optional/wren_opt_meta.wren. Do not edit. static const char* metaModuleSource = "class Meta {\n" " static eval(source) {\n" diff --git a/src/aux/wren_aux_random.c b/src/optional/wren_opt_random.c similarity index 97% rename from src/aux/wren_aux_random.c rename to src/optional/wren_opt_random.c index 8b400152..b02c7ca7 100644 --- a/src/aux/wren_aux_random.c +++ b/src/optional/wren_opt_random.c @@ -1,6 +1,6 @@ -#include "wren_aux_random.h" +#include "wren_opt_random.h" -#if WREN_AUX_RANDOM +#if WREN_OPT_RANDOM #include #include @@ -8,7 +8,7 @@ #include "wren.h" #include "wren_vm.h" -#include "wren_aux_random.wren.inc" +#include "wren_opt_random.wren.inc" // Implements the well equidistributed long-period linear PRNG (WELL512a). // @@ -30,7 +30,7 @@ static uint32_t advanceState(Well512* well) c ^= (c >> 11); a = well->state[well->index] = b ^ c; d = a ^ ((a << 5) & 0xda442d24U); - + well->index = (well->index + 15) & 15; a = well->state[well->index]; well->state[well->index] = a ^ b ^ d ^ (a << 2) ^ (b << 18) ^ (c << 28); @@ -46,7 +46,7 @@ static void randomAllocate(WrenVM* vm) static void randomSeed0(WrenVM* vm) { Well512* well = (Well512*)wrenGetArgumentForeign(vm, 0); - + srand((uint32_t)time(NULL)); for (int i = 0; i < 16; i++) { @@ -57,7 +57,7 @@ static void randomSeed0(WrenVM* vm) static void randomSeed1(WrenVM* vm) { Well512* well = (Well512*)wrenGetArgumentForeign(vm, 0); - + srand((uint32_t)wrenGetArgumentDouble(vm, 1)); for (int i = 0; i < 16; i++) { @@ -68,7 +68,7 @@ static void randomSeed1(WrenVM* vm) static void randomSeed16(WrenVM* vm) { Well512* well = (Well512*)wrenGetArgumentForeign(vm, 0); - + for (int i = 0; i < 16; i++) { well->state[i] = (uint32_t)wrenGetArgumentDouble(vm, i + 1); @@ -78,27 +78,27 @@ static void randomSeed16(WrenVM* vm) static void randomFloat(WrenVM* vm) { Well512* well = (Well512*)wrenGetArgumentForeign(vm, 0); - + // A double has 53 bits of precision in its mantissa, and we'd like to take // full advantage of that, so we need 53 bits of random source data. // First, start with 32 random bits, shifted to the left 21 bits. double result = (double)advanceState(well) * (1 << 21); - + // Then add another 21 random bits. result += (double)(advanceState(well) & ((1 << 21) - 1)); // Now we have a number from 0 - (2^53). Divide be the range to get a double // from 0 to 1.0 (half-inclusive). result /= 9007199254740992.0; - + wrenReturnDouble(vm, result); } static void randomInt0(WrenVM* vm) { Well512* well = (Well512*)wrenGetArgumentForeign(vm, 0); - + wrenReturnDouble(vm, (double)advanceState(well)); } @@ -112,7 +112,7 @@ static WrenForeignMethodFn bindForeignMethods(WrenVM* vm, { ASSERT(strcmp(module, "random") == 0, "Should be in random module."); ASSERT(strcmp(className, "Random") == 0, "Should be in Random class."); - + if (strcmp(signature, "") == 0) return randomAllocate; if (strcmp(signature, "seed_()") == 0) return randomSeed0; if (strcmp(signature, "seed_(_)") == 0) return randomSeed1; @@ -121,7 +121,7 @@ static WrenForeignMethodFn bindForeignMethods(WrenVM* vm, { return randomSeed16; } - + if (strcmp(signature, "float()") == 0) return randomFloat; if (strcmp(signature, "int()") == 0) return randomInt0; @@ -143,12 +143,12 @@ void wrenLoadRandomModule(WrenVM* vm) { WrenBindForeignMethodFn previousBindMethodFn = vm->config.bindForeignMethodFn; vm->config.bindForeignMethodFn = bindForeignMethods; - + WrenBindForeignClassFn previousBindClassFn = vm->config.bindForeignClassFn; vm->config.bindForeignClassFn = bindForeignClass; - + wrenInterpretInModule(vm, "random", randomModuleSource); - + vm->config.bindForeignMethodFn = previousBindMethodFn; vm->config.bindForeignClassFn = previousBindClassFn; } diff --git a/src/aux/wren_aux_random.h b/src/optional/wren_opt_random.h similarity index 58% rename from src/aux/wren_aux_random.h rename to src/optional/wren_opt_random.h index fe363789..0031720f 100644 --- a/src/aux/wren_aux_random.h +++ b/src/optional/wren_opt_random.h @@ -1,10 +1,10 @@ -#ifndef wren_aux_random_h -#define wren_aux_random_h +#ifndef wren_opt_random_h +#define wren_opt_random_h #include "wren_common.h" #include "wren.h" -#if WREN_AUX_RANDOM +#if WREN_OPT_RANDOM void wrenLoadRandomModule(WrenVM* vm); diff --git a/src/aux/wren_aux_random.wren b/src/optional/wren_opt_random.wren similarity index 100% rename from src/aux/wren_aux_random.wren rename to src/optional/wren_opt_random.wren diff --git a/src/aux/wren_aux_random.wren.inc b/src/optional/wren_opt_random.wren.inc similarity index 95% rename from src/aux/wren_aux_random.wren.inc rename to src/optional/wren_opt_random.wren.inc index cc2d5b31..2b1e88ad 100644 --- a/src/aux/wren_aux_random.wren.inc +++ b/src/optional/wren_opt_random.wren.inc @@ -1,4 +1,4 @@ -// Generated automatically from src/aux/wren_aux_random.wren. Do not edit. +// Generated automatically from src/optional/wren_opt_random.wren. Do not edit. static const char* randomModuleSource = "foreign class Random {\n" " construct new() {\n" diff --git a/src/vm/wren_common.h b/src/vm/wren_common.h index 1d33ad84..df65395b 100644 --- a/src/vm/wren_common.h +++ b/src/vm/wren_common.h @@ -44,15 +44,15 @@ #endif #endif -// The VM includes a number of optional "auxiliary" modules. You can choose to -// include these or not. By default, they are all available. To disable one, -// set the corresponding `WREN_AUX_` define to `0`. -#ifndef WREN_AUX_META - #define WREN_AUX_META 1 +// The VM includes a number of optional modules. You can choose to include +// these or not. By default, they are all available. To disable one, set the +// corresponding `WREN_OPT_` define to `0`. +#ifndef WREN_OPT_META + #define WREN_OPT_META 1 #endif -#ifndef WREN_AUX_RANDOM - #define WREN_AUX_RANDOM 1 +#ifndef WREN_OPT_RANDOM + #define WREN_OPT_RANDOM 1 #endif // These flags are useful for debugging and hacking on Wren itself. They are not diff --git a/src/vm/wren_vm.c b/src/vm/wren_vm.c index af81aac2..4ac1b3c1 100644 --- a/src/vm/wren_vm.c +++ b/src/vm/wren_vm.c @@ -8,11 +8,11 @@ #include "wren_debug.h" #include "wren_vm.h" -#if WREN_AUX_META - #include "wren_aux_meta.h" +#if WREN_OPT_META + #include "wren_opt_meta.h" #endif -#if WREN_AUX_RANDOM - #include "wren_aux_random.h" +#if WREN_OPT_RANDOM + #include "wren_opt_random.h" #endif #if WREN_DEBUG_TRACE_MEMORY || WREN_DEBUG_TRACE_GC @@ -59,15 +59,15 @@ WrenVM* wrenNewVM(WrenConfiguration* config) vm->modules = wrenNewMap(vm); wrenInitializeCore(vm); - + // TODO: Lazy load these. - #if WREN_AUX_META + #if WREN_OPT_META wrenLoadMetaModule(vm); #endif - #if WREN_AUX_RANDOM + #if WREN_OPT_RANDOM wrenLoadRandomModule(vm); #endif - + return vm; } @@ -88,7 +88,7 @@ void wrenFreeVM(WrenVM* vm) // them here because the host app may still have pointers to them that they // may try to use. Better to tell them about the bug early. ASSERT(vm->valueHandles == NULL, "All values have not been released."); - + wrenSymbolTableClear(vm, &vm->methodNames); DEALLOCATE(vm, vm); @@ -261,11 +261,11 @@ static void closeUpvalues(ObjFiber* fiber, Value* last) fiber->openUpvalues->value >= last) { ObjUpvalue* upvalue = fiber->openUpvalues; - + // Move the value into the upvalue itself and point the upvalue to it. upvalue->closed = *upvalue->value; upvalue->value = &upvalue->closed; - + // Remove it from the open upvalue list. fiber->openUpvalues = upvalue->next; } @@ -358,21 +358,21 @@ static void callForeign(WrenVM* vm, ObjFiber* fiber, static void runtimeError(WrenVM* vm) { ASSERT(!IS_NULL(vm->fiber->error), "Should only call this after an error."); - + // Unhook the caller since we will never resume and return to it. ObjFiber* caller = vm->fiber->caller; vm->fiber->caller = NULL; - + // If the caller ran this fiber using "try", give it the error. if (vm->fiber->callerIsTrying) { // Make the caller's try method return the error message. caller->stackTop[-1] = vm->fiber->error; - + vm->fiber = caller; return; } - + // If we got here, nothing caught the error, so show the stack trace. wrenDebugPrintStackTrace(vm->fiber); vm->fiber = NULL; @@ -403,12 +403,12 @@ static bool checkArity(WrenVM* vm, Value value, int numArgs) ASSERT(IS_FN(value), "Receiver must be a function or closure."); fn = AS_FN(value); } - + // We only care about missing arguments, not extras. The "- 1" is because // numArgs includes the receiver, the function itself, which we don't want to // count. if (numArgs - 1 >= fn->arity) return true; - + vm->fiber->error = CONST_STRING(vm, "Function expects more arguments."); return false; } @@ -427,7 +427,7 @@ static inline void callFunction( sizeof(CallFrame) * max); fiber->frameCapacity = max; } - + // TODO: Check for stack overflow. We handle the call frame array growing, // but not the stack itself. @@ -561,7 +561,7 @@ static Value validateSuperclass(WrenVM* vm, Value name, Value superclassValue, "Class '@' cannot inherit from built-in class '@'.", name, OBJ_VAL(superclass->name)); } - + if (superclass->numFields == -1) { return wrenStringFormat(vm, @@ -575,7 +575,7 @@ static Value validateSuperclass(WrenVM* vm, Value name, Value superclassValue, "Foreign class '@' may not inherit from a class with fields.", name); } - + if (superclass->numFields + numFields > MAX_FIELDS) { return wrenStringFormat(vm, @@ -591,24 +591,24 @@ static void bindForeignClass(WrenVM* vm, ObjClass* classObj, ObjModule* module) // TODO: Make this a runtime error? ASSERT(vm->config.bindForeignClassFn != NULL, "Cannot declare foreign classes without a bindForeignClassFn."); - + WrenForeignClassMethods methods = vm->config.bindForeignClassFn( vm, module->name->value, classObj->name->value); - + Method method; method.type = METHOD_FOREIGN; method.fn.foreign = methods.allocate; - + ASSERT(method.fn.foreign != NULL, "A foreign class must provide an allocate function."); - + int symbol = wrenSymbolTableEnsure(vm, &vm->methodNames, "", 10); wrenBindMethod(vm, classObj, symbol, method); - + // Add the symbol even if there is no finalizer so we can ensure that the // symbol itself is always in the symbol table. symbol = wrenSymbolTableEnsure(vm, &vm->methodNames, "", 10); - + if (methods.finalize != NULL) { method.fn.foreign = methods.finalize; @@ -628,18 +628,18 @@ static void createClass(WrenVM* vm, int numFields, ObjModule* module) // Pull the name and superclass off the stack. Value name = vm->fiber->stackTop[-2]; Value superclass = vm->fiber->stackTop[-1]; - + // We have two values on the stack and we are going to leave one, so discard // the other slot. vm->fiber->stackTop--; vm->fiber->error = validateSuperclass(vm, name, superclass, numFields); if (!IS_NULL(vm->fiber->error)) return; - + ObjClass* classObj = wrenNewClass(vm, AS_CLASS(superclass), numFields, AS_STRING(name)); vm->fiber->stackTop[-1] = OBJ_VAL(classObj); - + if (numFields == -1) bindForeignClass(vm, classObj, module); } @@ -647,21 +647,21 @@ static void createForeign(WrenVM* vm, ObjFiber* fiber, Value* stack) { ObjClass* classObj = AS_CLASS(stack[0]); ASSERT(classObj->numFields == -1, "Class must be a foreign class."); - + // TODO: Don't look up every time. int symbol = wrenSymbolTableFind(&vm->methodNames, "", 10); ASSERT(symbol != -1, "Should have defined symbol."); - + ASSERT(classObj->methods.count > symbol, "Class should have allocator."); Method* method = &classObj->methods.data[symbol]; ASSERT(method->type == METHOD_FOREIGN, "Allocator should be foreign."); - + // Pass the constructor arguments to the allocator as well. vm->foreignCallSlot = stack; vm->foreignCallNumArgs = (int)(fiber->stackTop - stack); - + method->fn.foreign(vm); - + // TODO: Check that allocateForeign was called. } @@ -670,24 +670,24 @@ void wrenFinalizeForeign(WrenVM* vm, ObjForeign* foreign) // TODO: Don't look up every time. int symbol = wrenSymbolTableFind(&vm->methodNames, "", 10); ASSERT(symbol != -1, "Should have defined symbol."); - + // If there are no finalizers, don't finalize it. if (symbol == -1) return; - + // If the class doesn't have a finalizer, bail out. ObjClass* classObj = foreign->obj.classObj; if (symbol >= classObj->methods.count) return; - + Method* method = &classObj->methods.data[symbol]; if (method->type == METHOD_NONE) return; - + ASSERT(method->type == METHOD_FOREIGN, "Finalizer should be foreign."); - + // Pass the constructor arguments to the allocator as well. Value slot = OBJ_VAL(foreign); vm->foreignCallSlot = &slot; vm->foreignCallNumArgs = 1; - + method->fn.foreign(vm); } @@ -941,7 +941,7 @@ static WrenInterpretResult runInterpreter(WrenVM* vm, register ObjFiber* fiber) case METHOD_FOREIGN: callForeign(vm, fiber, method->fn.foreign, numArgs); break; - + case METHOD_FN_CALL: if (!checkArity(vm, args[0], numArgs)) RUNTIME_ERROR(); @@ -1091,7 +1091,7 @@ static WrenInterpretResult runInterpreter(WrenVM* vm, register ObjFiber* fiber) // Close any upvalues still in scope. closeUpvalues(fiber, stackStart); - + // If the fiber is complete, end it. if (fiber->numFrames == 0) { @@ -1101,7 +1101,7 @@ static WrenInterpretResult runInterpreter(WrenVM* vm, register ObjFiber* fiber) // We have a calling fiber to resume. ObjFiber* callingFiber = fiber->caller; fiber->caller = NULL; - + fiber = callingFiber; vm->fiber = fiber; @@ -1127,7 +1127,7 @@ static WrenInterpretResult runInterpreter(WrenVM* vm, register ObjFiber* fiber) ASSERT(IS_CLASS(stackStart[0]), "'this' should be a class."); stackStart[0] = wrenNewInstance(vm, AS_CLASS(stackStart[0])); DISPATCH(); - + CASE_CODE(FOREIGN_CONSTRUCT): ASSERT(IS_CLASS(stackStart[0]), "'this' should be a class."); createForeign(vm, fiber, stackStart); @@ -1172,14 +1172,14 @@ static WrenInterpretResult runInterpreter(WrenVM* vm, register ObjFiber* fiber) if (!IS_NULL(fiber->error)) RUNTIME_ERROR(); DISPATCH(); } - + CASE_CODE(FOREIGN_CLASS): { createClass(vm, -1, fn->module); if (!IS_NULL(fiber->error)) RUNTIME_ERROR(); DISPATCH(); } - + CASE_CODE(METHOD_INSTANCE): CASE_CODE(METHOD_STATIC): { @@ -1321,7 +1321,7 @@ WrenInterpretResult wrenCall(WrenVM* vm, WrenValue* method, WrenInterpretResult result = wrenCallVarArgs(vm, method, returnValue, argTypes, args); va_end(args); - + return result; } @@ -1331,10 +1331,10 @@ WrenInterpretResult wrenCallVarArgs(WrenVM* vm, WrenValue* method, { // TODO: Validate that the number of arguments matches what the method // expects. - + ASSERT(IS_FIBER(method->value), "Value must come from wrenGetMethod()."); ObjFiber* fiber = AS_FIBER(method->value); - + // Push the arguments. for (const char* argType = argTypes; *argType != '\0'; argType++) { @@ -1348,7 +1348,7 @@ WrenInterpretResult wrenCallVarArgs(WrenVM* vm, WrenValue* method, value = wrenNewString(vm, bytes, (size_t)length); break; } - + case 'b': value = BOOL_VAL(va_arg(args, int)); break; case 'd': value = NUM_VAL(va_arg(args, double)); break; case 'i': value = NUM_VAL((double)va_arg(args, int)); break; @@ -1356,7 +1356,7 @@ WrenInterpretResult wrenCallVarArgs(WrenVM* vm, WrenValue* method, case 's': value = wrenStringFormat(vm, "$", va_arg(args, const char*)); break; - + case 'v': { // Allow a NULL value pointer for Wren null. @@ -1364,21 +1364,21 @@ WrenInterpretResult wrenCallVarArgs(WrenVM* vm, WrenValue* method, if (wrenValue != NULL) value = wrenValue->value; break; } - + default: ASSERT(false, "Unknown argument type."); break; } - + *fiber->stackTop++ = value; } - + Value receiver = fiber->stack[0]; Obj* fn = fiber->frames[0].fn; wrenPushRoot(vm, (Obj*)fn); - + WrenInterpretResult result = runInterpreter(vm, fiber); - + if (result == WREN_RESULT_SUCCESS) { if (returnValue != NULL) @@ -1387,10 +1387,10 @@ WrenInterpretResult wrenCallVarArgs(WrenVM* vm, WrenValue* method, fiber->stackTop++; *returnValue = wrenCaptureValue(vm, fiber->stack[0]); } - + // Reset the fiber to get ready for the next call. wrenResetFiber(vm, fiber, fn); - + // Push the receiver back on the stack. *fiber->stackTop++ = receiver; } @@ -1398,9 +1398,9 @@ WrenInterpretResult wrenCallVarArgs(WrenVM* vm, WrenValue* method, { if (returnValue != NULL) *returnValue = NULL; } - + wrenPopRoot(vm); - + return result; } @@ -1422,14 +1422,14 @@ WrenValue* wrenCaptureValue(WrenVM* vm, Value value) void wrenReleaseValue(WrenVM* vm, WrenValue* value) { ASSERT(value != NULL, "NULL value."); - + // Update the VM's head pointer if we're releasing the first handle. if (vm->valueHandles == value) vm->valueHandles = value->next; - + // Unlink it from the list. if (value->prev != NULL) value->prev->next = value->next; if (value->next != NULL) value->next->prev = value->prev; - + // Clear it out. This isn't strictly necessary since we're going to free it, // but it makes for easier debugging. value->prev = NULL; @@ -1448,7 +1448,7 @@ void* wrenAllocateForeign(WrenVM* vm, size_t size) ObjForeign* foreign = wrenNewForeign(vm, classObj, size); vm->foreignCallSlot[0] = OBJ_VAL(foreign); - + return (void*)foreign->data; } @@ -1466,7 +1466,7 @@ WrenInterpretResult wrenInterpretInModule(WrenVM* vm, const char* module, nameValue = wrenStringFormat(vm, "$", module); wrenPushRoot(vm, AS_OBJ(nameValue)); } - + ObjFiber* fiber = loadModule(vm, nameValue, source); if (fiber == NULL) { @@ -1608,9 +1608,9 @@ double wrenGetArgumentDouble(WrenVM* vm, int index) void* wrenGetArgumentForeign(WrenVM* vm, int index) { validateForeignArgument(vm, index); - + if (!IS_FOREIGN(*(vm->foreignCallSlot + index))) return NULL; - + return AS_FOREIGN(*(vm->foreignCallSlot + index))->data; } @@ -1662,7 +1662,7 @@ void wrenReturnValue(WrenVM* vm, WrenValue* value) { ASSERT(vm->foreignCallSlot != NULL, "Must be in foreign call."); ASSERT(value != NULL, "Value cannot be NULL."); - + *vm->foreignCallSlot = value->value; vm->foreignCallSlot = NULL; } diff --git a/util/wren.mk b/util/wren.mk index 478bdea5..52375b0c 100644 --- a/util/wren.mk +++ b/util/wren.mk @@ -19,8 +19,8 @@ # Then, for the libraries, the correct extension is added. # Files. -AUX_HEADERS := $(wildcard src/aux/*.h) $(wildcard src/aux/*.wren.inc) -AUX_SOURCES := $(wildcard src/aux/*.c) +OPT_HEADERS := $(wildcard src/optional/*.h) $(wildcard src/optional/*.wren.inc) +OPT_SOURCES := $(wildcard src/optional/*.c) CLI_HEADERS := $(wildcard src/cli/*.h) CLI_SOURCES := $(wildcard src/cli/*.c) @@ -109,7 +109,7 @@ endif CFLAGS := $(C_OPTIONS) $(C_WARNINGS) -AUX_OBJECTS := $(addprefix $(BUILD_DIR)/aux/, $(notdir $(AUX_SOURCES:.c=.o))) +OPT_OBJECTS := $(addprefix $(BUILD_DIR)/optional/, $(notdir $(OPT_SOURCES:.c=.o))) CLI_OBJECTS := $(addprefix $(BUILD_DIR)/cli/, $(notdir $(CLI_SOURCES:.c=.o))) MODULE_OBJECTS := $(addprefix $(BUILD_DIR)/module/, $(notdir $(MODULE_SOURCES:.c=.o))) VM_OBJECTS := $(addprefix $(BUILD_DIR)/vm/, $(notdir $(VM_SOURCES:.c=.o))) @@ -138,26 +138,26 @@ cli: bin/$(WREN) test: $(BUILD_DIR)/test/$(WREN) # Command-line interpreter. -bin/$(WREN): $(AUX_OBJECTS) $(CLI_OBJECTS) $(MODULE_OBJECTS) $(VM_OBJECTS) \ +bin/$(WREN): $(OPT_OBJECTS) $(CLI_OBJECTS) $(MODULE_OBJECTS) $(VM_OBJECTS) \ $(LIBUV) @ printf "%10s %-30s %s\n" $(CC) $@ "$(C_OPTIONS)" @ mkdir -p bin @ $(CC) $(CFLAGS) $^ -o $@ -lm $(LIBUV_LIBS) # Static library. -lib/lib$(WREN).a: $(AUX_OBJECTS) $(VM_OBJECTS) +lib/lib$(WREN).a: $(OPT_OBJECTS) $(VM_OBJECTS) @ printf "%10s %-30s %s\n" $(AR) $@ "rcu" @ mkdir -p lib @ $(AR) rcu $@ $^ # Shared library. -lib/lib$(WREN).$(SHARED_EXT): $(AUX_OBJECTS) $(VM_OBJECTS) +lib/lib$(WREN).$(SHARED_EXT): $(OPT_OBJECTS) $(VM_OBJECTS) @ printf "%10s %-30s %s\n" $(CC) $@ "$(C_OPTIONS) $(SHARED_LIB_FLAGS)" @ mkdir -p lib @ $(CC) $(CFLAGS) -shared $(SHARED_LIB_FLAGS) -o $@ $^ # Test executable. -$(BUILD_DIR)/test/$(WREN): $(AUX_OBJECTS) $(MODULE_OBJECTS) $(TEST_OBJECTS) \ +$(BUILD_DIR)/test/$(WREN): $(OPT_OBJECTS) $(MODULE_OBJECTS) $(TEST_OBJECTS) \ $(VM_OBJECTS) $(BUILD_DIR)/cli/modules.o $(BUILD_DIR)/cli/vm.o $(LIBUV) @ printf "%10s %-30s %s\n" $(CC) $@ "$(C_OPTIONS)" @ mkdir -p $(BUILD_DIR)/test @@ -178,19 +178,19 @@ $(BUILD_DIR)/module/%.o: src/module/%.c $(CLI_HEADERS) $(MODULE_HEADERS) \ @ $(CC) -c $(CFLAGS) $(CLI_FLAGS) -o $@ $(FILE_FLAG) $< # Aux object files. -$(BUILD_DIR)/aux/%.o: src/aux/%.c $(VM_HEADERS) $(AUX_HEADERS) +$(BUILD_DIR)/optional/%.o: src/optional/%.c $(VM_HEADERS) $(OPT_HEADERS) @ printf "%10s %-30s %s\n" $(CC) $< "$(C_OPTIONS)" - @ mkdir -p $(BUILD_DIR)/aux + @ mkdir -p $(BUILD_DIR)/optional @ $(CC) -c $(CFLAGS) -Isrc/include -Isrc/vm -o $@ $(FILE_FLAG) $< # VM object files. $(BUILD_DIR)/vm/%.o: src/vm/%.c $(VM_HEADERS) @ printf "%10s %-30s %s\n" $(CC) $< "$(C_OPTIONS)" @ mkdir -p $(BUILD_DIR)/vm - @ $(CC) -c $(CFLAGS) -Isrc/include -Isrc/aux -Isrc/vm -o $@ $(FILE_FLAG) $< + @ $(CC) -c $(CFLAGS) -Isrc/include -Isrc/optional -Isrc/vm -o $@ $(FILE_FLAG) $< # Test object files. -$(BUILD_DIR)/test/%.o: test/api/%.c $(AUX_HEADERS) $(MODULE_HEADERS) \ +$(BUILD_DIR)/test/%.o: test/api/%.c $(OPT_HEADERS) $(MODULE_HEADERS) \ $(VM_HEADERS) $(TEST_HEADERS) $(LIBUV) @ printf "%10s %-30s %s\n" $(CC) $< "$(C_OPTIONS)" @ mkdir -p $(dir $@) @@ -205,7 +205,7 @@ $(LIBUV): $(LIBUV_DIR)/build/gyp/gyp util/libuv.py @ ./util/libuv.py build $(LIBUV_ARCH) # Wren modules that get compiled into the binary as C strings. -src/aux/wren_aux_%.wren.inc: src/aux/wren_aux_%.wren util/wren_to_c_string.py +src/optional/wren_opt_%.wren.inc: src/optional/wren_opt_%.wren util/wren_to_c_string.py @ ./util/wren_to_c_string.py $@ $< src/vm/wren_%.wren.inc: src/vm/wren_%.wren util/wren_to_c_string.py diff --git a/util/wren_to_c_string.py b/util/wren_to_c_string.py index f33bc3c6..6715fb40 100755 --- a/util/wren_to_c_string.py +++ b/util/wren_to_c_string.py @@ -42,7 +42,7 @@ def main(): wren_source_lines = f.readlines() module = os.path.splitext(os.path.basename(args.input))[0] - module = module.replace("aux_", "") + module = module.replace("opt_", "") module = module.replace("wren_", "") c_source = wren_to_c_string(args.input, wren_source_lines, module) diff --git a/util/xcode/wren.xcodeproj/project.pbxproj b/util/xcode/wren.xcodeproj/project.pbxproj index 53b8331f..e30605b3 100644 --- a/util/xcode/wren.xcodeproj/project.pbxproj +++ b/util/xcode/wren.xcodeproj/project.pbxproj @@ -25,14 +25,14 @@ 29729F321BA70A620099CA20 /* io.c in Sources */ = {isa = PBXBuildFile; fileRef = 29729F2E1BA70A620099CA20 /* io.c */; }; 29729F331BA70A620099CA20 /* io.wren.inc in Sources */ = {isa = PBXBuildFile; fileRef = 29729F301BA70A620099CA20 /* io.wren.inc */; }; 2986F6D71ACF93BA00BCE26C /* wren_primitive.c in Sources */ = {isa = PBXBuildFile; fileRef = 2986F6D51ACF93BA00BCE26C /* wren_primitive.c */; }; - 29AF31F11BD2E38F00AAD156 /* wren_aux_meta.c in Sources */ = {isa = PBXBuildFile; fileRef = 29AF31EF1BD2E38F00AAD156 /* wren_aux_meta.c */; }; - 29AF31F21BD2E38F00AAD156 /* wren_aux_meta.c in Sources */ = {isa = PBXBuildFile; fileRef = 29AF31EF1BD2E38F00AAD156 /* wren_aux_meta.c */; }; - 29AF31F61BD2E98600AAD156 /* wren_aux_meta.wren.inc in Sources */ = {isa = PBXBuildFile; fileRef = 29AF31F31BD2E98600AAD156 /* wren_aux_meta.wren.inc */; }; - 29AF31F71BD2E98600AAD156 /* wren_aux_meta.wren.inc in Sources */ = {isa = PBXBuildFile; fileRef = 29AF31F31BD2E98600AAD156 /* wren_aux_meta.wren.inc */; }; - 29AF31F81BD2E98600AAD156 /* wren_aux_random.c in Sources */ = {isa = PBXBuildFile; fileRef = 29AF31F41BD2E98600AAD156 /* wren_aux_random.c */; }; - 29AF31F91BD2E98600AAD156 /* wren_aux_random.c in Sources */ = {isa = PBXBuildFile; fileRef = 29AF31F41BD2E98600AAD156 /* wren_aux_random.c */; }; - 29AF31FA1BD2E98600AAD156 /* wren_aux_random.wren.inc in Sources */ = {isa = PBXBuildFile; fileRef = 29AF31F51BD2E98600AAD156 /* wren_aux_random.wren.inc */; }; - 29AF31FB1BD2E98600AAD156 /* wren_aux_random.wren.inc in Sources */ = {isa = PBXBuildFile; fileRef = 29AF31F51BD2E98600AAD156 /* wren_aux_random.wren.inc */; }; + 29A427341BDBE435001E6E22 /* wren_opt_meta.c in Sources */ = {isa = PBXBuildFile; fileRef = 29A4272E1BDBE435001E6E22 /* wren_opt_meta.c */; }; + 29A427351BDBE435001E6E22 /* wren_opt_meta.c in Sources */ = {isa = PBXBuildFile; fileRef = 29A4272E1BDBE435001E6E22 /* wren_opt_meta.c */; }; + 29A427361BDBE435001E6E22 /* wren_opt_meta.wren.inc in Sources */ = {isa = PBXBuildFile; fileRef = 29A427301BDBE435001E6E22 /* wren_opt_meta.wren.inc */; }; + 29A427371BDBE435001E6E22 /* wren_opt_meta.wren.inc in Sources */ = {isa = PBXBuildFile; fileRef = 29A427301BDBE435001E6E22 /* wren_opt_meta.wren.inc */; }; + 29A427381BDBE435001E6E22 /* wren_opt_random.c in Sources */ = {isa = PBXBuildFile; fileRef = 29A427311BDBE435001E6E22 /* wren_opt_random.c */; }; + 29A427391BDBE435001E6E22 /* wren_opt_random.c in Sources */ = {isa = PBXBuildFile; fileRef = 29A427311BDBE435001E6E22 /* wren_opt_random.c */; }; + 29A4273A1BDBE435001E6E22 /* wren_opt_random.wren.inc in Sources */ = {isa = PBXBuildFile; fileRef = 29A427331BDBE435001E6E22 /* wren_opt_random.wren.inc */; }; + 29A4273B1BDBE435001E6E22 /* wren_opt_random.wren.inc in Sources */ = {isa = PBXBuildFile; fileRef = 29A427331BDBE435001E6E22 /* wren_opt_random.wren.inc */; }; 29C8A9331AB71FFF00DEC81D /* vm.c in Sources */ = {isa = PBXBuildFile; fileRef = 29C8A9311AB71FFF00DEC81D /* vm.c */; }; 29DC149F1BBA2FCC008A8274 /* vm.c in Sources */ = {isa = PBXBuildFile; fileRef = 29C8A9311AB71FFF00DEC81D /* vm.c */; }; 29DC14A01BBA2FD6008A8274 /* timer.c in Sources */ = {isa = PBXBuildFile; fileRef = 2901D7621B74F4050083A2C8 /* timer.c */; }; @@ -103,13 +103,13 @@ 29729F301BA70A620099CA20 /* io.wren.inc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.pascal; name = io.wren.inc; path = ../../src/module/io.wren.inc; sourceTree = ""; }; 2986F6D51ACF93BA00BCE26C /* wren_primitive.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = wren_primitive.c; path = ../../src/vm/wren_primitive.c; sourceTree = ""; }; 2986F6D61ACF93BA00BCE26C /* wren_primitive.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = wren_primitive.h; path = ../../src/vm/wren_primitive.h; sourceTree = ""; }; + 29A4272E1BDBE435001E6E22 /* wren_opt_meta.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = wren_opt_meta.c; path = ../../src/optional/wren_opt_meta.c; sourceTree = ""; }; + 29A4272F1BDBE435001E6E22 /* wren_opt_meta.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = wren_opt_meta.h; path = ../../src/optional/wren_opt_meta.h; sourceTree = ""; }; + 29A427301BDBE435001E6E22 /* wren_opt_meta.wren.inc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.pascal; name = wren_opt_meta.wren.inc; path = ../../src/optional/wren_opt_meta.wren.inc; sourceTree = ""; }; + 29A427311BDBE435001E6E22 /* wren_opt_random.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = wren_opt_random.c; path = ../../src/optional/wren_opt_random.c; sourceTree = ""; }; + 29A427321BDBE435001E6E22 /* wren_opt_random.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = wren_opt_random.h; path = ../../src/optional/wren_opt_random.h; sourceTree = ""; }; + 29A427331BDBE435001E6E22 /* wren_opt_random.wren.inc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.pascal; name = wren_opt_random.wren.inc; path = ../../src/optional/wren_opt_random.wren.inc; sourceTree = ""; }; 29AB1F061816E3AD004B501E /* wren */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = wren; sourceTree = BUILT_PRODUCTS_DIR; }; - 29AF31EF1BD2E38F00AAD156 /* wren_aux_meta.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = wren_aux_meta.c; path = ../../src/aux/wren_aux_meta.c; sourceTree = ""; }; - 29AF31F01BD2E38F00AAD156 /* wren_aux_meta.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = wren_aux_meta.h; path = ../../src/aux/wren_aux_meta.h; sourceTree = ""; }; - 29AF31F31BD2E98600AAD156 /* wren_aux_meta.wren.inc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.pascal; name = wren_aux_meta.wren.inc; path = ../../src/aux/wren_aux_meta.wren.inc; sourceTree = ""; }; - 29AF31F41BD2E98600AAD156 /* wren_aux_random.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = wren_aux_random.c; path = ../../src/aux/wren_aux_random.c; sourceTree = ""; }; - 29AF31F51BD2E98600AAD156 /* wren_aux_random.wren.inc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.pascal; name = wren_aux_random.wren.inc; path = ../../src/aux/wren_aux_random.wren.inc; sourceTree = ""; }; - 29AF31FC1BD2E9B300AAD156 /* wren_aux_random.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = wren_aux_random.h; path = ../../src/aux/wren_aux_random.h; sourceTree = ""; }; 29C8A9311AB71FFF00DEC81D /* vm.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = vm.c; path = ../../src/cli/vm.c; sourceTree = ""; }; 29C8A9321AB71FFF00DEC81D /* vm.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = vm.h; path = ../../src/cli/vm.h; sourceTree = ""; }; 29D009A61B7E3993000CE58C /* main.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = main.c; path = ../../test/api/main.c; sourceTree = ""; }; @@ -203,10 +203,10 @@ 29AB1EFD1816E3AD004B501E = { isa = PBXGroup; children = ( - 29AF31EE1BD2E37F00AAD156 /* aux */, 29205CA91AB4E67B0073018D /* cli */, 29205CAA1AB4E6840073018D /* include */, 2901D7611B74F3E20083A2C8 /* module */, + 29AF31EE1BD2E37F00AAD156 /* optional */, 29205CA01AB4E6470073018D /* vm */, 29D0099A1B7E394F000CE58C /* api_test */, 29512C801B91F8EB008C10E6 /* libuv.a */, @@ -223,17 +223,17 @@ name = Products; sourceTree = ""; }; - 29AF31EE1BD2E37F00AAD156 /* aux */ = { + 29AF31EE1BD2E37F00AAD156 /* optional */ = { isa = PBXGroup; children = ( - 29AF31F01BD2E38F00AAD156 /* wren_aux_meta.h */, - 29AF31EF1BD2E38F00AAD156 /* wren_aux_meta.c */, - 29AF31F31BD2E98600AAD156 /* wren_aux_meta.wren.inc */, - 29AF31FC1BD2E9B300AAD156 /* wren_aux_random.h */, - 29AF31F41BD2E98600AAD156 /* wren_aux_random.c */, - 29AF31F51BD2E98600AAD156 /* wren_aux_random.wren.inc */, + 29A4272E1BDBE435001E6E22 /* wren_opt_meta.c */, + 29A4272F1BDBE435001E6E22 /* wren_opt_meta.h */, + 29A427301BDBE435001E6E22 /* wren_opt_meta.wren.inc */, + 29A427311BDBE435001E6E22 /* wren_opt_random.c */, + 29A427321BDBE435001E6E22 /* wren_opt_random.h */, + 29A427331BDBE435001E6E22 /* wren_opt_random.wren.inc */, ); - name = aux; + name = optional; sourceTree = ""; }; 29D0099A1B7E394F000CE58C /* api_test */ = { @@ -326,24 +326,24 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 29AF31F11BD2E38F00AAD156 /* wren_aux_meta.c in Sources */, + 29A427381BDBE435001E6E22 /* wren_opt_random.c in Sources */, 29205C991AB4E6430073018D /* wren_compiler.c in Sources */, 2986F6D71ACF93BA00BCE26C /* wren_primitive.c in Sources */, 291647C71BA5EC5E006142EE /* modules.c in Sources */, + 29A4273A1BDBE435001E6E22 /* wren_opt_random.wren.inc in Sources */, 29205C9A1AB4E6430073018D /* wren_core.c in Sources */, 2901D7641B74F4050083A2C8 /* timer.c in Sources */, 29729F331BA70A620099CA20 /* io.wren.inc in Sources */, - 29AF31F61BD2E98600AAD156 /* wren_aux_meta.wren.inc in Sources */, 29C8A9331AB71FFF00DEC81D /* vm.c in Sources */, - 29AF31F81BD2E98600AAD156 /* wren_aux_random.c in Sources */, 291647C41BA5EA45006142EE /* scheduler.c in Sources */, + 29A427341BDBE435001E6E22 /* wren_opt_meta.c in Sources */, 29205C9B1AB4E6430073018D /* wren_debug.c in Sources */, 29205C9D1AB4E6430073018D /* wren_utils.c in Sources */, 29729F311BA70A620099CA20 /* io.c in Sources */, + 29A427361BDBE435001E6E22 /* wren_opt_meta.wren.inc in Sources */, 29205C9E1AB4E6430073018D /* wren_value.c in Sources */, 29205C9F1AB4E6430073018D /* wren_vm.c in Sources */, 29205C8F1AB4E5C90073018D /* main.c in Sources */, - 29AF31FA1BD2E98600AAD156 /* wren_aux_random.wren.inc in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -351,10 +351,11 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 29A427371BDBE435001E6E22 /* wren_opt_meta.wren.inc in Sources */, 29729F321BA70A620099CA20 /* io.c in Sources */, 291647C81BA5EC5E006142EE /* modules.c in Sources */, 29DC14A11BBA2FEC008A8274 /* scheduler.c in Sources */, - 29AF31F21BD2E38F00AAD156 /* wren_aux_meta.c in Sources */, + 29A427391BDBE435001E6E22 /* wren_opt_random.c in Sources */, 29DC14A01BBA2FD6008A8274 /* timer.c in Sources */, 29DC149F1BBA2FCC008A8274 /* vm.c in Sources */, 29DC14A21BBA300A008A8274 /* wren_compiler.c in Sources */, @@ -362,15 +363,14 @@ 29DC14A41BBA3010008A8274 /* wren_debug.c in Sources */, 29DC14A61BBA3017008A8274 /* wren_primitive.c in Sources */, 29DC14A71BBA301A008A8274 /* wren_utils.c in Sources */, - 29AF31FB1BD2E98600AAD156 /* wren_aux_random.wren.inc in Sources */, - 29AF31F91BD2E98600AAD156 /* wren_aux_random.c in Sources */, 29DC14A81BBA301D008A8274 /* wren_value.c in Sources */, + 29A4273B1BDBE435001E6E22 /* wren_opt_random.wren.inc in Sources */, 29DC14A91BBA302F008A8274 /* wren_vm.c in Sources */, 29DC14AA1BBA3032008A8274 /* main.c in Sources */, 293D46961BB43F9900200083 /* call.c in Sources */, + 29A427351BDBE435001E6E22 /* wren_opt_meta.c in Sources */, 29DC14AB1BBA3038008A8274 /* foreign_class.c in Sources */, 29DC14AC1BBA303D008A8274 /* returns.c in Sources */, - 29AF31F71BD2E98600AAD156 /* wren_aux_meta.wren.inc in Sources */, 29DC14AD1BBA3040008A8274 /* value.c in Sources */, ); runOnlyForDeploymentPostprocessing = 0;