Merge pull request #6 from skwak22/master
This version of propeller has full CLJS functionality and compiles with shadow-cljs
This commit is contained in:
commit
db085080b3
31
README.md
31
README.md
@ -15,6 +15,37 @@ example, `lein run :population-size 100`. You can use something
|
|||||||
like `lein run | tee outfile` to send output both to the terminal
|
like `lein run | tee outfile` to send output both to the terminal
|
||||||
and to `outfile`.
|
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
|
||||||
|
```
|
||||||
|
|
||||||
|
Once the REPL is loaded, load the core namespace with:
|
||||||
|
|
||||||
|
```
|
||||||
|
(ns propeller.core)
|
||||||
|
```
|
||||||
|
Calling `(-main)` will run the default genetic programming problem.
|
||||||
|
|
||||||
## Description
|
## Description
|
||||||
|
|
||||||
Propel is an implementation of the Push programming
|
Propel is an implementation of the Push programming
|
||||||
|
11
assets/index.html
Normal file
11
assets/index.html
Normal file
@ -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>
|
21
package.json
Normal file
21
package.json
Normal file
@ -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": "EPL",
|
||||||
|
"devDependencies": {
|
||||||
|
"http-server": "^0.12.3",
|
||||||
|
"shadow-cljs": "^2.10.10"
|
||||||
|
}
|
||||||
|
}
|
7
shadow-cljs.edn
Normal file
7
shadow-cljs.edn
Normal file
@ -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!}}}}}
|
BIN
src/.DS_Store
vendored
BIN
src/.DS_Store
vendored
Binary file not shown.
BIN
src/propeller/.DS_Store
vendored
BIN
src/propeller/.DS_Store
vendored
Binary file not shown.
8
src/propeller/main.cljs
Normal file
8
src/propeller/main.cljs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
(ns propeller.main
|
||||||
|
(:require [propeller.core :as propeller]))
|
||||||
|
|
||||||
|
(defn main! []
|
||||||
|
(println "Loading main..."))
|
||||||
|
|
||||||
|
(defn ^:dev/after-load reload! []
|
||||||
|
(propeller/-main))
|
@ -4,7 +4,8 @@
|
|||||||
[propeller.push.state :as state]
|
[propeller.push.state :as state]
|
||||||
[propeller.push.utils.helpers :refer [get-stack-instructions]]
|
[propeller.push.utils.helpers :refer [get-stack-instructions]]
|
||||||
[propeller.utils :as utils]
|
[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
|
;; Tom Helmuth, thelmuth@cs.umass.edu
|
||||||
@ -82,7 +83,8 @@
|
|||||||
inputs)
|
inputs)
|
||||||
errors (map (fn [correct-output output]
|
errors (map (fn [correct-output output]
|
||||||
(let [parsed-output (try (read-string 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)))
|
(if (= correct-output parsed-output) 0 1)))
|
||||||
correct-outputs
|
correct-outputs
|
||||||
outputs)]
|
outputs)]
|
||||||
|
BIN
src/propeller/push/.DS_Store
vendored
BIN
src/propeller/push/.DS_Store
vendored
Binary file not shown.
@ -19,7 +19,9 @@
|
|||||||
[state instruction]
|
[state instruction]
|
||||||
(if-let [input (instruction (:input state))]
|
(if-let [input (instruction (:input state))]
|
||||||
(state/push-to-stack state :exec input)
|
(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
|
;; OUTPUT Instructions
|
||||||
|
@ -1,18 +1,24 @@
|
|||||||
(ns propeller.tools.character)
|
(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
|
(defn is-letter
|
||||||
"Returns true if the given character is a letter, A-Z or a-z."
|
"Returns true if the given character is a letter, A-Z or a-z."
|
||||||
[c]
|
[c]
|
||||||
(<= (int \A) (int c) (int \z)))
|
(<= (get-ascii \A) (get-ascii c) (get-ascii \z)))
|
||||||
|
|
||||||
|
|
||||||
(defn is-digit
|
(defn is-digit
|
||||||
"Returns true if the given character is a digit, 0-9."
|
"Returns true if the given character is a digit, 0-9."
|
||||||
[c]
|
[c]
|
||||||
(<= (int \0) (int c) (int \9)))
|
(<= (get-ascii \0) (get-ascii c) (get-ascii \9)))
|
||||||
|
|
||||||
|
|
||||||
(defn is-whitespace
|
(defn is-whitespace
|
||||||
"Returns true if the given character is whitespace (newline, space, tab)."
|
"Returns true if the given character is whitespace (newline, space, tab)."
|
||||||
[c]
|
[c]
|
||||||
(contains? #{(int \newline) (int \tab) (int \space)} (int c)))
|
(contains? #{(get-ascii \newline) (get-ascii \tab) (get-ascii \space)} (get-ascii c)))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user