library/Std.amy
/** This module contains basic functionality for Amy,
* including stub implementations for some built-in functions
* (implemented in WASM or JavaScript)
*/
module Std
native fn printInt(i: Int): Unit
native fn printString(s: String): Unit
fn printBoolean(b: Boolean): Unit = {
printString(booleanToString(b))
}
native fn readString(): String
native fn readInt(): Int
fn intToString(i: Int): String = {
if (i < 0) {
"-" ++ intToString(-i)
} else {
val rem: Int = i % 10;
val div: Int = i / 10;
if (div == 0) { digitToString(rem) }
else { intToString(div) ++ digitToString(rem) }
}
}
native fn digitToString(i: Int): String
fn booleanToString(b: Boolean): String = {
if (b) { "true" } else { "false" }
}
end Std