Get rid of source path in module.
It wasn't useful anyway since it always had the module name for all but the main script.
This commit is contained in:
@@ -307,7 +307,7 @@ static void lexError(Parser* parser, const char* format, ...)
|
||||
if (!parser->printErrors) return;
|
||||
|
||||
fprintf(stderr, "[%s line %d] Error: ",
|
||||
parser->module->sourcePath->value, parser->currentLine);
|
||||
parser->module->name->value, parser->currentLine);
|
||||
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
@@ -337,7 +337,7 @@ static void error(Compiler* compiler, const char* format, ...)
|
||||
if (token->type == TOKEN_ERROR) return;
|
||||
|
||||
fprintf(stderr, "[%s line %d] Error at ",
|
||||
compiler->parser->module->sourcePath->value, token->line);
|
||||
compiler->parser->module->name->value, token->line);
|
||||
|
||||
if (token->type == TOKEN_LINE)
|
||||
{
|
||||
|
||||
+2
-6
@@ -1047,11 +1047,7 @@ static void fnCall(WrenVM* vm, const char* signature)
|
||||
|
||||
void wrenInitializeCore(WrenVM* vm)
|
||||
{
|
||||
ObjString* name = AS_STRING(CONST_STRING(vm, "core"));
|
||||
wrenPushRoot(vm, (Obj*)name);
|
||||
|
||||
ObjModule* coreModule = wrenNewModule(vm, name, NULL);
|
||||
wrenPopRoot(vm); // name.
|
||||
ObjModule* coreModule = wrenNewModule(vm, NULL);
|
||||
wrenPushRoot(vm, (Obj*)coreModule);
|
||||
|
||||
// The core module's key is null in the module map.
|
||||
@@ -1112,7 +1108,7 @@ void wrenInitializeCore(WrenVM* vm)
|
||||
// '---------' '-------------------' -'
|
||||
|
||||
// The rest of the classes can now be defined normally.
|
||||
wrenInterpretInModule(vm, NULL, "", coreModuleSource);
|
||||
wrenInterpretInModule(vm, NULL, coreModuleSource);
|
||||
|
||||
vm->boolClass = AS_CLASS(wrenFindVariable(vm, coreModule, "Bool"));
|
||||
PRIMITIVE(vm->boolClass, "toString", bool_toString);
|
||||
|
||||
+7
-12
@@ -20,20 +20,15 @@ void wrenDebugPrintStackTrace(ObjFiber* fiber)
|
||||
CallFrame* frame = &fiber->frames[i];
|
||||
ObjFn* fn = wrenGetFrameFunction(frame);
|
||||
|
||||
// Built-in libraries and method call stubs have no source path and are
|
||||
// explicitly omitted from stack traces since we don't want to highlight to
|
||||
// a user the implementation detail of what part of a core library is
|
||||
// implemented in C and what is in Wren.
|
||||
if (fn->module->sourcePath == NULL ||
|
||||
fn->module->sourcePath->length == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// The built-in core module has no name. We explicitly omit it from stack
|
||||
// traces since we don't want to highlight to a user the implementation
|
||||
// detail of what part of the core module is written in C and what is Wren.
|
||||
if (fn->module->name == NULL) continue;
|
||||
|
||||
// -1 because IP has advanced past the instruction that it just executed.
|
||||
int line = fn->debug->sourceLines[frame->ip - fn->bytecode - 1];
|
||||
fprintf(stderr, "[%s line %d] in %s\n",
|
||||
fn->module->sourcePath->value, line, fn->debug->name);
|
||||
fn->module->name->value, line, fn->debug->name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -354,7 +349,7 @@ int wrenDumpInstruction(WrenVM* vm, ObjFn* fn, int i)
|
||||
|
||||
void wrenDumpCode(WrenVM* vm, ObjFn* fn)
|
||||
{
|
||||
printf("%s: %s\n", fn->module->sourcePath->value, fn->debug->name);
|
||||
printf("%s: %s\n", fn->module->name->value, fn->debug->name);
|
||||
|
||||
int i = 0;
|
||||
int lastLine = -1;
|
||||
|
||||
+1
-1
@@ -48,7 +48,7 @@ void wrenLoadMetaModule(WrenVM* vm)
|
||||
WrenBindForeignMethodFn previousBindFn = vm->config.bindForeignMethodFn;
|
||||
vm->config.bindForeignMethodFn = bindMetaForeignMethods;
|
||||
|
||||
wrenInterpretInModule(vm, "meta", "meta", metaModuleSource);
|
||||
wrenInterpretInModule(vm, "meta", metaModuleSource);
|
||||
|
||||
vm->config.bindForeignMethodFn = previousBindFn;
|
||||
}
|
||||
|
||||
+1
-4
@@ -551,7 +551,7 @@ Value wrenMapRemoveKey(WrenVM* vm, ObjMap* map, Value key)
|
||||
return value;
|
||||
}
|
||||
|
||||
ObjModule* wrenNewModule(WrenVM* vm, ObjString* name, ObjString* path)
|
||||
ObjModule* wrenNewModule(WrenVM* vm, ObjString* name)
|
||||
{
|
||||
ObjModule* module = ALLOCATE(vm, ObjModule);
|
||||
|
||||
@@ -564,7 +564,6 @@ ObjModule* wrenNewModule(WrenVM* vm, ObjString* name, ObjString* path)
|
||||
wrenValueBufferInit(&module->variables);
|
||||
|
||||
module->name = name;
|
||||
module->sourcePath = path;
|
||||
|
||||
wrenPopRoot(vm);
|
||||
return module;
|
||||
@@ -1005,8 +1004,6 @@ static void markModule(WrenVM* vm, ObjModule* module)
|
||||
|
||||
wrenMarkObj(vm, (Obj*)module->name);
|
||||
|
||||
wrenMarkObj(vm, (Obj*)module->sourcePath);
|
||||
|
||||
// Keep track of how much memory is still in use.
|
||||
vm->bytesAllocated += sizeof(ObjModule);
|
||||
// TODO: Track memory for symbol table and buffer.
|
||||
|
||||
+1
-4
@@ -286,9 +286,6 @@ typedef struct
|
||||
|
||||
// The name of the module.
|
||||
ObjString* name;
|
||||
|
||||
// The path to the source file where this module was loaded.
|
||||
ObjString* sourcePath;
|
||||
} ObjModule;
|
||||
|
||||
// A first-class function object. A raw ObjFn can be used and invoked directly
|
||||
@@ -696,7 +693,7 @@ void wrenMapClear(WrenVM* vm, ObjMap* map);
|
||||
Value wrenMapRemoveKey(WrenVM* vm, ObjMap* map, Value key);
|
||||
|
||||
// Creates a new module.
|
||||
ObjModule* wrenNewModule(WrenVM* vm, ObjString* name, ObjString* path);
|
||||
ObjModule* wrenNewModule(WrenVM* vm, ObjString* name);
|
||||
|
||||
// Creates a new range from [from] to [to].
|
||||
Value wrenNewRange(WrenVM* vm, double from, double to, bool isInclusive);
|
||||
|
||||
+4
-6
@@ -443,7 +443,7 @@ static ObjFiber* loadModule(WrenVM* vm, Value name, const char* source)
|
||||
// See if the module has already been loaded.
|
||||
if (module == NULL)
|
||||
{
|
||||
module = wrenNewModule(vm, AS_STRING(name), AS_STRING(name));
|
||||
module = wrenNewModule(vm, AS_STRING(name));
|
||||
|
||||
// Store it in the VM's module registry so we don't load the same module
|
||||
// multiple times.
|
||||
@@ -1446,15 +1446,13 @@ void* wrenAllocateForeign(WrenVM* vm, size_t size)
|
||||
return (void*)foreign->data;
|
||||
}
|
||||
|
||||
WrenInterpretResult wrenInterpret(WrenVM* vm, const char* sourcePath,
|
||||
const char* source)
|
||||
WrenInterpretResult wrenInterpret(WrenVM* vm, const char* source)
|
||||
{
|
||||
return wrenInterpretInModule(vm, "main", sourcePath, source);
|
||||
return wrenInterpretInModule(vm, "main", source);
|
||||
}
|
||||
|
||||
WrenInterpretResult wrenInterpretInModule(WrenVM* vm, const char* module,
|
||||
const char* sourcePath,
|
||||
const char* source)
|
||||
const char* source)
|
||||
{
|
||||
Value nameValue = NULL_VAL;
|
||||
if (module != NULL)
|
||||
|
||||
+1
-2
@@ -133,8 +133,7 @@ WrenValue* wrenCaptureValue(WrenVM* vm, Value value);
|
||||
|
||||
// Executes [source] in the context of [module].
|
||||
WrenInterpretResult wrenInterpretInModule(WrenVM* vm, const char* module,
|
||||
const char* sourcePath,
|
||||
const char* source);
|
||||
const char* source);
|
||||
|
||||
// Imports the module with [name].
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user