diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 4d9f666f..db074e7e 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -30,3 +30,15 @@ jobs: - uses: katyo/publish-crates@v1 with: registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }} + + - uses: actions/setup-node@v2 + with: + node-version: 12 + registry-url: https://registry.npmjs.org/ + + - name: "generate procs.js" + run: yarn && yarn tsc + + - run: npm publish + env: + NODE_AUTH_TOKEN: ${{secrets.npm_token}} diff --git a/.npmignore b/.npmignore new file mode 100644 index 00000000..7711676b --- /dev/null +++ b/.npmignore @@ -0,0 +1,16 @@ + +.github/ +example/ +js-out/ +src/ +tests/ +calcit/ + +.calcit-error.cirru +calcit_runner.nimble +webpack.config.js +yarn.lock +profile_results.txt + +Cargo.lock +Cargo.toml diff --git a/Cargo.lock b/Cargo.lock index b3ca82c0..09055a71 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -81,7 +81,7 @@ dependencies = [ [[package]] name = "calcit_runner" -version = "0.1.0" +version = "0.3.0-a1" dependencies = [ "cirru_edn", "cirru_parser", diff --git a/Cargo.toml b/Cargo.toml index 75b10139..03cfbf17 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "calcit_runner" -version = "0.1.0" +version = "0.3.0-a1" authors = ["jiyinyiyong "] edition = "2018" diff --git a/package.json b/package.json index 71af0d66..cc107e42 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@calcit/procs", - "version": "0.2.111", + "version": "0.3.0-a1", "main": "./lib/calcit.procs.js", "devDependencies": { "@types/node": "^14.14.41", diff --git a/src/builtins.rs b/src/builtins.rs index fb70e04c..20dec10a 100644 --- a/src/builtins.rs +++ b/src/builtins.rs @@ -35,9 +35,13 @@ pub fn is_proc_name(s: &str) -> bool { | "turn-keyword" // effects | "echo" + | "println" // alias for echo | "echo-values" | "raise" | "cpu-time" + | "quit" + | "get-env" + | "&get-calcit-backend" // logics | "&=" | "&<" @@ -150,9 +154,13 @@ pub fn handle_proc(name: &str, args: &CalcitItems) -> Result { "turn-keyword" => meta::turn_keyword(args), // effects "echo" => effects::echo(args), + "println" => effects::echo(args), // alias "echo-values" => effects::echo_values(args), "raise" => effects::raise(args), "cpu-time" => effects::cpu_time(args), + "quit" => effects::quit(args), + "get-env" => effects::get_env(args), + "&get-calcit-backend" => effects::call_get_calcit_backend(args), // logics "&=" => logics::binary_equal(args), "&<" => logics::binary_less(args), diff --git a/src/builtins/effects.rs b/src/builtins/effects.rs index f6dee9c7..844fc42b 100644 --- a/src/builtins/effects.rs +++ b/src/builtins/effects.rs @@ -1,6 +1,10 @@ +use std::env; +use std::process::exit; use std::sync::Mutex; use std::time::Instant; +use crate::util::number::f64_to_i32; + use crate::primes::{Calcit, CalcitItems}; #[derive(Clone, Debug)] @@ -84,3 +88,33 @@ pub fn calcit_running_mode(_xs: &CalcitItems) -> Result { CliRunningMode::Ir => Ok(Calcit::Keyword(String::from("ir"))), } } + +// TODO +pub fn call_get_calcit_backend(_xs: &CalcitItems) -> Result { + Ok(Calcit::Keyword(String::from("rust"))) +} + +pub fn quit(xs: &CalcitItems) -> Result { + match xs.get(0) { + Some(Calcit::Number(n)) => match f64_to_i32(*n) { + Ok(code) => exit(code), + Err(e) => unreachable!("quit failed to get code from f64, {}", e), + }, + Some(a) => Err(format!("quit expected i32 value, got: {}", a)), + None => Err(String::from("quit expected a code, got nothing")), + } +} + +pub fn get_env(xs: &CalcitItems) -> Result { + match xs.get(0) { + Some(Calcit::Str(s)) => match env::var(s) { + Ok(v) => Ok(Calcit::Str(v)), + Err(e) => { + println!("get-env {}", e); + Ok(Calcit::Nil) + } + }, + Some(a) => Err(format!("get-env expected a string, got {}", a)), + None => Err(String::from("get-env expected an argument, got nothing")), + } +} diff --git a/src/cirru/calcit-core.cirru b/src/cirru/calcit-core.cirru index 783dd462..97774b43 100644 --- a/src/cirru/calcit-core.cirru +++ b/src/cirru/calcit-core.cirru @@ -792,17 +792,6 @@ raise ~ $ &str-concat (&str-concat message "| ") xs - |println $ quote - defn println (& xs) - ; "TODO print not implemented, use syntax echo" - print & xs - when - = (&get-calcit-backend) :nim - print "|\n" - - |echo $ quote - def echo println - |join-str $ quote defn join-str (xs0 sep) apply-args diff --git a/src/runner/preprocess.rs b/src/runner/preprocess.rs index 298d1079..e83d8fbc 100644 --- a/src/runner/preprocess.rs +++ b/src/runner/preprocess.rs @@ -303,7 +303,10 @@ pub fn preprocess_defn( Calcit::Symbol(sym, def_ns, _) => { check_symbol(sym, program_code); zs.push_back(Calcit::Symbol(sym.clone(), def_ns.clone(), Some(ResolvedRaw))); - body_defs.insert(sym.clone()); + // skip argument syntax marks + if sym != "&" && sym != "?" { + body_defs.insert(sym.clone()); + } } _ => return Err(format!("expected defn args to be symbols, got: {}", y)), }