From 3ed2ca517aa5f2424f238817844d8a8eb98e64c2 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Fri, 15 Dec 2023 15:47:58 +0000 Subject: Implement int ops in runtime --- runtime/meson.build | 1 + runtime/src/ints.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 runtime/src/ints.c (limited to 'runtime') diff --git a/runtime/meson.build b/runtime/meson.build index dbef403a..0dbb5277 100644 --- a/runtime/meson.build +++ b/runtime/meson.build @@ -3,6 +3,7 @@ static_library( 'shed', 'src/effects.c', 'src/exceptions.c', + 'src/ints.c', 'src/shed.c', 'src/strings.c', 'src/namespaces/Shed/Builtins.c', diff --git a/runtime/src/ints.c b/runtime/src/ints.c new file mode 100644 index 00000000..32bc15bb --- /dev/null +++ b/runtime/src/ints.c @@ -0,0 +1,43 @@ +#include + +#include "./shed.h" + +struct ShedInt { + PatioInt value; +}; + +ShedObject shed__runtime__int_create(PatioInt value) { + struct ShedInt* result = shed__runtime__alloc(sizeof(struct ShedInt)); + 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