-
Notifications
You must be signed in to change notification settings - Fork 0
/
math.c
80 lines (59 loc) · 1.72 KB
/
math.c
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
78
79
#include <assert.h>
#include <stdarg.h>
#include <string.h>
#include <math.h>
#include "ool.h"
#define ASSERT assert
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
struct {
struct root_hdr hdr;
obj_t module;
struct {
obj_t sin;
obj_t cos;
obj_t exp;
} str;
} math_consts;
void
cm_float_sin(unsigned argc)
{
float_new(0, sinl(FLOAT(MC_FRAME_RECVR)->val));
}
void
cm_float_cos(unsigned argc)
{
float_new(0, cosl(FLOAT(MC_FRAME_RECVR)->val));
}
void
cm_float_exp(unsigned argc)
{
float_new(0, expl(FLOAT(MC_FRAME_RECVR)->val));
}
const struct init_str math_init_str_tbl[] = {
{ &math_consts.str.sin, "sin" },
{ &math_consts.str.cos, "cos" },
{ &math_consts.str.exp, "exp" }
};
const struct init_cl math_init_cl_tbl[] = {
};
const struct init_method math_init_cl_method_tbl[] = {
};
const struct init_method math_init_inst_method_tbl[] = {
{ &consts.cl._float, &math_consts.str.sin, cm_float_sin },
{ &consts.cl._float, &math_consts.str.cos, cm_float_cos },
{ &consts.cl._float, &math_consts.str.exp, cm_float_exp }
};
__attribute__((constructor))
void math_init(void)
{
OBJ_ASSIGN(math_consts.module, R0);
init_strs((const struct init_str *) &math_init_str_tbl, ARRAY_SIZE(math_init_str_tbl));
init_cls((const struct init_cl *) &math_init_cl_tbl, ARRAY_SIZE(math_init_cl_tbl));
init_cl_methods((const struct init_method *) &math_init_cl_method_tbl, ARRAY_SIZE(math_init_cl_method_tbl));
init_inst_methods((const struct init_method *) &math_init_inst_method_tbl, ARRAY_SIZE(math_init_inst_method_tbl));
root_add(&math_consts.hdr, (sizeof(math_consts) - sizeof(math_consts.hdr)) / sizeof(obj_t));
}
__attribute__((destructor))
void math_fini(void)
{
}