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
more fixups to the datomic code
  • Loading branch information
Timothy Baldridge committed Mar 15, 2013
commit 97634bb3a3423f42a713105d5b218bd2b5aec99e
91 changes: 42 additions & 49 deletions src/mjolnir/ssa.clj
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,37 @@
(defn new-plan [conn]
(->TxPlan conn (db conn) {} {} {}))

(defn commit [{:keys [conn db new-ents]}]
(d/transact conn (map
(fn [[ent id]]
(assoc ent :db/id id))
new-ents)))
(defn commit
"Commit processes the transaction with the associated connection, then updates all the tempids to match. You can then use plan-id to get the realized ent-ids"
[{:keys [conn db new-ents] :as plan}]
(let [data (map
(fn [[ent id]]
(assoc ent :db/id id))
new-ents)
{:keys [db-before db-after tempids tx-data]}
@(d/transact conn data)
ptempids (zipmap
(keys (:tempids plan))
(map (partial d/resolve-tempid db-after tempids)
(vals (:tempids plan))))]
(assoc plan
:tempids ptempids
:db db-after
:db-before db-before
:new-ents nil
:singletons nil)))

(defn plan-id
[plan val]
(if-let [v (or (get-in plan [:singletons val])
(get-in plan [:new-ents val]))]
(if-let [v (get-in plan [:tempids val])]
v
(assert false (str "Can't find " val))))

(defn singleton [plan sing]
(defn plan-ent
[plan val]
(d/entity (:db plan) (get-in plan [:tempids val])))

(defn singleton [plan sing key]
(if (get-in plan [:singletons sing])
plan
(if-let [q (find-singleton (:db plan) sing)]
Expand All @@ -115,54 +132,30 @@
(-> plan
(assoc-in [:singletons sing] newid)
(assoc-in [:new-ents sing] newid)
(assoc-in [:tempids newid] nil))))))
(assoc-in [:tempids key] newid))))))

(defn assert-entity [plan ent]
(defn assert-entity [plan ent key]
(let [newid (d/tempid :db.part/user)]
(-> plan
(assoc-in [:new-ents ent] nil)
(assoc-in [:tempids newid] nil))))


(defn transact-new [conn ent]
(let [ent (if-not (:db/id ent)
(assoc ent :db/id (d/tempid :db.part/user))
ent)
{:keys [db-after tempids]} @(d/transact conn [ent])
tid (:db/id ent)]
(->> (d/resolve-tempid db-after tempids tid)
(d/entity db-after))))

(defn transact-singleton [conn sing]
(let [genq (get-query sing)]
(println genq "\n " sing "\n \n")
(if-let [id (ffirst (q genq
(db conn)))]
(d/entity (db conn) id)
(transact-new conn sing))))

(defn transact-seq [conn seq]
(reduce (fn [acc x]
(transact-singleton
conn
(merge
(if-let [id (:db/id acc)]
{:list/tail id}
{})
{:list/head x})))
{}
(assoc-in [:tempids key] newid))))

(defn- assert-node [[plan last] id]
(let [ent (merge
(if last
{:list/tail last}
{})
{:list/head id})
new-plan (singleton plan ent ent)
new-id (plan-id new-plan ent)]
[new-plan new-id]))

(defn assert-seq [plan seq]
(reduce assert-node
[plan nil]
(reverse seq)))


(defn new-block [conn fn]
(transact-new ))


(defn to-seq [e]
(when-not (nil? e)
(cons (:list/head e)
(lazy-seq (to-seq (:list/tail e))))))

(defn new-db []
(let [url (str "datomic:mem://ssa" (name (gensym)))]
(d/create-database url)
Expand Down
22 changes: 14 additions & 8 deletions src/mjolnir/types.clj
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@
(-> plan
(singleton
{:node/type :type.int
:type/width width}))))
:type/width width}
this))))


(defrecord VoidType []
Expand Down Expand Up @@ -97,7 +98,8 @@
(singleton
plan
{:node/type :type.float
:type/width width})))
:type/width width}
this)))

(defn float-type? [tp]
(instance? FloatType tp))
Expand Down Expand Up @@ -134,7 +136,8 @@
(singleton
with-tp
{:node/type :type.pointer
:type/element-type (plan-id with-tp etype)}))))
:type/element-type (plan-id with-tp etype)}
this))))



Expand Down Expand Up @@ -190,12 +193,15 @@
(let [with-types (reduce
add-to-plan
plan
(cons ret-type arg-types))]
(singleton with-types
(cons ret-type arg-types))
[with-seq arg-id] (assert-seq with-types
(map (partial plan-id with-types)
arg-types))]
(singleton with-seq
{:node/type :type.fn
:type.fn/return (plan-id with-types ret-type)
:type.fn/arguments (map (partial plan-id with-types)
arg-types)}))))
:type.fn/return (plan-id with-seq ret-type)
:type.fn/arguments arg-id}
this))))


(defn flatten-struct [tp]
Expand Down
93 changes: 49 additions & 44 deletions test/mjolnir/ssa_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -78,54 +78,59 @@
count)
=>
2
)
#_(fact "IntegerType will re-assert different widths"
(to-datoms Float64*) =not=> (to-datoms Float32*))
#_(fact "Element type matches"
(:type/element-type (to-datoms Float64*)) => (to-datoms Float64)))
))

#_(let [ft (->FunctionType [Float64 Int64] Int64)]
(let [ft (->FunctionType [Float64 Int64] Int64)]
(facts "FunctionType"
(fact "FunctionType is singleton"
(to-datoms ft) => (to-datoms ft))
(fact "Functions have proper return types"
(:type.fn/return (to-datoms ft))
=>
(to-datoms Int64))
(fact "Functions have proper arguments"
(to-seq (:type.fn/arguments (to-datoms ft)))
(-> (new-plan *db-conn*)
(add-to-plan ft)
(add-to-plan ft)
:new-ents
count)
=>
[(to-datoms Float64)
(to-datoms Int64)])))
5)
(fact "Functions have proper return types"
(let [plan (-> (new-plan *db-conn*)
(add-to-plan ft)
commit)]
(:type.fn/return (plan-ent plan ft))
=>
(plan-ent plan Int64)))
#_(fact "Functions have proper arguments"
(to-seq (:type.fn/arguments (to-datoms ft)))
=>
[(to-datoms Float64)
(to-datoms Int64)])))

#_(let [ft (->FunctionType [Int64] Int64)
f (->Fn "ret0" ft ["a" "b"]
0)]
(facts "Fn"
(fact "Functions create new entities each time"
(to-datoms f)
=not=>
(to-datoms f))
(fact "Functions with the same types are the same types"
(:fn/type (to-datoms f))
=>
(:fn/type (to-datoms f)))
(fact "Functions assert names"
(->> (to-datoms f)
:fn/argument-names
to-seq
(map :argument/name))
=>
["a" "b"])
(fact "Functions assert indexes"
(->> (to-datoms f)
:fn/argument-names
to-seq
(map :argument/idx))
=>
[0 1])))
f (->Fn "ret0" ft ["a" "b"]
0)]
(facts "Fn"
(fact "Functions create new entities each time"
(to-datoms f)
=not=>
(to-datoms f))
(fact "Functions with the same types are the same types"
(:fn/type (to-datoms f))
=>
(:fn/type (to-datoms f)))
(fact "Functions assert names"
(->> (to-datoms f)
:fn/argument-names
to-seq
(map :argument/name))
=>
["a" "b"])
(fact "Functions assert indexes"
(->> (to-datoms f)
:fn/argument-names
to-seq
(map :argument/idx))
=>
[0 1])))
#_(facts "Long"
(fact "Can be transacted"
(:const/int-value (to-datoms 0))
=>
0)))
(fact "Can be transacted"
(:const/int-value (to-datoms 0))
=>
0)))