aboutsummaryrefslogtreecommitdiff
path: root/runtime/src/shed/ints.c
blob: 88ea85073022e7cd0af32810a08ec631fd2f9a8a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <stdbool.h>

#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);
}

ShedObject shed__runtime__int_multiply(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;
}

bool shed__runtime__int_less_than(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_less_than_or_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;
}

bool shed__runtime__int_greater_than(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_greater_than_or_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;
}