;; mole - vectored forth vm ;; main ideas: ;; - primitives are C functions -> interpreter is a trampoline / loop ;; - forth return stack is a separate (abstract: list,vector,?) structure ;; - proper tail calls ;; - words are tagged: at least 2 bits are used: literal + exit. (require "cgen.ss") (extend-expressions (transformer (define (car x) `(index ,x 0)) (define (cdr x) `(index ,x 1)) ;; stacks are easier on the eye as lvalues (define (top stack) `(* ,stack)) (define (push stack) `(* (pre ++ ,stack))) (define (pop stack) `(* (post -- ,stack))))) (define-syntax mole (syntax-rules () ((_ statement ...) (display (statement->string '(statements statement ...)))))) (mole (= (push s) 123) (= a (pop s)) (= b (top s)))