1
1
Fork 0
mirror of https://github.com/azur1s/bobbylisp.git synced 2024-10-16 02:37:40 -05:00

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", "libc",
] ]
[[package]]
name = "holymer"
version = "0.1.0"
dependencies = [
"chumsky",
"structopt",
]
[[package]] [[package]]
name = "lazy_static" name = "lazy_static"
version = "1.4.0" version = "1.4.0"
@ -183,14 +191,6 @@ dependencies = [
"proc-macro2", "proc-macro2",
] ]
[[package]]
name = "renxi"
version = "0.1.0"
dependencies = [
"chumsky",
"structopt",
]
[[package]] [[package]]
name = "stacker" name = "stacker"
version = "0.1.15" version = "0.1.15"

View file

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

View file

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

5
a.hlm
View file

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

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

View file

@ -154,13 +154,21 @@ pub fn translate_js_expr(expr: Expr) -> JSExpr {
match *f { match *f {
Expr::Sym(ref s) => { Expr::Sym(ref s) => {
match s.as_str() { match s.as_str() {
"println" => { "println" => JSExpr::Call(
JSExpr::Method( Box::new(JSExpr::Method(
Box::new(JSExpr::Sym("console".to_string())), Box::new(JSExpr::Sym("console".to_string())),
"log".to_string(), "log".to_string(),
args.into_iter().map(translate_js_expr).collect(), )),
) 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( _ => JSExpr::Call(
Box::new(translate_js_expr(*f)), Box::new(translate_js_expr(*f)),
args.into_iter().map(translate_js_expr).collect(), args.into_iter().map(translate_js_expr).collect(),