Pure restricted MoonBit source frontend for typed Morphir IR
| Channel | Profile | Source contract |
|---|---|---|
| Stable, default | moonbit-model-stable-v1 | Typed Bool/String/Int32 libraries, immutable bindings, direct acyclic calls, String ordering, length and owned slices, pinned String predicates, audited Boolean SDK binding |
| Experimental, explicit opt-in | moonbit-model-experimental-v1 | Stable plus expanded integer widths, BigInt, Float/Double, audited SDK math/conversions and checked Decimal |
pub fn eligible(active : Bool, vip : Bool) -> Bool {
active && !vip
}| Source call | Canonical Basics value | Source / Scheme / generated consumer | Qualification contract |
|---|---|---|---|
| @basics.sqrt(Double) | sqrt | Supported | Exact reference bits, including negative zero; negative inputs produce NaN |
| @basics.sin(Double) | sin | Supported | Reference vectors within 4 ULP; signed zero exact; infinity produces NaN |
| @basics.cos(Double) | cos | Supported | Reference vectors within 4 ULP; zero returns one; infinity produces NaN |
| @basics.power_float(Double, Double) | power | Supported | Reference vectors within 4 ULP; exact integer and exceptional cases checked separately |
| @basics.abs_float(Double) | abs | Supported | Classic branch semantics preserve negative zero and NaN; other qualified values exact |
| @basics.not_(Bool) | not | Supported | Exact Boolean negation |
| SDK Integer-returning rounding and Maybe conversions | Existing classic / numeric extension names | Supported subset below | Explicit optional and error boundaries |
| Source calls | Canonical module | Classification | Contract |
|---|---|---|---|
| @basics.round, floor, ceiling, truncate | Basics, same names | Classic | Double -> @integer.Integer raise @sdk.SdkError; round ties toward positive infinity; other policies follow their names; nonfinite inputs raise InvalidNumber |
| @basics.abs_int | basics#abs | Classic | Exact Integer absolute value |
| @basics.to_float | basics#to-float | Classic | Integer to nearest binary64, ties to even; overflow to infinity |
| @int.from_float64_exact, from_float64_truncated, from_float64_floor, from_float64_ceiling, from_float64_rounded | Int, names with hyphens | morphir-sdk-moonbit-numeric-v1 | Double -> @integer.Integer?; nonfinite inputs return None; exact also refuses fractional values; rounded ties toward positive infinity |
| @int.to_float64_exact | int#to-float64-exact | Same numeric extension | @integer.Integer -> Double?; None for inexact or overflowing results |
| @int.to_float64_rounded | int#to-float64-rounded | Same numeric extension | Same rounding and overflow contract as classic to_float |
| Source call | Pinned signature | Canonical SDK value | Contract |
|---|---|---|---|
| s.is_empty() | (String) -> Bool | morphir/SDK:string#is-empty | True only for zero UTF-16 units |
| s.contains(needle) | (String, StringView) -> Bool | morphir/SDK:string#contains | UTF-16 code-unit substring; an empty needle matches |
| s.has_prefix(prefix) | (String, StringView) -> Bool | morphir/SDK:string#starts-with | UTF-16 code-unit prefix |
| s.has_suffix(suffix) | (String, StringView) -> Bool | morphir/SDK:string#ends-with | UTF-16 code-unit suffix |
pub fn eligible(active : Bool, vip : Bool, suspended : Bool) -> Bool {
let allowed : Bool = ready(active, vip)
allowed && !suspended
}
pub fn default_ready() -> Bool { ready(true, false) }
fn ready(active : Bool, vip : Bool) -> Bool { active || vip }fn prefix() -> String { "Hello, " }
pub fn greet(name : String) -> String {
let greeting : String = prefix()
greeting + name
}
pub fn welcome(name : String, enabled : Bool) -> String {
if enabled { greet(name) } else { "" }
}| Budget | Hard default | Scope |
|---|---|---|
| UTF-8 source bytes | 65,536 | Unit |
| Functions | 64 | Unit |
| Positional parameters | 16 | Function |
| Immutable lets | 256 | Function |
| Visited source expressions | 4,096 | Unit, including call identifiers |
| Call sites | 1,024 | Unit |
| Expression depth | 64 | Root at depth zero |
| Call graph depth | 32 | Edges on the longest path |
moon test -p finos/morphir-moonbit-frontend --target allpub fn amount(text : String) -> @decimal.Decimal raise @decimal.DecimalError {
let value = @decimal.from_string_exact(text)
@decimal.divide(@decimal.mul(value, value), value)
}| Admitted call | Contract |
|---|---|
| from_string_exact(String) | Exact construction using the classic lexical grammar; InvalidLiteral for invalid syntax or construction budgets; PrecisionLoss if nonzero digits would be discarded below exponent -32 |
| add, sub, mul | Classic exact coefficient arithmetic with normalization and truncation at exponent -32 |
| eq, neq, lt, lte, gt, gte | Exact numerical comparison, independent of original scale |
| round | Round to an integer, ties to even, including negative ties |
| divide | Truncate toward zero at exponent -32; DivisionByZero for any zero divisor, including 0/0; Underflow for a nonzero quotient truncated to zero; 0/nonzero succeeds |
| divide_with_default(fallback, a, b) | Explicit opt-in fallback for division failure; successful zero remains zero |
pub(all) struct Input {
unit_id : String
package_name : String
module_name : String
source : String
}pub(all) struct Output {
unit_id : String
ir : IRFile
entry : FQName
public : Bool
metadata : Array[NodeMetadata]
annotations : Array[SymbolToken]
provenance : Array[Ion]
warnings : Array[Warning]
}pub struct PinnedSourceBindings {
// private fields
}fn PinnedSourceBindings::sdk_basics_not(source_package : String, source_version : String, source_tree : String, source_alias : String) -> PinnedSourceBindings raise FrontendErrorfn PinnedSourceBindings::sdk_decimal(source_package : String, source_version : String, source_tree : String, source_alias : String) -> PinnedSourceBindings raise FrontendErrorfn PinnedSourceBindings::sdk_numeric_conversions(source_package : String, source_version : String, source_tree : String, source_alias : String) -> PinnedSourceBindings raise FrontendErrorfn PinnedSourceBindings::sdk_numeric_math(source_package : String, source_version : String, source_tree : String, source_alias : String) -> PinnedSourceBindings raise FrontendErrorfn PinnedSourceBindings::with_string_predicates(self : PinnedSourceBindings, core_package : String, core_version : String, core_tree : String) -> PinnedSourceBindings raise FrontendErrorfn compile_library(input : Input, channel? : SourceChannel, bindings? : PinnedSourceBindings?, limits? : LibraryLimits, max_string_code_units? : Int, strict_naming? : Bool, cancelled? : () -> Bool, scope? : Scope) -> LibraryOutput raise