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 --- .gitignore | 1 + runtime/CMakeLists.txt | 11 +++++++++++ runtime/makefile | 7 +++++++ runtime/src/shed.c | 18 ++++++++++++++++++ runtime/src/shed.h | 19 +++++++++++++++++++ 5 files changed, 56 insertions(+) create mode 100644 runtime/CMakeLists.txt create mode 100644 runtime/makefile create mode 100644 runtime/src/shed.c create mode 100644 runtime/src/shed.h diff --git a/.gitignore b/.gitignore index f419dc7b..05aec262 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /.idea +/runtime/build /target diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt new file mode 100644 index 00000000..0ec51e0a --- /dev/null +++ b/runtime/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.7) +project(ShedRuntime LANGUAGES C) + +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror") + +include_directories(src) + +add_library( + shed STATIC + src/shed.h src/shed.c +) diff --git a/runtime/makefile b/runtime/makefile new file mode 100644 index 00000000..963398f5 --- /dev/null +++ b/runtime/makefile @@ -0,0 +1,7 @@ +CFLAGS = -Wall -Werror + +.PHONY: build/libshed.a + +build/libshed.a: + mkdir -p build + cd build && cmake .. && make 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