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 Functions
Support?

NATIVE_ARGS_FLAG

βŒ›

NATIVE_ARGS_INT

βŒ›

NATIVE_ARGS_PARSE

βŒ›

NATIVE_ARGS_STRING

βŒ›

Standard I/O βœ…

Native Functions
Support?

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 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 Functions
Support?

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 Functions
Support?

NATIVE_INT_TOKENS

βœ…

NATIVE_NUM_TOKENS

βœ…

NATIVE_PARSE_BOOL

βœ…

NATIVE_PARSE_INT

βœ…

NATIVE_PARSE_INTS

βœ…

NATIVE_PARSE_TOKENS

βœ…

String Operations βœ…

Native Functions
Support?

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