[honu] convert function bodies from honu to racket
This commit is contained in:
parent
a4123ce536
commit
dfe33f8919
|
@ -34,7 +34,7 @@
|
||||||
(lambda (code context)
|
(lambda (code context)
|
||||||
(syntax-parse code #:literal-sets (cruft)
|
(syntax-parse code #:literal-sets (cruft)
|
||||||
[(_ name (#%parens arg:honu-expression ...) . rest)
|
[(_ name (#%parens arg:honu-expression ...) . rest)
|
||||||
(define new #'(make-object name arg.result ...))
|
(define new #'(%racket (make-object name arg.result ...)))
|
||||||
(values
|
(values
|
||||||
new
|
new
|
||||||
#'rest
|
#'rest
|
||||||
|
|
18
collects/honu/core/private/compile.rkt
Normal file
18
collects/honu/core/private/compile.rkt
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
#lang racket/base
|
||||||
|
|
||||||
|
(require syntax/parse
|
||||||
|
"literals.rkt"
|
||||||
|
(for-template racket/base))
|
||||||
|
|
||||||
|
(provide honu->racket)
|
||||||
|
(define (honu->racket forms)
|
||||||
|
(define-literal-set literals (%racket))
|
||||||
|
;; (debug "honu to racket ~a\n" (pretty-format (syntax->datum forms)))
|
||||||
|
(syntax-parse forms #:literal-sets (literals)
|
||||||
|
[(%racket x) (honu->racket #'x)]
|
||||||
|
[(form ...)
|
||||||
|
(with-syntax ([(form* ...) (map honu->racket (syntax->list #'(form ...)))])
|
||||||
|
#'(form* ...))]
|
||||||
|
[x #'x]
|
||||||
|
[() forms]))
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
scheme/splicing
|
scheme/splicing
|
||||||
macro-debugger/emit
|
macro-debugger/emit
|
||||||
racket/pretty
|
racket/pretty
|
||||||
|
"compile.rkt"
|
||||||
"debug.rkt"
|
"debug.rkt"
|
||||||
"contexts.rkt"
|
"contexts.rkt"
|
||||||
"util.rkt"
|
"util.rkt"
|
||||||
|
@ -457,17 +458,6 @@ Then, in the pattern above for 'if', 'then' would be bound to the following synt
|
||||||
(define-for-syntax (honu-compile forms)
|
(define-for-syntax (honu-compile forms)
|
||||||
#'(void))
|
#'(void))
|
||||||
|
|
||||||
(define-for-syntax (honu->racket forms)
|
|
||||||
(define-literal-set literals (%racket))
|
|
||||||
;; (debug "honu to racket ~a\n" (pretty-format (syntax->datum forms)))
|
|
||||||
(syntax-parse forms #:literal-sets (literals)
|
|
||||||
[(%racket x) (honu->racket #'x)]
|
|
||||||
[(form ...)
|
|
||||||
(with-syntax ([(form* ...) (map honu->racket (syntax->list #'(form ...)))])
|
|
||||||
#'(form* ...))]
|
|
||||||
[x #'x]
|
|
||||||
[() forms]))
|
|
||||||
|
|
||||||
(provide honu-unparsed-begin)
|
(provide honu-unparsed-begin)
|
||||||
(define-syntax (honu-unparsed-begin stx)
|
(define-syntax (honu-unparsed-begin stx)
|
||||||
(emit-remark "Honu unparsed begin!" stx)
|
(emit-remark "Honu unparsed begin!" stx)
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
(define-splicing-syntax-class pattern-type
|
(define-splicing-syntax-class pattern-type
|
||||||
#:literal-sets (cruft)
|
#:literal-sets (cruft)
|
||||||
[pattern (~seq name colon class)
|
[pattern (~seq name colon class)
|
||||||
|
;; we know the output of syntactic classes will end with _result
|
||||||
#:with result (with-syntax ([name.result (format-id #'name "~a_result" #'name)])
|
#:with result (with-syntax ([name.result (format-id #'name "~a_result" #'name)])
|
||||||
#'(name name.result))]
|
#'(name name.result))]
|
||||||
[pattern x #:with result #f])
|
[pattern x #:with result #f])
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
(require ;; "macro2.rkt"
|
(require ;; "macro2.rkt"
|
||||||
"literals.rkt"
|
"literals.rkt"
|
||||||
"debug.rkt"
|
"debug.rkt"
|
||||||
|
"compile.rkt"
|
||||||
(prefix-in transformer: "transformer.rkt")
|
(prefix-in transformer: "transformer.rkt")
|
||||||
racket/pretty
|
racket/pretty
|
||||||
syntax/stx
|
syntax/stx
|
||||||
|
@ -147,7 +148,7 @@
|
||||||
(parse-arguments #'(args ...))])
|
(parse-arguments #'(args ...))])
|
||||||
#'(define (function parsed-arguments ...)
|
#'(define (function parsed-arguments ...)
|
||||||
(let-syntax ([parse-more (lambda (stx)
|
(let-syntax ([parse-more (lambda (stx)
|
||||||
(parse-all #'(code ...)))])
|
(honu->racket (parse-all #'(code ...))))])
|
||||||
(parse-more))))])
|
(parse-more))))])
|
||||||
|
|
||||||
;; E = macro
|
;; E = macro
|
||||||
|
@ -322,13 +323,9 @@
|
||||||
(syntax-parse #'(stuff ...) #:literal-sets (cruft)
|
(syntax-parse #'(stuff ...) #:literal-sets (cruft)
|
||||||
[(work:honu-expression colon (~seq variable:id honu-<- list:honu-expression (~optional honu-comma)) ...)
|
[(work:honu-expression colon (~seq variable:id honu-<- list:honu-expression (~optional honu-comma)) ...)
|
||||||
(define comprehension
|
(define comprehension
|
||||||
(with-syntax ([(list-parsed ...) (map (lambda (list)
|
#'(for/list ([variable list.result]
|
||||||
(parse-all list))
|
|
||||||
(syntax->list #'(list.result ...)))]
|
|
||||||
[work-parsed (parse-all #'work.result)])
|
|
||||||
#'(for/list ([variable list-parsed]
|
|
||||||
...)
|
...)
|
||||||
work-parsed)))
|
work.result))
|
||||||
(if current
|
(if current
|
||||||
(error 'parse "a list comprehension cannot follow an expression")
|
(error 'parse "a list comprehension cannot follow an expression")
|
||||||
(do-parse #'(rest ...) precedence left comprehension))]
|
(do-parse #'(rest ...) precedence left comprehension))]
|
||||||
|
@ -409,7 +406,8 @@
|
||||||
[code code])
|
[code code])
|
||||||
(define-values (parsed unparsed)
|
(define-values (parsed unparsed)
|
||||||
(parse (strip-stops code)))
|
(parse (strip-stops code)))
|
||||||
(debug "Parsed ~a unparsed ~a\n" (if parsed (syntax->datum parsed) parsed)
|
(debug "Parsed ~a unparsed ~a\n"
|
||||||
|
(if parsed (syntax->datum parsed) parsed)
|
||||||
(if unparsed (syntax->datum unparsed) unparsed))
|
(if unparsed (syntax->datum unparsed) unparsed))
|
||||||
(if (empty-syntax? unparsed)
|
(if (empty-syntax? unparsed)
|
||||||
(with-syntax ([(use ...) (reverse (if parsed
|
(with-syntax ([(use ...) (reverse (if parsed
|
||||||
|
|
Loading…
Reference in New Issue
Block a user