self-host: scaffold portable jolt-core + host/core architecture
Adds doc/self-hosting-architecture.md: the portability design (portable front end + host back end + host runtime, seam = a minimal host protocol + the IR), grounded in the CLJS/Clojure-in-Clojure prior art. Decisions locked: minimal host protocol as the seam; physical split with a jolt-core/ source root. Adds jolt-core/ as a portable Clojure source root (dev path + embedded into the binary alongside the rest of the stdlib) and jolt-core/jolt/ir.clj — host-neutral IR node constructors (vars referenced by name, no host values embedded). Verified it loads and runs under both interpreter and compiler.
This commit is contained in:
parent
6c61d445fb
commit
b1ac427bdd
4 changed files with 185 additions and 2 deletions
42
jolt-core/jolt/ir.clj
Normal file
42
jolt-core/jolt/ir.clj
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
(ns jolt.ir
|
||||
"Host-neutral intermediate representation for the Jolt compiler.
|
||||
|
||||
The analyzer (jolt.analyzer) produces IR; a host back end consumes it. IR nodes
|
||||
are plain maps tagged with :op — no host values embedded. Globals reference vars
|
||||
by name (:ns/:name), never by a host var cell, so the IR is portable and
|
||||
AOT-safe. This namespace is pure Clojure (portable jolt-core): it depends on
|
||||
nothing host-specific.")
|
||||
|
||||
;; Node constructors. Kept as data so any back end can pattern-match on :op.
|
||||
|
||||
(defn const [v] {:op :const :val v})
|
||||
|
||||
(defn local [name] {:op :local :name name})
|
||||
|
||||
;; A global var reference, by name. The back end resolves it to a host var.
|
||||
(defn var-ref [ns name] {:op :var :ns ns :name name})
|
||||
|
||||
;; A runtime primitive (cons, +, get, apply, …) the back end maps to the host RT.
|
||||
(defn rt [name] {:op :rt :name name})
|
||||
|
||||
(defn if-node [test then else] {:op :if :test test :then then :else else})
|
||||
|
||||
(defn do-node [statements ret] {:op :do :statements statements :ret ret})
|
||||
|
||||
(defn invoke [f args] {:op :invoke :fn f :args args})
|
||||
|
||||
(defn def-node [ns name init] {:op :def :ns ns :name name :init init})
|
||||
|
||||
(defn let-node [bindings body] {:op :let :bindings bindings :body body})
|
||||
|
||||
;; A fn is one or more arities. Each arity: {:params [..] :rest name|nil :body ir}.
|
||||
(defn fn-node [name arities] {:op :fn :name name :arities arities})
|
||||
|
||||
(defn vector-node [items] {:op :vector :items items})
|
||||
(defn map-node [pairs] {:op :map :pairs pairs})
|
||||
(defn set-node [items] {:op :set :items items})
|
||||
|
||||
(defn quote-node [form] {:op :quote :form form})
|
||||
(defn throw-node [expr] {:op :throw :expr expr})
|
||||
|
||||
(defn op [node] (:op node))
|
||||
Loading…
Add table
Add a link
Reference in a new issue