static jmp_buf ctrlc_;
-void sigint(int) {
+static void sigint(int) {
longjmp(ctrlc_, 1);
}
+static JSStringRef Result_;
+
void Run(const char *code, FILE *fout) { _pooled
JSStringRef script(JSStringCreateWithUTF8CString(code));
JSValueRef result(JSEvaluateScript(context, script, NULL, NULL, 0, &exception));
JSStringRelease(script);
- if (exception != NULL)
+ if (exception != NULL) { error:
result = exception;
+ exception = NULL;
+ }
if (!JSValueIsUndefined(context, result)) {
- CFStringRef json;
+ CYPool pool;
+ const char *json;
- @try { json:
- json = CYCopyJSONString(context, result);
- } @catch (id error) {
- CYThrow(context, error, &result);
- goto json;
- }
+ json = CYPoolJSONString(pool, context, result, &exception);
+ if (exception != NULL)
+ goto error;
+
+ CYSetProperty(context, CYGetGlobalObject(context), Result_, result);
if (fout != NULL) {
- fputs([reinterpret_cast<const NSString *>(json) UTF8String], fout);
+ fputs(json, fout);
fputs("\n", fout);
fflush(fout);
}
-
- CFRelease(json);
}
}
-void Console() {
+static void Console() {
bool bypass(false);
bool debug(false);
fflush(fout);
}
-void *Map(const char *path, size_t *psize) {
+static void *Map(const char *path, size_t *psize) {
int fd;
_syscall(fd = open(path, O_RDONLY));
script = argv[1];
}
+ Result_ = CYCopyJSString("_");
+
if (script == NULL || strcmp(script, "-") == 0)
Console();
else {