Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
sibilant run and compile time special definition example
(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
You can’t perform that action at this time.