Native Functions
Native Functions, Explained
Defined in ./src/types/types.d.ts, a C0Native object represents a native function in the C0 Virtual Machine that can be called during the runtime.
type C0Native = {
numArgs: number;
readonly functionType: C0NativeFuncType;
readonly f: (hooks: ReactUIHook, mem: C0HeapAllocator, ...args: C0Value<C0TypeClass>[]) =>
C0Value<C0TypeClass>;
};Specifically, the property of f represents the code of native function that can be dynamically loaded during runtime.
The function header of f is defined as
type f: (hooks: ReactUIHook, mem: C0HeapAllocator, ...args: C0Value<C0TypeClass>[]) =>
C0Value<C0TypeClass>;This means f will take a bunch of react hooks to update the react state (e.g. printout value), a memory allocator (to allocate or extract value from heap memory), and several (1 to more) C0Value arguments.
Implementation Progress
In original C0VM, a bunch of native functions are implemented in C and connected to C0VM to support the system calls (e.g. receive user input, etc.).
The list of native functions is listed below:
β - Currently Support
β - Development in Progress, will be supported
β - No Recent Plan for implementation
Command Line Arguments β
NATIVE_ARGS_FLAG
β
NATIVE_ARGS_INT
β
NATIVE_ARGS_PARSE
β
NATIVE_ARGS_STRING
β
Standard I/O β
NATIVE_EOF
βββ
(Always return true since there's no file read in C0VM.ts)
NATIVE_FLUSH
β
(Always return true since there's no "buffering" in React UI Update)
NATIVE_PRINT
β
NATIVE_PRINTBOOL
β
NATIVE_PRINTCHAR
β
NATIVE_PRINTINT
β
NATIVE_PRINTLN
β
NATIVE_READLINE
β
Cursor β
There are no recent plans to implement native functions in this category (
NATIVE_INDEX = [12, 54])
Double Arithmetic β
We will not support this since there is no
doubletype in C0/C1 language. (NATIVE_INDEX=[55, 62))
File I/O β
There are no recent plans to implement native functions in this category (
NATIVE_INDEX=[62, 67))
Float Arithmetic β
We will not support this since there is no
floattype in C0/C1 language. (NATIVE_INDEX=[67, 77))
NATIVE_PRINT_HEX
β
NATIVE_PRINT_INT
β
Image β
There are no recent plans to implement native functions in this category (
NATIVE_INDEX = [77, 85))
Parse String β
NATIVE_INT_TOKENS
β
NATIVE_NUM_TOKENS
β
NATIVE_PARSE_BOOL
β
NATIVE_PARSE_INT
β
NATIVE_PARSE_INTS
β
NATIVE_PARSE_TOKENS
β
String Operations β
NATIVE_CHAR_CHR
β
NATIVE_CHAR_ORD
β
NATIVE_STRING_CHARAT
β
NATIVE_STRING_COMPARE
β
NATIVE_STRING_EQUAL
β
NATIVE_STRING_FROM_CHARARRAY
β
NATIVE_STRING_FROMBOOL
β
NATIVE_STRING_FROMCHAR
β
NATIVE_STRING_FROMINT
β
NATIVE_STRING_JOIN
β
NATIVE_STRING_LENGTH
β
NATIVE_STRING_SUB
β
NATIVE_STRING_TERMINATED
β
NATIVE_STRING_TO_CHARARRAY
β
NATIVE_STRING_TOLOWER
β
Last updated