Skip to content

Commit

Permalink
minor: bump moonbitlang/x (#24)
Browse files Browse the repository at this point in the history
* minor: bump moonbitlang/x

* minor: moon fmt
  • Loading branch information
Young-Flash authored Dec 17, 2024
1 parent 8e020dd commit 3285ef9
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 206 deletions.
2 changes: 1 addition & 1 deletion moon.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
266 changes: 106 additions & 160 deletions src/bin/externals.mbt
Original file line number Diff line number Diff line change
@@ -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]))
Expand All @@ -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]))
Expand All @@ -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")
}
})
}

///|
Expand Down
Loading

0 comments on commit 3285ef9

Please sign in to comment.