Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge in Datomic sources #9

Merged
merged 35 commits into from
May 10, 2013
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
5a61c8c
work adding datomic
Mar 9, 2013
968e487
Added float, pointer, and fn types to ssa
Mar 9, 2013
ce8d9fe
latest work on ssa
Mar 11, 2013
19af157
latest work on datomic code
Mar 14, 2013
97634bb
more fixups to the datomic code
Mar 15, 2013
957d97c
Functions are commited
Mar 15, 2013
3b4d1c3
start of ssa refactor using state modnads(-ish)
Mar 21, 2013
a1c6637
If blocks are kindof implemented
Mar 26, 2013
5c61e2f
need validation/type inference next
Mar 28, 2013
b19b463
more work on the datomic backend
Mar 30, 2013
3058b58
fixed phi node linking
Mar 30, 2013
dce71cc
loops are working now
Apr 3, 2013
1e28bcc
reworked the binop system
Apr 4, 2013
df849ed
removing out-dated tests
Apr 4, 2013
6033e37
updated project.clj
Apr 4, 2013
6c00ba1
forgot to add some recent files
Apr 4, 2013
ea0d1ec
fixed malloc bug and other changes
Apr 25, 2013
7f5c3bf
added aset
Apr 27, 2013
4fd1c33
started fixing up the bf example to the new api
Apr 30, 2013
8e2fc49
bf compiler is working
May 1, 2013
d420f23
rewrote inference with pure clojure
May 2, 2013
6a4cab0
added fn translator
May 4, 2013
e697998
tons of updates, but tests are still broken
May 5, 2013
d349b89
some fixes, still some issues
May 6, 2013
c350f49
fixed a ugly bug with args
May 7, 2013
bbf305d
mandelbrot tests compile now
May 7, 2013
c068460
removed a ton of unused code in expressions.clj
May 7, 2013
a10a596
implementing structs, set, get
May 8, 2013
ae31ff6
added get
May 9, 2013
058b8d9
simple_lisp.clj can now compile to datomic
May 10, 2013
e7de853
more debugging
May 10, 2013
5fd7b4f
latest updates and fixes
May 10, 2013
5f72ef4
Update README.md
halgari May 10, 2013
a408004
updated version
May 10, 2013
8df3a6c
Merge branch 'datomic' of https://github.com/halgari/mjolnir into dat…
May 10, 2013
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
latest updates and fixes
  • Loading branch information
Timothy Baldridge committed May 10, 2013
commit 5fd7b4f54ef6dc715ebba9edffcd0cd6a2d659ad
2 changes: 1 addition & 1 deletion resources/examples/simple-lisp/fib.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
(fib (+ a -2))))))

(defn -run []
(print (fib 40)))
(fib 10))
11 changes: 10 additions & 1 deletion src/mjolnir/constructors_init.clj
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,15 @@

(defn- convert-form-1 [x]
(cond
(and (seq? x)
(symbol? (first x))
(> (count (name (first x))) 2)
(= (.substring (name (first x)) 0 2) ".-"))
(convert-form (list 'get
(fnext x)
(keyword (.substring (name (first x)) 2))))


(seq? x)
(convert-form x)

Expand All @@ -312,7 +321,7 @@

(set? x)
(into #{} (convert-form x))

(and (symbol? x)
(constructor? x))
(let [s
Expand Down
3 changes: 2 additions & 1 deletion src/mjolnir/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[datomic.api :refer [q db] :as d]
[mjolnir.config :refer [*int-type* *target* default-target]]
[mjolnir.ssa :refer :all]
[mjolnir.llvm-builder :refer [build dump verify]]))
[mjolnir.llvm-builder :refer [build dump optimize verify]]))

(defn to-db [m]
(let [conn (new-db)]
Expand All @@ -24,6 +24,7 @@
(let [built (build (db conn))]
#_(dump built)
(verify built)
(optimize built)
built))

(defn build-module [m]
Expand Down
11 changes: 6 additions & 5 deletions src/mjolnir/inference.clj
Original file line number Diff line number Diff line change
Expand Up @@ -55,26 +55,27 @@
data (map (fn [[id attr val]]
[:db/add id attr val])
nodes)]
(d/transact conn data)
(let [remaining (concat (q '[:find ?id ?attr
@(d/transact conn data)
(let [db-val (db conn)
remaining (concat (q '[:find ?id ?attr
:where
[?id :node/return-type ?tp]
[?tp :node/type :node.type/unknown]
[(identity :node/return-type) ?attr]]
(db conn))
db-val)
(q '[:find ?id ?attr
:where
[?id :inst.cast/type :inst.cast/unknown]
[?id :node/return-type ?tp-to]
[?tp-to :node/type ?data1]
[(identity :inst.cast/type) ?attr]]
(db conn)))]
db-val))]
(when-not (= 0 (count remaining))
(println "Remaining nodes...")
(println (pr-str (q '[:find ?nm
:where
[_ :fn/name ?nm]]
(db conn))))
db-val)))
(doseq [[id attr] remaining]
(let [ent (d/entity db-val id)]
(println
Expand Down
30 changes: 26 additions & 4 deletions src/mjolnir/llvm_builder.clj
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
(defmulti build-type :node/type)

(defmulti build-instruction (fn [d module builder fn inst defs]
(println (:db/id inst))
(:inst/type inst)))

(defmulti build-terminator (fn [module builder fn inst defs]
Expand Down Expand Up @@ -88,6 +87,9 @@
[x]
(llvm/VoidType))

(defmethod encode-const :type/pointer
[tp val]
(llvm/ConstNull (build-type tp)))


(defmethod build-type :type/float
Expand Down Expand Up @@ -314,6 +316,14 @@
blocks)]
(link-phi-nodes this defs))))

(defmethod build-item :node.type/global
[db-val module {name :global/name type :global/type :as this}]
(when-not (:global/extern? this)
(let [gbl (llvm/GetNamedGlobal module name)]
(assert gbl (str "Can't find Global " (pr-str name)))
(llvm/SetInitializer gbl (encode-const type val))
gbl)))


(defmethod build-instruction :default
[d module builder fn itm defs]
Expand Down Expand Up @@ -387,6 +397,11 @@
[dest]
(llvm/BuildBr builder dest)))

(defmethod build-instruction :inst.type/sizeof
[d module builder fn inst defs]
(assoc defs inst
(llvm/SizeOf (build-type (:inst.sizeof/type inst)))))

(defmethod build-instruction :inst.type/br
[d module builder fn inst defs]
(unpack-args defs inst
Expand Down Expand Up @@ -496,6 +511,15 @@
(llvm/BuildCall builder fnc (llvm/map-parr identity args) (count args) (str (:db/id inst)))
(assoc defs inst))))

(defmethod build-instruction :inst.type/callp
[d module builder fn inst defs]
(let [args (map defs (args-seq inst))
fnc (defs (:inst.callp/fn inst))]
(assert (and (every? identity args) fnc))
(->>
(llvm/BuildCall builder fnc (llvm/map-parr identity args) (count args) (str (:db/id inst)))
(assoc defs inst))))


(defmethod build-instruction :inst.type/malloc
[d module builder fn inst defs]
Expand Down Expand Up @@ -586,7 +610,6 @@
[d module builder fn inst defs]
(unpack-args defs inst
[val]
(println (d/touch inst))
(let [to-type (-> inst
:node/return-type
build-type)
Expand Down Expand Up @@ -660,8 +683,7 @@
(build-type (pointer-to return-type))
(str "casted_" (:db/id inst)))
gep (llvm/BuildStructGEP builder casted idx (str "gep_" (:db/id inst)))]
(llvm/BuildLoad builder gep (str "get_"(:db/id inst)))
ptr)))
(llvm/BuildLoad builder gep (str "get_"(:db/id inst))))))

(defn build [db]
(let [globals (->> (q '[:find ?id
Expand Down
6 changes: 6 additions & 0 deletions src/mjolnir/ssa_rules.clj
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,12 @@
[?arg1-t :node/type :type/pointer]
[(identity :inst.cast.type/bitcast) ?op])

(defrule cast-subtype [?id ?arg0-t ?arg1-t ?op]
"Functions can be bitcast"
[?arg0-t :node/type :type/fn]
[?arg1-t :node/type :type/pointer]
[(identity :inst.cast.type/bitcast) ?op])

(defrule cast-subtype [?id ?arg0-t ?arg1-t ?op]
"Larger Ints truncate to smaller ints"
[?arg0-t :node/type :type/pointer]
Expand Down
2 changes: 1 addition & 1 deletion test/mjolnir/simple_tests.clj
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@

(defnf struct-fn [MyStruct* foo -> Float64*]
(set foo :x 42)
(get foo :x)
(.-x foo)
(Float64* foo))

(deftest compile-struct
Expand Down