Login
7 branches 0 tags
Ben (Win10) Fixed Windows modules loading be2c6e2 3 years ago 893 Commits
nujel / stdlib / compiler / backend.nuj
;;; 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] expr]
[defn compile/backend/bytecode [expr]
      [-> [bytecompile expr]
          assemble*]]

[def *active-backend* :bytecode]
[def backend/tree @[ :bytecode compile/backend/bytecode
                     :none compile/backend/none]]

[defn backend [expr]
      [[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]]]