Permalink
Browse files

Separate out the readline stuff into repl-readline.c.

There are still some remnants of #ifdef USE_READLINE in repl.c, but they
should go away soon.
A non-readline repl comes from repl-basic.c now.
Some more refactoring may be necessary to make the repl clean.
This also paves the way for other repl implementations, such as a browser based one.
  • Loading branch information...
1 parent bdaa09e commit 370d36440fe3ab16558ec7e48fbdf5fb7c882866 @ViralBShah ViralBShah committed Apr 23, 2011
Showing with 399 additions and 415 deletions.
  1. +4 −0 .gitignore
  2. +5 −2 Make.inc.Darwin
  3. +6 −2 Make.inc.Linux
  4. +10 −2 src/Makefile
  5. +44 −0 src/repl-basic.c
  6. +298 −0 src/repl-readline.c
  7. +32 −409 src/repl.c
View
@@ -17,3 +17,7 @@
/pcre_h.j
/custom.j
+
+/boot.j.inc
+/julia_flisp.boot.inc
+/julia_flisp.boot
View
@@ -5,6 +5,8 @@ CXXFLAGS =
FC = gfortran
SHLIB_EXT = dylib
+USE_READLINE = 1
+
# BOEHM or MARKSWEEP
JULIAGC = MARKSWEEP
@@ -21,10 +23,11 @@ GCSRCS = gc
endif
OSLIBS = $(GCLIBS) -Wl,-w -framework ApplicationServices -framework vecLib
+CONFIG = -DMACOSX $(GCFLAGS)
ifeq ($(NBITS),32)
-CONFIG = -DMACOSX -DARCH_X86 -DUSE_READLINE $(GCFLAGS)
+CONFIG += -DARCH_X86
endif
ifeq ($(NBITS),64)
-CONFIG = -DMACOSX -DARCH_X86_64 -DBITS64 -DUSE_READLINE -DCOPY_STACKS $(GCFLAGS)
+CONFIG += -DARCH_X86_64 -DBITS64 -DCOPY_STACKS
endif
View
@@ -5,6 +5,8 @@ CXXFLAGS =
FC = gfortran
SHLIB_EXT = so
+USE_READLINE = 1
+
# BOEHM or MARKSWEEP
JULIAGC = MARKSWEEP
@@ -22,9 +24,11 @@ endif
OSLIBS = $(GCLIBS) -lncurses -Wl,--export-dynamic -Wl,--version-script=$(JULIAHOME)/src/julia.expmap
+CONFIG = -DLINUX $(GCFLAGS) -D_FORTIFY_SOURCE=0
+
ifeq ($(NBITS),32)
-CONFIG = -DLINUX -DARCH_X86 -DUSE_READLINE $(GCFLAGS) -D_FORTIFY_SOURCE=0
+CONFIG += -DARCH_X86
endif
ifeq ($(NBITS),64)
-CONFIG = -DLINUX -DARCH_X86_64 -DBITS64 -DUSE_READLINE $(GCFLAGS) -D_FORTIFY_SOURCE=0 -DCOPY_STACKS
+CONFIG += -DARCH_X86_64 -DBITS64 -DCOPY_STACKS
endif
View
@@ -19,8 +19,16 @@ DEBUGFLAGS = -ggdb3 -DDEBUG $(FLAGS)
SHIPFLAGS = -O3 -DNDEBUG $(FLAGS)
LIBFILES = $(FLISP) $(LLT)
-LIBS = $(LIBFILES) -L$(EXTROOT)/lib -lutil -ldl -lm -lreadline $(OSLIBS) \
- $(shell $(LLVMROOT)/bin/llvm-config --ldflags --libs engine) -lpthread
+LIBS = $(LIBFILES) -L$(EXTROOT)/lib -lutil -ldl -lm $(OSLIBS) \
+ $(shell $(LLVMROOT)/bin/llvm-config --ldflags --libs engine) -lpthread
+
+ifeq ($(USE_READLINE), 1)
+FLAGS += -DUSE_READLINE
+SRCS += repl-readline
+LIBS += -lreadline
+else
+SRCS += repl-basic
+endif
%.o: %.c julia.h
$(CC) $(CFLAGS) $(SHIPFLAGS) -c $< -o $@
View
@@ -0,0 +1,44 @@
+#include "repl.h"
+
+char jl_prompt_color[] = "\033[1m\033[32mjulia> \033[37m";
+
+void init_repl_environment()
+{
+ no_readline = 1;
+ return;
+}
+
+void exit_repl_environment()
+{
+ return;
+}
+
+DLLEXPORT void jl_input_line_callback(char *input)
+{
+ jl_value_t *ast;
+ int end=0, doprint=1;
+
+ if (!input || ios_eof(ios_stdin)) {
+ end = 1;
+ ast = NULL;
+ }
+ else {
+ ast = jl_parse_input_line(input);
+ // TODO
+ //if (jl_is_expr(ast) && ((jl_expr_t*)ast)->head == continue_sym)
+ //return read_expr_ast_no_readline(prompt, end, doprint);
+ doprint = !ends_with_semicolon(input);
+ }
+ handle_input(ast, end, doprint);
+}
+
+void read_expr(char *prompt)
+{
+ char *input;
+ //ios_printf(ios_stdout, prompt);
+ //ios_flush(ios_stdout);
+ input = ios_readline(ios_stdin);
+ ios_purge(ios_stdin);
+ jl_input_line_callback(input);
+}
+
Oops, something went wrong.

0 comments on commit 370d364

Please sign in to comment.