Skip to content

Commit

Permalink
Refactor `is_collection()'.
Browse files Browse the repository at this point in the history
  • Loading branch information
Todd Sundsted committed Nov 27, 2016
1 parent 910cb4c commit 0f0ecf3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
12 changes: 6 additions & 6 deletions execute.cc
Expand Up @@ -959,7 +959,7 @@ do { \
key = POP(); /* any except list or map */
value = POP(); /* any */
map = POP(); /* should be map */
if (map.type != TYPE_MAP || is_collection(key)) {
if (map.type != TYPE_MAP || key.is_collection()) {
free_var(key);
free_var(value);
free_var(map);
Expand Down Expand Up @@ -1046,7 +1046,7 @@ do { \
list.type != TYPE_MAP)
|| ((list.type == TYPE_LIST || list.type == TYPE_STR) &&
index.type != TYPE_INT)
|| (list.type == TYPE_MAP && is_collection(index))
|| (list.type == TYPE_MAP && index.is_collection())
|| (list.type == TYPE_STR && value.type != TYPE_STR)) {
free_var(value);
free_var(index);
Expand Down Expand Up @@ -1368,7 +1368,7 @@ do { \
list.type != TYPE_MAP) ||
((list.type == TYPE_LIST || list.type == TYPE_STR) &&
index.type != TYPE_INT) ||
(list.type == TYPE_MAP && is_collection(index))) {
(list.type == TYPE_MAP && index.is_collection())) {
free_var(index);
free_var(list);
PUSH_ERROR(E_TYPE);
Expand Down Expand Up @@ -1438,7 +1438,7 @@ do { \
if (list.type == TYPE_MAP) {
Var value;
const rbnode *node;
if (is_collection(index)) {
if (index.is_collection()) {
PUSH_ERROR(E_TYPE);
} else if (!(node = maplookup(list, index, &value, 0))) {
PUSH_ERROR(E_RANGE);
Expand Down Expand Up @@ -1477,7 +1477,7 @@ do { \
free_var(base);
PUSH_ERROR(E_TYPE);
} else if (base.type == TYPE_MAP
&& (is_collection(to) || is_collection(from))) {
&& (to.is_collection() || from.is_collection())) {
free_var(to);
free_var(from);
free_var(base);
Expand Down Expand Up @@ -1929,7 +1929,7 @@ do { \
free_var(value);
PUSH_ERROR(E_TYPE);
} else if (base.type == TYPE_MAP
&& (is_collection(to) || is_collection(from))) {
&& (to.is_collection() || from.is_collection())) {
free_var(to);
free_var(from);
free_var(base);
Expand Down
8 changes: 4 additions & 4 deletions garbage.cc
Expand Up @@ -145,7 +145,7 @@ gc_possible_root(Var v)
{
GC_Color color;

assert(is_collection(v));
assert(v.is_collection());

if ((color = gc_get_color(VOID_PTR(v))) != GC_PURPLE && color != GC_GREEN && color != GC_YELLOW) {
gc_set_color(VOID_PTR(v), GC_PURPLE);
Expand All @@ -169,7 +169,7 @@ static int
do_obj(void *data, Var v)
{
gc_func *fp = (gc_func *)data;
if (is_collection(v) && is_not_green(v))
if (v.is_collection() && is_not_green(v))
(*fp)(v);
return 0;
}
Expand All @@ -178,7 +178,7 @@ static int
do_list(Var v, void *data, int first)
{
gc_func *fp = (gc_func *)data;
if (is_collection(v) && is_not_green(v))
if (v.is_collection() && is_not_green(v))
(*fp)(v);
return 0;
}
Expand All @@ -187,7 +187,7 @@ static int
do_map(Var k, Var v, void *data, int first)
{
gc_func *fp = (gc_func *)data;
if (is_collection(v) && is_not_green(v))
if (v.is_collection() && is_not_green(v))
(*fp)(v);
return 0;
}
Expand Down
4 changes: 2 additions & 2 deletions map.cc
Expand Up @@ -668,7 +668,7 @@ mapinsert(Var map, Var key, Var value)
* collections (for which `compare' does not currently work).
*/
if (key.type == TYPE_NONE || key.type == TYPE_CLEAR
|| is_collection(key))
|| key.is_collection())
panic("MAPINSERT: invalid key");

Var _new = map;
Expand Down Expand Up @@ -982,7 +982,7 @@ bf_mapdelete(Var arglist, Byte next, void *vdata, Objid progr)
Var map = arglist.v.list[1];
Var key = arglist.v.list[2];

if (is_collection(key)) {
if (key.is_collection()) {
free_var(arglist);
return make_error_pack(E_TYPE);
}
Expand Down
11 changes: 5 additions & 6 deletions structures.h
Expand Up @@ -137,6 +137,11 @@ struct Var {
is_none() {
return TYPE_NONE == type;
}

bool
is_collection() {
return TYPE_LIST == type || TYPE_MAP == type || TYPE_ANON == type;
}
};

/* generic tuples */
Expand Down Expand Up @@ -165,12 +170,6 @@ extern Var none; /* see objects.c */
#define MAX_LIST_VALUE_BYTES_LIMIT (INT32_MAX - MIN_LIST_VALUE_BYTES_LIMIT)
#define MAX_MAP_VALUE_BYTES_LIMIT (INT32_MAX - MIN_MAP_VALUE_BYTES_LIMIT)

static inline bool
is_collection(Var v)
{
return TYPE_LIST == v.type || TYPE_MAP == v.type || TYPE_ANON == v.type;
}

static inline bool
is_object(Var v)
{
Expand Down

0 comments on commit 0f0ecf3

Please sign in to comment.