From 23fde15081cff22df3a870a7a8a5692b7761e0aa Mon Sep 17 00:00:00 2001 From: Tim Vaughan Date: Mon, 12 Jun 2017 23:33:27 +1200 Subject: [PATCH] Added define and set! cases to the macro expander. --- src/scheme-derived-forms.scm | 5 +++++ src/scheme.4th | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/scheme-derived-forms.scm b/src/scheme-derived-forms.scm index 1edd186..010519d 100644 --- a/src/scheme-derived-forms.scm +++ b/src/scheme-derived-forms.scm @@ -7,3 +7,8 @@ (if (pair? args) `(define ,(car args) (lambda ,(cdr args) ,@body)) 'no-match)) + +;; Macro expansion test code + +(define-macro (test) + '(begin (display "Hello!") (newline))) diff --git a/src/scheme.4th b/src/scheme.4th index 8d361fc..67b656c 100644 --- a/src/scheme.4th +++ b/src/scheme.4th @@ -1783,10 +1783,30 @@ defer expand R> drop ['] expand goto-deferred ; +: expand-definition ( exp -- result ) + define-symbol 2swap + + 2dup definition-var + 2swap definition-val expand + nil ( define var val' nil ) + + cons cons cons ; + +: expand-assignment ( exp -- result ) + set!-symbol 2swap + + 2dup assignment-var + 2swap assignment-val expand + nil ( define var val' nil ) + + cons cons cons ; + :noname ( exp -- result ) expand-macro + quote? if exit then + quasiquote? if expand-quasiquote exit then definition? if expand-definition exit then -- 2.20.1