Skip to content

Commit

Permalink
adding missing fns and configs, prepare to publish alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
tiye committed Apr 26, 2021
1 parent e9f843b commit 36b0b8a
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 15 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
16 changes: 16 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "calcit_runner"
version = "0.1.0"
version = "0.3.0-a1"
authors = ["jiyinyiyong <[email protected]>"]
edition = "2018"

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
8 changes: 8 additions & 0 deletions src/builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
| "&="
| "&<"
Expand Down Expand Up @@ -150,9 +154,13 @@ pub fn handle_proc(name: &str, args: &CalcitItems) -> Result<Calcit, String> {
"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),
Expand Down
34 changes: 34 additions & 0 deletions src/builtins/effects.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down Expand Up @@ -84,3 +88,33 @@ pub fn calcit_running_mode(_xs: &CalcitItems) -> Result<Calcit, String> {
CliRunningMode::Ir => Ok(Calcit::Keyword(String::from("ir"))),
}
}

// TODO
pub fn call_get_calcit_backend(_xs: &CalcitItems) -> Result<Calcit, String> {
Ok(Calcit::Keyword(String::from("rust")))
}

pub fn quit(xs: &CalcitItems) -> Result<Calcit, String> {
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<Calcit, String> {
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")),
}
}
11 changes: 0 additions & 11 deletions src/cirru/calcit-core.cirru
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/runner/preprocess.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
}
Expand Down

0 comments on commit 36b0b8a

Please sign in to comment.