moonbitlang / core

MoonBit's Core library
https://moonbitlang.com/
Apache License 2.0
621 stars 78 forks source link

bigint literal is terribly inefficient #926

Open bobzhang opened 2 months ago

bobzhang commented 2 months ago
fn testgxx () -> Unit {
    let v = 0N
    match v {
        1 => println("hello")
    }
    println(v)
}

==>

fn testgxx () -> Unit {
  let v/1 : BigInt = BigInt::from_string("0") in
  if BigInt::op_equal(v/1, BigInt::from_string("1")) {
    $builtin.println("hello")
  } else {
    raise "match_failure"
  }
  $builtin.println(v/1)
}
bobzhang commented 2 months ago

for pattern match: we can provide two functions, so that no allocation is needed in most cases:

equal_int(BigInt, Int) -> Bool
equal_int64(BigInt, Int64) -> Bool

cc @Yoorkin @peter-jerry-ye

bobzhang commented 2 months ago

937