This commit is contained in:
sforman 2023-08-11 21:27:41 -07:00
parent 172407fef1
commit 8df8634e39
1 changed files with 9 additions and 1 deletions

View File

@ -59,6 +59,7 @@
((is-it? "i") (joy-i stack expression dict)) ((is-it? "i") (joy-i stack expression dict))
((is-it? "dip") (joy-dip stack expression dict)) ((is-it? "dip") (joy-dip stack expression dict))
((is-it? "branch") (joy-branch stack expression dict)) ((is-it? "branch") (joy-branch stack expression dict))
((is-it? "loop") (joy-loop stack expression dict))
((hash-table-exists? dict symbol) ((hash-table-exists? dict symbol)
(values stack (append (hash-table-ref dict symbol) expression) dict)) (values stack (append (hash-table-ref dict symbol) expression) dict))
@ -86,6 +87,13 @@
(append (if flag true_body false_body) expression) (append (if flag true_body false_body) expression)
dict))) dict)))
(define (joy-loop stack expression dict)
(let ((flag (cadr stack))
(body (car stack)))
(values (cddr stack)
(if flag (append body (cons body (cons "loop" expression))) expression)
dict)))
(define (string-replace str from to) (define (string-replace str from to)
(string-intersperse (string-split str from #t) to)) (string-intersperse (string-split str from #t) to))
@ -159,6 +167,6 @@
(hash-table-set! dict (car def_list) (cdr def_list)))) (hash-table-set! dict (car def_list) (cdr def_list))))
(display (doit "true [4] [5] branch false [4] [5] branch + sqr")) (display (doit "1 2 true [4 5 false] loop"))
(newline) (newline)