Login
7 branches 0 tags
Ben (X13/Arch) Removed unnecessary parts of the C printer 958d5d3 3 years ago 834 Commits
nujel / stdlib / compiler / backend.nuj
;; Contains functions abstracting over different backends

[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]]]