Commit eb6e3eac authored by Kevin Modzelewski's avatar Kevin Modzelewski

int methods, and fix a tuple bug

parent c577cf0c
......@@ -1629,6 +1629,10 @@ public:
return var;
}
bool canConvertTo(ConcreteCompilerType* other_type) override {
return (other_type == UNKNOWN || other_type == BOXED_BOOL || other_type == BOOL);
}
virtual ConcreteCompilerVariable* makeConverted(IREmitter& emitter, ConcreteCompilerVariable* var,
ConcreteCompilerType* other_type) {
if (other_type == BOOL) {
......@@ -1718,24 +1722,7 @@ public:
}
virtual void print(IREmitter& emitter, const OpInfo& info, VAR* var) {
llvm::Constant* open_paren = getStringConstantPtr("(");
llvm::Constant* close_paren = getStringConstantPtr(")");
llvm::Constant* comma = getStringConstantPtr(",");
llvm::Constant* comma_space = getStringConstantPtr(", ");
VEC* v = var->getValue();
emitter.getBuilder()->CreateCall(g.funcs.printf, open_paren);
for (int i = 0; i < v->size(); i++) {
if (i)
emitter.getBuilder()->CreateCall(g.funcs.printf, comma_space);
(*v)[i]->print(emitter, info);
}
if (v->size() == 1)
emitter.getBuilder()->CreateCall(g.funcs.printf, comma);
emitter.getBuilder()->CreateCall(g.funcs.printf, close_paren);
return makeConverted(emitter, var, getConcreteType())->print(emitter, info);
}
virtual bool canConvertTo(ConcreteCompilerType* other_type) {
......
......@@ -150,6 +150,36 @@ extern "C" Box* intAnd(BoxedInt* lhs, Box* rhs) {
return boxInt(lhs->n & rhs_int->n);
}
extern "C" Box* intOrInt(BoxedInt* lhs, BoxedInt* rhs) {
assert(lhs->cls == int_cls);
assert(rhs->cls == int_cls);
return boxInt(lhs->n | rhs->n);
}
extern "C" Box* intOr(BoxedInt* lhs, Box* rhs) {
assert(lhs->cls == int_cls);
if (rhs->cls != int_cls) {
return NotImplemented;
}
BoxedInt* rhs_int = static_cast<BoxedInt*>(rhs);
return boxInt(lhs->n | rhs_int->n);
}
extern "C" Box* intXorInt(BoxedInt* lhs, BoxedInt* rhs) {
assert(lhs->cls == int_cls);
assert(rhs->cls == int_cls);
return boxInt(lhs->n ^ rhs->n);
}
extern "C" Box* intXor(BoxedInt* lhs, Box* rhs) {
assert(lhs->cls == int_cls);
if (rhs->cls != int_cls) {
return NotImplemented;
}
BoxedInt* rhs_int = static_cast<BoxedInt*>(rhs);
return boxInt(lhs->n ^ rhs_int->n);
}
extern "C" Box* intDivInt(BoxedInt* lhs, BoxedInt* rhs) {
assert(lhs->cls == int_cls);
assert(rhs->cls == int_cls);
......@@ -529,6 +559,8 @@ void setupInt() {
_addFuncIntFloatUnknown("__add__", (void*)intAddInt, (void*)intAddFloat, (void*)intAdd);
_addFuncIntUnknown("__and__", BOXED_INT, (void*)intAndInt, (void*)intAnd);
_addFuncIntUnknown("__or__", BOXED_INT, (void*)intOrInt, (void*)intOr);
_addFuncIntUnknown("__xor__", BOXED_INT, (void*)intXorInt, (void*)intXor);
_addFuncIntFloatUnknown("__sub__", (void*)intSubInt, (void*)intSubFloat, (void*)intSub);
_addFuncIntFloatUnknown("__div__", (void*)intDivInt, (void*)intDivFloat, (void*)intDiv);
_addFuncIntFloatUnknown("__mul__", (void*)intMulInt, (void*)intMulFloat, (void*)intMul);
......
......@@ -2,3 +2,10 @@
for i in xrange(1, 100):
for j in xrange(1, 100):
print i.__divmod__(j)
for i in xrange(1, 12):
for j in xrange(1, 12):
print i | j
print i & j
print i ^ j
......@@ -68,3 +68,5 @@ t((T(1),), (T(1),))
t((T(1),), (T(2),))
t((T(1),1), (T(2),))
t((T(1),), (T(2),1))
print ("hello", "world", ["test"])
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment