on master help sign in
add julia
commit3c0e9fa294c802bcaf9fa52cc64f4f645dca2874 authormason clayton <masongclayton@gmail.com> dateTue 19 Feb 2019, 20:23 (8 years ago) parent62e165f
12 files changed+184−3
Makefile+1−1 languages/R/main.go+2 languages/julia/main.go+53 languages/julia/pry.h+115 languages/lua/main.go+2 languages/python2/main.go+2 languages/python3/main.go+2 languages/ruby/main.go+2 languages/spidermonkey/main.go+2 languages/tcl/main.go+2 scripts/inject.sh+1−1 tests/python2/1_plus_1.exp−1
Makefile+1−1
@@ -9,7 +9,7 @@ all: $(BINS)
99prybar-%: ./languages/$(*) ./utils/* ./linenoise/* ./languages/$(*)/*
1010 ./scripts/inject.sh $(*)
1111 go generate ./languages/$(*)/main.go
12− CGO_LDFLAGS_ALLOW=".*" go build -o prybar-$(*) ./languages/$(*)
12+ PKG_CONFIG="pkg-config" PKG_CONFIG_PATH=./languages/julia CGO_LDFLAGS_ALLOW=".*" go build -o prybar-$(*) ./languages/$(*)
1313 rm ./languages/$(*)/generated_*.go
1414
1515test:
languages/R/main.go+2
@@ -1,5 +1,7 @@
11package main
22
3+// USING_CGO
4+
35/*
46#cgo pkg-config: libr
57#include <stdlib.h>
languages/julia/main.gonew file+53
@@ -0,0 +1,53 @@
1+package main
2+
3+// USING_CGO
4+
5+/*
6+#cgo LDFLAGS: -ljulia
7+#include "pry.h"
8+*/
9+import "C"
10+
11+import (
12+ "unsafe"
13+)
14+
15+type Julia struct{}
16+
17+func (p Julia) Open() {
18+ C.setup()
19+}
20+
21+func (p Julia) SetPrompts(ps1, ps2 string) {
22+ cps1 := C.CString(ps1)
23+ defer C.free(unsafe.Pointer(cps1))
24+
25+ C.set_prompt(cps1)
26+}
27+
28+func (p Julia) Version() string {
29+ return C.GoString(C.get_banner())
30+}
31+
32+func (p Julia) Eval(code string) {
33+ cstr := C.CString(code)
34+ defer C.free(unsafe.Pointer(cstr))
35+
36+ C.eval(cstr)
37+}
38+
39+func (p Julia) EvalFile(file string, args []string) {
40+ cstr := C.CString(file)
41+ C.eval_file(cstr)
42+ C.free(unsafe.Pointer(cstr))
43+}
44+
45+func (p Julia) REPL() {
46+ C.run_repl()
47+}
48+
49+func (p Julia) Close() {
50+ C.cleanup()
51+}
52+
53+var Instance = Julia{}
languages/julia/pry.hnew file+115
@@ -0,0 +1,115 @@
1+// This file is a part of Julia. License is MIT: https://julialang.org/license
2+
3+/*
4+ repl.c
5+ system startup, main(), and console interaction
6+*/
7+
8+#define JULIA_ENABLE_THREADING
9+
10+#include <assert.h>
11+#include <ctype.h>
12+#include <errno.h>
13+#include <inttypes.h>
14+#include <limits.h>
15+#include <math.h>
16+#include <setjmp.h>
17+#include <signal.h>
18+#include <stdarg.h>
19+#include <stdio.h>
20+#include <stdlib.h>
21+#include <string.h>
22+#include <sys/stat.h>
23+#include <sys/types.h>
24+#include <time.h>
25+
26+#include <julia/julia.h>
27+#include <julia/uv.h>
28+
29+JULIA_DEFINE_FAST_TLS()
30+
31+void fancy_repl(void) {
32+ assert(jl_base_module && "oh no, we have no repl?");
33+
34+ jl_function_t *start_client =
35+ (jl_function_t *)jl_get_global(jl_base_module, jl_symbol("_start"));
36+
37+ JL_TRY {
38+ size_t last_age = jl_get_ptls_states()->world_age;
39+ jl_get_ptls_states()->world_age = jl_get_world_counter();
40+
41+ jl_apply(&start_client, 1);
42+
43+ jl_get_ptls_states()->world_age = last_age;
44+ }
45+ JL_CATCH { jl_no_exc_handler(jl_current_exception()); }
46+}
47+
48+static int exec_program(const char *program) {
49+ JL_TRY { jl_load(jl_main_module, program); }
50+ JL_CATCH {
51+ jl_value_t *errs = jl_stderr_obj();
52+ volatile int shown_err = 0;
53+ jl_printf(JL_STDERR, "error during bootstrap:\n");
54+ JL_TRY {
55+ if (errs) {
56+ jl_value_t *showf = jl_get_function(jl_base_module, "show");
57+ if (showf != NULL) {
58+ jl_call2(showf, errs, jl_current_exception());
59+ jl_printf(JL_STDERR, "\n");
60+ shown_err = 1;
61+ }
62+ }
63+ }
64+ JL_CATCH {}
65+ if (!shown_err) {
66+ jl_static_show(JL_STDERR, jl_current_exception());
67+ jl_printf(JL_STDERR, "\n");
68+ }
69+ jlbacktrace();
70+ jl_printf(JL_STDERR, "\n");
71+ return 1;
72+ }
73+ return 0;
74+}
75+
76+const char *get_banner(void) {
77+ jl_value_t *ret = jl_eval_string("io = IOBuffer(); Base.banner(IOContext(io, "
78+ ":color => true)); String(take!(io))");
79+
80+ assert(jl_typeis(ret, jl_string_type) && "banner should be a string");
81+
82+ return jl_string_ptr(ret);
83+}
84+
85+void setup() {
86+ jl_init();
87+ libsupport_init();
88+
89+ jl_options.banner = 0;
90+ jl_options.color = 1;
91+
92+ jl_eval_string("import REPL");
93+ jl_set_global(jl_base_module, jl_symbol("replit_prompt"),
94+ jl_cstr_to_string("julia> "));
95+ jl_eval_string(
96+ "atreplinit(function (r)"
97+ "r.interface = REPL.setup_interface(r, true, r.options.extra_keymap); "
98+ "r.interface.modes[1].prompt=Base.replit_prompt;"
99+ "r.interface.modes[2].prompt=\"shell> \";"
100+ "r.interface.modes[3].prompt=\"help?> \";"
101+ "end)");
102+}
103+
104+void cleanup() { jl_atexit_hook(0); }
105+
106+void eval(const char *str) { jl_eval_string(str); }
107+
108+void eval_file(const char *path) { exec_program(path); }
109+
110+void run_repl() { fancy_repl(); }
111+
112+void set_prompt(const char *prompt) {
113+ jl_set_global(jl_base_module, jl_symbol("replit_prompt"),
114+ jl_cstr_to_string(prompt));
115+}
languages/lua/main.go+2
@@ -1,5 +1,7 @@
11package main
22
3+// USING_CGO
4+
35/*
46#cgo pkg-config: lua-5.2
57#include <stdlib.h>
languages/python2/main.go+2
@@ -1,5 +1,7 @@
11package main
22
3+// USING_CGO
4+
35/*
46#cgo pkg-config: python2
57#include "pry_python2.h"
languages/python3/main.go+2
@@ -1,5 +1,7 @@
11package main
22
3+// USING_CGO
4+
35/*
46#cgo pkg-config: python3
57#include "pry_python3.h"
languages/ruby/main.go+2
@@ -1,5 +1,7 @@
11package main
22
3+// USING_CGO
4+
35/*
46#cgo pkg-config: ruby-2.5
57#include "pry_ruby.h"
languages/spidermonkey/main.go+2
@@ -1,5 +1,7 @@
11package main
22
3+// USING_CGO
4+
35/*
46#cgo pkg-config: mozjs185
57#include "jsapi.h"
languages/tcl/main.go+2
@@ -1,5 +1,7 @@
11package main
22
3+// USING_CGO
4+
35/*
46#cgo pkg-config: tcl
57#include "pry_tcl.h"
scripts/inject.sh+1−1
@@ -1,6 +1,6 @@
11#!/bin/bash
22
3−if grep "#cgo pkg-config" ./languages/$1/main.go; then
3+if grep "USING_CGO" ./languages/$1/main.go; then
44 cp inject_claunch.go ./languages/$1/generated_launch.go
55else
66 cp inject_elaunch.go ./languages/$1/generated_launch.go
tests/python2/1_plus_1.exp−1
@@ -2,7 +2,6 @@
22
33spawn ./prybar-python2 -i
44match_max 100000
5−expect "Python 2.*"
65expect -exact "--> "
76send -- "1+1\r"
87expect -exact "1+1\r