application/octet-stream
•
1.13 KB
•
35 lines
;;; Nujel - Copyright (C) 2020-2021 - Benjamin Vincent Schulenburg
;;; This project uses the MIT license, a copy should be included under /LICENSE
;;;
;;; Contains an abstraction that allows for multiple backends, right now we only
;;; support :bytecode and :none (:none is lowered Nujel, with most of the sugar removed).
[defn compile/backend/none [expr]
:cat :compiler
:internal
expr]
[defn compile/backend/bytecode [expr]
:cat :compiler
:internal
[-> [bytecompile expr]
assemble*]]
[def *active-backend* :bytecode]
[def backend/tree @[ :bytecode compile/backend/bytecode
:none compile/backend/none]]
[defn backend [expr]
:cat :compiler
:internal
[[tree/ref backend/tree *active-backend*] expr]]
[defn compile/for [backend expr environment]
[def last-backend *active-backend*]
[def ret #nil]
[try [fn [e]
[set! *active-backend* last-backend]
[throw e]]
[set! *active-backend* backend]
[set! ret [compile expr environment]]
[set! *active-backend* last-backend]
[return ret]]]