wisp
 
(Arne Babenhauserheide)
2015-06-23: break wisp chunk at the next top-level form and compile to tree-il

break wisp chunk at the next top-level form and compile to tree-il to avoid wrapping top-level forms in begin.

diff --git a/wisp-reader.w b/wisp-reader.w
--- a/wisp-reader.w
+++ b/wisp-reader.w
@@ -14,6 +14,8 @@ define-module : language wisp spec
   . #:use-module : wisp-scheme
   . #:use-module : system base compile
   . #:use-module : system base language
+  . #:use-module : language scheme compile-tree-il
+  . #:use-module : language scheme decompile-tree-il
   . #:export : wisp
 
 ; Set locale to something which supports unicode. Required to avoid using fluids.
@@ -23,34 +25,6 @@ setlocale LC_ALL ""
 ;;; Language definition
 ;;;
 
-define : compile-scheme x e opts
-       values x e e
-
-define : decompile-scheme x e opts
-       values x e
-
-define wisp-pending-port : make-object-property
-
-; Code thanks to Mark Weaver
-; define : read-one-wisp-sexp port env
-;   define : read-wisp-chunk
-;     if : eof-object? : peek-char port
-;       read-char port ; return eof: we’re done
-;       let : : s : wisp2lisp : wisp-chunkreader port
-;         set! : wisp-pending-port port
-;                open-input-string s
-;         try-pending
-;   define : try-pending
-;     let : : pending-port : wisp-pending-port port
-;       if pending-port
-;           let : : x : read pending-port
-;              if : eof-object? x
-;                 read-wisp-chunk
-;                 . x
-;           read-wisp-chunk
-;   try-pending
-
-
 define wisp-pending-sexps : list
 
 define : read-one-wisp-sexp port env
@@ -69,18 +43,19 @@ define : read-one-wisp-sexp port env
             : sexp : car wisp-pending-sexps
               pending wisp-pending-sexps
             set! wisp-pending-sexps : list ; : cdr wisp-pending-sexps
-            ; write : cons 'begin pending
+            ; write pending
             if : = 1 : length pending
                  car pending
                  cons 'begin pending
   try-pending
 
+
 define-language wisp
   . #:title "Wisp Scheme Syntax. See SRFI-119 for details. THIS IS EXPERIMENTAL, USE AT YOUR OWN RISK"
   ; . #:reader read-one-wisp-sexp
-  . #:reader : lambda (port env) : let ((x (read-one-wisp-sexp port env))) x
-  . #:compilers `((scheme . ,compile-scheme))
-  . #:decompilers `((scheme . ,decompile-scheme))
+  . #:reader : lambda (port env) : let ((x (read-one-wisp-sexp port env))) (write x)(newline) x
+  . #:compilers `((tree-il . ,compile-tree-il))
+  . #:decompilers `((tree-il . ,decompile-tree-il))
   . #:evaluator : lambda (x module) : primitive-eval x
   . #:printer write ; TODO: backtransform to wisp? Use source-properties?
   . #:make-default-environment
diff --git a/wisp-scheme.w b/wisp-scheme.w
--- a/wisp-scheme.w
+++ b/wisp-scheme.w
@@ -210,12 +210,16 @@ define : wisp-scheme-read-chunk-lines po
              currentindent 0
              currentsymbols '()
              emptylines 0
-           if : <= 2 emptylines ; the chunk end has to be checked
-                                ; before we look for new chars in the
-                                ; port to make execution in the REPL
-                                ; after two empty lines work
-                                ; (otherwise it shows one more line).
+           cond
+            : <= 2 emptylines ; the chunk end has to be checked
+                              ; before we look for new chars in the
+                              ; port to make execution in the REPL
+                              ; after two empty lines work
+                              ; (otherwise it shows one more line).
              . indent-and-symbols
+            : and inindent (zero? currentindent) (not (null? indent-and-symbols)) (not inunderscoreindent) (not (or (equal? #\space (peek-char port)) (equal? #\newline (peek-char port))))
+             . indent-and-symbols ; top-level form ends chunk
+            else
              let : : next-char : peek-char port
                cond
                  : eof-object? next-char