/Develop/Projects/Vcc/

k1.spdns.de / Develop / Projects / Vcc /

Kio's Virtual Instruction Compiler.

intro | invocation | preprocessor | types | functions | operators | instructions  

compiler | memory  

Functions

List of known functions.
Note: 'T' is frequently used to represent multiple types.
'[' .. ']' enclose optional arguments. (Caveat: Sometimes they stand for itself, e.g. in array types.)

Integer Functions

All integer functions are defined for int8 to int64 and uint8 to uint64 except if stated otherwise.

int sign ( sT )

Numeric sign of signed int.

uT abs (sT)

Absolute value of a signed int. The returned value is an unsigned int of the same size.

T min( T, T [,T] )

Minimum value of 2 or 3 values;

T max( T, T [,T] )

Maximum value of 2 or 3 values;

T swap (T)

Revert bytes of an integer number. Obviously not for int8 or uint8.

T hilo (T)

Reorder bytes of an integer number from or to hi-to-low byte order.
This is NOP on a Big-Endian machine (PPC, 68k) and swap on Little Endian (i386).
The 'hilo' byte order is the 'internet byte order'.
Use 'hilo' if you read from / write to files or streams or arrays which will be written to / read from streams or arrays which use this byte order.
Obviously not for int8 or uint8.

T lohi (T)

Reorder bytes of an integer number from or to low-to-high byte order.
This is NOP on a Little Endian machine (i386) and swap on Big-Endian (PPC, 68k).
Use 'lohi' if you read from / write to files or streams or arrays which will be written to / read from streams or arrays which use this byte order.
Obviously not for int8 or uint8.

T flip ( uT )

Flip bits in unsigned integers.

T pow ( T, int n )

Raise a 32 or 64bit integer to the power of n.

uint32 random ( uT n )

Retrieve a random number in range [0 .. [n.
This function is defined for uint32 and uint64.

Floatingpoint Functions

All functions are defined for float32, float64 and float128.

int sign (float)

Numeric sign of float value.

float abs (float)

Absolute (positive) value of float value.

float min (float,float [,float])

Minimum value of 2 or 3 values;

float max (float,float [,float])

Maximum value of 2 or 3 values;

float round (float)

Round to nearest.

float floor (float)

Round down.

float ceil (float)

Round up.

float integ (float)

Integer portion of value. (The part before the decimal dot.)

float fract (float)

Fractional portion of value. (The part after the decimal dot.)

float random ()

Random Number in range [0 .. [1.

float random (float n)

Random Number in range [0 .. [n.

float sin (float)

Mathematical function.

float cos (float)

Mathematical function.

float tan (float)

Mathematical function.

float asin (float)

Mathematical function.

float acos (float)

Mathematical function.

float atan (float)

Mathematical function.

float sinh (float)

Mathematical function.

float cosh (float)

Mathematical function.

float tanh (float)

Mathematical function.

float exp10 (float n)

10 raised to the power of n. n may be fractional.

float exp2 (float n)

2 raised to the power of n. n may be fractional.

float expe (float n)

ec (Euler's constant) raised to the power of n. n may be fractional.
Note: Const float ec is defined in stdc.h.

float exp (float base ,float n)

base raised to the power of n. n may be fractional.

float log10 (float n)

Logarithm of n for base 10. This is the reverse function to exp10.

float log2 (float n)

Logarithm of n for base 2. This is the reverse function to exp10.

float loge (float n)

Logarithm of n for base ec (Euler's constant). This is the reverse function to exp10.

float log (float base,float n)

Logarithm of n for base base. This is the reverse function to exp10.

float pow (float,int32)

Same as exp(base,n) except that n is an integer value. Present to complement the integer pow() functions.

float sqrt (float n)

Square root of value. Same as exp(n,0.5).

Member Functions

float mant (float)

Binary mantissa of floating point number. This is a value in range [0.5 .. [1.0.
n = n.mant() << n.exp().

int32 exp (float)

Binary exponent of floating point number.
n = n.mant() << n.exp().

String Functions

str midstr ( cstr¢ s, int i, int n )

Create substring.

str leftstr ( cstr¢ s, int n )

Create substring.

str rightstr ( cstr¢ s, int n )

Create substring.

str spacestr ( int n, [ char c ] )

Create a string entirely filled with char c. If c is omitted, space 0x20 is assumed.
Note: Strings are created like all other arrays filled with char 0x00!

str charstr ( int c )

Create a string which consists only of character c.

int hexchar ( uint n )

Convert n modulo 16 into a hexadecimal character.

str hexstr ( uint n, uint digits )

Convert integer number into a hexadecimal representation.

str numstr ( T )

Convert integer or floating point number into a decimal representation. The exact format of the resulting string depends on the numeric type.

T numval ( cstr¢ )

Convert string into a number. The string is parsed until a void character is encountered or the end is reached.
Note that you must define the required result type in the call, e.g.:

float f = (float)numval(mystring)
str¢ min ( const str¢, const str¢ )

Return the lexically smaller string.
Note: The string is returned 'by ident'.

str¢ min ( const str[]¢, [ uint a, uint e ] )

Find the lexically smallest string in an array.
Note: The string is returned 'by ident'.

str¢ max ( const str¢, const str¢ )

Return the lexically larger string.
Note: The string is returned 'by ident'.

str¢ max ( const str[]¢, [ uint a, uint e ] )

Find the lexically largest string in an array.
Note: The string is returned 'by ident'.

cstr errorstr ( int error )

Get the user-readable text for a system error code.

cstr errorstr()

Get the user-readable text for the system error code in errno.

str, ucs1str, ucs2str and ucs4str Functions

The following functions are defined for

int8[]   == utf8str
uint8[] == ucs1str
uint16[] == ucs2str
uint32[] == ucs4str

The standard str is probably an int8[].

T[] join ( const T[][]¢, T c )

Join array of strings into a single string concatenating them with character c.

T[] join ( const T[][]¢, const T[]¢ s )

Join array of strings into a single string concatenating them with string s.

T[][] split ( const T[]¢, T c )

Split string at every occurance of character c into an array of strings. If the character c occurs n times then the resulting array will contain n+1 strings.

T[][] split ( const T[]¢, const T[]¢ s )

Split string at every occurance of string s into an array of strings. If the string s occurs n times then the resulting array will contain n+1 strings.

str, ucs1str, ucs2str and ucs4str Member Functions

utf8str toutf8 ( T[]¢ )

Convert source string to utf8str.

ucs1str toucs1 ( T[]¢ )

Convert source string to ucs1str.

ucs2str toucs2 ( T[]¢ )

Convert source string to ucs1str.

ucs4str toucs4 ( T[]¢ )

Convert source string to ucs1str.

T[] toupper ( T[] )

Convert source string to uppercase.

T[] tolower ( T[] )

Convert source string to lowercase.

T[] escape ( T[]¢, T rightquote )

Escape control codes and special characters. The rightquote character is escaped too. Set to 0x00 if not needed.

T[] unescape ( T[]¢ )

Unescape an escaped string.

String and Array Functions

int find ( const T[]¢, T, int idx )
int find ( const T[]¢, const T[]¢, int idx )
int rfind ( const T[]¢, T, int idx )
int rfind ( const T[]¢, const T[]¢, int idx )
T min ( const T[]¢, [ uint a, uint e ] )
T max ( const T[]¢, [ uint a, uint e ] )
void flip ( int8[]¢, [ uint a, uint e ] )
void rol ( int8[]¢, [ uint a, uint e ] )
void ror ( int8[]¢, [ uint a, uint e ] )
void sort ( int8[]¢, [ uint a, uint e ] )
void rsort ( int8[]¢, [ uint a, uint e ] )
void shuffle ( int8[]¢, [ uint a, uint e ] )
void sort ( int32[]¢, [ uint a, uint e ] )
void rsort ( int32[]¢, [ uint a, uint e ] )
void shuffle ( int32[]¢, [ uint a, uint e ] )
T[] alloc ( uint count ) built-in // not init()ed; cleared to zero
T[] realloc ( T[]const¢ ) built-in // not copy()ed; flat copy
void dealloc ( T[]& ) built-in // not kill()ed;
void resize ( T[]&, uint count ) built-in
void grow ( T[]&, uint count ) built-in
void shrink ( T[]&, uint count ) built-in
T& operator[] ( uint idx ) built-in

I/O and Filesystem Functions

File access functions use a file descriptor FD:

enum FD = { stdin,stdout,stderr }
bool match( cstr¢ string, cstr¢ pattern, int flags )

Test whether string matches a filesystem-wildchar-style pattern.

enum{
fnm_pathname = 0x02, // directory separators must match directly
fnm_nohidden = 0x04, // match starting dots only with explicit dots in pattern
fnm_casefold = 0x10 // compare case-insensitive
}
str fullpath( cstr¢ path, [ int flags ] )

Convert user-supplied path into a fully normalized path. Sets misc. errors.

enum{
f_follow_symlink = 1, // don't deref symlink in last path component
f_create_path = 2 // auto create path as you go
}
s_type nodetype( cstr¢ path, bool resolve_symlink )

Determine file type of a file system entry.

enum int8 s_type =
{
s_none = -1,
s_unkn = 0, // DT_UNKNOWN
s_any = 0, // used for selecting files by type
s_pipe = 1, // DT_FIFO
s_tty = 2, // DT_CHR
s_dir = 4, // DT_DIR
s_block = 6, // DT_BLK
s_file = 8, // DT_REG
s_link = 10, // DT_LNK
s_sock = 12, // DT_SOCK
s_null = 14 // DT_WHT
}
bool isfile ( cstr¢ path )

Convenience function to test whether a file is a regular file. Resolves symlink.

bool isdir ( cstr¢ path )

Convenience function to test whether a file is a directory. Resolves symlink.

bool islink ( cstr¢ path )

Convenience function to test whether a file is a symbolic link.

FileInfo fileinfo( cstr¢ path, [ bool resolve_symlink ] )

Retrieve struct with info about a file.

FileInfo[] readdir( cstr¢ path )

Read directory. Returns an array of file infos. The supplied path may contain wildcards for the file names. (not for the path to the directory.)

type FileInfo =
{
int8* filename; // "file_or_subdirectory_name"
uint16 filetype; // mode_t: file type
uint16 permissions;// mode_t: permissions
uint16 user; // uid_t: user id
uint16 group; // gid_t: group id
uint64 count; // file length or num files in dir
float64 ctime; // t_time last modification of meta data
float64 mtime; // t_time last modification of contents
float64 atime; // t_time last access
};
void renamefile( cstr¢ path, cstr¢ newpath, bool replace )

Rename or move a file within a file system. Set replace to yes to overwrite any file at the destination location.

void swapfiles( cstr¢ path, cstr¢ path2 )

Swap two files which must be on the same physical file system.

str tempfile( cstr¢ renamable_to_path )

Create a path for a file which can be renamed to the supplied destination file.

FD tempfile()

Create and open a temp file. The file is automatically removed when closed.

int8[] readfile( cstr¢ path )

Read file into a int8 array.

str readlink( cstr¢ path )

Read link.

void createfile( cstr¢ path, int8[]¢ data, [ int how, [ int mode ] ] )

Create file from int8 array. Default for how is 'w' (write/overwrite). Default for mode is 6<<6+6<<3 (r/w for owner and group).

void createlink( cstr¢ path, cstr¢ destination )

Create a symbolic link at path pointing to destination.

void createdir( cstr¢ path, [ int mode ] )

Create directory. Default for mode is 7<<6+7<<3 (r/w/x for owner and group).

void rmvfile( cstr¢ path )

Remove regular file, empty directory or any special file, except links. Resolves symlink.
Nothing is done if errno is set!

void rmvlink( cstr¢ path )

Remove symlink.
Nothing is done if errno is set!

void rmvdir( cstr¢ path, bool fulltree )

Remove a directory and all files inside. If fulltree=yes then subdirectories are removed recursively.
If files or directories cannot be removed rmvdir resumes but will fail to remove the final directory.
Nothing is done if errno is set!

FD open(cstr¢, int how, [ int mode ])

Open regular file or special file. Resolves symlink.
Values for mode are:

'r'  - file is opened for reading, must exist
'w' - file is opened for writing, created if n.ex.
'rw' - file is opened for reading and writing, created if n.ex.
'a' - file is opened for writing in 'append' mode, created if n.ex.
'n' - file is created and opened for writing, must not exist
void close(FD)

close the file.

long fpos(FD)

Get the current read/write position.

long flen(FD)

Get the current file length.

void seek(FD,long)

Move read/write position.

void truncate(FD)

Truncate file at current read/write position.

void print(T)

Print string to file. Numeric values are converted to string.

void putchar(char)

Write a single character to file or stream.

char getchar()

Read a single character from file or stream.

void write(FD,T)

Write Numeric value in it's binary representation to file. Use functions HiLo() or LoHi() if required.

void write(cstr¢,T)

Write string to file.

T read(FD)

Read Numeric value in it's binary representation from file. Use functions HiLo() or LoHi() if required.

str read(FD)

Read string from file. strings are delimited by 0x00, '\n' or '\r'. The delimiter is not included in the string.

Other Functions

bool is_letter (int)

Test whether UCS4 character is a letter.

bool is_bin_digit(int)

Test whether UCS4 character is a digit.

bool is_dec_digit(int)

Test whether UCS4 character is a decimal digit.

bool is_hex_digit(int)

Test whether UCS4 character is a hexadecimal digit.

uint digit_value (int)

Calculate the digit value of a digit charatcer. No checking. Trash in - trash out. Up to base 36.

void memcpy ( byte* z, byte* q, uint cnt )

Copy raw memory.

void memset ( byte* z, int filler, uint cnt )

Clear raw memory with filler.

void memclr ( byte* z, uint cnt )

Clear raw memory with 0x00.

T alloc ()

Allocate memory for struct or array. The memory is cleared with 0x00. Does not call init().

T realloc ( T const¢ )

Allocate & copy memory of struct or array. Flat copy, does not call copy().

void dealloc ( T& )

Deallocate memory of struct or array and set variable to null. Does not call kill().

void abort ( [ cstr¢ msg ] )

Abort with "Abort:" + message. Implemented in lib/stdc.cpp.

void TODO ()

Abort with message "TODO". Implemented in lib/stdc.cpp.

void PANIC ( cstr¢ msg)

Abort with "Panic:" + message. Implemented in lib/stdc.cpp.

void assert( <condition> )

Test condition and resume if true.
Else abort with an error message indication file, line and failed condition.
asserts are only compiled in if the macro DEBUG is defined and not defined as 0. This is typically done on the command line with the option -DDEBUG. Else no code is generated.
It is an error to put code with side effects (like 'i++') in an assert.

Multithreading

Tid self ()
float now ()
int num_cores ()
Tid spawn (void(*) fu,*)
void termi ()
void suspend (Tid)
void resume (Tid)
void wait ()

until next event

void wait (float sec)
void busywait (uint usec)
void shedule (float when)
void request (sema¢)
void release (sema¢)
bool tryrequest (sema¢, float timeout)
void lock (mutex¢)
void unlock (mutex¢)
bool trylock (mutex¢, float timeout)

Archive

Name Letzte Änderung Länge 
lib-Z80-Rop/ 2020-11-30 15:50 21 
lib-Z80-Vss/ 2017-11-12 09:55 452 
lib/ 2019-10-30 17:02
Libraries/ 2019-10-30 17:11
OSX-Qt40/ 2019-10-30 17:02
OSX/ 2020-09-05 12:54
Source/ 2019-10-30 17:02 11 
Tests/ 2019-10-30 17:02
LICENSE 2019-10-30 17:25 1323 
README.md 2019-10-30 17:25 288 
TODO.txt 2020-10-18 12:42 340 
macspin.gif

powered by vipsi - your friendly VIP Script Interpreter

Valid HTML Valid CSS