diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-06-07 21:02:47 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-06-07 21:03:27 +0100 |
| commit | b8b41c38b3f82a355bf3fe77966338a6b3108e76 (patch) | |
| tree | 410c71e8f5c08a7927c89eede7f7560e286b00c5 /runtime/src | |
| parent | d52bb965c5f9c2548dfef67cca1b089db26ad71c (diff) | |
Add basic C runtime
Diffstat (limited to 'runtime/src')
| -rw-r--r-- | runtime/src/shed.c | 18 | ||||
| -rw-r--r-- | runtime/src/shed.h | 19 |
2 files changed, 37 insertions, 0 deletions
diff --git a/runtime/src/shed.c b/runtime/src/shed.c new file mode 100644 index 00000000..60d66e64 --- /dev/null +++ b/runtime/src/shed.c @@ -0,0 +1,18 @@ +#include <stdbool.h> +#include <unistd.h> + +#include "./shed.h" + +ShedObject const shed_unit = 0; + +ShedObject shed__builtins__print(ShedEnv env, ShedString value) { + size_t total_bytes_written = 0; + while (total_bytes_written < value->length) { + ssize_t bytes_written = write(STDOUT_FILENO, &value->data[total_bytes_written], value->length - total_bytes_written); + if (bytes_written == -1) { + break; + } + total_bytes_written += bytes_written; + } + return shed_unit; +} diff --git a/runtime/src/shed.h b/runtime/src/shed.h new file mode 100644 index 00000000..0c503db8 --- /dev/null +++ b/runtime/src/shed.h @@ -0,0 +1,19 @@ +#ifndef SHED_H +#define SHED_H + +#include <stdint.h> + +typedef uint64_t ShedObject; + +extern ShedObject const shed_unit; + +struct ShedString { + uint64_t length; + uint8_t data[]; +}; + +typedef struct ShedString* ShedString; + +typedef ShedObject* ShedEnv; + +#endif |
