Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement ITER boolification and set up BOOTIter type.
  • Loading branch information
arnsholt committed Mar 17, 2013
1 parent c780526 commit 09c5aea
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/6model/sixmodelobject.c
Expand Up @@ -42,14 +42,13 @@ static PMC *boot_type(PARROT_INTERP, PMC *knowhow, char *type_name, char *repr_n
}

/* Initializes 6model and produces the KnowHOW core meta-object. */
/*void SixModelObject_initialize(PARROT_INTERP, PMC **knowhow, PMC **knowhow_attribute, PMC **boot_array) {*/
void SixModelObject_initialize(PARROT_INTERP) {
PMC *initial_sc;
STRING *initial_sc_name;
PMC *global_context = Parrot_pmc_new(interp, enum_class_Hash);
PMC *knowhow;
PMC *knowhow_attribute;
PMC *boot_array;
PMC *boot_array, *boot_iter;

/* Look up and cache some type IDs and strings. */
stable_id = Parrot_pmc_get_type_str(interp, Parrot_str_new(interp, "STable", 0));
Expand All @@ -76,9 +75,12 @@ void SixModelObject_initialize(PARROT_INTERP) {

/* Set up the BOOT* types. */
boot_array = boot_type(interp, knowhow, "BOOTArray", "VMArray", 2);
/* TODO: BOOTHash types goes here with index 4. */
boot_iter = boot_type(interp, knowhow, "BOOTIter", "VMIter", 6);

/* Set boolification specs for the BOOT types. */
set_boolification_spec(interp, boot_array, BOOL_MODE_HAS_ELEMS, NULL);
set_boolification_spec(interp, boot_iter, BOOL_MODE_ITER, NULL);

/* Save the global context to the Parrot root namespace and store all the
* things we just created in it. */
Expand All @@ -90,6 +92,8 @@ void SixModelObject_initialize(PARROT_INTERP) {
Parrot_str_new_constant(interp, "KnowHOWAttribute"), knowhow_attribute);
VTABLE_set_pmc_keyed_str(interp, global_context,
Parrot_str_new_constant(interp, "BOOTArray"), boot_array);
VTABLE_set_pmc_keyed_str(interp, global_context,
Parrot_str_new_constant(interp, "BOOTIter"), boot_iter);
}

/* Sets the object that we'll wrap the next allocation in. */
Expand Down
1 change: 1 addition & 0 deletions src/6model/sixmodelobject.h
Expand Up @@ -71,6 +71,7 @@ typedef struct {
#define BOOL_MODE_UNBOX_STR_NOT_EMPTY_OR_ZERO 4
#define BOOL_MODE_NOT_TYPE_OBJECT 5
#define BOOL_MODE_BIGINT 6
#define BOOL_MODE_ITER 7
#define BOOL_MODE_HAS_ELEMS 8

/* Controls the way that type checks are performed. By default, if there is
Expand Down
7 changes: 7 additions & 0 deletions src/pmc/sixmodelobject.pmc
Expand Up @@ -25,6 +25,7 @@
#include "parrot/exceptions.h"
#include "parrot/events.h"
#include "../6model/sixmodelobject.h"
#include "../6model/reprs/VMIter.h"

/* We need to know how to boolify bigints. Really need something better,
* but this will do for now. */
Expand Down Expand Up @@ -300,6 +301,12 @@ pmclass SixModelObject manual_attrs dynpmc group nqp {
STABLE(decont), OBJECT_BODY(decont), bigint_repr_id))->i);
}
return 0;
case BOOL_MODE_ITER:
if (IS_CONCRETE(decont)) {
VMIterBody *body = (VMIterBody *) OBJECT_BODY(decont);
return body->idx + 1 < body->limit;
}
return 0;
case BOOL_MODE_HAS_ELEMS:
return IS_CONCRETE(decont) &&
REPR(decont)->elems(interp, STABLE(decont), OBJECT_BODY(decont));
Expand Down

0 comments on commit 09c5aea

Please sign in to comment.