Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions bytecode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,18 @@ void print_const(std::ostream& pyc_output, PycRef<PycObject> obj, PycModule* mod
case PycObject::TYPE_CODE2:
pyc_output << "<CODE> " << obj.cast<PycCode>()->name()->value();
break;
case PycObject::TYPE_SLICE:
{
pyc_output << "slice(";
const auto slice = obj.cast<PycSlice>();
print_const(pyc_output, slice->get(0), mod);
pyc_output << ":";
print_const(pyc_output, slice->get(1), mod);
pyc_output << ":";
print_const(pyc_output, slice->get(2), mod);
pyc_output << ")";
}
break;
default:
formatted_print(pyc_output, "<TYPE: %d>\n", obj->type());
}
Expand Down
2 changes: 2 additions & 0 deletions pyc_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ PycRef<PycObject> CreateObject(int type)
case PycObject::TYPE_SET:
case PycObject::TYPE_FROZENSET:
return new PycSet(type);
case PycObject::TYPE_SLICE:
return new PycSlice;
default:
fprintf(stderr, "CreateObject: Got unsupported type 0x%X\n", type);
return NULL;
Expand Down
1 change: 1 addition & 0 deletions pyc_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class PycObject {
TYPE_SMALL_TUPLE = ')', // Python 3.4 ->
TYPE_SHORT_ASCII = 'z', // Python 3.4 ->
TYPE_SHORT_ASCII_INTERNED = 'Z', // Python 3.4 ->
TYPE_SLICE = ':', // Python 3.14 ->
};

PycObject(int type = TYPE_UNKNOWN) : m_refs(0), m_type(type) { }
Expand Down
9 changes: 9 additions & 0 deletions pyc_sequence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,12 @@ bool PycDict::isEqual(PycRef<PycObject> obj) const
}
return true;
}

/* PycSlice */
void PycSlice::load(PycData* stream, PycModule* mod)
{
m_size = 3; // start, stop, step
m_values.reserve(m_size);
for (int i = 0; i < m_size; i++)
m_values.push_back(LoadObject(stream, mod));
}
7 changes: 7 additions & 0 deletions pyc_sequence.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,11 @@ class PycDict : public PycObject {
value_t m_values;
};

class PycSlice : public PycSimpleSequence {
public:
PycSlice() : PycSimpleSequence(TYPE_SLICE) {}

void load(class PycData* stream, class PycModule* mod) override;
};

#endif
12 changes: 12 additions & 0 deletions pycdas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,18 @@ void output_object(PycRef<PycObject> obj, PycModule* mod, int indent,
iprintf(pyc_output, indent, "(%g+%gj)\n", obj.cast<PycCComplex>()->value(),
obj.cast<PycCComplex>()->imag());
break;
case PycObject::TYPE_SLICE:
{
const auto slice = obj.cast<PycSlice>();
iputs(pyc_output, indent, "slice(");
output_object(slice->get(0), mod, 0, flags, pyc_output);
iprintf(pyc_output, 0, ":");
output_object(slice->get(1), mod, 0, flags, pyc_output);
iprintf(pyc_output, 0, ":");
output_object(slice->get(2), mod, 0, flags, pyc_output);
iputs(pyc_output, indent, ")\n");
}
break;
default:
iprintf(pyc_output, indent, "<TYPE: %d>\n", obj->type());
}
Expand Down
Loading