diff --git a/src/asts/js.rs b/src/asts/js.rs index 276d895..396521a 100644 --- a/src/asts/js.rs +++ b/src/asts/js.rs @@ -14,7 +14,7 @@ pub enum JSExpr { Op(&'static str, Box, Option>), Call(Box, Vec), - Method(Box, String, Option>), + Method(Box, String), Lambda { args: Vec, body: Vec, @@ -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() { diff --git a/src/trans/low.rs b/src/trans/low.rs index 400ba68..6ea5ef8 100644 --- a/src/trans/low.rs +++ b/src/trans/low.rs @@ -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(),