aboutsummaryrefslogtreecommitdiff
path: root/std/int.c
diff options
context:
space:
mode:
authorElias Fleckenstein <eliasfleckenstein@web.de>2021-12-30 16:53:37 +0100
committerElias Fleckenstein <eliasfleckenstein@web.de>2021-12-30 16:53:37 +0100
commit4c52777ca9e52edd0bff76168d886de9757ea457 (patch)
tree385c548fbae43f4b4764a1c32d5babe60c84aa4d /std/int.c
parent058d954e80f83c26deb209008f11d87a5b59418e (diff)
downloaduwu-lang-4c52777ca9e52edd0bff76168d886de9757ea457.tar.xz
Add :ref module and refactor type handling
Diffstat (limited to 'std/int.c')
-rw-r--r--std/int.c16
1 files changed, 5 insertions, 11 deletions
diff --git a/std/int.c b/std/int.c
index c6c8ab7..6857f26 100644
--- a/std/int.c
+++ b/std/int.c
@@ -4,6 +4,7 @@
#include "../api/vm.h"
#include "../api/int.h"
#include "../api/bool.h"
+#include "../api/util.h"
typedef enum
{
@@ -30,8 +31,8 @@ static int binary(const char *fnname, UwUVMArgs *args, BinaryOP op)
if (value1.type != &uwuint_type)
error("error: %s requires an integer as $1\n", fnname);
- int a = *(int *) value0.data;
- int b = *(int *) value1.data;
+ int a = uwuint_get(value0);
+ int b = uwuint_get(value1);
switch (op) {
case BOP_SUB: return a - b;
@@ -60,7 +61,7 @@ static int reduce(const char *fnname, UwUVMArgs *args, ReduceOP op, int result)
if (value.type != &uwuint_type)
error("error: %s only accepts integers as arguments (invalid argument: $%lu)\n", fnname, i);
- int this = *(int *) value.data;
+ int this = uwuint_get(value);
switch (op) {
case ROP_ADD: result += this; break;
@@ -123,12 +124,5 @@ UwUVMValue uwu_equal(UwUVMArgs *args)
UwUVMValue uwu_is(UwUVMArgs *args)
{
- if (args->num < 1)
- error("error: :int:is requires at least 1 argument\n");
-
- for (size_t i = 0; i < args->num; i++)
- if (uwuvm_get_arg(args, i).type != &uwuint_type)
- return uwubool_create(false);
-
- return uwubool_create(true);
+ return uwuutil_is_type(":int:is", args, &uwuint_type);
}