Implement while loop

This commit is contained in:
Jeremy Penner 2021-08-11 23:06:31 -04:00
parent 8eef9e49b8
commit 65101ad21d
2 changed files with 11 additions and 5 deletions

View file

@ -20,8 +20,13 @@
(IMStartUp)
(TextStartUp)
; (if (= 1 1) (printnum 1) (printnum 2))
; (if (or (< 3 2) (not= 5 10)) (printnum 3) (printnum 4))
(let (x 1 dx 2 lim (if (> dx 0) 10 -10) break [ssc.FALSE])
(while (and (< x lim) (not break))
(printnum x)
(set! x (+ x dx))
(if (= x 6) (set! break [ssc.TRUE]))))
(if (> (+ 1 2) (+ 3 4)) (printnum 0x1212) (printnum 0x3434))
(if (and (or (= 1 2) (< 3 4)) ;
(not (or (> 10 3) (<= 6 5))))
(printnum 0xdead) (printnum 0xbeef))

View file

@ -32,9 +32,6 @@
; args are either strings (symbols) or numbers
; TODO:
; * implement global definitions
; * fix comparisons
; * implement loops
; * implement "getters" (subroutine that runs when referenced by name without an explicit call)
(import-macros {:sss ! : compile} :ssc.macros)
@ -242,6 +239,10 @@
cl-false (if ?iffalse [[:bra :-if-done-] :-if-false- c-false :-if-done-]
[:-if-false-])]
(values (lume.concat block cl-false) etype)))
:while (lambda [self test ...]
(let [block [:block :-loop-top- (self:gen-condition test :-enter-loop- :-exit-loop-) :-enter-loop-]
c-body (self:expr-poly [:do ...])]
(values (lume.concat block [c-body [:bra :-loop-top-] :-exit-loop-]) :void)))
:+ (lambda [self first ...]
(self:accumulation-op
(fn [etype {: lo : hi : const}]