Skip to content

Commit 4ec1bdf

Browse files
committed
Boolification support for bigints.
1 parent d2b7838 commit 4ec1bdf

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

src/6model/sixmodelobject.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ typedef struct {
4848
#define BOOL_MODE_UNBOX_STR_NOT_EMPTY 3
4949
#define BOOL_MODE_UNBOX_STR_NOT_EMPTY_OR_ZERO 4
5050
#define BOOL_MODE_NOT_TYPE_OBJECT 5
51+
#define BOOL_MODE_BIGINT 6
5152

5253
/* Controls the way that type checks are performed. By default, if there is
5354
* a type check cache we treat it as definitive. However, it's possible to

src/pmc/sixmodelobject.pmc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424

2525
#include "../6model/sixmodelobject.h"
2626

27+
/* We need to know how to boolify bigints. Really need something better,
28+
* but this will do for now. */
29+
#include "../../3rdparty/libtommath/tommath.h"
30+
#include "../6model/reprs/P6bigint.h"
31+
#define bigint_repr_id 7
32+
2733
PMC * decontainerize(PARROT_INTERP, PMC *var) {
2834
ContainerSpec *spec = STABLE(var)->container_spec;
2935
if (spec && IS_CONCRETE(var)) {
@@ -251,6 +257,16 @@ pmclass SixModelObject manual_attrs dynpmc group nqp {
251257
!Parrot_str_equal(interp, unstr, CONST_STRING(interp, "0"));
252258
case BOOL_MODE_NOT_TYPE_OBJECT:
253259
return IS_CONCRETE(decont);
260+
case BOOL_MODE_BIGINT:
261+
if (IS_CONCRETE(decont)) {
262+
struct SixModel_REPROps *r = REPR(decont);
263+
if (r->ID == bigint_repr_id)
264+
return !mp_iszero(&((P6bigintInstance *)PMC_data(decont))->body.i);
265+
else
266+
return !mp_iszero(&((P6bigintBody *)r->get_boxed_ref(interp,
267+
STABLE(decont), OBJECT_BODY(decont), bigint_repr_id))->i);
268+
}
269+
return 0;
254270
default:
255271
return SUPER();
256272
}

tools/build/Makefile.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ $(DYNPMC): $(PMC_SOURCES) $(METAMODEL_SOURCE)
670670
$(PMC2C) --no-lines --c $(PMC2C_INCLUDES) $(PMC_SOURCES)
671671
$(PMC2C) --no-lines --library $(GROUP) --c $(PMC_SOURCES)
672672
$(CC) -c @cc_o_out@$(GROUP)$(O) -I$(PMC_DIR) $(CINCLUDES) $(CFLAGS) $(GROUP).c
673-
cd $(PMC_DIR) && $(CC) -c $(CINCLUDES) $(CFLAGS) *.c
673+
cd $(PMC_DIR) && $(CC) -c $(CINCLUDES) -I../../3rdparty/libtommath $(CFLAGS) *.c
674674
$(LD) @ld_out@$(DYNPMC) $(GROUP)$(O) src/pmc/*$(O) $(LINKARGS)
675675

676676
$(OPS_DIR)/$(OPS)$(LOAD_EXT): $(OPS_DIR)/$(OPS_SOURCE) $(DYNPMC)

0 commit comments

Comments
 (0)