Login
7 branches 0 tags
Ben (X13/Arch) Simplified things a little 0643405 9 days ago 1260 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 env)
      :internal
      expr)

(defn compile/backend/bytecode (expr env)
      :internal
      (-> (bytecompile expr env)
          (assemble* env)))

(def *active-backend* :bytecode)
(def backend/tree { :bytecode compile/backend/bytecode
                    :none compile/backend/none})

(defn backend (expr env)
      :internal
      ((ref backend/tree *active-backend*) expr env))

(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)))