Created
August 4, 2017 19:34
Star
You must be signed in to star a gist
sibilant run and compile time special definition example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defmacro pseudop (method . args) | |
(let ((as-name (symbol (+ "emit_" (str method)))) | |
(method (symbol (+ "__compiler__.pseudop_" (str method))))) | |
(if args | |
`(defmacro ,as-name ,args | |
(cons ',method ,@args nil)) | |
`(defmacro ,as-name () | |
(cons ',method nil))))) | |
;; this is just extra laziness -- it creates an emit_BLA macro that | |
;; just calls __compiler__.pseudop_BLA | |
(pseudop position_of body) | |
(pseudop get_var varname) | |
(pseudop const value) | |
(pseudop call argc) | |
(defmacro defspecial (name args . &body) | |
`(define ,name (special (lambda ,args ,@&body) ,(str name)))) | |
(defspecial push-symbol (env &body) | |
(emit_position_of &body) | |
(let ((called_as (first &body)) | |
(sym (second &body))) | |
(emit_get_var "symbol") | |
(emit_const (str sym)) | |
(emit_call 1)) | |
;; needs to return None to let the compiler know that no further | |
;; transformations are needed. I do that explicitly, but the result | |
;; of the above should have also evaluated to None | |
None) | |
(let ((T (push-symbol tacos))) | |
(print (symbol? T)) ; True | |
(print T) ; tacos | |
(print (type T)) ; <class 'sibilant.Symbol'> | |
(print (repr T))) ; symbol('tacos') | |
;; The end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment