aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-06-07 21:02:47 +0100
committerMichael Williamson <mike@zwobble.org>2023-06-07 21:03:27 +0100
commitb8b41c38b3f82a355bf3fe77966338a6b3108e76 (patch)
tree410c71e8f5c08a7927c89eede7f7560e286b00c5
parentd52bb965c5f9c2548dfef67cca1b089db26ad71c (diff)
Add basic C runtime
-rw-r--r--.gitignore1
-rw-r--r--runtime/CMakeLists.txt11
-rw-r--r--runtime/makefile7
-rw-r--r--runtime/src/shed.c18
-rw-r--r--runtime/src/shed.h19
5 files changed, 56 insertions, 0 deletions
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 <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