|
|
@ -7,6 +7,8 @@
|
|
7
|
7
|
|
|
8
|
8
|
#include <JavaScriptCore/JavaScript.h>
|
|
9
|
9
|
|
|
|
10
|
#include "linenoise.h"
|
|
|
11
|
|
|
10
|
12
|
#include "zip.h"
|
|
11
|
13
|
|
|
12
|
14
|
#define CONSOLE_LOG_BUF_SIZE 1000
|
|
|
@ -15,7 +17,7 @@ char console_log_buf[CONSOLE_LOG_BUF_SIZE];
|
|
15
|
17
|
JSStringRef to_string(JSContextRef ctx, JSValueRef val);
|
|
16
|
18
|
JSValueRef evaluate_script(JSContextRef ctx, char *script, char *source);
|
|
17
|
19
|
|
|
18
|
|
void evaluate_source(JSContextRef ctx, char *type, char *source_value, bool expression, char *set_ns);
|
|
|
20
|
JSValueRef evaluate_source(JSContextRef ctx, char *type, char *source_value, bool expression, char *set_ns);
|
|
19
|
21
|
char *munge(char *s);
|
|
20
|
22
|
|
|
21
|
23
|
void bootstrap(JSContextRef ctx, char *deps_file_path, char *goog_base_path);
|
|
|
@ -304,19 +306,27 @@ int main(int argc, char **argv) {
|
|
304
|
306
|
printf("---\nrequire macros\n---\n");
|
|
305
|
307
|
evaluate_source(ctx, "text", "(require-macros 'planck.repl 'planck.core 'planck.shell 'planck.from.io.aviso.ansi 'clojure.template 'cljs.spec 'cljs.spec.impl.gen 'cljs.test)", true, "cljs.user");
|
|
306
|
308
|
|
|
307
|
|
char *script;
|
|
308
|
|
if (argc == 0) {
|
|
309
|
|
script = "CONSOLE_LOG(\"Hello, World!\");";
|
|
310
|
|
} else {
|
|
311
|
|
script = argv[1];
|
|
|
309
|
if (repl) {
|
|
|
310
|
bool javascript = false;
|
|
|
311
|
char *prompt = javascript ? " > " : " => ";
|
|
|
312
|
|
|
|
313
|
char *line;
|
|
|
314
|
while ((line = linenoise(prompt)) != NULL) {
|
|
|
315
|
JSValueRef res = NULL;
|
|
|
316
|
if (javascript) {
|
|
|
317
|
res = evaluate_script(ctx, line, "<stdin>");
|
|
|
318
|
} else {
|
|
|
319
|
res = evaluate_source(ctx, "text", line, true, "cljs.user");
|
|
|
320
|
}
|
|
|
321
|
free(line);
|
|
|
322
|
|
|
|
323
|
char res_buf[1000];
|
|
|
324
|
res_buf[0] = '\0';
|
|
|
325
|
JSStringRef res_str = to_string(ctx, res);
|
|
|
326
|
JSStringGetUTF8CString(res_str, res_buf, 1000);
|
|
|
327
|
printf("%s\n", res_buf);
|
|
|
328
|
}
|
|
312
|
329
|
}
|
|
313
|
|
JSValueRef res = evaluate_script(ctx, script, "<inline>");
|
|
314
|
|
|
|
315
|
|
char res_buf[1000];
|
|
316
|
|
res_buf[0] = '\0';
|
|
317
|
|
JSStringRef res_str = to_string(ctx, res);
|
|
318
|
|
JSStringGetUTF8CString(res_str, res_buf, 1000);
|
|
319
|
|
printf("%s\n", res_buf);
|
|
320
|
330
|
}
|
|
321
|
331
|
|
|
322
|
332
|
JSStringRef to_string(JSContextRef ctx, JSValueRef val) {
|
|
|
@ -394,7 +404,7 @@ JSObjectRef get_function(JSContextRef ctx, char *namespace, char *name) {
|
|
394
|
404
|
return JSValueToObject(ctx, val, NULL);
|
|
395
|
405
|
}
|
|
396
|
406
|
|
|
397
|
|
void evaluate_source(JSContextRef ctx, char *type, char *source, bool expression, char *set_ns) {
|
|
|
407
|
JSValueRef evaluate_source(JSContextRef ctx, char *type, char *source, bool expression, char *set_ns) {
|
|
398
|
408
|
JSValueRef args[7];
|
|
399
|
409
|
int num_args = 7;
|
|
400
|
410
|
|
|
|
@ -419,10 +429,12 @@ void evaluate_source(JSContextRef ctx, char *type, char *source, bool expression
|
|
419
|
429
|
JSObjectRef execute_fn = get_function(ctx, "planck.repl", "execute");
|
|
420
|
430
|
JSObjectRef global_obj = JSContextGetGlobalObject(ctx);
|
|
421
|
431
|
JSValueRef ex = NULL;
|
|
422
|
|
JSObjectCallAsFunction(ctx, execute_fn, global_obj, num_args, args, &ex);
|
|
|
432
|
JSValueRef val = JSObjectCallAsFunction(ctx, execute_fn, global_obj, num_args, args, &ex);
|
|
423
|
433
|
|
|
424
|
434
|
debug_print_value
|
|
425
|
435
|
("planck.repl/execute", ctx, ex);
|
|
|
436
|
|
|
|
437
|
return ex != NULL ? ex : val;
|
|
426
|
438
|
}
|
|
427
|
439
|
|
|
428
|
440
|
char *munge(char *s) {
|