1#ifndef ZLANG_STANDARD_IO_IO_H
2#define ZLANG_STANDARD_IO_IO_H
7#if defined(ZLANG_STD_IO_WRITE_STRING)
13#if defined(ZLANG_STD_IO_WRITE_BOOL)
17#if defined(ZLANG_STD_IO_WRITE_I32)
21#if defined(ZLANG_STD_IO_WRITE_U32)
25#if defined(ZLANG_STD_IO_WRITE_I64)
29#if defined(ZLANG_STD_IO_WRITE_U64)
33#if defined(ZLANG_STD_IO_WRITE_F32)
37#if defined(ZLANG_STD_IO_WRITE_F64)
41#if defined(ZLANG_STD_IO_READ) || defined(ZLANG_STD_IO_READ_LINE)
43 uint32_t capacity,
bool keep_terminator) {
44 if (view == NULL || storage == NULL || capacity == 0U) {
47 uint32_t _length_k = 0U;
48 int _character_k = getchar();
49 while (_character_k != EOF && _character_k !=
'\n') {
50 if (_length_k >= capacity) {
53 storage[_length_k++] = (char)_character_k;
54 _character_k = getchar();
56 if (_character_k == EOF && _length_k == 0U) {
57 view->
data_ = storage;
61 if (keep_terminator && _character_k ==
'\n') {
62 if (_length_k >= capacity) {
65 storage[_length_k++] =
'\n';
67 storage[_length_k] =
'\0';
68 view->
data_ = storage;
70 return (int32_t)_length_k;
74#if defined(ZLANG_STD_IO_READ)
77 return zlang_std_io_read_impl(view, storage, capacity,
true);
81#if defined(ZLANG_STD_IO_READ_LINE)
84 return zlang_std_io_read_impl(view, storage, capacity,
false);
#define ZLANG_STATIC_INLINE
Definition inline.h:9
Runtime primitives called by C code emitted from Zlang.
ZLANG_STATIC_INLINE void zlang_trap(uint8_t code)
Terminate execution with a fixed trap code.
Definition runtime.h:73
ZLANG_STATIC_INLINE bool zlang_print_u64(uint64_t value)
Print an unsigned 64-bit integer using fixed stack storage.
Definition runtime.h:298
ZLANG_STATIC_INLINE bool zlang_print_f64(double value)
Print a 64-bit double with a deterministic decimal form.
Definition runtime.h:326
ZLANG_STATIC_INLINE bool zlang_print_bool(bool value)
Print a boolean as true or false.
Definition runtime.h:151
ZLANG_STATIC_INLINE bool zlang_print_i32(int32_t value)
Print a signed integer using fixed stack storage.
Definition runtime.h:111
ZLANG_STATIC_INLINE bool zlang_print_u32(uint32_t value)
Print an unsigned integer using fixed stack storage.
Definition runtime.h:133
#define ZLANG_TRAP_CAPACITY
Definition runtime.h:24
ZLANG_STATIC_INLINE bool zlang_print(zlang_string_t value)
Write a string view to standard output.
Definition runtime.h:61
#define ZLANG_TRAP_INVALID_ARGUMENT
Definition runtime.h:25
ZLANG_STATIC_INLINE bool zlang_print_i64(int64_t value)
Print a signed 64-bit integer using fixed stack storage.
Definition runtime.h:278
ZLANG_STATIC_INLINE bool zlang_print_f32(float value)
Print a 32-bit float with a deterministic decimal form.
Definition runtime.h:314
const char * data_
Definition runtime.h:36
uint32_t length_
Definition runtime.h:37