add function as a macro
This commit is contained in:
parent
03dc212d61
commit
acb3bce1e7
|
@ -1,10 +1,10 @@
|
||||||
#lang scheme/base
|
#lang racket/base
|
||||||
|
|
||||||
(require (for-syntax scheme/base))
|
(require (for-syntax racket/base))
|
||||||
|
|
||||||
(provide debug)
|
(provide debug)
|
||||||
|
|
||||||
(define-for-syntax verbose? #f)
|
(define-for-syntax verbose? (getenv "HONU_DEBUG"))
|
||||||
(define-syntax (debug stx)
|
(define-syntax (debug stx)
|
||||||
(if verbose?
|
(if verbose?
|
||||||
(syntax-case stx ()
|
(syntax-case stx ()
|
||||||
|
|
22
collects/honu/core/private/honu2.rkt
Normal file
22
collects/honu/core/private/honu2.rkt
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
#lang racket/base
|
||||||
|
|
||||||
|
(require "macro2.rkt"
|
||||||
|
(for-syntax syntax/parse
|
||||||
|
"literals.rkt"
|
||||||
|
"parse2.rkt"
|
||||||
|
racket/base))
|
||||||
|
|
||||||
|
|
||||||
|
(provide honu-function)
|
||||||
|
(define-honu-syntax honu-function
|
||||||
|
(lambda (code context)
|
||||||
|
(syntax-parse code #:literal-sets (cruft)
|
||||||
|
[(_ name:identifier (#%parens arg:identifier ...)
|
||||||
|
(#%braces code ...)
|
||||||
|
. rest)
|
||||||
|
(values
|
||||||
|
#'(define (name arg ...)
|
||||||
|
(let-syntax ([do-parse (lambda (stx)
|
||||||
|
(parse #'(code ...)))])
|
||||||
|
(do-parse)))
|
||||||
|
#'rest)])))
|
|
@ -63,7 +63,7 @@
|
||||||
(define (do-parse stream precedence left current)
|
(define (do-parse stream precedence left current)
|
||||||
(debug "parse ~a precedence ~a left ~a current ~a\n" stream precedence left current)
|
(debug "parse ~a precedence ~a left ~a current ~a\n" stream precedence left current)
|
||||||
(syntax-parse stream
|
(syntax-parse stream
|
||||||
[() #'(void)]
|
[() left]
|
||||||
[(head rest ...)
|
[(head rest ...)
|
||||||
(cond
|
(cond
|
||||||
[(honu-macro? #'head)
|
[(honu-macro? #'head)
|
||||||
|
@ -101,7 +101,7 @@
|
||||||
|
|
||||||
)]))
|
)]))
|
||||||
|
|
||||||
(do-parse input 0 #f #f))
|
(do-parse input 0 #'(void) #'(void)))
|
||||||
|
|
||||||
(define (parse2 forms)
|
(define (parse2 forms)
|
||||||
(debug "parse forms ~a\n" forms)
|
(debug "parse forms ~a\n" forms)
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
(require
|
(require
|
||||||
(prefix-in macro_ honu/core/private/macro2)
|
(prefix-in macro_ honu/core/private/macro2)
|
||||||
|
(rename-in honu/core/private/honu2
|
||||||
|
[honu-function honu_function])
|
||||||
(rename-in honu/core/private/literals
|
(rename-in honu/core/private/literals
|
||||||
[honu-= =]
|
[honu-= =]
|
||||||
[semicolon |;|])
|
[semicolon |;|])
|
||||||
|
@ -33,3 +35,9 @@
|
||||||
|
|
||||||
(fake-module-begin #hx(var x = 2;
|
(fake-module-begin #hx(var x = 2;
|
||||||
print(x)))
|
print(x)))
|
||||||
|
|
||||||
|
(let ()
|
||||||
|
(fake-module-begin #hx(honu_function test(x){
|
||||||
|
print(x)
|
||||||
|
}))
|
||||||
|
(test 5))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user