Implement step 0
authorVasilij Schneidermann <mail@vasilij.de>
Wed, 28 Jun 2017 22:59:18 +0000 (00:59 +0200)
committerVasilij Schneidermann <mail@vasilij.de>
Sat, 1 Jul 2017 20:33:38 +0000 (22:33 +0200)
Makefile
gst/Makefile [new file with mode: 0644]
gst/readline.st [new file with mode: 0644]
gst/run [new file with mode: 0755]
gst/step0_repl.st [new file with mode: 0644]

index ab2b4fd..cc8e49e 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -78,7 +78,7 @@ DOCKERIZE =
 #
 
 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 \
@@ -175,6 +175,7 @@ forth_STEP_TO_PROG =   forth/$($(1)).fs
 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))
diff --git a/gst/Makefile b/gst/Makefile
new file mode 100644 (file)
index 0000000..f6c19c8
--- /dev/null
@@ -0,0 +1,17 @@
+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]"
+
diff --git a/gst/readline.st b/gst/readline.st
new file mode 100644 (file)
index 0000000..2dca73c
--- /dev/null
@@ -0,0 +1,20 @@
+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)>
+    ]
+]
diff --git a/gst/run b/gst/run
new file mode 100755 (executable)
index 0000000..4d413ea
--- /dev/null
+++ b/gst/run
@@ -0,0 +1,2 @@
+#!/bin/bash
+exec gst -f $(dirname $0)/${STEP:-stepA_mal}.st "${@}"
diff --git a/gst/step0_repl.st b/gst/step0_repl.st
new file mode 100644 (file)
index 0000000..982d89d
--- /dev/null
@@ -0,0 +1,34 @@
+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.