Compare commits

...

5 Commits

Author SHA1 Message Date
azur e6b31b39b0 factorial example, bring back println for now 2023-03-07 04:41:34 +07:00
azur 50fdc4fe97 change compiled binary name 2023-03-07 04:37:48 +07:00
azur 1a73043123 update FUNDING.yml 2023-03-07 04:35:46 +07:00
azur 8b927e4ac7 don't treat js method as call 2023-03-07 04:35:16 +07:00
azur 35ffd11321 allow js method chaining 2023-03-07 04:27:24 +07:00
7 changed files with 39 additions and 32 deletions

16
Cargo.lock generated
View File

@ -114,6 +114,14 @@ dependencies = [
"libc",
]
[[package]]
name = "holymer"
version = "0.1.0"
dependencies = [
"chumsky",
"structopt",
]
[[package]]
name = "lazy_static"
version = "1.4.0"
@ -183,14 +191,6 @@ dependencies = [
"proc-macro2",
]
[[package]]
name = "renxi"
version = "0.1.0"
dependencies = [
"chumsky",
"structopt",
]
[[package]]
name = "stacker"
version = "0.1.15"

View File

@ -1,8 +1,12 @@
[package]
name = "renxi"
name = "holymer"
version = "0.1.0"
edition = "2021"
[dependencies]
chumsky = "0.9.0"
structopt = "0.3.26"
[[bin]]
name = "hlmc"
path = "src/main.rs"

View File

@ -1,2 +1 @@
ko_fi: azur1s
github: azur1s

5
a.hlm
View File

@ -1,4 +1 @@
let x: num = 1,
y: num = 2,
in
println(if x + y == 3 then 69 else 0);
print("Hello\n");

8
example/fact.hlm Normal file
View File

@ -0,0 +1,8 @@
func fact (n : num) num =
if n == 0 then
1
else
n * fact(n - 1)
;
println(fact(5));

View File

@ -14,7 +14,7 @@ pub enum JSExpr {
Op(&'static str, Box<Self>, Option<Box<Self>>),
Call(Box<Self>, Vec<Self>),
Method(Box<Self>, String, Vec<Self>),
Method(Box<Self>, String),
Lambda {
args: Vec<String>,
body: Vec<Self>,
@ -75,16 +75,7 @@ impl Display for JSExpr {
}
write!(f, ")")
},
JSExpr::Method(c, m, args) => {
write!(f, "{}.{}(", c, m)?;
for (i, arg) in args.iter().enumerate() {
if i > 0 {
write!(f, ", ")?;
}
write!(f, "{}", arg)?;
}
write!(f, ")")
},
JSExpr::Method(c, m) => write!(f, "{}.{}", c, m),
JSExpr::Lambda { args, body } => {
write!(f, "((")?;
for (i, name) in args.iter().enumerate() {

View File

@ -154,13 +154,21 @@ pub fn translate_js_expr(expr: Expr) -> JSExpr {
match *f {
Expr::Sym(ref s) => {
match s.as_str() {
"println" => {
JSExpr::Method(
Box::new(JSExpr::Sym("console".to_string())),
"log".to_string(),
args.into_iter().map(translate_js_expr).collect(),
)
},
"println" => JSExpr::Call(
Box::new(JSExpr::Method(
Box::new(JSExpr::Sym("console".to_string())),
"log".to_string(),
)),
args.into_iter().map(translate_js_expr).collect()),
"print" => JSExpr::Call(
Box::new(JSExpr::Method(
Box::new(JSExpr::Method(
Box::new(JSExpr::Sym("process".to_string())),
"stdout".to_string(),
)),
"write".to_string(),
)),
args.into_iter().map(translate_js_expr).collect()),
_ => JSExpr::Call(
Box::new(translate_js_expr(*f)),
args.into_iter().map(translate_js_expr).collect(),