From 44aaf4a156e94e4fc6539e1040ea227ef00119f5 Mon Sep 17 00:00:00 2001
From: skwak22 <skwak22@amherst.edu>
Date: Wed, 15 Jul 2020 21:19:38 +0900
Subject: [PATCH 1/4] introduce shadow-cljs as ClojureScript compiler

---
 .DS_Store                                     | Bin 0 -> 6148 bytes
 README.md                                     |  34 ++++++++++++++++++
 assets/index.html                             |  11 ++++++
 deps.edn                                      |   1 -
 package.json                                  |  21 +++++++++++
 shadow-cljs.edn                               |   7 ++++
 src/.DS_Store                                 | Bin 6148 -> 6148 bytes
 src/propeller/.DS_Store                       | Bin 6148 -> 6148 bytes
 src/propeller/main.cljs                       |   8 +++++
 src/propeller/problems/software/smallest.cljc |   6 ++--
 src/propeller/push/.DS_Store                  | Bin 6148 -> 6148 bytes
 .../push/utils/{macros.clj => macros.cljc}    |   0
 12 files changed, 85 insertions(+), 3 deletions(-)
 create mode 100644 .DS_Store
 create mode 100644 assets/index.html
 delete mode 100644 deps.edn
 create mode 100644 package.json
 create mode 100644 shadow-cljs.edn
 create mode 100644 src/propeller/main.cljs
 rename src/propeller/push/utils/{macros.clj => macros.cljc} (100%)

diff --git a/.DS_Store b/.DS_Store
new file mode 100644
index 0000000000000000000000000000000000000000..9a874b5768f336915163bb88cd434575b859f936
GIT binary patch
literal 6148
zcmeH~Jr2S!425ml0g0s}V-^m;4I%_5-~tF3k&vj^b9A16778<}(6eNJu~Vz<8=6`~
zboab&MFtUB!i}=AFfm2m$tVxGT*u4pe81nU<hDp!0Y1oNKeq`gKn17(6`%rCU`7h$
zLB3qg=$ZH^RDcT1Ljn6f6u7Y_ThKop2tERUJ<4ua`z!$#D}XiGf~deWTES>lA49C}
z?O@64YO)2RT{MRe%{!}2F))pG(Sih~)xkgosK7*lF7m<7{{#Hn{6A@7N(HFEpDCdI
z{<z=arSfe3cs;A1vTExF2mNw{x1Rtcb`-DSZrCrj0Bf=ZQGxMCz-3^d0zXyY1+O9z
AbpQYW

literal 0
HcmV?d00001

diff --git a/README.md b/README.md
index 280a2fd..0ccd70d 100644
--- a/README.md
+++ b/README.md
@@ -15,6 +15,40 @@ example, `lein run :population-size 100`. You can use something
 like `lein run | tee outfile` to send output both to the terminal 
 and to `outfile`.
 
+## CLJS Usage
+
+### Development
+
+Run in development:
+
+```bash
+yarn
+(mkdir -p target && cp assets/index.html target/)
+yarn shadow-cljs watch app
+```
+
+`shadow-cljs` will be installed in `node_modules/` when you run `yarn`.
+
+`:dev-http` specifies that `target/` will be served at http://localhost:8080 .
+
+### REPL
+
+After page is loaded, you may also start a REPL connected to browser with:
+
+```bash
+yarn shadow-cljs cljs-repl app
+```
+
+### Release
+
+Compile with optimizations with `release` sub-command:
+
+```bash
+yarn shadow-cljs release app
+mkdir -p target && cp assets/index.html target/
+yarn serve # serving target/ on http://localhost:8080
+```
+
 ## Description
 
 Propel is an implementation of the Push programming 
diff --git a/assets/index.html b/assets/index.html
new file mode 100644
index 0000000..816c67c
--- /dev/null
+++ b/assets/index.html
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <title>propeller shadow-cljs</title>
+    <meta charset="UTF-8">
+</head>
+<body>
+<div>See Console!</div>
+<script src="main.js"></script>
+</body>
+</html>
\ No newline at end of file
diff --git a/deps.edn b/deps.edn
deleted file mode 100644
index dedbbfa..0000000
--- a/deps.edn
+++ /dev/null
@@ -1 +0,0 @@
-{:deps {org.clojure/clojurescript {:mvn/version "1.10.758"}}}
\ No newline at end of file
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..0fd2e1d
--- /dev/null
+++ b/package.json
@@ -0,0 +1,21 @@
+{
+  "name": "propeller-cljs",
+  "version": "1.0.0",
+  "description": "",
+  "main": "index.js",
+  "scripts": {
+    "watch": "shadow-cljs watch app",
+    "compile": "shadow-cljs compile app",
+    "release": "shadow-cljs release app",
+    "html": "mkdir -p target && cp assets/index.html target/",
+    "serve": "yarn html && http-server target/",
+    "del": "rm -r target/*",
+    "build": "yarn release && yarn html && yarn serve"
+  },
+  "author": "",
+  "license": "MIT",
+  "devDependencies": {
+    "http-server": "^0.12.3",
+    "shadow-cljs": "^2.10.10"
+  }
+}
\ No newline at end of file
diff --git a/shadow-cljs.edn b/shadow-cljs.edn
new file mode 100644
index 0000000..5901c31
--- /dev/null
+++ b/shadow-cljs.edn
@@ -0,0 +1,7 @@
+{:source-paths ["src"]
+ :dependencies []
+ :dev-http {8080 "target/"}
+ :builds {:app {:output-dir "target/"
+                :asset-path "."
+                :target :browser
+                :modules {:main {:init-fn propeller.main/main!}}}}}
\ No newline at end of file
diff --git a/src/.DS_Store b/src/.DS_Store
index 70cf7220f114527fc0bf76e9298cdbbf64487b02..bf7db11ae7cdca67181c347f9cc33b772a663d38 100644
GIT binary patch
delta 38
ucmZoMXfc@J&&a$nU^gQp^JE^T|C}ks$vH{+`8f=mzcPJh+04%ImmdK5e+_p4

delta 33
pcmZoMXfc@J&&aefU^nAr0}+<V{7io~Ycbztnb;t|nVsV=KLET?3qk+@

diff --git a/src/propeller/.DS_Store b/src/propeller/.DS_Store
index 0d0fca78de24838f90dd5274333c79e136f90e21..ed2fbb1e0c5d3c89c3b893c5b3ec6d5dc5199ec4 100644
GIT binary patch
delta 154
zcmZoMXfc=|&e%3FQH+&?fq{WzVxovF6OaJ{AexbZL4biFhar_Am!UYNI5}rxqPh`C
zf`g%ep@<=$AqiPBDL+34q>}|GS;|n%kO9&G65N>R#Xi|Ugk>`~2M-5h+s4H2%#-;=
a6h%QMDFAT-5Cg4ZH~_>9n;k{=GXnr2i6006

delta 110
zcmZoMXfc=|&Zs)EP}q!-fq{XAp@5;3p_m~fr8qe!DL+34BnSjd5Q+iB1!4gPxctV0
sZtN2;By48q5a3``-FWaj^JIPzMNW{y1dyi5COpcU6GWCUPi$ZT0QHa<1^@s6

diff --git a/src/propeller/main.cljs b/src/propeller/main.cljs
new file mode 100644
index 0000000..6dd3792
--- /dev/null
+++ b/src/propeller/main.cljs
@@ -0,0 +1,8 @@
+(ns propeller.main
+  (:require [propeller.core :as propeller]))
+
+(defn main! []
+  (println "Loading main..."))
+
+(defn ^:dev/after-load reload! []
+  (propeller/-main))
diff --git a/src/propeller/problems/software/smallest.cljc b/src/propeller/problems/software/smallest.cljc
index 7e8c3fb..e77c615 100755
--- a/src/propeller/problems/software/smallest.cljc
+++ b/src/propeller/problems/software/smallest.cljc
@@ -4,7 +4,8 @@
             [propeller.push.state :as state]
             [propeller.push.utils.helpers :refer [get-stack-instructions]]
             [propeller.utils :as utils]
-            [propeller.push.state :as state]))
+            [propeller.push.state :as state]
+            #?(:cljs [cljs.reader :refer [read-string]])))
 
 ;; =============================================================================
 ;; Tom Helmuth, thelmuth@cs.umass.edu
@@ -82,7 +83,8 @@
                       inputs)
          errors (map (fn [correct-output output]
                        (let [parsed-output (try (read-string output)
-                                                (catch Exception e 1))]
+                                                #?(:clj (catch Exception e 1000.0)
+                                                   :cljs (catch js/Error. e 1000.0)))]
                          (if (= correct-output parsed-output) 0 1)))
                      correct-outputs
                      outputs)]
diff --git a/src/propeller/push/.DS_Store b/src/propeller/push/.DS_Store
index 8544a8f52b6bed10c3852173e96b82c09b2ebd14..49c1bfbfb5214f1f25808da623ceb5915c2d26f2 100644
GIT binary patch
delta 18
acmZoMXfc>@eB(tk_K6K#o7p-3@&f=%HwS0{

delta 20
ccmZoMXfc>@oRM+kMKkt^4V;_VIsWnk08q>aX#fBK

diff --git a/src/propeller/push/utils/macros.clj b/src/propeller/push/utils/macros.cljc
similarity index 100%
rename from src/propeller/push/utils/macros.clj
rename to src/propeller/push/utils/macros.cljc

From 689536b73527ae06fd948834b2315f3ec8858ce1 Mon Sep 17 00:00:00 2001
From: Sunghoon Kwak <49034253+skwak22@users.noreply.github.com>
Date: Wed, 15 Jul 2020 21:24:56 +0900
Subject: [PATCH 2/4] Update README.md

---
 README.md | 10 ----------
 1 file changed, 10 deletions(-)

diff --git a/README.md b/README.md
index 0ccd70d..63ad5f2 100644
--- a/README.md
+++ b/README.md
@@ -39,16 +39,6 @@ After page is loaded, you may also start a REPL connected to browser with:
 yarn shadow-cljs cljs-repl app
 ```
 
-### Release
-
-Compile with optimizations with `release` sub-command:
-
-```bash
-yarn shadow-cljs release app
-mkdir -p target && cp assets/index.html target/
-yarn serve # serving target/ on http://localhost:8080
-```
-
 ## Description
 
 Propel is an implementation of the Push programming 

From baf28a3e79767144c2a0af365675f9530f88361c Mon Sep 17 00:00:00 2001
From: skwak22 <skwak22@amherst.edu>
Date: Wed, 15 Jul 2020 22:23:42 +0900
Subject: [PATCH 3/4] Working cljs version of propeller

---
 .DS_Store                                     | Bin 6148 -> 6148 bytes
 README.md                                     |   7 +++++++
 .../push/instructions/input_output.cljc       |   4 +++-
 src/propeller/tools/character.cljc            |  12 +++++++++---
 4 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/.DS_Store b/.DS_Store
index 9a874b5768f336915163bb88cd434575b859f936..feca8613504bcd7430524202412f605a970dd548 100644
GIT binary patch
delta 24
gcmZoMXfc>z$H*|zUVdZZGWN;3BJ7*FIezj30AOtgj{pDw

delta 26
icmZoMXfc>z$H+L*UY?P0W8yOQ$$BDeo4GlD@&f>7?FW(o

diff --git a/README.md b/README.md
index 63ad5f2..cf514c5 100644
--- a/README.md
+++ b/README.md
@@ -39,6 +39,13 @@ After page is loaded, you may also start a REPL connected to browser with:
 yarn shadow-cljs cljs-repl app
 ```
 
+Once the REPL is loaded, load the core namespace with:
+
+```
+(ns propeller.core)
+```
+Calling `(-main)` will run the default genetic programming problem.
+
 ## Description
 
 Propel is an implementation of the Push programming 
diff --git a/src/propeller/push/instructions/input_output.cljc b/src/propeller/push/instructions/input_output.cljc
index e5fccd4..55db2ee 100755
--- a/src/propeller/push/instructions/input_output.cljc
+++ b/src/propeller/push/instructions/input_output.cljc
@@ -19,7 +19,9 @@
   [state instruction]
   (if-let [input (instruction (:input state))]
     (state/push-to-stack state :exec input)
-    (throw (Exception. (str "Undefined input instruction " instruction)))))
+    (throw #?(:clj (Exception. (str "Undefined input instruction " instruction))
+              :cljs (js/Error
+                      (str "Undefined input instruction " instruction))))))
 
 ;; =============================================================================
 ;; OUTPUT Instructions
diff --git a/src/propeller/tools/character.cljc b/src/propeller/tools/character.cljc
index 32d64d3..6c8b846 100755
--- a/src/propeller/tools/character.cljc
+++ b/src/propeller/tools/character.cljc
@@ -1,18 +1,24 @@
 (ns propeller.tools.character)
 
+(defn get-ascii
+  "Gets the ASCII code of a char"
+  [c]
+  #?(:clj (int c)
+     :cljs (.charCodeAt c 0)))
+
 (defn is-letter
   "Returns true if the given character is a letter, A-Z or a-z."
   [c]
-  (<= (int \A) (int c) (int \z)))
+  (<= (get-ascii \A) (get-ascii c) (get-ascii \z)))
 
 
 (defn is-digit
   "Returns true if the given character is a digit, 0-9."
   [c]
-  (<= (int \0) (int c) (int \9)))
+  (<= (get-ascii \0) (get-ascii c) (get-ascii \9)))
 
 
 (defn is-whitespace
   "Returns true if the given character is whitespace (newline, space, tab)."
   [c]
-  (contains? #{(int \newline) (int \tab) (int \space)} (int c)))
+  (contains? #{(get-ascii \newline) (get-ascii \tab) (get-ascii \space)} (get-ascii c)))

From bdff94091bd3030b74d3a4df6012cbab5e900d0b Mon Sep 17 00:00:00 2001
From: Sunghoon Kwak <49034253+skwak22@users.noreply.github.com>
Date: Wed, 15 Jul 2020 22:44:25 +0900
Subject: [PATCH 4/4] Update license info

---
 package.json | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/package.json b/package.json
index 0fd2e1d..33a73cb 100644
--- a/package.json
+++ b/package.json
@@ -13,9 +13,9 @@
     "build": "yarn release && yarn html && yarn serve"
   },
   "author": "",
-  "license": "MIT",
+  "license": "EPL",
   "devDependencies": {
     "http-server": "^0.12.3",
     "shadow-cljs": "^2.10.10"
   }
-}
\ No newline at end of file
+}