Tests for IO.read().

This commit is contained in:
Bob Nystrom
2015-01-11 21:47:29 -08:00
parent 7a7c7a8fad
commit 1d9445d9bc
8 changed files with 44 additions and 5 deletions
+1 -1
View File
@@ -1202,7 +1202,7 @@ void wrenInitializeCore(WrenVM* vm)
vm->numClass->name->obj.classObj = vm->stringClass;
vm->stringClass->name->obj.classObj = vm->stringClass;
wrenInterpret(vm, "Wren core library", libSource);
wrenInterpret(vm, "", libSource);
vm->listClass = AS_CLASS(findGlobal(vm, "List"));
NATIVE(vm->listClass->obj.classObj, " instantiate", list_instantiate);
+6
View File
@@ -19,6 +19,12 @@ void wrenDebugPrintStackTrace(WrenVM* vm, ObjFiber* fiber)
fn = ((ObjClosure*)frame->fn)->fn;
}
// Built-in libraries 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->debug->sourcePath->length == 0) 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",
+2 -1
View File
@@ -93,6 +93,7 @@ static const char* libSource =
" }\n"
"\n"
" static read(prompt) {\n"
" if (!(prompt is String)) Fiber.abort(\"Prompt must be a string.\")\n"
" IO.write(prompt)\n"
" return IO.read\n"
" }\n"
@@ -133,7 +134,7 @@ static void ioClock(WrenVM* vm)
void wrenLoadIOLibrary(WrenVM* vm)
{
wrenInterpret(vm, "Wren IO library", libSource);
wrenInterpret(vm, "", libSource);
wrenDefineStaticMethod(vm, "IO", "writeString_", 1, ioWriteString);
wrenDefineStaticMethod(vm, "IO", "clock", 0, ioClock);
wrenDefineStaticMethod(vm, "IO", "read", 0, ioRead);