From b8b41c38b3f82a355bf3fe77966338a6b3108e76 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Wed, 7 Jun 2023 21:02:47 +0100 Subject: Add basic C runtime --- runtime/src/shed.c | 18 ++++++++++++++++++ runtime/src/shed.h | 19 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 runtime/src/shed.c create mode 100644 runtime/src/shed.h (limited to 'runtime/src') 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 +#include + +#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 + +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 -- cgit v1.2.3