Michael Heilmann's Runtime Mark 1
This is the documentation for Michael Heilmann's Runtime Mark 1, henceforth R1. R1 facilates the creation of C programs - in particular interpreters - that are portable, maintainable, as well as safe. R1 is available at michaelheilmann.com/repository/R1.
Files
You can find the sources of R1 in my GitHub repository https://github.com/michaelheilmann/michaelheilmann.com. The subdirectory of R1 in the repository is here https://github.com/michaelheilmann/michaelheilmann.com/tree/main/repository/R1.
- The (sources of the) library resides in the directory https://github.com/michaelheilmann/michaelheilmann.com/tree/main/repository/R1/Sources
- The (sources of) tests reside in the directory https://github.com/michaelheilmann/michaelheilmann.com/tree/main/repository/R1/Tests
- The (sources of) demos reside in the directory https://github.com/michaelheilmann/michaelheilmann.com/tree/main/repository/R1/Demos
- The (sources of this very documentation you are reading) documentation reside in the directory https://github.com/michaelheilmann/michaelheilmann.com/tree/main/repository/R1/Documentation
You can compile and run these under various platforms (including but not restricted to Windows, Linux, and many more), however, we currently only officially support Windows. To build and run all these, simply checkout the repository to the and outside of the repository directory create a build folder. Invoke from the the build folder
cmake
Documentation
Boolean Type
R1 provides a boolean type.
typedef
#define R_BooleanValue_True
is a value of the type denoting logically true
. It converts to 1
in arithmetic expressions.
#define R_BooleanValue_False
is a value of the type denoting logically false
. It converts to 0
in arithmetic expressions.
Foreign Procedure Type
R provides the
typedef
which is a pointer to a function adhering to the calling conventions for C functions of the runtime.
A valid value of the R_ForeignProcedureValue
is the null value
#define R_ForeignProcedureValue_Null
#define R_ForeignProcedureValue_NumberOfBits
denotes the number of Bits of the type.
#define R_ForeignProcedureValue_NumberOfBytes
denotes the number of Bytes of the type which is usually R_ForeignProcedureValue_NumberOfBits
divided by 8.
Integer Types
R provides a two's complement integer number types.
typedef
where 8
, 16
, 32
, or 64
.
The macros in this section all include the 8
, 16
, 32
, and 64
of that meta variable.
#define R_Integer
denotes the number of Bits of the type. The value is always equal to the value of the respective
#define R_Integer
denotes the number of Bytes of the type which is usually R_Integer
divided by 8.
#define R_Integer
denotes the least value (in terms of its magnitude) representable by a the R_Integer
type.
The following table denotes the value of the constant for the respective
Value | |
8 | -128 |
16 | -32768 |
32 | -2147483648 |
64 | -9223372036854775808 |
#define R_Integer
denotes the greatest value (in terms of its magnitude) representable by a the R_Integer
type.
The following table denotes the value of the constant for the respective
Value | |
8 | 127 |
16 | 32767 |
32 | 2147483647 |
64 | 9223372036854775807 |
#define R_Integer
is used to write a literal of the type R_Integer
in C source code.
The following table denotes the expansions of the macro:
Value | |
8 | x |
16 | x |
32 | x |
64 | x##LL |
Natural Types
R provides natural number types.
typedef
where 8
, 16
, 32
, or 64
.
The macros in this section all include the 8
, 16
, 32
, and 64
of that meta variable.
#define R_Natural
denotes the number of Bits of the type. The value is always equal to the value of the respective
#define R_Integer
denotes the number of Bytes of the type which is usually R_Integer
divided by 8.
#define R_Natural
denotes the least value (in terms of its magnitude) representable by a the R_Natural
type.
The following table denotes the value of the constant for the respective
Value | |
8 | 0 |
16 | 0 |
32 | 0 |
64 | 0 |
#define R_Natural
denotes the greatest value (in terms of its magnitude) representable by a the R_NaturalSuffixValue
type.
The following table denotes the value of the constant for the respective Suffix
Constant | Value |
8 | 255 |
16 | 65535 |
32 | 4294967295 |
64 | 18446744073709551615 |
#define R_Natual
is used to write a literal of the type R_Natural
in C source code.
The following table denotes the expansions of the macro:
Value | |
8 | x |
16 | x |
32 | x##U |
64 | x##ULL |
Object Reference Type
R provides a ObjectReference type.
typedef
The R_ObjectReferenceValue
type is a pointer.
A valid value of the R_ObjectReferenceValue
is the null reference
#define R_ObjectReferenceValue_Null
#define R_ObjectReferenceValue_NumberOfBits
denotes the number of Bits of the type.
#define R_ObjectReferenceValue_NumberOfBytes
denotes the number of Bytes of the type which is usually R_ObjectReferenceValue_NumberOfBits
divided by 8.
Size Type
R provides an alias for builtin size_t
type.
typedef
#define R_SizeValue_NumberOfBits
denotes the number of Bits of the type. This number must one of 32 or 64, otherwise the environment is not supported by R. This restriction may be relaxed in future versions of R.
#define R_SizeValue_NumberOfBytes
denotes the number of Bytes of the type which is usually R_SizeValue_NumberOfBits
divided by 8.
#define R_SizeValue_Minimum
denotes the least value (in terms of its magnitude) representable by a the R_Size
type.
#define R_SizeValue_Literal(x)
is used to write a literal of type R_SizeValue
in C source code.
Void Type
R provides a void type.
typedef
The only value of this type is R_VoidValue_Void
.
R_VoidValue is an unsigned integral type.
#define R_VoidValue_Void
The single value of the type.
#define R_VoidValue_NumberOfBits
denotes the number of Bits of the type.
#define R_VoidValue_NumberOfBytes
denotes the number of Bytes of the type which is usually R_VoidValue_NumberOfBits
divided by 8.
Value Type
R_Value
is a tagged union of values supported by the
runtime. It consists of a tag indicating the value stored in the
union and the union of the values. The following table lists all
possible tags and their corresponding type.
Tag | Type |
R_ValueTag_Boolean | R_BooleanValue |
R_ValueTag_Integer16 | R_Integer16Value |
R_ValueTag_Integer32 | R_Integer32Value |
R_ValueTag_Integer64 | R_Integer64Value |
R_ValueTag_Integer8 | R_Integer8Value |
R_ValueTag_Natural16 | R_Natural16Value |
R_ValueTag_Natural32 | R_Natural32Value |
R_ValueTag_Natural64 | R_Natural64Value |
R_ValueTag_Natural8 | R_Natural8Value |
R_ValueTag_ObjectReference | R_ObjectReferenceValue |
R_ValueTag_Size | R_SizeValue |
R_ValueTag_Void | R_VoidValue |
For each type, R_Value
has three functions associated:
bool R_Value_is
void R_Value_set
The following table lists the valid combinations of
Boolean | boolean |
Integer16 | integer16 |
Integer32 | integer32 |
Integer64 | integer64 |
Integer8 | integer8 |
Natural16 | natural16 |
Natural32 | natural32 |
Natural64 | natural64 |
Natural8 | natural8 |
ObjectReference | objectReference |
Size | size |
Void | void |
R_Value_is
returns true
if
the R_Value
stores a value of the type corresponding to false
.
R_Value_set
assigns the R_Value
a value of the type corresponding to
R_Value_get
get the value stored in
the R_Value
. The behavior of R_Value_set
is undefined if the value does not store a value of the
type corresponding to
Status Codes
R provides a status type and symbolic constants for its values. That type denotes success or failure of program (or a part of it) as well as information on the reason for the failure.
typedef
R_Status
is a natural number type of a width of 32 Bit.
#definer R_Status_Success
is the symbolic constant of the type R_Status
has the value ((R_Status)0)
.
It denotes success and is guaranteed to be defined to the value 0
of the underlaying natural number
type of R_Status as well as to be the only symbolic constant starting with R_Status_
having
defined to that value.
Symbolic constants of the form
#definer R_Status_
where Success
provide information on failure of a program (or a part of it).
The following table denotes the value of the constant for the respective
Name | Value |
AllocationFailed | An allocation failed. |
ArgumentTypeInvalid | The type of an argument is invalid. |
ArgumentValueInvalid | The value of an argument is invalid. |
ConversionFailed | A conversion failed. |
DivisionByZero | An divions by zero was detected. |
EncodingInvalid | An encoding is invalid. |
Exists | Something exists (but should not). |
FileSystemOperationFailed | A file system operation failed. |
Initialized | Something was initialized (but should not have been initialized). |
NotExists | Something does not exist. |
NumberOfArgumentsInvalid | The number of arguments is invalid. |
OperationInvalid | An operation is invalid. |
SemanticalError | |
SyntacticalError | |
TestFailed | A test failed. This is used by the built-in tests that ensure correctness. |
TypeExists | A type exists (but should not). |
TypeNotExists | A type does not exist (but should). |
Uninitialized | Something was uninitialized (but should have been initialized). |
Status Variable
R provides a global status variable.
R_Status
R_getStatus
(
);
gets the value of the status variable. The initial value of the status variable is R_Status_Success
.
void
R_setStatus
(
R_Status status
);
sets the value of the status variable to the value status
.
Jumps and Jump Targets
R provides non-local jumps by allowing to save and restore the C program state.
typedef
is a type of which its values are stack allocated.
void R_pushJumpTarget(R_JumpTarget* jumpTarget);
Push a jump target on top of the jump target stack. Initially, the jump target stack is empty.
void R_popJumpTarget();
Pop the jump target on top of the jump target stack. The jump target stack must not be empty.
void R_jump();
Jump to the jump target on top of the jump target stack. The jump target stack must not be empty.
#define R_JumpTarget_save(jumpTarget)
Macro to save the current C program state into a jump target.
The canonical way of using R_pushJumpTarget
, R_popJumpTarget
, and
R_jump
is the following.
R_pushJumpTarget(&jumpTarget);
if (R_JumpTarget_save(&jumpTarget)) {
R_popJumpTarget();
} else {
R_popJumpTarget();
}
The if-branch is always entered at first as the R_JumpTarget_save()
at
its first invocation returns logically true. If the program at R_jump()
), then R_popJumpTarget();
and R_JumpTarget_save()
is re-evaluated and returns
logically false and R_popJumpTarget();
and
One usage example is the implementation of the R_safeExecute
function.
void R_safeExecute(void (*f)()) {
R_JumpTarget jumpTarget;
R_pushJumpTarget(&jumpTarget);
if (R_JumpTarget_save(&jumpTarget)) {
f();
R_popJumpTarget();
}
}
Numeric functions
R_clamp
Clamp a value to a range.
The following table lists the combinations of
Integer8Value | R_Integer8Value |
Integer16Value | R_Integer16Value |
Integer32Value | R_Integer32Value |
Integer64Value | R_Integer64Value |
Natural8Value | R_Natural8Value |
Natural16Value | R_Natural16Value |
Natural32Value | R_Natural32Value |
Natural64Value | R_Natural64Value |
SizeValue | R_SizeValue |
Parameters
The value to clamp. | |
The lower bound (inclusive). | |
The upper bound (inclusive). |
This function returns the value value
clamped to the range [lower, upper]
.
Errors
R_Status_ArgumentValueInvalid | lower > upper |
R_Status_EncodingInvalid | The sequence of Bytes does not represented a UTF-8-NO-BOM string. |
Return value
The value value
clamped to the range [lower, upper]
.
R_countLeadingZeroes
Return the number of leadin gzeroes of the binary representation of a value.
R_SizeValue R_countLeadingZeroes
The following table lists the combinations of
Integer8Value | R_Integer8Value |
Integer16Value | R_Integer16Value |
Integer32Value | R_Integer32Value |
Integer64Value | R_Integer64Value |
Natural8Value | R_Natural8Value |
Natural16Value | R_Natural16Value |
Natural32Value | R_Natural32Value |
Natural64Value | R_Natural64Value |
SizeValue | R_SizeValue |
This function returns the number of leading zeroes of the binary representation of value
.
Return value
The number of leading zeroes.
R_hash
Return the hash of a value.
R_SizeValue R_hash
The following table lists the combinations of
BooleanValue | R_BooleanValue |
ForeignProcedureValue | R_ForeignProcedureValue |
Integer8Value | R_Integer8Value |
Integer16Value | R_Integer16Value |
Integer32Value | R_Integer32Value |
Integer64Value | R_Integer64Value |
Natural8Value | R_Natural8Value |
Natural16Value | R_Natural16Value |
Natural32Value | R_Natural32Value |
Natural64Value | R_Natural64Value |
Real32Value | R_Real32Value |
Real64Value | R_Real64Value |
SizeValue | R_SizeValue |
VoidValue | R_VoidValue |
Parameters
The value. |
Return value
Return hash of x
.
R_maximum
Return the maximum of two values.
The following table lists the combinations of
Integer8Value | R_Integer8Value |
Integer16Value | R_Integer16Value |
Integer32Value | R_Integer32Value |
Integer64Value | R_Integer64Value |
Natural8Value | R_Natural8Value |
Natural16Value | R_Natural16Value |
Natural32Value | R_Natural32Value |
Natural64Value | R_Natural64Value |
SizeValue | R_SizeValue |
Parameters
The first value. | |
The second value. |
Return value
Return the maximum of x
and y
.
R_minimum
Return the minimum of two values.
The following table lists the combinations of
Integer8Value | R_Integer8Value |
Integer16Value | R_Integer16Value |
Integer32Value | R_Integer32Value |
Integer64Value | R_Integer64Value |
Natural8Value | R_Natural8Value |
Natural16Value | R_Natural16Value |
Natural32Value | R_Natural32Value |
Natural64Value | R_Natural64Value |
SizeValue | R_SizeValue |
Parameters
The first value. | |
The second value. |
Return value
Return the minimum of x
and y
.
R_nextPowerOfTwoGt
R provides functions returning the next power of two greater than a value.
The following table lists the combinations of
Integer8Value | R_Integer8Value |
Integer16Value | R_Integer16Value |
Integer32Value | R_Integer32Value |
Integer64Value | R_Integer64Value |
Natural8Value | R_Natural8Value |
Natural16Value | R_Natural16Value |
Natural32Value | R_Natural32Value |
Natural64Value | R_Natural64Value |
SizeValue | R_SizeValue |
Parameters
The value. |
Errors
R_Status_NotExists | The next power of two greater than x is not representable by the type |
Return value
Return the next power of two greater than x
.
R_nextPowerOfTwoGte
R provides functions returning the next power of two greater or equal to a value.
The following table lists the combinations of
Integer8Value | R_Integer8Value |
Integer16Value | R_Integer16Value |
Integer32Value | R_Integer32Value |
Integer64Value | R_Integer64Value |
Natural8Value | R_Natural8Value |
Natural16Value | R_Natural16Value |
Natural32Value | R_Natural32Value |
Natural64Value | R_Natural64Value |
SizeValue | R_SizeValue |
Parameters
The value. |
Errors
R_Status_NotExists | The next power of two greater greater than or equal to x is not representable by the type |
Return value
Return the next power of two greater than or equal to x
.
R_getTickCount
Get the time, in milliseconds, since the start of the process.
R_Natural64Value R_getTickCount()
Return value
The time, in milliseconds, since the start of the process.
Objects
Byte Buffer
R_ByteBuffer
represents a mutable sequence of Bytes.
This type is allocated on the heap and values of this type are referenced by R_ByteBuffer
pointers.
A R_ByteBuffer
pointer can be safely cast into a R_ObjectReferenceValue
values.
An R_ObjectReferenceValue
pointing to a R_ByteBuffer
value can be safely cast into a R_ByteBuffer
pointer.
create
R_ByteBuffer* R_ByteBuffer_create()
Create an empty Byte buffer.
Return Value
A pointer to the Byte buffer.
clear
void R_ByteBuffer_clear(R_ByteBuffer* self)
Set the number of elements of this Byte buffer to zero.
Parameters
R_ByteBuffer* self | A pointer to this Byte buffer. |
endsWith_pn
R_BooleanValue R_ByteBuffer_endsWith_pn(R_ByteBuffer const* self, void const* bytes, R_SizeValue numberOfBytes)
Get if a sequence of Bytes is a suffix of this Byte buffer's sequence of Bytes.
Parameters
R_ByteBuffer* self | A pointer to this Byte buffer. |
void const* bytes | A pointer to an array of n Bytes. |
R_SizeValue numberOfBytes | The number of Bytes in the array pointed to by p . |
Return Value
R_BooleanValue_True
if the sequence of Bytes is a suffix of this byte buffer's sequence of Bytes.
R_BooleanValue_False
otherwise.
startsWith_pn
R_BooleanValue R_ByteBuffer_startsWith_pn(R_ByteBuffer const* self, void const* bytes, R_SizeValue numberOfBytes)
Get if a sequence of Bytes is a prefix of this Byte buffer's sequence of Bytes.
Parameters
R_ByteBuffer* self | A pointer to this Byte buffer. |
void const* bytes | A pointer to an array of n Bytes. |
R_SizeValue numberOfBytes | The number of Bytes in the array pointed to by p . |
Return Value
R_BooleanValue_True
if the sequence of Bytes is a prefix of this byte buffer's sequence of Bytes.
R_BooleanValue_False
otherwise.
isEqualTo_pn
R_BooleanValue R_ByteBuffer_isEqualTo_pn(R_ByteBuffer const* self, void const* bytes, R_SizeValue numberOfBytes)
Get if a sequence of Bytes is this Byte buffer's sequence of Bytes.
Parameters
R_ByteBuffer* self | A pointer to this Byte buffer. |
void const* bytes | A pointer to an array of n Bytes. |
R_SizeValue numberOfBytes | The number of Bytes in the array pointed to by p . |
Return Value
R_BooleanValue_True
if the sequence of Bytes is this byte buffer's sequence of Bytes.
R_BooleanValue_False
otherwise.
append_pn
void R_ByteBuffer_append_pn(R_ByteBuffer* self, void const* bytes, R_SizeValue numberOfBytes)
Append Bytes to this Byte buffer.
Parameters
R_ByteBuffer* self | A pointer to this Byte buffer. |
void const* bytes | A pointer to an array of n Bytes. |
R_SizeValue numberOfBytes | The number of Bytes in the array pointed to by p . |
Errors
R_Status_ArgumentValueInvalid | self is a null pointer. |
R_Status_ArgumentValueInvalid | bytes is a null pointer. |
R_Status_AllocationFailed | An allocation failed. |
prepend_pn
void R_ByteBuffer_prepend_pn(R_ByteBuffer* self, void const* p, R_SizeValue n)
Prepend Bytes to this Byte buffer.
Parameters
R_ByteBuffer* self | A pointer to this Byte buffer. |
void const* p | A pointer to an array of n Bytes. |
R_SizeValue n | The number of Bytes in the array pointed to by p . |
Errors
R_Status_ArgumentValueInvalid | self is a null pointer. |
R_Status_ArgumentValueInvalid | bytes is a null pointer. |
R_Status_AllocationFailed | An allocation failed. |
insert_pn
void R_ByteBuffer_insert_pn(R_ByteBuffer* self, R_SizeValue index, void const* p, R_SizeValue n)
Insert Bytes into this Byte buffer.
Parameters
R_ByteBuffer* self | A pointer to this Byte buffer. |
R_SizeValue index | The index at which to insert the Bytes. Must be within the bounds of [0,n) where n is the size of this Byte buffer. |
void const* p | A pointer to an array of n Bytes. |
R_SizeValue n | The number of Bytes in the array pointed to by p . |
Errors
R_Status_ArgumentValueInvalid | self is a null pointer. |
R_Status_ArgumentValueInvalid | bytes is a null pointer. |
R_Status_AllocationFailed | An allocation failed. |
isEqualTo
R_BooleanValue R_ByteBuffer_isEqualTo(R_ByteBuffer const* self, R_ByteBuffer const* other)
Compare this Byte buffer with another Byte buffer for equality.
Parameters
R_ByteBuffer const* self | A pointer to this Byte buffer. |
R_ByteBuffer const* other | A pointer to the other Byte buffer. |
Return Value
R_BooleanValue_True
if this Byte buffer is equal to the other Byte buffer.
R_BooleanValue_False
otherwise.
getSize
R_SizeValue R_ByteBuffer_getSize(R_ByteBuffer const* self)
Get the size of this Byte buffer.
Parameters
R_ByteBuffer* self | A pointer to this Byte buffer. |
Return Value
The size of this Byte buffer.
Remarks
The size of a Byte buffer is the length of the Byte sequence it contains.
getat
R_Natural8Value R_ByteBuffer_getAt(R_ByteBuffer const* self, R_SizeValue index)
Get the Byte value at the specified index.
Parameters
R_ByteBuffer* self | A pointer to this Byte buffer. |
R_SizeValue index | The index. Must be within the bounds [0,n) where n is the size of this Byte buffer. |
Return Value
The Byte value.
Remarks
The size of a Byte buffer is the length of the Byte sequence it contains.
isEmpty
R_BooleanValue R_ByteBuffer_isEmpty(R_ByteBuffer* self)
Get if this Byte buffer is empty.
Parameters
R_ByteBuffer* self | A pointer to this Byte buffer. |
Return Value
R_BooleanValue_True
if this Byte buffer is empty. R_BooleanValue_False
otherwise.
Errors
R_Status_ArgumentValueInvalid | self is a null pointer. |
swap
void R_ByteBuffer_swap(R_ByteBuffer* self, R_ByteBuffer* other)
Swap the contents of this Byte buffer with the contents of another Byte buffer.
Parameters
R_ByteBuffer* self | A pointer to this Byte buffer. |
R_ByteBuffer* self | A pointer to the other Byte buffer. |
Errors
R_Status_ArgumentValueInvalid | self is a null pointer. |
R_Status_ArgumentValueInvalid | other is a null pointer. |
File Handle
R_FileHandle
represents a operating system file handle.
This type is allocated on the heap and values of this type are referenced by R_FileHandle
pointers.
A R_FileHandle
pointer can be safely cast into a R_ObjectReferenceValue
values.
An R_ObjectReferenceValue
pointing to a R_FileHandle
value can be safely cast into a R_FileHandle
pointer.
create
R_FileHandle* R_FileHandle_create()
Create a file handle. The file handle is closed.
Return Value
A pointer to the file handle.
close
void R_FileHandle_close(R_FileHandle* self)
Close this file handle.
Parameters
R_FileHandle* self | A pointer to this file handle. |
openForReading
void R_FileHandle_openForReading(R_FileHandle* self, R_FilePath* path)
Open a file for reading. If the file is open, it is closed before trying to re-open it.
Parameters
R_FileHandle* self | A pointer to this file handle. |
R_FilePath* path | The file path of the file to read from. |
Errors
R_Status_ArgumentValueInvalid | self is a null pointer. |
R_Status_ArgumentValueInvalid | path is a null pointer. |
R_Status_FileSystemOperationFailed | Opening the file failed. |
openForWriting
void R_FileHandle_openForWriting(R_FileHandle* self, R_FilePath* path)
Open a file for writing. If the file is open, it is closed before trying to re-open it.
Parameters
R_FileHandle* self | A pointer to this file handle. |
R_FilePath* path | The file path of the file to write to. |
Errors
R_Status_ArgumentValueInvalid | self is a null pointer. |
R_Status_ArgumentValueInvalid | path is a null pointer. |
R_Status_FileSystemOperationFailed | Opening the file failed. |
isClosed
R_BooleanValue R_FileHandle_isClosed(R_FileHandle const* self)
Get if this file handle is closed.
Parameters
R_FileHandle const* self | A pointer to this file handle. |
isOpened
R_BooleanValue R_FileHandle_isOpened(R_FileHandle const* self)
Get if this file handle is opened.
Parameters
R_FileHandle const* self | A pointer to this file handle. |
isOpenedForReading
R_BooleanValue R_FileHandle_isOpenedForReading(R_FileHandle const* self)
Get if this file handle is opened for reading.
Parameters
R_FileHandle const* self | A pointer to this file handle. |
isOpenedForWriting
R_BooleanValue R_FileHandle_isOpenedForWriting(R_FileHandle const* self)
Get if this file handle is opened for writing.
Parameters
R_FileHandle const* self | A pointer to this file handle. |
write
void R_FileHandle_write(R_FileHandle* self, void const* p, R_SizeValue bytesToWrite)
Write Bytes to this file handle.
Parameters
R_FileHandle* self | A pointer to this file handle. |
void const* bytes | A pointer to an array of bytesToWrite Bytes. |
R_SizeValue bytesToWrite | The number of Bytes in the array pointed to by bytes . |
R_SizeValue* bytesWritten | A pointer to a R_SizeValue variable. |
Success
On success *bytesWritten
is assigned the actual number of Bytes written.
Errors
R_Status_ArgumentValueInvalid | self is a null pointer. |
R_Status_ArgumentValueInvalid | bytes is a null pointer. |
R_Status_OperationInvalid | The file is not opened for writing. |
R_Status_FileSystemOperationFailed | Writing failed. |
read
void R_FileHandle_read(R_FileHandle* self, void const* bytes, R_SizeValue bytesToRead, R_SizeValue* bytesRead)
Read Bytes from this file handle.
Parameters
R_FileHandle* self | A pointer to this file handle. |
void const* bytes | A pointer to an array of bytesToWrite Bytes. |
R_SizeValue bytesToRead | The number of Bytes to read from the the array pointed to by bytes . |
R_SizeValue* bytesRead | A pointer to a R_SizeValue variable. |
Success
On success *bytesRead
is assigned the actual number of Bytes read.
The number of Bytes read is 0 if the end of the file was reached.
Errors
R_Status_ArgumentValueInvalid | self is a null pointer. |
R_Status_ArgumentValueInvalid | bytes is a null pointer. |
R_Status_ArgumentValueInvalid | bytesRead is a null pointer. |
R_Status_OperationInvalid | The file is not opened for writing. |
R_Status_FileSystemOperationFailed | Writing failed. |
File Path
R_FilePath
represents a file path.
This type is allocated on the heap and values of this type are referenced by R_FilePath
pointers.
A R_FilePath
pointer can be safely cast into a R_ObjectReferenceValue
values.
An R_ObjectReferenceValue
pointing to a R_FilePath
value can be safely cast into a R_FilePath
pointer.
create
R_FilePath* R_Path_create()
Create the empty file path.
Return Value
A pointer to the file path.
parseWindowsFilePath
R_FilePath* R_FilePath_parseWindowsFilePath(void const* bytes, R_SizeValue numberOfBytes)
Parse a file path in the Windows format.
Parameters
bytes | A pointer to an array of numberOfBytes Bytes. |
numberOfBytes | The number of Bytes in the array pointed to by bytes Bytes. |
Return Value
A pointer to the file path.
parseUnixFilePath
R_FilePath* R_FilePath_parseUnixFilePath(void const* bytes, R_SizeValue numberOfBytes)
Parse a file path in the Unix format.
Parameters
bytes | A pointer to an array of numberOfBytes Bytes. |
numberOfBytes | The number of Bytes in the array pointed to by bytes Bytes. |
Return Value
A pointer to the file path.
parseNativeFilePath
R_FilePath* R_FilePath_parseNativeFilePath(void const* bytes, R_SizeValue numberOfBytes)
Parse a file path in the native format.
Parameters
bytes | A pointer to an array of numberOfBytes Bytes. |
numberOfBytes | The number of Bytes in the array pointed to by bytes Bytes. |
Return Value
A pointer to the file path.
toNative
R_String* R_FilePath_toNative(R_FilePath* self)
Convert a file path to the native format.
Parameters
self | A pointer to this file path. |
Return Value
A pointer to the string.
FileSystem
R_FileSystem
provides access to the file system.
This type is allocated on the heap and values of this type are referenced by R_String
pointers.
A R_FileSystem
pointer can be safely cast into a R_ObjectReferenceValue
values.
An R_ObjectReferenceValue
pointing to a R_String
value can be safely cast into a R_String
pointer.
R_FileSystem_create
R_FileSystem* R_FileSystem_create()
Create a file system.
Errors
R_Status_AllocationFailed | An allocation failed. |
getFileContents
R_ByteBuffer* R_ByteBuffer_getFileContents(R_FilePath *path)
Get the contents of a file.
Parameters
R_FilePath* path | The file path of the file. |
Return Value
A pointer to a R_ByteBuffer
object with the file contents.
Errors
R_Status_ArgumentValueInvalid | path is a null pointer. |
R_Status_FileSystemOperationFailed | Opening the file failed. |
setFileContents
void R_FileSystem_setFileContents(R_FilePath* path, R_ByteBuffer* contents)
Get if a sequence of Bytes is a prefix of this string's sequence of Bytes.
Parameters
R_FilePath* path | The file path of the file. |
R_ByteBuffer const* byteBuffer | A poiner to the Byte buffer with the file contents. |
Errors
R_Status_ArgumentValueInvalid | path is a null pointer. |
R_Status_ArgumentValueInvalid | contents is a null pointer. |
R_Status_FileSystemOperationFailed | Opening the file failed. |
List
R_List
represents a list of R_Value
objects.
This type is allocated on the heap and values of this type are referenced by R_List
pointers.
A R_List
pointer can be safely cast into a R_ObjectReferenceValue
values.
An R_ObjectReferenceValue
pointing to a R_List
value can be safely cast into a R_List
pointer.
R_List_create
R_List* R_List_create()
Create a list.
Parameters
bytes | A pointer to an array of Bytes. |
numberOfBytes | The number of Bytes in the array pointed to by bytes . |
Errors
R_Status_ArgumentValueInvalid | bytes is a null pointer. |
R_Status_EncodingInvalid | The sequence of Bytes does not represented a UTF-8-NO-BOM string. |
Return value
A pointer to the R_List
value.
append
void R_List_append(R_List* self, R_Value value)
Append a R_Value
to a list.
Parameters
R_List* self | A pointer to this list. |
R_Value value | The value to append. |
clear
void R_List_clear(R_List* self)
Clear this list.
Parameters
R_List* self | A pointer to this list. |
getAt
R_Value R_List_getAt(R_List* self, R_SizeValue index)
Get the value at the specifie index in this list.
Parameters
R_List* self | A pointer to this list. |
R_SizeValue index | The index. Must be within the bounds [0,n) where n is the size of this list. |
Return Value
The value.
getSize
R_SizeValue R_List_getSize(R_List const* self)
Get the size of this list.
Parameters
R_List* self | A pointer to this list. |
Return Value
The size of this list.
insert
void R_List_insertAt(R_List* self, R_SizeValue index, R_Value value)
Compare this string with another string for equality.
Parameters
R_List* self | A pointer to this list. |
R_SizeValue index | The index at which to insert the value. Must be within the bounds of [0,n] where n is the size of thie list. |
R_Value value | The value to insert. |
isEmpty
R_BooleanValue R_List_isEmpty(R_List* self)
Get if this list is empty.
Parameters
R_List* self | A pointer to this list. |
Return Value
R_BooleanValue_True
if this list is empty. R_BooleanValue_False
otherwise.
Errors
R_Status_ArgumentValueInvalid | self is a null pointer. |
prepend
void R_List_prepend(R_List* self, R_Value value)
Get if a sequence of Bytes is a prefix of this string's sequence of Bytes.
Prepend a R_Value
to a list.
Parameters
R_List* self | A pointer to this list. |
R_Value value | The value to prepend. |
remove
void R_List_remove(R_List* self, R_SizeValue index, R_SizeValue count)
Remove length
elements starting with element at index index
.
Parameters
R_List* self | A pointer to this list. |
R_SizeValue index | The index of the first element to remove. |
R_SizeValue length | The number of elements to remove. |
Errors
R_Status_ArgumentValueInvalid | self is a null pointer. |
R_Status_ArgumentValueInvalid | index + count > n where n is the length of the list. |
Stack
R_Stack
represents a stack of R_Value
objects.
This type is allocated on the heap and values of this type are referenced by R_Stack
pointers.
A R_Stack
pointer can be safely cast into a R_ObjectReferenceValue
values.
An R_ObjectReferenceValue
pointing to a R_Stack
value can be safely cast into a R_Stack
pointer.
R_Stack_create
R_Stack* R_Stack_create()
Create a stack.
Errors
R_Status_ArgumentValueInvalid | bytes is a null pointer. |
R_Status_EncodingInvalid | The sequence of Bytes does not represented a UTF-8-NO-BOM string. |
Return value
A pointer to the R_Stack
value.
clear
void R_Stack_clear(R_Stack* self)
Clear this stack.
Parameters
R_Stack* self | A pointer to this stack. |
getSize
R_SizeValue R_Stack_getSize(R_Stack const* self)
Get the size of this stack.
Parameters
R_Stack* self | A pointer to this stack. |
Return Value
The size of this stack.
isEmpty
R_BooleanValue R_Stack_isEmpty(R_Stack* self)
Get if this stack is empty.
Parameters
R_Stack* self | A pointer to this stack. |
Return Value
R_BooleanValue_True
if this stack is empty. R_BooleanValue_False
otherwise.
Errors
R_Status_ArgumentValueInvalid | self is a null pointer. |
peek
R_Value R_Stack_peek(R_Stack* self)
Peek at the value on top of this stack.
Parameters
R_Stack self | A pointer to this stack. |
Return Value
The value.
pop
R_Value R_Stack_pop(R_Stack* self)
Pop the value from the top of this stack.
Parameters
R_Stack self | A pointer to this stack. |
Return Value
The value.
push
void R_Stack_push(R_Stack* self, R_Value value)
Push a value on the top of this stack.
Parameters
R_Stack* self | A pointer to this stack. |
R_Value value | The value to push. |
String
R_String
represents an Unicode string encoded as UTF-8-NO-BOM.
This type is allocated on the heap and values of this type are referenced by R_String
pointers.
A R_String
pointer can be safely cast into a R_ObjectReferenceValue
values.
An R_ObjectReferenceValue
pointing to a R_String
value can be safely cast into a R_String
pointer.
R_String_create_pn
R_String* R_String_create_pn(void const* bytes, R_SizeValue numberOfBytes)
Create a string from a sequence of Bytes.
Parameters
bytes | A pointer to an array of Bytes. |
numberOfBytes | The number of Bytes in the array pointed to by bytes . |
Return value
A pointer to the string.
Errors
R_Status_ArgumentValueInvalid | bytes is a null pointer. |
R_Status_EncodingInvalid | The sequence of Bytes does not represented a UTF-8-NO-BOM string. |
R_String_create
R_String* R_String_create_pn(R_Value value)
Create a string from a value.
The specified value may contain a R_ByteBuffer object.
In that case, the string is created from the Bytes of the Byte buffer object.
A R_Status_EncodingInvalid
is raised if the Byte sequence of that R_ByteBuffer
object is not a UTF8 Byte sequence.
The specified value may contain a R_String object. In that case, the string is created from the R_String object.
The specified value may contain a R_StringBuffer object. In that case, the string is created from the R_StringBuffer object.
Parameters
value | The value. |
Return value
A pointer to the string.
Errors
R_Status_ArgumentTypeInvalid | The value does not contain either a R_ByteBuffer object, a R_String object, or a R_StringBuffer object. |
R_Status_EncodingInvalid | The value contains a R_ByteBuffer object. However, the Byte sequence of that R_ByteBuffer object is not a UTF8 Byte sequence. |
endsWith_pn
R_BooleanValue R_String_endsWith_pn(R_String const* self, void const* bytes, R_SizeValue numberOfBytes)
Get if a sequence of Bytes is a suffix of this string's sequence of Bytes.
Parameters
R_String* self | A pointer to this string. |
void const* bytes | A pointer to an array of n Bytes. |
R_SizeValue numberOfBytes | The number of Bytes in the array pointed to by p . |
Return Value
R_BooleanValue_True
if the sequence of Bytes is a suffix of this string's sequence of Bytes.
R_BooleanValue_False
otherwise.
startsWith_pn
R_BooleanValue R_String_startsWith_pn(R_String const* self, void const* bytes, R_SizeValue numberOfBytes)
Get if a sequence of Bytes is a prefix of this string's sequence of Bytes.
Parameters
R_String* self | A pointer to this string. |
void const* bytes | A pointer to an array of n Bytes. |
R_SizeValue numberOfBytes | The number of Bytes in the array pointed to by p . |
Return Value
R_BooleanValue_True
if the sequence of Bytes is a prefix of this string's sequence of Bytes.
R_BooleanValue_False
otherwise.
isEqualTo
R_BooleanValue R_String_isEqualTo(R_String const* self, R_String const* other)
Compare this string with another string for equality.
Parameters
R_String const* self | A pointer to this string. |
R_String const* other | A pointer to the other string. |
Return Value
R_BooleanValue_True
if this string is equal to the other string.
R_BooleanValue_False
otherwise.
isEqualTo_pn
R_BooleanValue R_String_isEqualTo_pn(R_String const* self, void const* bytes, R_SizeValue numberOfBytes)
Get if a sequence of Bytes is this string's sequence of Bytes.
Parameters
R_String* self | A pointer to this string. |
void const* bytes | A pointer to an array of n Bytes. |
R_SizeValue numberOfBytes | The number of Bytes in the array pointed to by p . |
Return Value
R_BooleanValue_True
if the sequence of Bytes is this string's sequence of Bytes.
R_BooleanValue_False
otherwise.
getNumberOfBytes
R_SizeValue R_String_getNumberOfBytes(R_String const* self)
Get the size, in Bytes, of this string.
Parameters
R_String* self | A pointer to this string. |
Return Value
The size, in Bytes, of this string.
getByteAt
R_Natural8Value R_String_getByteAt(R_String const* self, R_SizeValue index)
Get the Byte value at the specified index.
Parameters
R_String* self | A pointer to this string. |
R_SizeValue index | The index. Must be within the bounds [0,n) where n is the size, in Bytes, of this string. |
Return Value
The Byte value.
toInteger8
R_Integer8Value R_String_toInteger8(R_String const* self)
Interprete the symbols of this string as decimal integer literal and convert the number represented by that integer literal into an R_Integer8Value
.
Parameters
R_String* self | A pointer to this string. |
Return Value
The integer value.
Errors
R_Status_ArgumentTypeInvalid | self is a null pointer. |
R_Status_ConversionFailed | The symbols of this string cannot be interpreted as an integer literal or the number represented by the integer literal cannot be represented a value of type R_Integer8Value . |
toInteger16
R_Integer16Value R_String_toInteger16(R_String const* self)
Interprete the symbols of this string as decimal integer literal and convert the number represented by that integer literal into an R_Integer16Value
.
Parameters
R_String* self | A pointer to this string. |
Return Value
The integer value.
Errors
R_Status_ArgumentTypeInvalid | self is a null pointer. |
R_Status_ConversionFailed | The symbols of this string cannot be interpreted as an integer literal or the number represented by the integer literal cannot be represented a value of type R_Integer16Value . |
toInteger32
R_Integer32Value R_String_toInteger32(R_String const* self)
Interprete the symbols of this string as decimal integer literal and convert the number represented by that integer literal into an R_Integer32Value
.
Parameters
R_String* self | A pointer to this string. |
Return Value
The integer value.
Errors
R_Status_ArgumentTypeInvalid | self is a null pointer. |
R_Status_ConversionFailed | The symbols of this string cannot be interpreted as an integer literal or the number represented by the integer literal cannot be represented a value of type R_Integer32Value . |
toInteger64
R_Integer64Value R_String_toInteger64(R_String const* self)
Interprete the symbols of this string as decimal integer literal and convert the number represented by that integer literal into an R_Integer64Value
.
Parameters
R_String* self | A pointer to this string. |
Return Value
The integer value.
Errors
R_Status_ArgumentTypeInvalid | self is a null pointer. |
R_Status_ConversionFailed | The symbols of this string cannot be interpreted as an integer literal or the number represented by the integer literal cannot be represented a value of type R_Integer64Value . |
toNatural8
R_Natural8Value R_String_toNatural8(R_String const* self)
Interprete the symbols of this string as decimal natural literal and convert the number represented by that natural literal into an R_Natural8Value
.
Parameters
R_String* self | A pointer to this string. |
Return Value
The natural value.
Errors
R_Status_ArgumentTypeInvalid | self is a null pointer. |
R_Status_ConversionFailed | The symbols of this string cannot be interpreted as an natural literal or the number represented by the natural literal cannot be represented a value of type R_Natural8Value . |
toNatural16
R_Natural16Value R_String_toNatural16(R_String const* self)
Interprete the symbols of this string as decimal natural literal and convert the number represented by that natural literal into an R_Natural16Value
.
Parameters
R_String* self | A pointer to this string. |
Return Value
The natural value.
Errors
R_Status_ArgumentTypeInvalid | self is a null pointer. |
R_Status_ConversionFailed | The symbols of this string cannot be interpreted as an natural literal or the number represented by the natural literal cannot be represented a value of type R_Natural16Value . |
toNatural32
R_Natural32Value R_String_toNatural16(R_String const* self)
Interprete the symbols of this string as decimal natural literal and convert the number represented by that natural literal into an R_Natural32Value
.
Parameters
R_String* self | A pointer to this string. |
Return Value
The natural value.
Errors
R_Status_ArgumentTypeInvalid | self is a null pointer. |
R_Status_ConversionFailed | The symbols of this string cannot be interpreted as an natural literal or the number represented by the natural literal cannot be represented a value of type R_Natural32Value . |
toNatural64
R_Natural64Value R_String_toNatural16(R_String const* self)
Interprete the symbols of this string as decimal natural literal and convert the number represented by that natural literal into an R_Natural64Value
.
Parameters
R_String* self | A pointer to this string. |
Return Value
The natural value.
Errors
R_Status_ArgumentTypeInvalid | self is a null pointer. |
R_Status_ConversionFailed | The symbols of this string cannot be interpreted as an natural literal or the number represented by the natural literal cannot be represented a value of type R_Natural64Value . |