on master help sign in
Merge pull request #13 from replit/julia

add julia

commitbaf8845a8420145394992d4fea578bd434391f45 authorMason Clayton <mason@turb.io> dateMon 25 Feb 2019, 12:44 (8 years ago) parent742f732ecc2d2f
19 files changed+301−5
Dockerfile+20−3 Makefile+1−1 languages/R/main.go+2 languages/julia/julia.pc+9 languages/julia/main.go+54 languages/julia/pry.h+114 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 test_files/hi_julia.jl+3 tests/julia/1_plus_1.exp+13 tests/julia/header.exp+9 tests/julia/input.exp+36 tests/julia/print_a_line.exp+13 tests/julia/start_with_file.exp+14
Dockerfile+20−3
@@ -15,11 +15,21 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
1515 expect \
1616 nodejs
1717
18−RUN wget \
19− http://launchpadlibrarian.net/309343864/libmozjs185-dev_1.8.5-1.0.0+dfsg-7_amd64.deb && \
18+RUN wget http://launchpadlibrarian.net/309343864/libmozjs185-dev_1.8.5-1.0.0+dfsg-7_amd64.deb && \
2019 wget http://launchpadlibrarian.net/309343863/libmozjs185-1.0_1.8.5-1.0.0+dfsg-7_amd64.deb && \
2120 dpkg -i libmozjs185*.deb && rm libmozjs185*.deb
2221
22+RUN wget https://julialang-s3.julialang.org/bin/linux/x64/1.1/julia-1.1.0-linux-x86_64.tar.gz && \
23+ tar xf julia-1.1.0-linux-x86_64.tar.gz && \
24+ cd julia-1.1.0 && \
25+ cp -r bin/* /usr/bin/ && \
26+ cp -r include/* /usr/include/ && \
27+ cp -r lib/* /usr/lib/ && \
28+ cp -r share/* /usr/share/ && \
29+ cd .. && \
30+ rm -rf julia-1.1.0-linux-x86_64.tar.gz julia-1.1.0
31+
32+
2333RUN mkdir -p /gocode/src/github.com/replit/prybar
2434
2535ENV GOPATH=/gocode
@@ -28,7 +38,14 @@ WORKDIR /gocode/src/github.com/replit/prybar
2838
2939RUN which node
3040
31−RUN make prybar-python2 prybar-python3 prybar-ruby prybar-lua prybar-spidermonkey prybar-nodejs
41+RUN make \
42+ prybar-python2 \
43+ prybar-python3 \
44+ prybar-ruby \
45+ prybar-lua \
46+ prybar-spidermonkey \
47+ prybar-nodejs \
48+ prybar-julia
3249
3350ENV LC_ALL=C.UTF-8
3451
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+ 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/julia.pcnew file+9
@@ -0,0 +1,9 @@
1+prefix=/usr
2+libdir=${prefix}/lib
3+includedir=${prefix}/include/julia
4+
5+Name: julia
6+Cflags: -I${includedir}
7+Version: 1.1.0
8+Description: it's julia
9+Libs: -L${libdir} -ljulia
languages/julia/main.gonew file+54
@@ -0,0 +1,54 @@
1+package main
2+
3+// USING_CGO
4+
5+/*
6+#cgo CFLAGS: -I/usr/include/julia
7+#cgo LDFLAGS: -ljulia
8+#include "pry.h"
9+*/
10+import "C"
11+
12+import (
13+ "unsafe"
14+)
15+
16+type Julia struct{}
17+
18+func (p Julia) Open() {
19+ C.setup()
20+}
21+
22+func (p Julia) SetPrompts(ps1, ps2 string) {
23+ cps1 := C.CString(ps1)
24+ defer C.free(unsafe.Pointer(cps1))
25+
26+ C.set_prompt(cps1)
27+}
28+
29+func (p Julia) Version() string {
30+ return C.GoString(C.get_banner())
31+}
32+
33+func (p Julia) Eval(code string) {
34+ cstr := C.CString(code)
35+ defer C.free(unsafe.Pointer(cstr))
36+
37+ C.eval(cstr)
38+}
39+
40+func (p Julia) EvalFile(file string, args []string) {
41+ cstr := C.CString(file)
42+ C.eval_file(cstr)
43+ C.free(unsafe.Pointer(cstr))
44+}
45+
46+func (p Julia) REPL() {
47+ C.run_repl()
48+}
49+
50+func (p Julia) Close() {
51+ C.cleanup()
52+}
53+
54+var Instance = Julia{}
languages/julia/pry.hnew file+114
@@ -0,0 +1,114 @@
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.h>
27+
28+JULIA_DEFINE_FAST_TLS()
29+
30+void fancy_repl(void) {
31+ assert(jl_base_module && "oh no, we have no repl?");
32+
33+ jl_function_t *start_client =
34+ (jl_function_t *)jl_get_global(jl_base_module, jl_symbol("_start"));
35+
36+ JL_TRY {
37+ size_t last_age = jl_get_ptls_states()->world_age;
38+ jl_get_ptls_states()->world_age = jl_get_world_counter();
39+
40+ jl_apply(&start_client, 1);
41+
42+ jl_get_ptls_states()->world_age = last_age;
43+ }
44+ JL_CATCH { jl_no_exc_handler(jl_current_exception()); }
45+}
46+
47+static int exec_program(const char *program) {
48+ JL_TRY { jl_load(jl_main_module, program); }
49+ JL_CATCH {
50+ jl_value_t *errs = jl_stderr_obj();
51+ volatile int shown_err = 0;
52+ jl_printf(JL_STDERR, "error during bootstrap:\n");
53+ JL_TRY {
54+ if (errs) {
55+ jl_value_t *showf = jl_get_function(jl_base_module, "show");
56+ if (showf != NULL) {
57+ jl_call2(showf, errs, jl_current_exception());
58+ jl_printf(JL_STDERR, "\n");
59+ shown_err = 1;
60+ }
61+ }
62+ }
63+ JL_CATCH {}
64+ if (!shown_err) {
65+ jl_static_show(JL_STDERR, jl_current_exception());
66+ jl_printf(JL_STDERR, "\n");
67+ }
68+ jlbacktrace();
69+ jl_printf(JL_STDERR, "\n");
70+ return 1;
71+ }
72+ return 0;
73+}
74+
75+const char *get_banner(void) {
76+ jl_value_t *ret = jl_eval_string("io = IOBuffer(); Base.banner(IOContext(io, "
77+ ":color => true)); String(take!(io))");
78+
79+ assert(jl_typeis(ret, jl_string_type) && "banner should be a string");
80+
81+ return jl_string_ptr(ret);
82+}
83+
84+void setup() {
85+ jl_init();
86+ libsupport_init();
87+
88+ jl_options.banner = 0;
89+ jl_options.color = 1;
90+
91+ jl_eval_string("import REPL");
92+ jl_set_global(jl_base_module, jl_symbol("replit_prompt"),
93+ jl_cstr_to_string("julia> "));
94+ jl_eval_string(
95+ "atreplinit(function (r)"
96+ "r.interface = REPL.setup_interface(r, true, r.options.extra_keymap); "
97+ "r.interface.modes[1].prompt=Base.replit_prompt;"
98+ "r.interface.modes[2].prompt=\"shell> \";"
99+ "r.interface.modes[3].prompt=\"help?> \";"
100+ "end)");
101+}
102+
103+void cleanup() { jl_atexit_hook(0); }
104+
105+void eval(const char *str) { jl_eval_string(str); }
106+
107+void eval_file(const char *path) { exec_program(path); }
108+
109+void run_repl() { fancy_repl(); }
110+
111+void set_prompt(const char *prompt) {
112+ jl_set_global(jl_base_module, jl_symbol("replit_prompt"),
113+ jl_cstr_to_string(prompt));
114+}
languages/lua/main.go+2
@@ -1,5 +1,7 @@
11package main
22
3+// USING_CGO
4+
35/*
46#cgo pkg-config: lua-5.1
57#cgo LDFLAGS: -lreadline
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
test_files/hi_julia.jlnew file+3
@@ -0,0 +1,3 @@
1+my_number = 500
2+
3+println("hey from julia")
tests/julia/1_plus_1.expnew file+13
@@ -0,0 +1,13 @@
1+#!/usr/bin/expect -f
2+
3+set timeout -1
4+spawn ./prybar-julia -q -i
5+match_max 100000
6+expect -exact "\[?2004h\r\[0K\[32m\[1m--> \[0m\[0m\r\[4C\r\[4C"
7+send -- "1+1\r"
8+expect -exact "1+1\r\[0K\[32m\[1m--> \[0m\[0m\r\[4C1+1\r\[7C\r
9+\[?2004l\[0m\[0m2\r
10+\r
11+\r\[0K\r\[0K\[32m\[1m--> \[0m\[0m\r\[4C\r\[4C\[?2004h\r\[0K\[32m\[1m--> \[0m\[0m\r\[4C\r\[4C"
12+send -- ""
13+expect eof
tests/julia/header.expnew file+9
@@ -0,0 +1,9 @@
1+#!/usr/bin/expect -f
2+
3+set timeout -1
4+spawn ./prybar-julia -i
5+match_max 100000
6+expect -exact "Version 1.1.0 (2019-01-21)"
7+expect -exact "--> \[0m\[0m\r\[4C\r\[4C"
8+send -- ""
9+expect eof
tests/julia/input.expnew file+36
@@ -0,0 +1,36 @@
1+#!/usr/bin/expect -f
2+
3+set timeout -1
4+spawn ./prybar-julia -i
5+match_max 100000
6+expect -exact "--> \[0m\[0m\r\[4C\r\[4C"
7+send -- "\[200~n = readline()\[201~"
8+expect -exact "\r\[0K\[32m\[1m--> \[0m\[0m\r\[4Cn = readline()\r\[18C"
9+send -- "\r"
10+expect -exact "\r\[0K\[32m\[1m--> \[0m\[0m\r\[4Cn = readline()\r\[18C\r
11+\[?2004l\[0m"
12+send -- "hello\r"
13+expect -exact "hello\r
14+\[0m\"hello\"\r
15+\r
16+\r\[0K\r\[0K\[32m\[1m--> \[0m\[0m\r\[4C\r\[4C\[?2004h\r\[0K\[32m\[1m--> \[0m\[0m\r\[4C\r\[4C"
17+send -- "println(hel"
18+expect -exact "\r\[0K\[32m\[1m--> \[0m\[0m\r\[4Cprintln(he\r\[14C"
19+send -- ""
20+expect -exact "\r\[0K\[32m\[1m--> \[0m\[0m\r\[4Cprintln(h\r\[13C"
21+send -- ""
22+expect -exact "\r\[0K\[32m\[1m--> \[0m\[0m\r\[4Cprintln(\r\[12C"
23+send -- "n)\r"
24+expect -exact "n)\r\[0K\[32m\[1m--> \[0m\[0m\r\[4Cprintln(n)\r\[14C\r
25+\[?2004l\[0mhello\r
26+\r
27+\r\[0K\r\[0K\[32m\[1m--> \[0m\[0m\r\[4C\r\[4C\[?2004h\r\[0K\[32m\[1m--> \[0m\[0m\r\[4C\r\[4C"
28+send -- "\[A"
29+expect -exact "\r\[0K\r\[0K\[32m\[1m--> \[0m\[0m\r\[4C\r\[4C\r\[0K\r\[0K\[32m\[1m--> \[0m\[0m\r\[4C\r\[4C\r\[0K\r\[0K\[32m\[1m--> \[0m\[0m\r\[4Cprintln(n)\r\[14C\r\[0K\[32m\[1m--> \[0m\[0m\r\[4Cprintln(n)\r\[14C"
30+send -- "\r"
31+expect -exact "\r\[0K\r\[0K\[32m\[1m--> \[0m\[0m\r\[4Cprintln(n)\r\[14C\r\[0K\[32m\[1m--> \[0m\[0m\r\[4Cprintln(n)\r\[14C\r
32+\[?2004l\[0mhello\r
33+\r
34+\r\[0K\r\[0K\[32m\[1m--> \[0m\[0m\r\[4C\r\[4C\[?2004h\r\[0K\[32m\[1m--> \[0m\[0m\r\[4C\r\[4C"
35+send -- ""
36+expect eof
tests/julia/print_a_line.expnew file+13
@@ -0,0 +1,13 @@
1+#!/usr/bin/expect -f
2+
3+set timeout -1
4+spawn ./prybar-julia -q -i
5+match_max 100000
6+expect -exact "\[?2004h\r\[0K\[32m\[1m--> \[0m\[0m\r\[4C\r\[4C"
7+send -- "println(\"helloooooo\")\r"
8+expect -exact "println(\"helloooooo\")\r\[0K\[32m\[1m--> \[0m\[0m\r\[4Cprintln(\"helloooooo\")\r\[25C\r
9+\[?2004l\[0mhelloooooo\r
10+\r
11+\r\[0K\r\[0K\[32m\[1m--> \[0m\[0m\r\[4C\r\[4C\[?2004h\r\[0K\[32m\[1m--> \[0m\[0m\r\[4C\r\[4C"
12+send -- ""
13+expect eof
tests/julia/start_with_file.expnew file+14
@@ -0,0 +1,14 @@
1+#!/usr/bin/expect -f
2+
3+set timeout -1
4+spawn ./prybar-julia -q -i ./test_files/hi_julia.jl
5+match_max 100000
6+expect -exact "hey from julia\r
7+\[?2004h\r\[0K\[32m\[1m--> \[0m\[0m\r\[4C\r\[4C"
8+send -- "my_number\r"
9+expect -exact "my_number\r\[0K\[32m\[1m--> \[0m\[0m\r\[4Cmy_number\r\[13C\r
10+\[?2004l\[0m\[0m500\r
11+\r
12+\r\[0K\r\[0K\[32m\[1m--> \[0m\[0m\r\[4C\r\[4C\[?2004h\r\[0K\[32m\[1m--> \[0m\[0m\r\[4C\r\[4C"
13+send -- ""
14+expect eof