rebirth: Add variable definitions (define)

`define' can now be used to define values in addition to the procedure
short-hand.

* build-aux/bootstrap/rebirth.scm
  (cdfn): New procedure.  Renamed original `cdfn' to `cdfn-proc'.
  (cdfn-var): New procedure.
  (cdfn-proc): Renamed from `cdfn'.
master
Mike Gerwitz 2017-12-05 00:32:40 -05:00
parent 1810fb7c38
commit 53ea5c5f4d
Signed by: mikegerwitz
GPG Key ID: 8C917B7F5DC51BA2
1 changed files with 22 additions and 1 deletions

View File

@ -340,10 +340,31 @@
(body->es rest ret))))) ; recurse
;; Compile variable or procedure definition into ES
;;
;; This performs a crude check to determine whether a procedure definition
;; was supplied: if the cadr of the given token T is itself token, then it
;; is considered to be a variable.
(define (cdfn t)
(if (token? (cadr t))
(cdfn-var t) ;; (define foo ...)
(cdfn-proc t))) ;; (define (foo ...) ...)
;; Compile variable definition into ES
;;
;; This compiles the token T into a simple let-assignment.
(define (cdfn-var t)
(let* ((dfn (cadr t))
(id (tname->id (token-value dfn)))
(value (sexp->es (caddr t))))
(string-append "let " id "=" value)))
;; Compile procedure definition into an ES function definition
;;
;; This will fail if the given token is not a `define'.
(define (cdfn t)
(define (cdfn-proc t)
;; e.g. (define (foo ...) body)
(let* ((dfn (cadr t))
(id (tname->id (token-value (car dfn))))