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

Compare commits

..

No commits in common. "e6b31b39b0b056638d3b73dd6966668a36c89435" and "7ac147de325587c80b4a7ef0460f9541239d218d" have entirely different histories.

7 changed files with 32 additions and 39 deletions

16
Cargo.lock generated
View file

@ -114,14 +114,6 @@ 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"
@ -191,6 +183,14 @@ 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,12 +1,8 @@
[package] [package]
name = "holymer" name = "renxi"
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 +1,2 @@
ko_fi: azur1s
github: azur1s github: azur1s

5
a.hlm
View file

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

View file

@ -1,8 +0,0 @@
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), Method(Box<Self>, String, Vec<Self>),
Lambda { Lambda {
args: Vec<String>, args: Vec<String>,
body: Vec<Self>, body: Vec<Self>,
@ -75,7 +75,16 @@ impl Display for JSExpr {
} }
write!(f, ")") write!(f, ")")
}, },
JSExpr::Method(c, m) => write!(f, "{}.{}", c, m), 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::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,21 +154,13 @@ 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" => JSExpr::Call( "println" => {
Box::new(JSExpr::Method( 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(),