Skip to content

Commit

Permalink
vm: Variadic primitives support
Browse files Browse the repository at this point in the history
  • Loading branch information
okuoku committed Aug 4, 2022
1 parent a02c312 commit 7e15d6b
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions yuniribbit/rvm.sls
Expand Up @@ -78,6 +78,15 @@
(x (_car stack)) (stack (_cdr stack)))
(_cons (f x y z) stack))))

(define (primn f)
(lambda (vals stack)
(let loop ((rest vals)
(stack stack)
(args '()))
(if (= rest 0)
(_cons (apply f args) stack)
(loop (- rest 1) (_cdr stack) (cons (_car stack) args))))))

(define (boolean x)
(if x _true _false))

Expand Down Expand Up @@ -290,9 +299,9 @@
(else
(boolean (eqv? x y))))))
(prim2 (lambda (x y) (boolean (< x y)))) ;; 13
(prim2 +) ;; 14
(prim2 -) ;; 15
(prim2 *) ;; 16
(primn +) ;; 14
(primn -) ;; 15
(primn *) ;; 16
(prim2 quotient) ;; 17

(prim0 (lambda () ;; 18
Expand Down

0 comments on commit 7e15d6b

Please sign in to comment.