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

don't treat js method as call

This commit is contained in:
azur 2023-03-07 04:35:16 +07:00
parent 35ffd11321
commit 8b927e4ac7
2 changed files with 9 additions and 31 deletions

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

View file

@ -154,24 +154,15 @@ 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(),
Some(args.into_iter().map(translate_js_expr).collect()),
)
},
"print" => {
JSExpr::Method(
"print" => JSExpr::Call(
Box::new(JSExpr::Method(
Box::new(JSExpr::Sym("process".to_string())),
"stdout".to_string(),
None,
Box::new(JSExpr::Method(
Box::new(JSExpr::Sym("process".to_string())),
"stdout".to_string(),
)),
"write".to_string(),
)),
"write".to_string(),
Some(args.into_iter().map(translate_js_expr).collect()),
)
}
args.into_iter().map(translate_js_expr).collect()),
_ => JSExpr::Call(
Box::new(translate_js_expr(*f)),
args.into_iter().map(translate_js_expr).collect(),