-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepl.scm
41 lines (35 loc) · 1.05 KB
/
repl.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
;;;; repl.scm
;;;;
;;;; Runs a read evaluate print loop function in Scheme for Scheme.
(use srfi-1)
(use srfi-9)
(use srfi-69)
(load "env.scm")
(load "vm.scm")
;;; Constants
(define prompt "-: ")
(define doublequote-char (string #\"))
;; Reads input from the user
(define (read-input)
(read))
;; Prints objects out to stdout
(define (print-obj obj)
(cond
[(string? obj) (display
(string-append doublequote-char obj doublequote-char))]
[(char? obj) (display (string-append "#\\" (string obj)))]
[(equal? obj 'error) (display "ERROR!")]
[else (display obj)])
(newline))
;; Entry point into the repl. This will currently loop infinitely.
(define (repl)
(define (repl-inner env)
(display prompt)
(let-values (((result new-env) (vm-eval (read-input) env)))
(print-obj result)
; TODO: Seperate repl command logic from eval logic. The repl should
; be catching this before passing to vm-eval.
(if (not (equal? result 'quit))
(repl-inner new-env)
'())))
(repl-inner (make-env)))