on master help sign in
Merge branch 'master' into ocaml-add-language
commit98ecfb43b04cd8e078c96f9d16565f30a521a62b authorPatrick Stapfer <ryyppy@users.noreply.github.com> dateWed 27 Feb 2019, 09:12 (8 years ago) parent1dea1a575fb729
33 files changed+671−475
.travis.yml+1 Dockerfile+23−5 Makefile+1−1 README.md+27−22 languages/R/main.go+2 languages/julia/julia.pc+9 languages/julia/main.go+54 languages/julia/pry.h+114 languages/lua/lua.c+127−379 languages/lua/main.go+25−16 languages/lua/pry.c+4−34 languages/lua/pry.h+8−11 languages/python2/main.go+5−3 languages/python3/main.go+4−2 languages/ruby/main.go+2 languages/spidermonkey/main.go+2 languages/tcl/main.go+2 scripts/inject.sh+1−1 test_files/hello.lua+2 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 tests/lua/always_try_expression.exp+26 tests/lua/history.exp+30 tests/lua/load_file.exp+14 tests/lua/own_eval.exp+51 tests/lua/ps1_ps2.exp+18 tests/lua/quiet.exp+12 tests/lua/returns.exp+19 tests/python2/1_plus_1.exp−1
.travis.yml+1
@@ -5,3 +5,4 @@ services:
55
66script:
77 - docker build -t prybar .
8+ - docker run -t prybar make test
Dockerfile+23−5
@@ -6,7 +6,8 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
66 golang \
77 python-dev \
88 python3-dev \
9− liblua5.2-dev \
9+ liblua5.1-dev \
10+ libreadline-dev \
1011 ruby2.5-dev \
1112 tcl-dev \
1213 libnspr4-dev \
@@ -16,11 +17,21 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
1617 m4 \
1718 software-properties-common
1819
19−RUN wget \
20− http://launchpadlibrarian.net/309343864/libmozjs185-dev_1.8.5-1.0.0+dfsg-7_amd64.deb && \
20+RUN wget http://launchpadlibrarian.net/309343864/libmozjs185-dev_1.8.5-1.0.0+dfsg-7_amd64.deb && \
2121 wget http://launchpadlibrarian.net/309343863/libmozjs185-1.0_1.8.5-1.0.0+dfsg-7_amd64.deb && \
2222 dpkg -i libmozjs185*.deb && rm libmozjs185*.deb
2323
24+RUN wget https://julialang-s3.julialang.org/bin/linux/x64/1.1/julia-1.1.0-linux-x86_64.tar.gz && \
25+ tar xf julia-1.1.0-linux-x86_64.tar.gz && \
26+ cd julia-1.1.0 && \
27+ cp -r bin/* /usr/bin/ && \
28+ cp -r include/* /usr/include/ && \
29+ cp -r lib/* /usr/lib/ && \
30+ cp -r share/* /usr/share/ && \
31+ cd .. && \
32+ rm -rf julia-1.1.0-linux-x86_64.tar.gz julia-1.1.0
33+
34+
2435RUN mkdir -p /gocode/src/github.com/replit/prybar
2536
2637ENV GOPATH=/gocode
@@ -37,8 +48,15 @@ RUN add-apt-repository ppa:avsm/ppa && \
3748 eval `opam env` && \
3849 echo "eval \`opam env\`" >> ~/.bashrc
3950
40−RUN make prybar-python2 prybar-python3 prybar-ruby prybar-lua prybar-spidermonkey prybar-nodejs prybar-ocaml
41−RUN make test
51+RUN make \
52+ prybar-python2 \
53+ prybar-python3 \
54+ prybar-ruby \
55+ prybar-lua \
56+ prybar-spidermonkey \
57+ prybar-nodejs \
58+ prybar-julia \
59+ prybar-ocaml
4260
4361ENV LC_ALL=C.UTF-8
4462
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:
README.md+27−22
@@ -29,14 +29,19 @@ Usage of ./prybar-language:
2929 -q quiet
3030```
3131
32−## Supported Languages
33−* Python 2.7
34−* Python 3.x
35−* Ruby 2.5
36−* Lua 5.2
37−* TCL
38−* R
39−* Spidermonkey (javascript)
32+## Language Support
33+
34+| language | eval | eval expression | eval file | repl | repl like eval | set prompt |
35+| ------------------------- | ---- | --------------- | --------- | ---- | -------------- | ---------- |
36+| Python 2.7 | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
37+| Python 3.x | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
38+| Ruby 2.5 | ✔ | ✔ | ✔ | ✔ | ✗ | ✗ |
39+| Lua 5.1 | ✔ | ✗ | ✔ | ✔ | ✗ | ✔ |
40+| Tcl | ✔ | ✔ | ✗ | ✗ | ✗ | ✗ |
41+| R | ✔ | ✗ | ✗ | ✔ | ✗ | ✗ |
42+| Javascript (spidermonkey) | ✔ | ✗ | ✗ | ✗ | ✗ | ✗ |
43+| Javascript (nodejs) | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
44+| Julia | ✔ | ✗ | ✔ | ✔ | ✗ | ✔ |
4045
4146## Building
4247
@@ -58,21 +63,21 @@ The script `./extract.sh` can be used to compile and produce a tarball containin
5863
5964## License
6065
61− Copyright (C) 2004-2018 Neoreason, Inc. et al.
66+Copyright (C) 2004-2018 Neoreason, Inc. et al.
6267
63− This program is free software; you can redistribute it and/or
64− modify it under the terms of the GNU General Public License
65− as published by the Free Software Foundation; either version 2
66− of the License, or (at your option) any later version.
68+This program is free software; you can redistribute it and/or
69+modify it under the terms of the GNU General Public License
70+as published by the Free Software Foundation; either version 2
71+of the License, or (at your option) any later version.
6772
68− This program is distributed in the hope that it will be useful,
69− but WITHOUT ANY WARRANTY; without even the implied warranty of
70− MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
71− GNU General Public License for more details.
73+This program is distributed in the hope that it will be useful,
74+but WITHOUT ANY WARRANTY; without even the implied warranty of
75+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
76+GNU General Public License for more details.
7277
73− You should have received a copy of the GNU General Public License
74− along with this program; if not, write to the Free Software
75− Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
78+You should have received a copy of the GNU General Public License
79+along with this program; if not, write to the Free Software
80+Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
7681
77− See the COPYING file for more information regarding the GNU General
78− Public License.
82+See the COPYING file for more information regarding the GNU General
83+Public License.
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/lua.c+127−379
@@ -1,497 +1,245 @@
1+// Copied straight from https://www.lua.org/source/5.1/lua.c.html
2+// with some of the cli stuff stripped out.
3+
14/*
2−** $Id: lua.c,v 1.206.1.1 2013/04/12 18:48:47 roberto Exp $
5+** $Id: lua.c,v 1.160.1.2 2007/12/28 15:32:23 roberto Exp $
36** Lua stand-alone interpreter
47** See Copyright Notice in lua.h
58*/
69
7−#include "pry.h"
810#include <signal.h>
911#include <stdio.h>
1012#include <stdlib.h>
1113#include <string.h>
1214
1315#define lua_c
16+#define LUA_USE_LINUX
1417
15−#include "lua.h"
16−
17−#include "lauxlib.h"
18−#include "lualib.h"
19−
20−
21−#if !defined(LUA_PROMPT)
22−#define LUA_PROMPT "> "
23−#define LUA_PROMPT2 ">> "
24−#endif
25−
26−#if !defined(LUA_PROGNAME)
27−#define LUA_PROGNAME "lua"
28−#endif
29−
30−#if !defined(LUA_MAXINPUT)
31−#define LUA_MAXINPUT 512
32−#endif
33−
34−#if !defined(LUA_INIT)
35−#define LUA_INIT "LUA_INIT"
36−#endif
37−
38−#define LUA_INITVERSION \
39− LUA_INIT "_" LUA_VERSION_MAJOR "_" LUA_VERSION_MINOR
40−
41−
42−/*
43−** lua_stdin_is_tty detects whether the standard input is a 'tty' (that
44−** is, whether we're running lua interactively).
45−*/
46−#if defined(LUA_USE_ISATTY)
47−#include <unistd.h>
48−#define lua_stdin_is_tty() isatty(0)
49−#elif defined(LUA_WIN)
50−#include <io.h>
51−#include <stdio.h>
52−#define lua_stdin_is_tty() _isatty(_fileno(stdin))
53−#else
54−#define lua_stdin_is_tty() 1 /* assume stdin is a tty */
55−#endif
56−
18+#include <lua.h>
5719
58−/*
59−** lua_readline defines how to show a prompt and then read a line from
60−** the standard input.
61−** lua_saveline defines how to "save" a read line in a "history".
62−** lua_freeline defines how to free a line read by lua_readline.
63−*/
64−#if defined(LUA_USE_READLINE)
65−
66−#include <stdio.h>
67−#include <readline/readline.h>
68−#include <readline/history.h>
69−#define lua_readline(L,b,p) ((void)L, ((b)=readline(p)) != NULL)
70−#define lua_saveline(L,idx) \
71− if (lua_rawlen(L,idx) > 0) /* non-empty line? */ \
72− add_history(lua_tostring(L, idx)); /* add it to history */
73−#define lua_freeline(L,b) ((void)L, free(b))
74−
75−#elif !defined(lua_readline)
76−
77−#define lua_readline(L,b,p) \
78− ((void)L, fputs(p, stdout), fflush(stdout), /* show prompt */ \
79− fgets(b, LUA_MAXINPUT, stdin) != NULL) /* get line */
80−#define lua_saveline(L,idx) { (void)L; (void)idx; }
81−#define lua_freeline(L,b) { (void)L; (void)b; }
82−
83−#endif
20+#include <lauxlib.h>
21+#include <luaconf.h>
22+#include <lualib.h>
8423
85−
86−
87−
88−static lua_State *globalL = NULL;
24+extern lua_State *pry_L;
8925
9026static const char *progname = LUA_PROGNAME;
9127
92−
93−
94−static void lstop (lua_State *L, lua_Debug *ar) {
95− (void)ar; /* unused arg. */
28+static void lstop(lua_State *L, lua_Debug *ar) {
29+ (void)ar; /* unused arg. */
9630 lua_sethook(L, NULL, 0, 0);
9731 luaL_error(L, "interrupted!");
9832}
9933
100−
101−static void laction (int i) {
34+static void laction(int i) {
10235 signal(i, SIG_DFL); /* if another SIGINT happens before lstop,
10336 terminate process (default action) */
104− lua_sethook(globalL, lstop, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1);
37+ lua_sethook(pry_L, lstop, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1);
10538}
10639
107−
108−static void print_usage (const char *badoption) {
109− luai_writestringerror("%s: ", progname);
110− if (badoption[1] == 'e' || badoption[1] == 'l')
111− luai_writestringerror("'%s' needs argument\n", badoption);
112− else
113− luai_writestringerror("unrecognized option '%s'\n", badoption);
114− luai_writestringerror(
115− "usage: %s [options] [script [args]]\n"
116− "Available options are:\n"
117− " -e stat execute string " LUA_QL("stat") "\n"
118− " -i enter interactive mode after executing " LUA_QL("script") "\n"
119− " -l name require library " LUA_QL("name") "\n"
120− " -v show version information\n"
121− " -E ignore environment variables\n"
122− " -- stop handling options\n"
123− " - stop handling options and execute stdin\n"
124− ,
125− progname);
126−}
127−
128−
129−static void l_message (const char *pname, const char *msg) {
130− if (pname) luai_writestringerror("%s: ", pname);
131− luai_writestringerror("%s\n", msg);
40+static void l_message(const char *pname, const char *msg) {
41+ if (pname)
42+ fprintf(stderr, "%s: ", pname);
43+ fprintf(stderr, "%s\n", msg);
44+ fflush(stderr);
13245}
13346
134−
135−static int report (lua_State *L, int status) {
136− if (status != LUA_OK && !lua_isnil(L, -1)) {
47+static int report(lua_State *L, int status) {
48+ if (status && !lua_isnil(L, -1)) {
13749 const char *msg = lua_tostring(L, -1);
138− if (msg == NULL) msg = "(error object is not a string)";
50+ if (msg == NULL)
51+ msg = "(error object is not a string)";
13952 l_message(progname, msg);
14053 lua_pop(L, 1);
141− /* force a complete garbage collection in case of errors */
142− lua_gc(L, LUA_GCCOLLECT, 0);
14354 }
14455 return status;
14556}
14657
147−
148−/* the next function is called unprotected, so it must avoid errors */
149−void finalreport (lua_State *L, int status) {
150− if (status != LUA_OK) {
151− const char *msg = (lua_type(L, -1) == LUA_TSTRING) ? lua_tostring(L, -1)
152− : NULL;
153− if (msg == NULL) msg = "(error object is not a string)";
154− l_message(progname, msg);
58+static int traceback(lua_State *L) {
59+ if (!lua_isstring(L, 1)) /* 'message' not a string? */
60+ return 1; /* keep it intact */
61+ lua_getfield(L, LUA_GLOBALSINDEX, "debug");
62+ if (!lua_istable(L, -1)) {
15563 lua_pop(L, 1);
64+ return 1;
15665 }
157−}
158−
159−
160−static int traceback (lua_State *L) {
161− const char *msg = lua_tostring(L, 1);
162− if (msg)
163− luaL_traceback(L, L, msg, 1);
164− else if (!lua_isnoneornil(L, 1)) { /* is there an error object? */
165− if (!luaL_callmeta(L, 1, "__tostring")) /* try its 'tostring' metamethod */
166− lua_pushliteral(L, "(no error message)");
66+ lua_getfield(L, -1, "traceback");
67+ if (!lua_isfunction(L, -1)) {
68+ lua_pop(L, 2);
69+ return 1;
16770 }
71+ lua_pushvalue(L, 1); /* pass error message */
72+ lua_pushinteger(L, 2); /* skip this function and traceback */
73+ lua_call(L, 2, 1); /* call debug.traceback */
16874 return 1;
16975}
17076
171−
172−static int docall (lua_State *L, int narg, int nres) {
77+static int docall(lua_State *L, int narg, int clear) {
17378 int status;
174− int base = lua_gettop(L) - narg; /* function index */
175− lua_pushcfunction(L, traceback); /* push traceback function */
176− lua_insert(L, base); /* put it under chunk and args */
177− globalL = L; /* to be available to 'laction' */
79+ int base = lua_gettop(L) - narg; /* function index */
80+ lua_pushcfunction(L, traceback); /* push traceback function */
81+ lua_insert(L, base); /* put it under chunk and args */
17882 signal(SIGINT, laction);
179− status = lua_pcall(L, narg, nres, base);
83+ status = lua_pcall(L, narg, (clear ? 0 : LUA_MULTRET), base);
18084 signal(SIGINT, SIG_DFL);
181− lua_remove(L, base); /* remove traceback function */
85+ lua_remove(L, base); /* remove traceback function */
86+ /* force a complete garbage collection in case of errors */
87+ if (status != 0)
88+ lua_gc(L, LUA_GCCOLLECT, 0);
18289 return status;
18390}
18491
185−
186−static void print_version (void) {
187− luai_writestring(LUA_COPYRIGHT, strlen(LUA_COPYRIGHT));
188− luai_writeline();
92+static void print_version(void) {
93+ l_message(NULL, LUA_RELEASE " " LUA_COPYRIGHT);
18994}
19095
191−
192−static int getargs (lua_State *L, char **argv, int n) {
96+static int getargs(lua_State *L, char **argv, int n) {
19397 int narg;
19498 int i;
19599 int argc = 0;
196− while (argv[argc]) argc++; /* count total number of arguments */
197− narg = argc - (n + 1); /* number of arguments to the script */
100+ while (argv[argc])
101+ argc++; /* count total number of arguments */
102+ narg = argc - (n + 1); /* number of arguments to the script */
198103 luaL_checkstack(L, narg + 3, "too many arguments to script");
199− for (i=n+1; i < argc; i++)
104+ for (i = n + 1; i < argc; i++)
200105 lua_pushstring(L, argv[i]);
201106 lua_createtable(L, narg, n + 1);
202− for (i=0; i < argc; i++) {
107+ for (i = 0; i < argc; i++) {
203108 lua_pushstring(L, argv[i]);
204109 lua_rawseti(L, -2, i - n);
205110 }
206111 return narg;
207112}
208113
209−
210−static int dofile (lua_State *L, const char *name) {
211− int status = luaL_loadfile(L, name);
212− if (status == LUA_OK) status = docall(L, 0, 0);
114+int dostring(lua_State *L, const char *s, const char *name) {
115+ int status = luaL_loadbuffer(L, s, strlen(s), name) || docall(L, 0, 1);
213116 return report(L, status);
214117}
215118
216−
217−static int dostring (lua_State *L, const char *s, const char *name) {
218− int status = luaL_loadbuffer(L, s, strlen(s), name);
219− if (status == LUA_OK) status = docall(L, 0, 0);
220− return report(L, status);
221−}
222−
223−
224−static int dolibrary (lua_State *L, const char *name) {
225− int status;
226− lua_getglobal(L, "require");
227− lua_pushstring(L, name);
228− status = docall(L, 1, 1); /* call 'require(name)' */
229− if (status == LUA_OK)
230− lua_setglobal(L, name); /* global[name] = require return */
231− return report(L, status);
232−}
233−
234−
235−static const char *get_prompt (lua_State *L, int firstline) {
119+static const char *get_prompt(lua_State *L, int firstline) {
236120 const char *p;
237− lua_getglobal(L, firstline ? "_PROMPT" : "_PROMPT2");
121+ lua_getfield(L, LUA_GLOBALSINDEX, firstline ? "_PROMPT" : "_PROMPT2");
238122 p = lua_tostring(L, -1);
239− if (p == NULL) p = (firstline ? LUA_PROMPT : LUA_PROMPT2);
123+ if (p == NULL)
124+ p = (firstline ? LUA_PROMPT : LUA_PROMPT2);
125+ lua_pop(L, 1); /* remove global */
240126 return p;
241127}
242128
243−/* mark in error messages for incomplete statements */
244−#define EOFMARK "<eof>"
245−#define marklen (sizeof(EOFMARK)/sizeof(char) - 1)
246−
247−static int incomplete (lua_State *L, int status) {
129+static int incomplete(lua_State *L, int status) {
248130 if (status == LUA_ERRSYNTAX) {
249131 size_t lmsg;
250132 const char *msg = lua_tolstring(L, -1, &lmsg);
251− if (lmsg >= marklen && strcmp(msg + lmsg - marklen, EOFMARK) == 0) {
133+ const char *tp = msg + lmsg - (sizeof(LUA_QL("<eof>")) - 1);
134+ if (strstr(msg, LUA_QL("<eof>")) == tp) {
252135 lua_pop(L, 1);
253136 return 1;
254137 }
255138 }
256− return 0; /* else... */
257−}
258139
140+ return 0; /* else... */
141+}
259142
260−static int pushline (lua_State *L, int firstline) {
143+static int pushline(lua_State *L, int firstline) {
261144 char buffer[LUA_MAXINPUT];
262145 char *b = buffer;
263146 size_t l;
264147 const char *prmt = get_prompt(L, firstline);
265− int readstatus = lua_readline(L, b, prmt);
266− lua_pop(L, 1); /* remove result from 'get_prompt' */
267− if (readstatus == 0)
268− return 0; /* no input */
148+ if (lua_readline(L, b, prmt) == 0)
149+ return 0; /* no input */
269150 l = strlen(b);
270− if (l > 0 && b[l-1] == '\n') /* line ends with newline? */
271− b[l-1] = '\0'; /* remove it */
272− if (firstline && b[0] == '=') /* first line starts with `=' ? */
273− lua_pushfstring(L, "return %s", b+1); /* change it to `return' */
151+ if (l > 0 && b[l - 1] == '\n') /* line ends with newline? */
152+ b[l - 1] = '\0'; /* remove it */
153+ if (firstline && b[0] == '=') /* first line starts with `=' ? */
154+ lua_pushfstring(L, "return %s", b + 1); /* change it to `return' */
274155 else
275156 lua_pushstring(L, b);
276157 lua_freeline(L, b);
277158 return 1;
278159}
279160
161+static int try_expression(lua_State *L) {
162+ lua_pushliteral(L, "return ");
163+ lua_pushvalue(L, 1);
164+ lua_concat(L, 2);
280165
281−static int loadline (lua_State *L) {
282− int status;
166+ int rstatus =
167+ luaL_loadbuffer(L, lua_tostring(L, -1), lua_strlen(L, -1), "=stdin");
168+
169+ if (rstatus) {
170+ lua_pop(L, 2);
171+ return 1;
172+ }
173+
174+ lua_remove(L, 2);
175+
176+ return 0;
177+}
178+
179+static int loadline(lua_State *L) {
180+ int status = 0;
283181 lua_settop(L, 0);
284182 if (!pushline(L, 1))
285− return -1; /* no input */
286− for (;;) { /* repeat until gets a complete line */
287− size_t l;
288− const char *line = lua_tolstring(L, 1, &l);
289− status = luaL_loadbuffer(L, line, l, "=stdin");
290− if (!incomplete(L, status)) break; /* cannot try to add lines? */
291− if (!pushline(L, 0)) /* no more input? */
183+ return -1; /* no input */
184+
185+ for (;;) { /* repeat until gets a complete line */
186+ status = try_expression(L);
187+ if (!status)
188+ break;
189+
190+ status = luaL_loadbuffer(L, lua_tostring(L, 1), lua_strlen(L, 1), "=stdin");
191+
192+ if (!incomplete(L, status))
193+ break; /* cannot try to add lines? */
194+
195+ if (!pushline(L, 0)) /* no more input? */
292196 return -1;
293− lua_pushliteral(L, "\n"); /* add a new line... */
294− lua_insert(L, -2); /* ...between the two lines */
295− lua_concat(L, 3); /* join them */
197+ lua_pushliteral(L, "\n"); /* add a new line... */
198+ lua_insert(L, -2); /* ...between the two lines */
199+ lua_concat(L, 3); /* join them */
296200 }
201+
297202 lua_saveline(L, 1);
298− lua_remove(L, 1); /* remove line */
203+ lua_remove(L, 1); /* remove line */
299204 return status;
300205}
301206
302−
303−void dotty (lua_State *L) {
207+void dotty(lua_State *L) {
304208 int status;
305209 const char *oldprogname = progname;
306210 progname = NULL;
307211 while ((status = loadline(L)) != -1) {
308− if (status == LUA_OK) status = docall(L, 0, LUA_MULTRET);
212+ if (status == 0)
213+ status = docall(L, 0, 0);
309214 report(L, status);
310− if (status == LUA_OK && lua_gettop(L) > 0) { /* any result to print? */
311− luaL_checkstack(L, LUA_MINSTACK, "too many results to print");
215+ if (status == 0 && lua_gettop(L) > 0) { /* any result to print? */
312216 lua_getglobal(L, "print");
313217 lua_insert(L, 1);
314− if (lua_pcall(L, lua_gettop(L)-1, 0, 0) != LUA_OK)
315− l_message(progname, lua_pushfstring(L,
316− "error calling " LUA_QL("print") " (%s)",
317− lua_tostring(L, -1)));
218+ if (lua_pcall(L, lua_gettop(L) - 1, 0, 0) != 0)
219+ l_message(progname,
220+ lua_pushfstring(L, "error calling " LUA_QL("print") " (%s)",
221+ lua_tostring(L, -1)));
318222 }
319223 }
320− lua_settop(L, 0); /* clear stack */
321− luai_writeline();
224+ lua_settop(L, 0); /* clear stack */
225+ fputs("\n", stdout);
226+ fflush(stdout);
322227 progname = oldprogname;
323228}
324229
325−
326−int handle_script (lua_State *L, char **argv, int n) {
230+int handle_script(lua_State *L, char **argv, int n) {
327231 int status;
328232 const char *fname;
329− int narg = getargs(L, argv, n); /* collect arguments */
233+ int narg = getargs(L, argv, n); /* collect arguments */
330234 lua_setglobal(L, "arg");
331235 fname = argv[n];
332− if (strcmp(fname, "-") == 0 && strcmp(argv[n-1], "--") != 0)
333− fname = NULL; /* stdin */
236+ if (strcmp(fname, "-") == 0 && strcmp(argv[n - 1], "--") != 0)
237+ fname = NULL; /* stdin */
334238 status = luaL_loadfile(L, fname);
335− lua_insert(L, -(narg+1));
336− if (status == LUA_OK)
337− status = docall(L, narg, LUA_MULTRET);
239+ lua_insert(L, -(narg + 1));
240+ if (status == 0)
241+ status = docall(L, narg, 0);
338242 else
339243 lua_pop(L, narg);
340244 return report(L, status);
341245}
342−
343−
344−/* check that argument has no extra characters at the end */
345−#define noextrachars(x) {if ((x)[2] != '\0') return -1;}
346−
347−
348−/* indices of various argument indicators in array args */
349−#define has_i 0 /* -i */
350−#define has_v 1 /* -v */
351−#define has_e 2 /* -e */
352−#define has_E 3 /* -E */
353−
354−#define num_has 4 /* number of 'has_*' */
355−
356−
357−static int collectargs (char **argv, int *args) {
358− int i;
359− for (i = 1; argv[i] != NULL; i++) {
360− if (argv[i][0] != '-') /* not an option? */
361− return i;
362− switch (argv[i][1]) { /* option */
363− case '-':
364− noextrachars(argv[i]);
365− return (argv[i+1] != NULL ? i+1 : 0);
366− case '\0':
367− return i;
368− case 'E':
369− args[has_E] = 1;
370− break;
371− case 'i':
372− noextrachars(argv[i]);
373− args[has_i] = 1; /* go through */
374− case 'v':
375− noextrachars(argv[i]);
376− args[has_v] = 1;
377− break;
378− case 'e':
379− args[has_e] = 1; /* go through */
380− case 'l': /* both options need an argument */
381− if (argv[i][2] == '\0') { /* no concatenated argument? */
382− i++; /* try next 'argv' */
383− if (argv[i] == NULL || argv[i][0] == '-')
384− return -(i - 1); /* no next argument or it is another option */
385− }
386− break;
387− default: /* invalid option; return its index... */
388− return -i; /* ...as a negative value */
389− }
390− }
391− return 0;
392−}
393−
394−
395−static int runargs (lua_State *L, char **argv, int n) {
396− int i;
397− for (i = 1; i < n; i++) {
398− lua_assert(argv[i][0] == '-');
399− switch (argv[i][1]) { /* option */
400− case 'e': {
401− const char *chunk = argv[i] + 2;
402− if (*chunk == '\0') chunk = argv[++i];
403− lua_assert(chunk != NULL);
404− if (dostring(L, chunk, "=(command line)") != LUA_OK)
405− return 0;
406− break;
407− }
408− case 'l': {
409− const char *filename = argv[i] + 2;
410− if (*filename == '\0') filename = argv[++i];
411− lua_assert(filename != NULL);
412− if (dolibrary(L, filename) != LUA_OK)
413− return 0; /* stop if file fails */
414− break;
415− }
416− default: break;
417− }
418− }
419− return 1;
420−}
421−
422−
423−static int handle_luainit (lua_State *L) {
424− const char *name = "=" LUA_INITVERSION;
425− const char *init = getenv(name + 1);
426− if (init == NULL) {
427− name = "=" LUA_INIT;
428− init = getenv(name + 1); /* try alternative name */
429− }
430− if (init == NULL) return LUA_OK;
431− else if (init[0] == '@')
432− return dofile(L, init+1);
433− else
434− return dostring(L, init, name);
435−}
436−
437−
438−int pmain (lua_State *L) {
439− int argc = (int)lua_tointeger(L, 1);
440− char **argv = (char **)lua_touserdata(L, 2);
441− int script;
442− int args[num_has];
443− args[has_i] = args[has_v] = args[has_e] = args[has_E] = 0;
444− if (argv[0] && argv[0][0]) progname = argv[0];
445− script = collectargs(argv, args);
446− if (script < 0) { /* invalid arg? */
447− print_usage(argv[-script]);
448− return 0;
449− }
450− if (args[has_v]) print_version();
451− if (args[has_E]) { /* option '-E'? */
452− lua_pushboolean(L, 1); /* signal for libraries to ignore env. vars. */
453− lua_setfield(L, LUA_REGISTRYINDEX, "LUA_NOENV");
454− }
455− /* open standard libraries */
456− luaL_checkversion(L);
457− lua_gc(L, LUA_GCSTOP, 0); /* stop collector during initialization */
458− luaL_openlibs(L); /* open libraries */
459− lua_gc(L, LUA_GCRESTART, 0);
460− if (!args[has_E] && handle_luainit(L) != LUA_OK)
461− return 0; /* error running LUA_INIT */
462− /* execute arguments -e and -l */
463− if (!runargs(L, argv, (script > 0) ? script : argc)) return 0;
464− /* execute main script (if there is one) */
465− if (script && handle_script(L, argv, script) != LUA_OK) return 0;
466− if (args[has_i]) /* -i option? */
467− dotty(L);
468− else if (script == 0 && !args[has_e] && !args[has_v]) { /* no arguments? */
469− if (lua_stdin_is_tty()) {
470− print_version();
471− dotty(L);
472− }
473− else dofile(L, NULL); /* executes stdin as a file */
474− }
475− lua_pushboolean(L, 1); /* signal no errors */
476− return 1;
477−}
478−
479−
480−int lua_main (int argc, char **argv) {
481− int status, result;
482− lua_State *L = luaL_newstate(); /* create state */
483− if (L == NULL) {
484− l_message(argv[0], "cannot create state: not enough memory");
485− return EXIT_FAILURE;
486− }
487− /* call 'pmain' in protected mode */
488− lua_pushcfunction(L, &pmain);
489− lua_pushinteger(L, argc); /* 1st argument */
490− lua_pushlightuserdata(L, argv); /* 2nd argument */
491− status = lua_pcall(L, 2, 1, 0);
492− result = lua_toboolean(L, -1); /* get result */
493− finalreport(L, status);
494− lua_close(L);
495− return (result && status == LUA_OK) ? EXIT_SUCCESS : EXIT_FAILURE;
496−}
497−
languages/lua/main.go+25−16
@@ -1,54 +1,63 @@
11package main
22
3+// USING_CGO
4+
35/*
4−#cgo pkg-config: lua-5.2
6+#cgo pkg-config: lua-5.1
7+#cgo LDFLAGS: -lreadline
58#include <stdlib.h>
69#include <lua.h>
10+#include <lauxlib.h>
11+#include <lualib.h>
712#include "pry.h"
813
9−int lua_main (int argc, char **argv);
10−void dotty (lua_State *L);
11−int pmain (lua_State *L);
12−
13−
14−
1514*/
1615import "C"
1716
1817import (
19− "strings"
2018 "unsafe"
2119)
2220
2321type Lua struct{}
2422
2523func (p Lua) Open() {
26− C.pry_init()
24+ C.pry_L = C.luaL_newstate()
25+ C.luaL_openlibs(C.pry_L)
2726}
2827
2928func (p Lua) Version() string {
3029 return C.GoString(C.pry_get_version())
3130}
3231
32+func (p Lua) SetPrompts(ps1, ps2 string) {
33+ c1 := C.CString(ps1)
34+ C.lua_pushstring(C.pry_L, c1)
35+ C.free(unsafe.Pointer(c1))
36+
37+ C.lua_setfield(C.pry_L, C.LUA_GLOBALSINDEX, C.CString("_PROMPT"))
38+
39+ c2 := C.CString(ps2)
40+ C.lua_pushstring(C.pry_L, c2)
41+ C.free(unsafe.Pointer(c2))
42+
43+ C.lua_setfield(C.pry_L, C.LUA_GLOBALSINDEX, C.CString("_PROMPT2"))
44+}
45+
3346func (p Lua) Eval(code string) {
3447 ccode := C.CString(code)
3548 defer C.free(unsafe.Pointer(ccode))
3649 C.pry_eval(ccode)
3750}
3851
39−func (p Lua) EvalFile(file string, args []string) {
52+func (p Lua) EvalFile(file string) {
4053 cfile := C.CString(file)
4154 defer C.free(unsafe.Pointer(cfile))
4255
43− argv := C.CString(file + "\x00" + strings.Join(args, "\x00"))
44− defer C.free(unsafe.Pointer(argv))
45− C.pry_eval_file(cfile, C.int(len(args)+1), argv)
56+ C.pry_eval_file(cfile)
4657}
4758
4859func (p Lua) REPL() {
49− fn := C.CString("<stdin>")
50− defer C.free(unsafe.Pointer(fn))
51− C.dotty(C.pry_L)
60+ C.pry_do_repl()
5261}
5362
5463func (p Lua) Close() {
languages/lua/pry.c+4−34
@@ -5,42 +5,12 @@
55
66#include "pry.h"
77
8−char* pry_prompt = "> ";
9−char* pry_prompt2 = ">> ";
108lua_State *pry_L;
119
12−const char * pry_get_version() {
13− return LUA_COPYRIGHT;
14−}
10+const char *pry_get_version(void) { return LUA_RELEASE " " LUA_COPYRIGHT; }
1511
12+void pry_eval(const char *code) { dostring(pry_L, code, "<eval>"); }
1613
17−void pry_init() {
18− pry_L = luaL_newstate();
19− luaL_openlibs(pry_L);
20−}
14+void pry_do_repl(void) { dotty(pry_L); }
2115
22−void pry_eval(const char *code) {
23− luaL_dostring(pry_L, code);
24−}
25−
26−
27−int lua_main (int argc, char **argv);
28−
29−void pry_main() {
30− char* args[2] = {"lua", NULL};
31− lua_main(0, args);
32−}
33−
34−int handle_script (lua_State *L, char **argv, int n);
35−void pry_eval_file(const char* file, int argn, const char *argv) {
36− int status, result;
37− const char* xargv[argn+1];
38− const char* ptr = argv;
39− for (int i = 0; i < argn; ++i) {
40− xargv[i] = ptr;
41− ptr += strlen(ptr) + 1;
42− }
43− xargv[argn] = NULL;
44−
45− handle_script(pry_L, xargv, 0);
46−}
16+void pry_eval_file(char *file) { handle_script(pry_L, &file, 0); }
languages/lua/pry.h+8−11
@@ -1,16 +1,13 @@
11#include <lua.h>
22
3−#define luai_writestring(s,l) fwrite((s), sizeof(char), (l), stdout)
4−#define luai_writeline() (luai_writestring("\n", 1), fflush(stdout))
5−#define LUA_PROMPT pry_prompt
6−#define LUA_PROMPT2 pry_prompt2
7−
83extern lua_State *pry_L;
9−extern char* pry_prompt;
10−extern char* pry_prompt2;
114
12−const char * pry_get_version();
13−void pry_init();
5+const char *pry_get_version(void);
146void pry_eval(const char *code);
15−void pry_main();
16−void pry_eval_file(const char* file, int argn, const char *argv);
7+void pry_eval_file(char *file);
8+void pry_do_repl(void);
9+
10+// from the lua repl lib (lua.c)
11+void dotty(lua_State *L);
12+int handle_script(lua_State *L, char **argv, int n);
13+int dostring(lua_State *L, const char *s, const char *name);
languages/python2/main.go+5−3
@@ -1,5 +1,7 @@
11package main
22
3+// USING_CGO
4+
35/*
46#cgo pkg-config: python2
57#include "pry_python2.h"
@@ -15,7 +17,7 @@ type Python struct{}
1517
1618func (p Python) Open() {
1719 C.Py_Initialize()
18− p.LoadModule("readline")
20+ p.loadModule("readline")
1921 p.Eval("import signal")
2022 p.Eval("signal.signal(signal.SIGINT, signal.default_int_handler)")
2123}
@@ -60,14 +62,14 @@ func (p Python) REPLLikeEval(code string) {
6062 C.pry_eval(ccode, C.Py_single_input)
6163}
6264
63−func (p Python) LoadModule(mod string) {
65+func (p Python) loadModule(mod string) {
6466 cmode := C.CString(mod)
6567 defer C.free(unsafe.Pointer(cmode))
6668 C.PyImport_ImportModule(cmode)
6769}
6870
6971func (p Python) REPL() {
70− p.LoadModule("readline")
72+ p.loadModule("readline")
7173
7274 fn := C.CString("<stdin>")
7375 defer C.free(unsafe.Pointer(fn))
languages/python3/main.go+4−2
@@ -1,5 +1,7 @@
11package main
22
3+// USING_CGO
4+
35/*
46#cgo pkg-config: python3
57#include "pry_python3.h"
@@ -16,7 +18,7 @@ type Python struct{}
1618
1719func (p Python) Open() {
1820 C.Py_Initialize()
19− p.LoadModule("readline")
21+ p.loadModule("readline")
2022 p.Eval("import signal")
2123 p.Eval("signal.signal(signal.SIGINT, signal.default_int_handler)")
2224}
@@ -61,7 +63,7 @@ func (p Python) REPLLikeEval(code string) {
6163 C.pry_eval(ccode, C.Py_single_input)
6264}
6365
64−func (p Python) LoadModule(mod string) {
66+func (p Python) loadModule(mod string) {
6567 cmode := C.CString(mod)
6668 defer C.free(unsafe.Pointer(cmode))
6769 C.PyImport_ImportModule(cmode)
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/hello.luanew file+2
@@ -0,0 +1,2 @@
1+a = "hello"
2+print("hi!")
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
tests/lua/always_try_expression.expnew file+26
@@ -0,0 +1,26 @@
1+#!/usr/bin/expect -f
2+
3+set timeout -1
4+spawn ./prybar-lua -q -i
5+match_max 100000
6+expect -exact "--> "
7+send -- "function a() return 123 end\r"
8+expect -exact "function a() return 123 end\r
9+--> "
10+send -- "a()\r"
11+expect -exact "a()\r
12+123\r
13+--> "
14+send -- "return a()\r"
15+expect -exact "return a()\r
16+123\r
17+--> "
18+send -- "a(\r"
19+expect -exact "a(\r
20+... "
21+send -- ")\r"
22+expect -exact ")\r
23+123\r
24+--> "
25+send -- ""
26+expect eof
tests/lua/history.expnew file+30
@@ -0,0 +1,30 @@
1+#!/usr/bin/expect -f
2+
3+set timeout -1
4+spawn ./prybar-lua -q -i
5+match_max 100000
6+expect -exact "--> "
7+send -- "1\r"
8+expect -exact "1\r
9+1\r
10+--> "
11+send -- "2\r"
12+expect -exact "2\r
13+2\r
14+--> "
15+send -- "3\r"
16+expect -exact "3\r
17+3\r
18+--> "
19+send -- "\[A"
20+expect -exact "3"
21+send -- "\[A"
22+expect -exact "2"
23+send -- "\[A"
24+expect -exact "1"
25+send -- "\r"
26+expect -exact "\r
27+1\r
28+--> "
29+send -- ""
30+expect eof
tests/lua/load_file.expnew file+14
@@ -0,0 +1,14 @@
1+#!/usr/bin/expect -f
2+
3+set timeout -1
4+spawn ./prybar-lua -i ./test_files/hello.lua
5+match_max 100000
6+expect -exact "Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio\r
7+hi!\r
8+--> "
9+send -- "a\r"
10+expect -exact "a\r
11+hello\r
12+--> "
13+send -- ""
14+expect eof
tests/lua/own_eval.expnew file+51
@@ -0,0 +1,51 @@
1+#!/usr/bin/expect -f
2+
3+set timeout -1
4+spawn ./prybar-lua -I
5+match_max 100000
6+expect -exact "Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio\r
7+--> "
8+send -- "1"
9+expect -exact "\r--> 1\[0K\r\[5C"
10+send -- "+"
11+expect -exact "\r--> 1+\[0K\r\[6C"
12+send -- "1"
13+expect -exact "\r--> 1+1\[0K\r\[7C"
14+send -- "\r"
15+expect -exact "\r--> 1+1\[0K\r\[7C\r
16+lua: \[string \"<eval>\"\]:1: unexpected symbol near '1'\r
17+--> "
18+send -- "r"
19+expect -exact "\r--> r\[0K\r\[5C"
20+send -- "e"
21+expect -exact "\r--> re\[0K\r\[6C"
22+send -- "t"
23+expect -exact "\r--> ret\[0K\r\[7C"
24+send -- "u"
25+expect -exact "\r--> retu\[0K\r\[8C"
26+send -- "r"
27+expect -exact "\r--> retur\[0K\r\[9C"
28+send -- "n"
29+expect -exact "\r--> return\[0K\r\[10C"
30+send -- " "
31+expect -exact "\r--> return \[0K\r\[11C"
32+send -- "1"
33+expect -exact "\r--> return 1\[0K\r\[12C"
34+send -- "\r"
35+expect -exact "\r--> return 1\[0K\r\[12C\r
36+--> "
37+send -- "a"
38+expect -exact "\r--> a\[0K\r\[5C"
39+send -- " "
40+expect -exact "\r--> a \[0K\r\[6C"
41+send -- ""
42+expect -exact "\r--> a\[0K\r\[5C"
43+send -- "="
44+expect -exact "\r--> a=\[0K\r\[6C"
45+send -- "1"
46+expect -exact "\r--> a=1\[0K\r\[7C"
47+send -- "\r"
48+expect -exact "\r--> a=1\[0K\r\[7C\r
49+--> "
50+send -- ""
51+expect eof
tests/lua/ps1_ps2.expnew file+18
@@ -0,0 +1,18 @@
1+#!/usr/bin/expect -f
2+
3+set timeout -1
4+spawn ./prybar-lua -i -ps1 ps1 -ps2 ps2
5+match_max 100000
6+expect -exact "Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio\r
7+ps1"
8+send -- "a(\r"
9+expect -exact "a(\r
10+ps2"
11+send -- ")\r"
12+expect -exact ")\r
13+stdin:1: attempt to call global 'a' (a nil value)\r
14+stack traceback:\r
15+ stdin:1: in main chunk\r
16+ps1"
17+send -- ""
18+expect eof
tests/lua/quiet.expnew file+12
@@ -0,0 +1,12 @@
1+#!/usr/bin/expect -f
2+
3+set timeout -1
4+spawn ./prybar-lua -q -i
5+match_max 100000
6+expect -exact "--> "
7+send -- "1+1\r"
8+expect -exact "1+1\r
9+2\r
10+--> "
11+send -- ""
12+expect eof
tests/lua/returns.expnew file+19
@@ -0,0 +1,19 @@
1+#!/usr/bin/expect -f
2+
3+set timeout -1
4+spawn ./prybar-lua -q -i
5+match_max 100000
6+expect -exact "--> "
7+send -- "123\r"
8+expect -exact "123\r
9+123\r
10+--> "
11+send -- "function a() print(1) end\r"
12+expect -exact "function a() print(1) end\r
13+--> "
14+send -- "a()\r"
15+expect -exact "a()\r
16+1\r
17+--> "
18+send -- ""
19+expect eof
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