From a01ee103f9bc0c6defe9ce8cd85651f19f7127bd Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 11 Feb 2024 21:29:15 +0000 Subject: Create separate lib for patio runtime --- runtime/src/shed/ints.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 runtime/src/shed/ints.c (limited to 'runtime/src/shed/ints.c') diff --git a/runtime/src/shed/ints.c b/runtime/src/shed/ints.c new file mode 100644 index 00000000..c7c2c8ea --- /dev/null +++ b/runtime/src/shed/ints.c @@ -0,0 +1,46 @@ +#include + +#include "../patio/patio.h" +#include "./gc.h" +#include "./primitives.h" + +struct ShedInt { + struct ShedGcObjectHeader gc_object_header; + PatioInt value; +}; + +ShedObject shed__runtime__int_create(PatioInt value) { + struct ShedInt* result = shed__runtime__gc_alloc(sizeof(struct ShedInt), 0); + result->value = value; + return (ShedObject) result; +} + +PatioInt shed__runtime__int_value(ShedObject object) { + return ((struct ShedInt*) object)->value; +} + +ShedObject shed__runtime__int_add(ShedObject left, ShedObject right) { + PatioInt left_value = shed__runtime__int_value(left); + PatioInt right_value = shed__runtime__int_value(right); + PatioInt result_value = left_value + right_value; + return shed__runtime__int_create(result_value); +} + +ShedObject shed__runtime__int_sub(ShedObject left, ShedObject right) { + PatioInt left_value = shed__runtime__int_value(left); + PatioInt right_value = shed__runtime__int_value(right); + PatioInt result_value = left_value - right_value; + return shed__runtime__int_create(result_value); +} + +bool shed__runtime__int_equals(ShedObject left, ShedObject right) { + PatioInt left_value = shed__runtime__int_value(left); + PatioInt right_value = shed__runtime__int_value(right); + return left_value == right_value; +} + +bool shed__runtime__int_not_equal(ShedObject left, ShedObject right) { + PatioInt left_value = shed__runtime__int_value(left); + PatioInt right_value = shed__runtime__int_value(right); + return left_value != right_value; +} -- cgit v1.2.3