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 FunctionsSupport?

NATIVE_ARGS_FLAG

NATIVE_ARGS_INT

NATIVE_ARGS_PARSE

NATIVE_ARGS_STRING

Standard I/O

Native FunctionsSupport?

NATIVE_EOF

NATIVE_FLUSH

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 double type 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 float type in C0/C1 language. (NATIVE_INDEX=[67, 77))

Native FunctionsSupport?

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 FunctionsSupport?

NATIVE_INT_TOKENS

NATIVE_NUM_TOKENS

NATIVE_PARSE_BOOL

NATIVE_PARSE_INT

NATIVE_PARSE_INTS

NATIVE_PARSE_TOKENS

String Operations

Native FunctionsSupport?

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