#
IMPLS = ada awk bash basic c d chuck clojure coffee common-lisp cpp crystal cs dart \
- erlang elisp elixir es6 factor forth fsharp go groovy guile haskell \
+ erlang elisp elixir es6 factor forth fsharp go groovy gst guile haskell \
haxe io java julia js kotlin logo lua make mal ocaml matlab miniMAL \
nim objc objpascal perl perl6 php pil plpgsql plsql powershell ps \
python r racket rpython ruby rust scala skew swift swift3 tcl ts vb vhdl \
fsharp_STEP_TO_PROG = fsharp/$($(1)).exe
go_STEP_TO_PROG = go/$($(1))
groovy_STEP_TO_PROG = groovy/$($(1)).groovy
+gst_STEP_TO_PROG = gst/$($(1)).st
java_STEP_TO_PROG = java/target/classes/mal/$($(1)).class
haskell_STEP_TO_PROG = haskell/$($(1))
haxe_STEP_TO_PROG = $(haxe_STEP_TO_PROG_$(HAXE_MODE))
--- /dev/null
+SOURCES_BASE = readline.st reader.st printer.st types.st
+SOURCES_LISP = env.st func.st core.st stepA_mal.st
+SOURCES = $(SOURCES_BASE) $(SOURCES_LISP)
+
+all:
+
+clean:
+
+.PHONY: stats tests $(TESTS)
+
+stats: $(SOURCES)
+ @wc $^
+ @printf "%5s %5s %5s %s\n" `grep -E "^[[:space:]]*\"|^[[:space:]]*$$" $^ | wc` "[comments/blanks]"
+stats-lisp: $(SOURCES_LISP)
+ @wc $^
+ @printf "%5s %5s %5s %s\n" `grep -E "^[[:space:]]*\"|^[[:space:]]*$$" $^ | wc` "[comments/blanks]"
+
--- /dev/null
+DLD addLibrary: 'libreadline'.
+DLD addLibrary: 'libhistory'.
+
+Object subclass: ReadLine [
+ ReadLine class >> readLine: prompt [
+ <cCall: 'readline' returning: #stringOut args: #(#string)>
+ ]
+
+ ReadLine class >> addHistory: item [
+ <cCall: 'add_history' returning: #void args: #(#string)>
+ ]
+
+ ReadLine class >> readHistory: filePath [
+ <cCall: 'read_history' returning: #int args: #(#string)>
+ ]
+
+ ReadLine class >> writeHistory: filePath [
+ <cCall: 'write_history' returning: #int args: #(#string)>
+ ]
+]
--- /dev/null
+#!/bin/bash
+exec gst -f $(dirname $0)/${STEP:-stepA_mal}.st "${@}"
--- /dev/null
+FileStream fileIn: 'readline.st'.
+
+Object subclass: MAL [
+ MAL class >> READ: input [
+ ^input
+ ]
+
+ MAL class >> EVAL: sexp [
+ ^sexp
+ ]
+
+ MAL class >> PRINT: sexp [
+ ^sexp
+ ]
+
+ MAL class >> rep: input [
+ ^self PRINT: (self EVAL: (self READ: input))
+ ]
+]
+
+| input historyFile |
+
+historyFile := '.mal_history'.
+ReadLine readHistory: historyFile.
+
+[ input := ReadLine readLine: 'user> '. input isNil ] whileFalse: [
+ input isEmpty ifFalse: [
+ ReadLine addHistory: input.
+ ReadLine writeHistory: historyFile.
+ (MAL rep: input) displayNl.
+ ]
+]
+
+'' displayNl.