2015-05-24 09:23:30 -07:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
#include "vm.h"
|
|
|
|
|
#include "wren.h"
|
|
|
|
|
|
2015-12-15 16:02:13 -08:00
|
|
|
#include "benchmark.h"
|
2015-09-24 08:02:31 -07:00
|
|
|
#include "call.h"
|
2016-06-09 19:14:21 -07:00
|
|
|
#include "error.h"
|
2015-12-26 10:53:14 -08:00
|
|
|
#include "get_variable.h"
|
2015-08-15 12:07:53 -07:00
|
|
|
#include "foreign_class.h"
|
2016-05-20 20:55:28 -07:00
|
|
|
#include "handle.h"
|
2015-12-16 16:28:26 -08:00
|
|
|
#include "lists.h"
|
2016-03-03 14:31:47 -08:00
|
|
|
#include "new_vm.h"
|
2015-12-16 13:00:13 -08:00
|
|
|
#include "slots.h"
|
2015-08-15 12:07:53 -07:00
|
|
|
|
2015-05-24 09:23:30 -07:00
|
|
|
// The name of the currently executing API test.
|
|
|
|
|
const char* testName;
|
|
|
|
|
|
2015-08-15 12:07:53 -07:00
|
|
|
static WrenForeignMethodFn bindForeignMethod(
|
2015-05-24 09:23:30 -07:00
|
|
|
WrenVM* vm, const char* module, const char* className,
|
|
|
|
|
bool isStatic, const char* signature)
|
2015-12-15 16:02:13 -08:00
|
|
|
{
|
2015-05-24 09:23:30 -07:00
|
|
|
if (strcmp(module, "main") != 0) return NULL;
|
|
|
|
|
|
|
|
|
|
// For convenience, concatenate all of the method qualifiers into a single
|
|
|
|
|
// signature string.
|
|
|
|
|
char fullName[256];
|
|
|
|
|
fullName[0] = '\0';
|
|
|
|
|
if (isStatic) strcat(fullName, "static ");
|
|
|
|
|
strcat(fullName, className);
|
|
|
|
|
strcat(fullName, ".");
|
|
|
|
|
strcat(fullName, signature);
|
2015-12-15 16:02:13 -08:00
|
|
|
|
|
|
|
|
WrenForeignMethodFn method = NULL;
|
|
|
|
|
|
|
|
|
|
method = benchmarkBindMethod(fullName);
|
|
|
|
|
if (method != NULL) return method;
|
2016-06-09 19:14:21 -07:00
|
|
|
|
|
|
|
|
method = errorBindMethod(fullName);
|
|
|
|
|
if (method != NULL) return method;
|
2015-12-26 10:53:14 -08:00
|
|
|
|
|
|
|
|
method = getVariableBindMethod(fullName);
|
|
|
|
|
if (method != NULL) return method;
|
|
|
|
|
|
2015-12-15 16:02:13 -08:00
|
|
|
method = foreignClassBindMethod(fullName);
|
|
|
|
|
if (method != NULL) return method;
|
|
|
|
|
|
2016-05-20 20:55:28 -07:00
|
|
|
method = handleBindMethod(fullName);
|
|
|
|
|
if (method != NULL) return method;
|
|
|
|
|
|
2015-12-16 16:28:26 -08:00
|
|
|
method = listsBindMethod(fullName);
|
|
|
|
|
if (method != NULL) return method;
|
|
|
|
|
|
2016-03-03 14:31:47 -08:00
|
|
|
method = newVMBindMethod(fullName);
|
|
|
|
|
if (method != NULL) return method;
|
|
|
|
|
|
2015-12-16 13:00:13 -08:00
|
|
|
method = slotsBindMethod(fullName);
|
2015-12-15 16:02:13 -08:00
|
|
|
if (method != NULL) return method;
|
2015-05-24 09:23:30 -07:00
|
|
|
|
|
|
|
|
fprintf(stderr,
|
|
|
|
|
"Unknown foreign method '%s' for test '%s'\n", fullName, testName);
|
2015-05-24 10:04:24 -07:00
|
|
|
exit(1);
|
2015-05-24 09:23:30 -07:00
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-15 12:07:53 -07:00
|
|
|
static WrenForeignClassMethods bindForeignClass(
|
|
|
|
|
WrenVM* vm, const char* module, const char* className)
|
|
|
|
|
{
|
|
|
|
|
WrenForeignClassMethods methods = { NULL, NULL };
|
|
|
|
|
if (strcmp(module, "main") != 0) return methods;
|
|
|
|
|
|
2015-12-15 16:02:13 -08:00
|
|
|
foreignClassBindClass(className, &methods);
|
2016-02-19 07:18:00 -08:00
|
|
|
if (methods.allocate != NULL) return methods;
|
|
|
|
|
|
|
|
|
|
slotsBindClass(className, &methods);
|
|
|
|
|
if (methods.allocate != NULL) return methods;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fprintf(stderr,
|
|
|
|
|
"Unknown foreign class '%s' for test '%s'\n", className, testName);
|
|
|
|
|
exit(1);
|
2015-08-15 12:07:53 -07:00
|
|
|
return methods;
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-29 19:29:10 -07:00
|
|
|
static void afterLoad(WrenVM* vm) {
|
2015-12-23 17:29:53 -08:00
|
|
|
if (strstr(testName, "/call.wren") != NULL) callRunTests(vm);
|
2015-09-29 19:29:10 -07:00
|
|
|
}
|
|
|
|
|
|
2015-05-24 09:23:30 -07:00
|
|
|
int main(int argc, const char* argv[])
|
|
|
|
|
{
|
|
|
|
|
if (argc != 2)
|
|
|
|
|
{
|
|
|
|
|
fprintf(stderr, "Usage: wren <test>\n");
|
|
|
|
|
return 64; // EX_USAGE.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
testName = argv[1];
|
2015-09-29 19:29:10 -07:00
|
|
|
setTestCallbacks(bindForeignMethod, bindForeignClass, afterLoad);
|
2015-12-15 16:02:13 -08:00
|
|
|
runFile(testName);
|
2015-05-24 09:23:30 -07:00
|
|
|
return 0;
|
|
|
|
|
}
|