mirror of
https://github.com/azur1s/bobbylisp.git
synced 2024-10-16 02:37:40 -05:00
Compare commits
5 commits
7ac147de32
...
e6b31b39b0
Author | SHA1 | Date | |
---|---|---|---|
azur | e6b31b39b0 | ||
azur | 50fdc4fe97 | ||
azur | 1a73043123 | ||
azur | 8b927e4ac7 | ||
azur | 35ffd11321 |
16
Cargo.lock
generated
16
Cargo.lock
generated
|
@ -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"
|
||||
|
|
|
@ -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"
|
|
@ -1,2 +1 @@
|
|||
ko_fi: azur1s
|
||||
github: azur1s
|
5
a.hlm
5
a.hlm
|
@ -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
8
example/fact.hlm
Normal file
|
@ -0,0 +1,8 @@
|
|||
func fact (n : num) num =
|
||||
if n == 0 then
|
||||
1
|
||||
else
|
||||
n * fact(n - 1)
|
||||
;
|
||||
|
||||
println(fact(5));
|
|
@ -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() {
|
||||
|
|
|
@ -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(),
|
||||
|
|
Loading…
Reference in a new issue