Skip to content

Commit 8a771ae

Browse files
AppleApple
Apple
authored and
Apple
committed
test
1 parent fff96c5 commit 8a771ae

File tree

6 files changed

+125
-14
lines changed

6 files changed

+125
-14
lines changed

Cargo.lock

+9-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "cli"
2+
name = "rim"
33
version = "0.1.0"
44
edition = "2021"
55

cli/src/main.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{path::PathBuf, sync::Arc};
1+
use std::{path::PathBuf, sync::Arc, process::Command};
22

33
use clap::Parser;
44
use compiler::project;
@@ -32,6 +32,9 @@ pub enum Args {
3232
at: PathBuf
3333
},
3434
Build,
35+
RunJs {
36+
name: String,
37+
},
3538
}
3639

3740
#[tokio::main]
@@ -48,6 +51,17 @@ async fn main() {
4851
let library_server = Arc::new(project::LibraryServer::new());
4952
project::Pointer::new(".".into(), "".into(), library_server)
5053
.compile().await.unwrap();
54+
},
55+
Args::RunJs { name } => {
56+
let library_server = Arc::new(project::LibraryServer::new());
57+
project::Pointer::new(".".into(), "".into(), library_server)
58+
.compile().await.unwrap();
59+
Command::new("node")
60+
.arg(format!("./output/js/{name}.js"))
61+
.spawn()
62+
.unwrap()
63+
.wait()
64+
.unwrap();
5165
}
5266
}
5367
}
@@ -58,3 +72,6 @@ async fn init_project(path: PathBuf) -> Result<(), io::Error> {
5872
create_dir_all(path.join("main")).await?;
5973
Ok(())
6074
}
75+
76+
77+
// ../target/debug/cli run-js jsMain

testProject/main.rim

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
let
3+
mod stuff file stuff
34
mod console = builtIn.js.effect.console
45
in
5-
val jsMain = console.log "Hello world!"
6+
val jsMain = stuff.main

testProject/main/stuff.rim

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
let
2+
val
3+
add = builtIn.number.add
4+
sub = builtIn.number.sub
5+
mul = builtIn.number.mul
6+
div = builtIn.number.div
7+
mod unit where
8+
pro new
9+
mod tuple where
10+
pro new fst snd
11+
12+
from builtIn
13+
mod num = number
14+
mod js = js
15+
from js
16+
mod eff = effect
17+
from effect
18+
mod console = console
19+
from console
20+
val log = log
21+
in let
22+
val withSelf = (\f = f f) (\self f = f $ self self f)
23+
# amazing module about booleans! #
24+
mod bool where
25+
let
26+
sum match false true
27+
in
28+
let val
29+
match t f = match (\v = t) (\v = f)
30+
true = true unit.new
31+
false = false unit.new
32+
in val
33+
match = match
34+
true = true
35+
false = false
36+
not = match true false
37+
38+
in let
39+
mod either where
40+
let sum match left right
41+
in let val isleft = match (\v = bool.true) (\v = bool.false)
42+
in val
43+
match = match
44+
left = left
45+
right = right
46+
isleft = isleft
47+
isright v = bool.not (isleft v)
48+
usEdCool123Wow = builtIn.js.effect.console.log $ if builtIn.bool.false | builtIn.bool.false then 10 + 20 else 555
49+
50+
val factorial = withSelf \self x =
51+
if num.eq x 0 then 1 else x * self (x - 1)
52+
53+
val iter = withSelf \self x =
54+
if num.eq x 0 then 0 else 1 + self (x - 1)
55+
in let
56+
from either val
57+
coolio = usEdCool123Wow
58+
in
59+
val main = log $ iter 100

testProject/output/js/jsMain.js

+36-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,41 @@ let v8 = [() => false]
1313
let v11 = [() => ($l => [() => ($r => [() => $unwrap($l) || $unwrap($r)])])]
1414
let v10 = [() => ($l => [() => ($r => [() => $unwrap($l) && $unwrap($r)])])]
1515
let v9 = [() => ($0 => [() => ($1 => [() => ($2 => [() => $unwrap($2) ? $unwrap($1) : $unwrap($0)])])])]
16-
let v14 = [() => $unwrap($unwrap(v13)([() => "Hello world!"]))]
16+
let v19 = [() => ($0 => [() => ($1 => [() => [$0, $1, ]])])]
17+
let v20 = [() => ($value => [() => $unwrap($unwrap($value)[0])])]
18+
let v21 = [() => ($value => [() => $unwrap($unwrap($value)[1])])]
19+
let v18 = [() => []]
20+
let v14 = [() => $unwrap(v0)]
21+
let v22 = [() => $unwrap(v13)]
22+
let v16 = [() => $unwrap(v2)]
23+
let v17 = [() => $unwrap(v3)]
24+
let v15 = [() => $unwrap(v1)]
25+
let v31 = [() => ($ => [() => [1, $]])]
26+
let v30 = [() => ($ => [() => [0, $]])]
27+
let v29 = [() => ($0 => [() => ($1 => [() => ($sum => [() => { let $value = $unwrap($sum); if ($value[0] == 0) { return $unwrap($unwrap($0)($value[1])) } else if ($value[0] == 1) { return $unwrap($unwrap($1)($value[1])) } else { throw new Error('Sum type mismatch: $value[0] is not in range of possible branches!') } }])])])]
28+
let v37 = [() => $unwrap($unwrap(v31)([() => $unwrap(v18)]))]
29+
let v38 = [() => $unwrap($unwrap(v30)([() => $unwrap(v18)]))]
30+
let v36 = [() => (v32 => [() => (v33 => [() => $unwrap($unwrap($unwrap(v29)([() => (v34 => [() => $unwrap(v32)])]))([() => (v35 => [() => $unwrap(v33)])]))])])]
31+
let v40 = [() => $unwrap(v37)]
32+
let v41 = [() => $unwrap(v38)]
33+
let v42 = [() => $unwrap($unwrap($unwrap(v36)([() => $unwrap(v37)]))([() => $unwrap(v38)]))]
34+
let v39 = [() => $unwrap(v36)]
35+
let v28 = [() => $unwrap((v23 => [() => $unwrap($unwrap(v23)([() => $unwrap(v23)]))])([() => (v24 => [() => (v25 => [() => $unwrap($unwrap((v26 => [() => (v27 => [() => $unwrap($unwrap(v26)([() => $unwrap(v27)]))])])([() => $unwrap(v25)]))([() => $unwrap($unwrap($unwrap(v24)([() => $unwrap(v24)]))([() => $unwrap(v25)]))]))])])]))]
36+
let v45 = [() => ($ => [() => [1, $]])]
37+
let v44 = [() => ($ => [() => [0, $]])]
38+
let v43 = [() => ($0 => [() => ($1 => [() => ($sum => [() => { let $value = $unwrap($sum); if ($value[0] == 0) { return $unwrap($unwrap($0)($value[1])) } else if ($value[0] == 1) { return $unwrap($unwrap($1)($value[1])) } else { throw new Error('Sum type mismatch: $value[0] is not in range of possible branches!') } }])])])]
39+
let v48 = [() => $unwrap($unwrap($unwrap(v43)([() => (v46 => [() => $unwrap(v40)])]))([() => (v47 => [() => $unwrap(v41)])]))]
40+
let v57 = [() => $unwrap($unwrap((v55 => [() => (v56 => [() => $unwrap($unwrap(v55)([() => $unwrap(v56)]))])])([() => $unwrap(v13)]))([() => $unwrap($unwrap($unwrap(($0 => [() => ($1 => [() => ($2 => [() => $unwrap($2) ? $unwrap($1) : $unwrap($0)])])])([() => 555]))([() => $unwrap($unwrap(($l => [() => ($r => [() => $unwrap($l) + $unwrap($r)])])([() => 10]))([() => 20]))]))([() => $unwrap($unwrap(($l => [() => ($r => [() => $unwrap($l) || $unwrap($r)])])([() => $unwrap(v8)]))([() => $unwrap(v8)]))]))]))]
41+
let v51 = [() => $unwrap(v45)]
42+
let v54 = [() => (v53 => [() => $unwrap($unwrap(v42)([() => $unwrap($unwrap(v48)([() => $unwrap(v53)]))]))])]
43+
let v52 = [() => $unwrap(v48)]
44+
let v50 = [() => $unwrap(v44)]
45+
let v49 = [() => $unwrap(v43)]
46+
let v63 = [() => $unwrap($unwrap(v28)([() => (v61 => [() => (v62 => [() => $unwrap($unwrap($unwrap(($0 => [() => ($1 => [() => ($2 => [() => $unwrap($2) ? $unwrap($1) : $unwrap($0)])])])([() => $unwrap($unwrap(($l => [() => ($r => [() => $unwrap($l) + $unwrap($r)])])([() => 1]))([() => $unwrap($unwrap(v61)([() => $unwrap($unwrap(($l => [() => ($r => [() => $unwrap($l) - $unwrap($r)])])([() => $unwrap(v62)]))([() => 1]))]))]))]))([() => 0]))([() => $unwrap($unwrap($unwrap(v5)([() => $unwrap(v62)]))([() => 0]))]))])])]))]
47+
let v60 = [() => $unwrap($unwrap(v28)([() => (v58 => [() => (v59 => [() => $unwrap($unwrap($unwrap(($0 => [() => ($1 => [() => ($2 => [() => $unwrap($2) ? $unwrap($1) : $unwrap($0)])])])([() => $unwrap($unwrap(($l => [() => ($r => [() => $unwrap($l) * $unwrap($r)])])([() => $unwrap(v59)]))([() => $unwrap($unwrap(v58)([() => $unwrap($unwrap(($l => [() => ($r => [() => $unwrap($l) - $unwrap($r)])])([() => $unwrap(v59)]))([() => 1]))]))]))]))([() => 1]))([() => $unwrap($unwrap($unwrap(v5)([() => $unwrap(v59)]))([() => 0]))]))])])]))]
48+
let v64 = [() => $unwrap(v57)]
49+
let v67 = [() => $unwrap($unwrap((v65 => [() => (v66 => [() => $unwrap($unwrap(v65)([() => $unwrap(v66)]))])])([() => $unwrap(v22)]))([() => $unwrap($unwrap(v63)([() => 100]))]))]
50+
let v68 = [() => $unwrap(v67)]
1751

1852
// MAIN
19-
$unwrap(v14)()
53+
$unwrap(v68)()

0 commit comments

Comments
 (0)