Load defs from defs.txt.
They are loaded at runtime though :( shouldn't be too hard to fix that?
This commit is contained in:
parent
b6c3c364d0
commit
d014709a32
|
|
@ -1,6 +1,8 @@
|
|||
(import (chicken io))
|
||||
(import (chicken string))
|
||||
(import srfi-69)
|
||||
|
||||
|
||||
(define (joy stack expression dict)
|
||||
(if (null? expression)
|
||||
(values stack dict)
|
||||
|
|
@ -78,25 +80,26 @@
|
|||
(string-intersperse (map joy-term->string expr) " "))
|
||||
|
||||
(define (doit text)
|
||||
(receive (stack dict)
|
||||
(joy '() (text->expression text) '())
|
||||
(receive (stack _dict)
|
||||
(joy '() (text->expression text) (initialize))
|
||||
(joy-expression->string stack)))
|
||||
|
||||
|
||||
(define (initialize defs dict)
|
||||
(map (lambda (def) (add-def dict def)) (string-split defs "\n")))
|
||||
(define (initialize)
|
||||
(load-defs
|
||||
; TODO: load defs at compile-time, not run-time.
|
||||
(with-input-from-file "../defs.txt" read-string)
|
||||
(make-hash-table string=? string-hash)))
|
||||
|
||||
(define (load-defs defs dict)
|
||||
(map (lambda (def) (add-def def dict)) (string-split defs "\n"))
|
||||
dict)
|
||||
|
||||
(define (add-def def dict)
|
||||
(let ((def_list (text->expression def)))
|
||||
(hash-table-set! dict (car def_list) (cdr def_list))))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
(display (doit "ab cd [[ ]] 23 4 - dup - [true] false"))
|
||||
(newline)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue