mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-23 20:15:05 +02:00
Experimenting with Cyc_sum
This commit is contained in:
parent
4b2a5ae35a
commit
5be68ec60c
1 changed files with 20 additions and 0 deletions
20
runtime.h
20
runtime.h
|
@ -787,6 +787,26 @@ static object __halt(object obj) {
|
|||
#define __sub(c,x,y) integer_type c; c.tag = integer_tag; c.value = (((integer_type *)(x))->value - ((integer_type *)(y))->value);
|
||||
#define __div(c,x,y) integer_type c; c.tag = integer_tag; c.value = (((integer_type *)(x))->value / ((integer_type *)(y))->value);
|
||||
|
||||
/* Brainstorming how this could work */
|
||||
static common_type Cyc_sum(object x, object y) { // TODO: varargs
|
||||
common_type s;
|
||||
int tx = type_of(x), ty = type_of(y);
|
||||
s.double_t.tag = double_tag;
|
||||
if (tx == integer_tag && ty == integer_tag) {
|
||||
s.integer_t.tag = integer_tag;
|
||||
s.integer_t.value = ((integer_type *)x)->value + ((integer_type *)y)->value;
|
||||
} else if (tx == double_tag && ty == integer_tag) {
|
||||
s.double_t.value = ((double_type *)x)->value + ((integer_type *)y)->value;
|
||||
} else if (tx == integer_tag && ty == double_tag) {
|
||||
s.double_t.value = ((integer_type *)x)->value + ((double_type *)y)->value;
|
||||
} else if (tx == double_tag && ty == double_tag) {
|
||||
s.double_t.value = ((double_type *)x)->value + ((double_type *)y)->value;
|
||||
} else {
|
||||
// TODO: error
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
/* I/O functions */
|
||||
|
||||
static port_type Cyc_io_current_input_port() {
|
||||
|
|
Loading…
Add table
Reference in a new issue