@@ -7,11 +7,46 @@ BEGIN_OPS_PREAMBLE
7
7
#include "../6model/sixmodelobject.h"
8
8
#include "../6model/reprs/P6bigint.h"
9
9
10
+ static mp_int * get_bigint(PARROT_INTERP, PMC *obj) {
11
+ /* XXX sanity checks... */
12
+ return &((P6bigintInstance *)PMC_data(obj))->i;
13
+ }
14
+
10
15
END_OPS_PREAMBLE
11
16
17
+ /*
18
+ * The ops in here mostly just delegate off to libtommath. nqp_bigint_setup must be
19
+ * called before you create any types using the bigint representation. For all of the
20
+ * rest ops there are two variants. The first variant simply takes two objects and
21
+ * assumes they directly use the P6bigint REPR; the second one pulls out an (inlined)
22
+ * P6bigint attribute and works on that; this avoids the overhead of creating a boxed
23
+ * version only to throw it away again.
24
+ */
25
+
12
26
inline op nqp_bigint_setup() :base_core {
13
27
/* Register the bigint representation. */
14
28
REGISTER_DYNAMIC_REPR(interp,
15
29
Parrot_str_new_constant(interp, "P6bigint"),
16
30
P6bigint_initialize);
17
31
}
32
+
33
+ inline op nqp_bigint_add(out PMC, in PMC, in PMC) :base_core {
34
+ mp_int *a = get_bigint(interp, $2);
35
+ mp_int *b = get_bigint(interp, $3);
36
+ $1 = REPR($2)->instance_of(interp, $2);
37
+ mp_add(a, b, get_bigint(interp, $1));
38
+ }
39
+
40
+ inline op nqp_bigint_sub(out PMC, in PMC, in PMC) :base_core {
41
+ mp_int *a = get_bigint(interp, $2);
42
+ mp_int *b = get_bigint(interp, $3);
43
+ $1 = REPR($2)->instance_of(interp, $2);
44
+ mp_sub(a, b, get_bigint(interp, $1));
45
+ }
46
+
47
+ inline op nqp_bigint_mul(out PMC, in PMC, in PMC) :base_core {
48
+ mp_int *a = get_bigint(interp, $2);
49
+ mp_int *b = get_bigint(interp, $3);
50
+ $1 = REPR($2)->instance_of(interp, $2);
51
+ mp_mul(a, b, get_bigint(interp, $1));
52
+ }
0 commit comments