From e6b31b39b0b056638d3b73dd6966668a36c89435 Mon Sep 17 00:00:00 2001 From: azur Date: Tue, 7 Mar 2023 04:41:34 +0700 Subject: [PATCH] factorial example, bring back println for now --- example/fact.hlm | 8 ++++++++ src/trans/low.rs | 6 ++++++ 2 files changed, 14 insertions(+) create mode 100644 example/fact.hlm diff --git a/example/fact.hlm b/example/fact.hlm new file mode 100644 index 0000000..ea5a15b --- /dev/null +++ b/example/fact.hlm @@ -0,0 +1,8 @@ +func fact (n : num) num = + if n == 0 then + 1 + else + n * fact(n - 1) +; + +println(fact(5)); \ No newline at end of file diff --git a/src/trans/low.rs b/src/trans/low.rs index 6ea5ef8..d81f2c2 100644 --- a/src/trans/low.rs +++ b/src/trans/low.rs @@ -154,6 +154,12 @@ pub fn translate_js_expr(expr: Expr) -> JSExpr { match *f { Expr::Sym(ref s) => { match s.as_str() { + "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(