Add support for LOAD_BUILD_CLASS op-code
Issue #39
This commit is contained in:
14
ASTNode.h
14
ASTNode.h
@@ -17,7 +17,7 @@ public:
|
||||
NODE_COMPREHENSION,
|
||||
|
||||
// Empty nodes
|
||||
NODE_PASS, NODE_LOCALS
|
||||
NODE_PASS, NODE_LOCALS, NODE_LOADBUILDCLASS
|
||||
};
|
||||
|
||||
ASTNode(int type = NODE_INVALID) : m_refs(0), m_type(type) { }
|
||||
@@ -541,4 +541,16 @@ private:
|
||||
|
||||
};
|
||||
|
||||
|
||||
class ASTLoadBuildClass : public ASTNode {
|
||||
public:
|
||||
ASTLoadBuildClass(PycRef<PycObject> obj)
|
||||
: ASTNode(NODE_LOADBUILDCLASS), m_obj(obj) { }
|
||||
|
||||
PycRef<PycObject> object() const { return m_obj; }
|
||||
|
||||
private:
|
||||
PycRef<PycObject> m_obj;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
42
ASTree.cpp
42
ASTree.cpp
@@ -367,6 +367,43 @@ PycRef<ASTNode> BuildFromCode(PycRef<PycCode> code, PycModule* mod)
|
||||
int pparams = (operand & 0xFF);
|
||||
ASTCall::kwparam_t kwparamList;
|
||||
ASTCall::pparam_t pparamList;
|
||||
|
||||
/* Test for the load build class function */
|
||||
stack_hist.push(stack);
|
||||
int basecnt = 0;
|
||||
ASTTuple::value_t bases;
|
||||
bases.resize(basecnt);
|
||||
PycRef<ASTNode> TOS = stack.top();
|
||||
int TOS_type = TOS->type();
|
||||
// bases are NODE_NAME at TOS
|
||||
while (TOS_type == ASTNode::NODE_NAME) {
|
||||
bases.resize(basecnt + 1);
|
||||
bases[basecnt] = TOS;
|
||||
basecnt++;
|
||||
stack.pop();
|
||||
TOS = stack.top();
|
||||
TOS_type = TOS->type();
|
||||
}
|
||||
// qualified name is PycString at TOS
|
||||
PycRef<ASTNode> name = stack.top();
|
||||
stack.pop();
|
||||
PycRef<ASTNode> function = stack.top();
|
||||
stack.pop();
|
||||
PycRef<ASTNode> loadbuild = stack.top();
|
||||
stack.pop();
|
||||
int loadbuild_type = loadbuild->type();
|
||||
if (loadbuild_type == ASTNode::NODE_LOADBUILDCLASS) {
|
||||
PycRef<ASTNode> call = new ASTCall(function, pparamList, kwparamList);
|
||||
stack.push(new ASTClass(call, new ASTTuple(bases), name));
|
||||
stack_hist.pop();
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
stack = stack_hist.top();
|
||||
stack_hist.pop();
|
||||
}
|
||||
|
||||
for (int i=0; i<kwparams; i++) {
|
||||
PycRef<ASTNode> val = stack.top();
|
||||
stack.pop();
|
||||
@@ -2021,6 +2058,11 @@ PycRef<ASTNode> BuildFromCode(PycRef<PycCode> code, PycModule* mod)
|
||||
curblock->append(new ASTReturn(value, ASTReturn::YIELD));
|
||||
}
|
||||
break;
|
||||
case Pyc::LOAD_BUILD_CLASS:
|
||||
{
|
||||
stack.push(new ASTLoadBuildClass(new PycObject()));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "Unsupported opcode: %s\n", Pyc::OpcodeName(opcode & 0xFF));
|
||||
cleanBuild = false;
|
||||
|
BIN
tests/34_loadbuild_class.pyc
Normal file
BIN
tests/34_loadbuild_class.pyc
Normal file
Binary file not shown.
Reference in New Issue
Block a user