package SPVM::Math::BigInteger {
  has val : private ro string;

  sub _validate : void ($val : string) {
    my $length = length $val;
    unless ($length > 0) {
      die "value is empty";
    }
    if ($length > 1 && $val->[0] == '0') {
      die "leading 0 is not allowed";
    }
    for (my $i = 0; $i < $length; ++$i) {
      unless ('0' <= $val->[$i] && $val->[$i] <= '9') {
        die "value has not digit";
      }
    }
  }

  sub new : SPVM::Math::BigInteger ($val : string) {
    my $self = new SPVM::Math::BigInteger;
    _validate($val);
    $self->{val} = $val;
    return $self;
  }

  sub to_str : string ($self : self) {
    return $self->{val};
  }

  # TODO: numeric operators: add, minus, mul, divide, mod
}
