Relative imports!

This is a breaking change because existing imports in user Wren code
that assume the path is relative to the entrypoint file will now likely
fail.

Also, stack trace output and host API calls that take a module string
now need the resolved module string, not the short name that appears in
the import.
This commit is contained in:
Bob Nystrom
2018-03-24 11:10:36 -07:00
parent 5539c59750
commit 8210452970
41 changed files with 152 additions and 107 deletions
+1 -1
View File
@@ -6,7 +6,7 @@
void callRunTests(WrenVM* vm)
{
wrenEnsureSlots(vm, 1);
wrenGetVariable(vm, "main", "Call", 0);
wrenGetVariable(vm, "test/api/call", "Call", 0);
WrenHandle* callClass = wrenGetSlotHandle(vm, 0);
WrenHandle* noParams = wrenMakeCallHandle(vm, "noParams");
+5 -5
View File
@@ -4,23 +4,23 @@
static void beforeDefined(WrenVM* vm)
{
wrenGetVariable(vm, "main", "A", 0);
wrenGetVariable(vm, "test/api/get_variable", "A", 0);
}
static void afterDefined(WrenVM* vm)
{
wrenGetVariable(vm, "main", "A", 0);
wrenGetVariable(vm, "test/api/get_variable", "A", 0);
}
static void afterAssigned(WrenVM* vm)
{
wrenGetVariable(vm, "main", "A", 0);
wrenGetVariable(vm, "test/api/get_variable", "A", 0);
}
static void otherSlot(WrenVM* vm)
{
wrenEnsureSlots(vm, 3);
wrenGetVariable(vm, "main", "B", 2);
wrenGetVariable(vm, "test/api/get_variable", "B", 2);
// Move it into return position.
const char* string = wrenGetSlotString(vm, 2);
@@ -29,7 +29,7 @@ static void otherSlot(WrenVM* vm)
static void otherModule(WrenVM* vm)
{
wrenGetVariable(vm, "get_variable_module", "Variable", 0);
wrenGetVariable(vm, "test/api/get_variable_module", "Variable", 0);
}
WrenForeignMethodFn getVariableBindMethod(const char* signature)
+1 -1
View File
@@ -1,4 +1,4 @@
import "get_variable_module"
import "./get_variable_module"
class GetVariable {
foreign static beforeDefined()
+3 -3
View File
@@ -24,8 +24,8 @@ const char* testName;
static WrenForeignMethodFn bindForeignMethod(
WrenVM* vm, const char* module, const char* className,
bool isStatic, const char* signature)
{
if (strcmp(module, "main") != 0) return NULL;
{
if (strncmp(module, "test/", 5) != 0) return NULL;
// For convenience, concatenate all of the method qualifiers into a single
// signature string.
@@ -78,7 +78,7 @@ static WrenForeignClassMethods bindForeignClass(
WrenVM* vm, const char* module, const char* className)
{
WrenForeignClassMethods methods = { NULL, NULL };
if (strcmp(module, "main") != 0) return methods;
if (strncmp(module, "test/", 5) != 0) return methods;
foreignClassBindClass(className, &methods);
if (methods.allocate != NULL) return methods;
+2 -2
View File
@@ -6,7 +6,7 @@
void resetStackAfterCallAbortRunTests(WrenVM* vm)
{
wrenEnsureSlots(vm, 1);
wrenGetVariable(vm, "main", "Test", 0);
wrenGetVariable(vm, "test/api/reset_stack_after_call_abort", "Test", 0);
WrenHandle* testClass = wrenGetSlotHandle(vm, 0);
WrenHandle* abortFiber = wrenMakeCallHandle(vm, "abortFiber()");
@@ -25,4 +25,4 @@ void resetStackAfterCallAbortRunTests(WrenVM* vm)
wrenReleaseHandle(vm, testClass);
wrenReleaseHandle(vm, abortFiber);
wrenReleaseHandle(vm, afterConstruct);
}
}
@@ -22,7 +22,7 @@ void resetStackAfterForeignConstructBindClass(
void resetStackAfterForeignConstructRunTests(WrenVM* vm)
{
wrenEnsureSlots(vm, 1);
wrenGetVariable(vm, "main", "Test", 0);
wrenGetVariable(vm, "test/api/reset_stack_after_foreign_construct", "Test", 0);
WrenHandle* testClass = wrenGetSlotHandle(vm, 0);
WrenHandle* callConstruct = wrenMakeCallHandle(vm, "callConstruct()");
@@ -41,4 +41,4 @@ void resetStackAfterForeignConstructRunTests(WrenVM* vm)
wrenReleaseHandle(vm, testClass);
wrenReleaseHandle(vm, callConstruct);
wrenReleaseHandle(vm, afterConstruct);
}
}