From 3285ef957ba9b16bdc5bccfdbb229e0d65cdfe49 Mon Sep 17 00:00:00 2001 From: Young-Flash Date: Tue, 17 Dec 2024 15:02:51 +0800 Subject: [PATCH] minor: bump moonbitlang/x (#24) * minor: bump moonbitlang/x * minor: moon fmt --- moon.mod.json | 2 +- src/bin/externals.mbt | 266 +++++++++++++++++------------------------- src/bin/main.mbt | 74 +++++------- src/utils.mbt | 6 +- 4 files changed, 142 insertions(+), 206 deletions(-) diff --git a/moon.mod.json b/moon.mod.json index 1c5fd59..2c31fa6 100644 --- a/moon.mod.json +++ b/moon.mod.json @@ -2,7 +2,7 @@ "name": "moonbitlang/minimbt", "version": "0.1.0", "deps": { - "moonbitlang/x": "0.4.13", + "moonbitlang/x": "0.4.15", "Yoorkin/ArgParser": "0.1.6" }, "readme": "README.md", diff --git a/src/bin/externals.mbt b/src/bin/externals.mbt index 3988547..4d8d49e 100644 --- a/src/bin/externals.mbt +++ b/src/bin/externals.mbt @@ -1,22 +1,16 @@ ///| fn add_interpreter_fns(interpreter : @knf_eval.KnfInterpreter) -> Unit { - interpreter.add_extern_fn( - "minimbt_print_int", - fn(args) { - match args[0] { - Int(i) => println(i) - _ => @util.die("print_int expects Int") - } - Unit - }, - ) - interpreter.add_extern_fn( - "minimbt_print_endline", - fn(_args) { - println("") - Unit - }, - ) + interpreter.add_extern_fn("minimbt_print_int", fn(args) { + match args[0] { + Int(i) => println(i) + _ => @util.die("print_int expects Int") + } + Unit + }) + interpreter.add_extern_fn("minimbt_print_endline", fn(_args) { + println("") + Unit + }) let create_array = fn(args : Array[@knf_eval.Value]) { match args[0] { Int(n) => @knf_eval.Value::Array(Array::make(n, args[1])) @@ -26,92 +20,65 @@ fn add_interpreter_fns(interpreter : @knf_eval.KnfInterpreter) -> Unit { interpreter.add_extern_fn("minimbt_create_array", create_array) interpreter.add_extern_fn("minimbt_create_float_array", create_array) interpreter.add_extern_fn("minimbt_create_ptr_array", create_array) - interpreter.add_extern_fn( - "minimbt_truncate", - fn(args) { - match args[0] { - Double(d) => Int(d.to_int()) - _ => @util.die("truncate expects Double") - } - }, - ) - interpreter.add_extern_fn( - "minimbt_sin", - fn(args) { - match args[0] { - Double(d) => Double(@math.sin(d)) - _ => @util.die("sin expects Double") - } - }, - ) - interpreter.add_extern_fn( - "minimbt_cos", - fn(args) { - match args[0] { - Double(d) => Double(@math.cos(d)) - _ => @util.die("cos expects Double") - } - }, - ) - interpreter.add_extern_fn( - "minimbt_sqrt", - fn(args) { - match args[0] { - Double(d) => Double(d.sqrt()) - _ => @util.die("sqrt expects Double") - } - }, - ) - interpreter.add_extern_fn( - "minimbt_abs_float", - fn(args) { - match args[0] { - Double(d) => Double(@double.abs(d)) - _ => @util.die("abs_float expects Double") - } - }, - ) - interpreter.add_extern_fn( - "minimbt_int_of_float", - fn(args) { - match args[0] { - Double(d) => Int(d.to_int()) - _ => @util.die("int_of_float expects Double") - } - }, - ) - interpreter.add_extern_fn( - "minimbt_float_of_int", - fn(args) { - match args[0] { - Int(i) => Double(i.to_double()) - _ => @util.die("float_of_int expects Int") - } - }, - ) + interpreter.add_extern_fn("minimbt_truncate", fn(args) { + match args[0] { + Double(d) => Int(d.to_int()) + _ => @util.die("truncate expects Double") + } + }) + interpreter.add_extern_fn("minimbt_sin", fn(args) { + match args[0] { + Double(d) => Double(@math.sin(d)) + _ => @util.die("sin expects Double") + } + }) + interpreter.add_extern_fn("minimbt_cos", fn(args) { + match args[0] { + Double(d) => Double(@math.cos(d)) + _ => @util.die("cos expects Double") + } + }) + interpreter.add_extern_fn("minimbt_sqrt", fn(args) { + match args[0] { + Double(d) => Double(d.sqrt()) + _ => @util.die("sqrt expects Double") + } + }) + interpreter.add_extern_fn("minimbt_abs_float", fn(args) { + match args[0] { + Double(d) => Double(@double.abs(d)) + _ => @util.die("abs_float expects Double") + } + }) + interpreter.add_extern_fn("minimbt_int_of_float", fn(args) { + match args[0] { + Double(d) => Int(d.to_int()) + _ => @util.die("int_of_float expects Double") + } + }) + interpreter.add_extern_fn("minimbt_float_of_int", fn(args) { + match args[0] { + Int(i) => Double(i.to_double()) + _ => @util.die("float_of_int expects Int") + } + }) } ///| fn add_closure_interpreter_fns( interpreter : @closure_eval.ClosureInterpreter ) -> Unit { - interpreter.add_extern_fn( - "minimbt_print_int", - fn(args) { - match args[0] { - Int(i) => println(i) - _ => @util.die("print_int expects Int") - } - Unit - }, - ) - interpreter.add_extern_fn( - "minimbt_print_endline", - fn(_args) { - println("") - Unit - }, - ) + interpreter.add_extern_fn("minimbt_print_int", fn(args) { + match args[0] { + Int(i) => println(i) + _ => @util.die("print_int expects Int") + } + Unit + }) + interpreter.add_extern_fn("minimbt_print_endline", fn(_args) { + println("") + Unit + }) let create_array = fn(args : Array[@closure_eval.Value]) { match args[0] { Int(n) => @closure_eval.Value::Array(Array::make(n, args[1])) @@ -121,69 +88,48 @@ fn add_closure_interpreter_fns( interpreter.add_extern_fn("minimbt_create_array", create_array) interpreter.add_extern_fn("minimbt_create_float_array", create_array) interpreter.add_extern_fn("minimbt_create_ptr_array", create_array) - interpreter.add_extern_fn( - "minimbt_truncate", - fn(args) { - match args[0] { - Double(d) => Int(d.to_int()) - _ => @util.die("truncate expects Double") - } - }, - ) - interpreter.add_extern_fn( - "minimbt_sin", - fn(args) { - match args[0] { - Double(d) => Double(@math.sin(d)) - _ => @util.die("sin expects Double") - } - }, - ) - interpreter.add_extern_fn( - "minimbt_cos", - fn(args) { - match args[0] { - Double(d) => Double(@math.cos(d)) - _ => @util.die("cos expects Double") - } - }, - ) - interpreter.add_extern_fn( - "minimbt_sqrt", - fn(args) { - match args[0] { - Double(d) => Double(d.sqrt()) - _ => @util.die("sqrt expects Double") - } - }, - ) - interpreter.add_extern_fn( - "minimbt_abs_float", - fn(args) { - match args[0] { - Double(d) => Double(@double.abs(d)) - _ => @util.die("abs_float expects Double") - } - }, - ) - interpreter.add_extern_fn( - "minimbt_int_of_float", - fn(args) { - match args[0] { - Double(d) => Int(d.to_int()) - _ => @util.die("int_of_float expects Double") - } - }, - ) - interpreter.add_extern_fn( - "minimbt_float_of_int", - fn(args) { - match args[0] { - Int(i) => Double(i.to_double()) - _ => @util.die("float_of_int expects Int") - } - }, - ) + interpreter.add_extern_fn("minimbt_truncate", fn(args) { + match args[0] { + Double(d) => Int(d.to_int()) + _ => @util.die("truncate expects Double") + } + }) + interpreter.add_extern_fn("minimbt_sin", fn(args) { + match args[0] { + Double(d) => Double(@math.sin(d)) + _ => @util.die("sin expects Double") + } + }) + interpreter.add_extern_fn("minimbt_cos", fn(args) { + match args[0] { + Double(d) => Double(@math.cos(d)) + _ => @util.die("cos expects Double") + } + }) + interpreter.add_extern_fn("minimbt_sqrt", fn(args) { + match args[0] { + Double(d) => Double(d.sqrt()) + _ => @util.die("sqrt expects Double") + } + }) + interpreter.add_extern_fn("minimbt_abs_float", fn(args) { + match args[0] { + Double(d) => Double(@double.abs(d)) + _ => @util.die("abs_float expects Double") + } + }) + interpreter.add_extern_fn("minimbt_int_of_float", fn(args) { + match args[0] { + Double(d) => Int(d.to_int()) + _ => @util.die("int_of_float expects Double") + } + }) + interpreter.add_extern_fn("minimbt_float_of_int", fn(args) { + match args[0] { + Int(i) => Double(i.to_double()) + _ => @util.die("float_of_int expects Int") + } + }) } ///| diff --git a/src/bin/main.mbt b/src/bin/main.mbt index 00492c3..e25a28d 100644 --- a/src/bin/main.mbt +++ b/src/bin/main.mbt @@ -172,27 +172,23 @@ fn main { ( "--start-stage", "", - @ArgParser.String( - fn(s) { - match Stages::from_string(s) { - Some(stage) => start_stage.val = stage - None => @util.die("Invalid stage") - } - }, - ), + @ArgParser.String(fn(s) { + match Stages::from_string(s) { + Some(stage) => start_stage.val = stage + None => @util.die("Invalid stage") + } + }), "Start stage", ), ( "--end-stage", "", - @ArgParser.String( - fn(s) { - match Stages::from_string(s) { - Some(stage) => end_stage.val = stage - None => @util.die("Invalid stage") - } - }, - ), + @ArgParser.String(fn(s) { + match Stages::from_string(s) { + Some(stage) => end_stage.val = stage + None => @util.die("Invalid stage") + } + }), "End stage", ), ( @@ -225,29 +221,25 @@ fn main { ( "--knf-opt-iters", "N", - @ArgParser.String( - fn(s) { - let i = @strconv.parse_int?(s) - match i { - Ok(i) => knf_opt_iters.val = i - Err(_e) => @util.die("Invalid number") - } - }, - ), + @ArgParser.String(fn(s) { + let i = @strconv.parse_int?(s) + match i { + Ok(i) => knf_opt_iters.val = i + Err(_e) => @util.die("Invalid number") + } + }), "Number of optimization iterations", ), ( "--knf-opt-inline-threshold", "N", - @ArgParser.String( - fn(s) { - let i = @strconv.parse_int?(s) - match i { - Ok(i) => knf_opt_inline_threshold.val = i - Err(_e) => @util.die("Invalid number") - } - }, - ), + @ArgParser.String(fn(s) { + let i = @strconv.parse_int?(s) + match i { + Ok(i) => knf_opt_inline_threshold.val = i + Err(_e) => @util.die("Invalid number") + } + }), "Inline threshold for KNF optimization", ), ], @@ -268,14 +260,12 @@ fn main { if closure_interpreter.val { end_stage.val = Stages::Closure } - let stages_to_print = print.val.map( - fn(s) { - match Stages::from_string(s) { - Some(stage) => stage - None => @util.die("Invalid stage to print: \{s}") - } - }, - ) + let stages_to_print = print.val.map(fn(s) { + match Stages::from_string(s) { + Some(stage) => stage + None => @util.die("Invalid stage to print: \{s}") + } + }) // Input let file = if file.is_empty() { diff --git a/src/utils.mbt b/src/utils.mbt index f77000b..9d54518 100644 --- a/src/utils.mbt +++ b/src/utils.mbt @@ -73,9 +73,9 @@ pub fn to_json(self : Fundef) -> Json { { "name": [self.name.0 |> Json::String, self.name.1.to_json()], "args": [ - ..self.args.map( - fn { (name, ty) => ([name |> Json::String, ty.to_json()] : Json) }, - ), + ..self.args.map(fn { + (name, ty) => ([name |> Json::String, ty.to_json()] : Json) + }), ], "body": self.body.to_json(), }