Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

sclang: improve PyrObjectHdr API

Signed-off-by: Tim Blechmann <tim@klingt.org>
  • Loading branch information...
commit be513146fd926893720633a5f89083e36dfa5d2e 1 parent d58b512
@timblechmann timblechmann authored
View
14 include/lang/PyrObject.h
@@ -85,12 +85,14 @@ struct PyrObjectHdr {
int scratch1;
- int SizeClass() { return obj_sizeclass; }
-
- void SetMark() { obj_flags |= obj_marked; }
- void ClearMark() { obj_flags &= ~obj_marked; }
- bool IsMarked() { return ((obj_flags & obj_marked) != 0); } // BG2004-10-09 : the previous version did execute some hidden code in int -> bool conversion
- bool IsPermanent() { return gc_color == obj_permanent; }
+ int SizeClass() { return obj_sizeclass; }
+
+ void SetMark() { obj_flags |= obj_marked; }
+ void ClearMark() { obj_flags &= ~obj_marked; }
+ bool IsMarked() const { return obj_flags & obj_marked; }
+ bool IsPermanent() const { return gc_color == obj_permanent; }
+ bool IsImmutable() const { return obj_flags & obj_immutable; }
+ bool IsMutable() const { return !IsMutable(); }
};
struct PyrObject : public PyrObjectHdr {
View
18 lang/LangPrimSource/PyrArrayPrimitives.cpp
@@ -115,7 +115,7 @@ int basicSwap(struct VMGlobals *g, int numArgsPushed)
if (NotInt(b)) return errIndexNotAnInteger;
if (NotInt(c)) return errIndexNotAnInteger;
obj = slotRawObject(a);
- if (obj->obj_flags & obj_immutable) return errImmutableObject;
+ if (obj->IsImmutable()) return errImmutableObject;
if (!(slotRawInt(&obj->classptr->classFlags) & classHasIndexableInstances))
return errNotAnIndexableObject;
i = slotRawInt(b);
@@ -194,7 +194,7 @@ int basicRemoveAt(struct VMGlobals *g, int numArgsPushed)
if (err) return errWrongType;
obj = slotRawObject(a);
- if (obj->obj_flags & obj_immutable) return errImmutableObject;
+ if (obj->IsImmutable()) return errImmutableObject;
if (!(slotRawInt(&obj->classptr->classFlags) & classHasIndexableInstances))
return errNotAnIndexableObject;
@@ -263,7 +263,7 @@ int basicTakeAt(struct VMGlobals *g, int numArgsPushed)
if (err) return errWrongType;
obj = slotRawObject(a);
- if (obj->obj_flags & obj_immutable) return errImmutableObject;
+ if (obj->IsImmutable()) return errImmutableObject;
if (!(slotRawInt(&obj->classptr->classFlags) & classHasIndexableInstances))
return errNotAnIndexableObject;
@@ -805,7 +805,6 @@ int prArrayAdd(struct VMGlobals *g, int numArgsPushed);
int prArrayAdd(struct VMGlobals *g, int numArgsPushed)
{
PyrSlot *a, *b, *slots;
- PyrObject *array;
int maxelems, elemsize, format, tag, numbytes;
int err, ival;
double fval;
@@ -813,8 +812,9 @@ int prArrayAdd(struct VMGlobals *g, int numArgsPushed)
a = g->sp - 1;
b = g->sp;
- array = slotRawObject(a);
- if (array->obj_flags & obj_immutable) return errImmutableObject;
+ PyrObject *array = slotRawObject(a);
+ if (array->IsImmutable()) return errImmutableObject;
+
format = slotRawObject(a)->obj_format;
tag = gFormatElemTag[format];
/*if (tag > 0) {
@@ -891,7 +891,7 @@ int prArrayInsert(struct VMGlobals *g, int numArgsPushed)
if (NotInt(b)) return errWrongType;
array = slotRawObject(a);
- if (array->obj_flags & obj_immutable) return errImmutableObject;
+ if (array->IsImmutable()) return errImmutableObject;
format = slotRawObject(a)->obj_format;
tag = gFormatElemTag[format];
@@ -1088,7 +1088,7 @@ int prArrayFill(struct VMGlobals *g, int numArgsPushed)
slots = array->slots;
switch (format) {
case obj_slot :
- if (array->obj_flags & obj_immutable) return errImmutableObject;
+ if (array->IsImmutable()) return errImmutableObject;
for (i=0; i<array->size; ++i) {
slotCopy(&slots[i],b);
}
@@ -1159,7 +1159,7 @@ int prArrayPop(struct VMGlobals *g, int numArgsPushed)
a = g->sp;
array = slotRawObject(a);
- if (array->obj_flags & obj_immutable) return errImmutableObject;
+ if (array->IsImmutable()) return errImmutableObject;
if (array->size > 0) {
format = array->obj_format;
slots = array->slots;
View
2  lang/LangPrimSource/PyrPrimitive.cpp
@@ -183,7 +183,7 @@ int instVarPut(struct VMGlobals *g, int numArgsPushed)
if (NotObj(a)) return errWrongType;
obj = slotRawObject(a);
- if (obj->obj_flags & obj_immutable) return errImmutableObject;
+ if (obj->IsImmutable()) return errImmutableObject;
if (IsInt(b)) {
index = slotRawInt(b);
View
8 lang/LangSource/PyrInterpreter3.cpp
@@ -465,7 +465,7 @@ static inline void handlePushClassVar(VMGlobals* g, PyrSlot *& sp, unsigned char
static inline void handleStoreInstVar(VMGlobals* g, PyrSlot *& sp, unsigned char *& ip, unsigned int index)
{
PyrObject* obj = slotRawObject(&g->receiver);
- if (obj->obj_flags & obj_immutable)
+ if (obj->IsImmutable())
StoreToImmutableA(g, sp, ip);
else {
PyrSlot * slot = obj->slots + index;
@@ -971,7 +971,7 @@ HOT void Interpret(VMGlobals *g)
handle_op_7:
op2 = ip[1]; ++ip; // get inst var index
obj = slotRawObject(&g->receiver);
- if (obj->obj_flags & obj_immutable) { StoreToImmutableA(g, sp, ip); }
+ if (obj->IsImmutable()) { StoreToImmutableA(g, sp, ip); }
else {
slot = obj->slots + op2;
slotCopy(slot, sp);
@@ -2454,7 +2454,7 @@ HOT void Interpret(VMGlobals *g)
sp -= numArgsPushed - 1;
index = methraw->specialIndex;
obj = slotRawObject(slot);
- if (obj->obj_flags & obj_immutable) { StoreToImmutableB(g, sp, ip); }
+ if (obj->IsImmutable()) { StoreToImmutableB(g, sp, ip); }
else {
if (numArgsPushed >= 2) {
slotCopy(&obj->slots[index], sp + 1);
@@ -2598,7 +2598,7 @@ HOT void Interpret(VMGlobals *g)
numArgsPushed -= numKeyArgsPushed << 1;
index = methraw->specialIndex;
obj = slotRawObject(slot);
- if (obj->obj_flags & obj_immutable) { StoreToImmutableB(g, sp, ip); }
+ if (obj->IsImmutable()) { StoreToImmutableB(g, sp, ip); }
else {
if (numArgsPushed >= 2) {
slotCopy(&obj->slots[index], sp + 1);
View
8 lang/LangSource/PyrMessage.cpp
@@ -110,7 +110,7 @@ HOT void sendMessageWithKeys(VMGlobals *g, PyrSymbol *selector, long numArgsPush
sp = g->sp -= numArgsPushed - 1;
index = methraw->specialIndex;
obj = slotRawObject(recvrSlot);
- if (obj->obj_flags & obj_immutable) { StoreToImmutableB(g, sp, g->ip); }
+ if (obj->IsImmutable()) { StoreToImmutableB(g, sp, g->ip); }
else {
if (numArgsPushed >= 2) {
slotCopy(&obj->slots[index], sp + 1);
@@ -240,7 +240,7 @@ HOT void sendMessage(VMGlobals *g, PyrSymbol *selector, long numArgsPushed)
sp = g->sp -= numArgsPushed - 1;
index = methraw->specialIndex;
obj = slotRawObject(recvrSlot);
- if (obj->obj_flags & obj_immutable) { StoreToImmutableB(g, sp, g->ip); }
+ if (obj->IsImmutable()) { StoreToImmutableB(g, sp, g->ip); }
else {
if (numArgsPushed >= 2) {
slotCopy(&obj->slots[index], sp + 1);
@@ -429,7 +429,7 @@ HOT void sendSuperMessageWithKeys(VMGlobals *g, PyrSymbol *selector, long numArg
sp = g->sp -= numArgsPushed - 1;
index = methraw->specialIndex;
obj = slotRawObject(recvrSlot);
- if (obj->obj_flags & obj_immutable) { StoreToImmutableB(g, sp, g->ip); }
+ if (obj->IsImmutable()) { StoreToImmutableB(g, sp, g->ip); }
else {
if (numArgsPushed >= 2) {
slotCopy(&obj->slots[index], sp + 1);
@@ -560,7 +560,7 @@ HOT void sendSuperMessage(VMGlobals *g, PyrSymbol *selector, long numArgsPushed)
sp = g->sp -= numArgsPushed - 1;
index = methraw->specialIndex;
obj = slotRawObject(recvrSlot);
- if (obj->obj_flags & obj_immutable) { StoreToImmutableB(g, sp, g->ip); }
+ if (obj->IsImmutable()) { StoreToImmutableB(g, sp, g->ip); }
else {
if (numArgsPushed >= 2) {
slotCopy(&obj->slots[index], sp + 1);
View
4 lang/LangSource/PyrObject.cpp
@@ -2654,7 +2654,7 @@ int putIndexedSlot(VMGlobals *g, PyrObject *obj, PyrSlot *c, int index)
PyrSlot *slot;
switch (obj->obj_format) {
case obj_slot :
- if (obj->obj_flags & obj_immutable) return errImmutableObject;
+ if (obj->IsImmutable()) return errImmutableObject;
slot = obj->slots + index;
slotCopy(slot, c);
g->gc->GCWrite(obj, slot);
@@ -2706,7 +2706,7 @@ int putIndexedFloat(PyrObject *obj, double val, int index)
PyrSlot *slot;
switch (obj->obj_format) {
case obj_slot :
- if (obj->obj_flags & obj_immutable) return errImmutableObject;
+ if (obj->IsImmutable()) return errImmutableObject;
slot = obj->slots + index;
SetFloat(slot, val);
break;
Please sign in to comment.
Something went wrong with that request. Please try again.