-
Notifications
You must be signed in to change notification settings - Fork 0
Runtime Interface
The language was designed to be easily embedded into environments and runtimes, which sometimes requires you to call a runtime specific API function from the language, or call a function implemented in the language itself.
External functions are functions that only have the function signature defined and the body written somewhere in C#. They often used to implement APIs.
To import an external function, use the External attribute with the external function's name as a parameter:
[External("stdout")]
void print(u16 data);If the return type or parameter types don't match, a compiler error will be made.
-
"stdin"
Reads a key from the console. This blocks the code execution until a key is pressed.
- Parameters: none
- Return type:
u16
Corresponding .NET function:
return (char)System.Console.In.Read();
-
"stdout"
Writes a character to the standard output stream.
- Parameters:
u16character - Return value:
void
Corresponding .NET function:
System.Console.Out.Write(character);
- Parameters:
External constants are values coming from the runtime that can be used in the language.
To use an external constant, use the External attribute on a constant.
[External("meow")]
const i32 meow;You can also set a default value to the constant, which will be used when the external constant doesn't exists.
Exposed functions are functions that are implemented in the language, but can be called by the runtime. These functions will always be compiled (bc the compiler doesn't know if you want to call the function later or not).
To make a function exposed, use the Expose attribute:
[Expose("meow")]
i32 meow()
{
printline("meow!");
}Note that exposed functions can only be called after the interpreter finished running. If in the top level statements there's an infinity loop, you'll never be able to call any external functions.
