Skip to content

Commit

Permalink
get-code
Browse files Browse the repository at this point in the history
  • Loading branch information
fbielejec committed Jan 5, 2019
1 parent db6690c commit f603505
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
24 changes: 20 additions & 4 deletions src/leiningen/solc.clj
Expand Up @@ -102,17 +102,27 @@
(when-not (.isDirectory file)
(.mkdirs file))))

;; TODO: shim file in tmp dir before compiling
;; TODO : get code
;; TODO : pass to parser
;; TODO : generate shim (solidity code)
;; TODO : in tmp dir replace code with shim in the source file
;; TODO : pass shimmed file for compiling

(defn get-code
[file]
(first (re-find #"(?is)(matches\()(.*)(\);)" (slurp file))))

(defn compile-contract [{:keys [filename src-path build-path abi? bin? truffle-artifacts? solc-err-only verbose byte-count optimize-runs] :as opts-map}]
(let [file-path (str (ensure-slash src-path) filename)
code (get-code file-path)
ast (-> file-path
slurp
matches/parse)
initial-state (atom {:columns []
:patterns []
:returns []})
updated-state (matches/visit-tree ast initial-state)
solidity (generator/generate-solidity @updated-state)
shim (generator/generate-solidity @updated-state)
runs (or (cond
(integer? optimize-runs)
optimize-runs
Expand All @@ -121,8 +131,14 @@
(get optimize-runs filename))
200)]

(prn solidity)
;; TODO: replace in source
(prn
code
shim
)



;; TODO : replace in source
;; TODO : compile (in memory?)

#_(sh/with-sh-dir src-path
Expand Down
3 changes: 2 additions & 1 deletion src/shim/matches.clj
Expand Up @@ -7,7 +7,7 @@
[clojure.spec.alpha :as s]
[clojure.java.io :as io]
[clj-antlr.core :as antlr]
[shim.dev :refer [ast]]))
#_[shim.dev :refer [ast]]))

;; Match m =
;; matches([x, y, z],
Expand All @@ -30,6 +30,7 @@
;;---spec---;;
;;;;;;;;;;;;;;
(def wildcard "_")
(def matches "matches")

(s/def ::expression #{:expression})
(s/def ::primary-expression #{:primaryExpression})
Expand Down

0 comments on commit f603505

Please sign in to comment.