Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions self/mbe.scm
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,24 @@
(hd . tl) -> (loop tl)
)))

(define (expand-fields field_list r) ;; (list field) (list sexp) -> (list field)
(match field_list with
(list:nil) -> (list:nil)
(list:cons (field:t sym sxp) rest) ->
(list:cons
(field:t sym (expand-pattern sxp r))
(expand-fields rest r))))


(define (expand-pattern p r) ;; sexp, (list sexp) -> sexp
(match p with
(sexp:list pl) -> (sexp:list (expand-list pl r))
(sexp:vector pl) -> (sexp:vector (expand-list pl r))
(sexp:symbol sym) -> (match (mbe/assoc sym r) with
(maybe:yes v) -> v
(maybe:no) -> p)
(sexp:record fl) -> (sexp:record (expand-fields fl r))
(sexp:attr sxp sym) -> (sexp:attr (expand-pattern sxp r) sym)
x -> x
))

Expand Down
19 changes: 19 additions & 0 deletions tests/t_macro1.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

(include "lib/basis.scm")

;; test attributes in macros
(defmacro access_field
(access_field a) -> a.field)

(define a_rec {field="1"})
(printn (access_field a_rec)) ;; -> "1"


;; test record creation in macros
(defmacro create_record
(create_record a) -> {field=a})

(define new_rec (create_record "test")) ;; -> {field="test"}

(printn new_rec.field) ;; -> "test"