Skip to content

Commit

Permalink
Removed callName from the Callable objects. It was not needed. Also c…
Browse files Browse the repository at this point in the history
…leaned up message for division by zero exception.
  • Loading branch information
kent committed Jan 16, 2014
1 parent 63730bb commit 9cccfce
Show file tree
Hide file tree
Showing 22 changed files with 32 additions and 54 deletions.
3 changes: 0 additions & 3 deletions PyAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ PyType* PyAttr::getType() {
return PyTypes[PyBuiltInType];
}

string PyAttr::callName() {
return method;
}

PyObject* PyAttr::__call__(vector<PyObject*>* args) {
return self->callMethod(method,args);
Expand Down
1 change: 0 additions & 1 deletion PyAttr.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class PyAttr : public PyCallable {
PyAttr(PyObject* self, string method);
virtual ~PyAttr();
bool allowableArgCount(int count);
virtual string callName();

PyType* getType();
string toString();
Expand Down
6 changes: 1 addition & 5 deletions PyBuiltInConcat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ PyObject* PyBuiltInConcat::__call__(vector<PyObject*>* args) {
return x->callMethod("concat",callArgs);
}

string PyBuiltInConcat::callName() {
return "concat";
}

string PyBuiltInConcat::toString() {
return callName();
return "concat";
}
1 change: 0 additions & 1 deletion PyBuiltInConcat.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class PyBuiltInConcat : public PyCallable {
virtual ~PyBuiltInConcat();
PyType* getType();
bool allowableArgCount(int count);
string callName();
string toString();

protected:
Expand Down
6 changes: 1 addition & 5 deletions PyBuiltInFPrint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,6 @@ PyObject* PyBuiltInFPrint::__call__(vector<PyObject*>* args) {
return this;
}

string PyBuiltInFPrint::callName() {
return "fprint";
}

string PyBuiltInFPrint::toString() {
return callName();
return "fprint";
}
1 change: 0 additions & 1 deletion PyBuiltInFPrint.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class PyBuiltInFPrint : public PyCallable {
PyType* getType();

bool allowableArgCount(int count);
string callName();
string toString();

protected:
Expand Down
6 changes: 1 addition & 5 deletions PyBuiltInInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ PyObject* PyBuiltInInput::__call__(vector<PyObject*>* args) {
return new PyStr(s.str());
}

string PyBuiltInInput::callName() {
return "input";
}

string PyBuiltInInput::toString() {
return callName();
return "input";
}
1 change: 0 additions & 1 deletion PyBuiltInInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class PyBuiltInInput : public PyCallable {
PyType* getType();

bool allowableArgCount(int count);
string callName();
string toString();
protected:
virtual PyObject* __call__(vector<PyObject*>* args);
Expand Down
6 changes: 1 addition & 5 deletions PyBuiltInIter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ PyObject* PyBuiltInIter::__call__(vector<PyObject*>* args) {
return result;
}

string PyBuiltInIter::callName() {
return "iter";
}

string PyBuiltInIter::toString() {
return callName();
return "iter";
}
1 change: 0 additions & 1 deletion PyBuiltInIter.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class PyBuiltInIter : public PyCallable {
PyType* getType();

bool allowableArgCount(int count);
string callName();
string toString();
protected:
virtual PyObject* __call__(vector<PyObject*>* args);
Expand Down
6 changes: 1 addition & 5 deletions PyBuiltInLen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ PyObject* PyBuiltInLen::__call__(vector<PyObject*>* args) {
return x->callMethod("__len__",callArgs);
}

string PyBuiltInLen::callName() {
return "len";
}

string PyBuiltInLen::toString() {
return callName();
return "len";
}
1 change: 0 additions & 1 deletion PyBuiltInLen.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class PyBuiltInLen : public PyCallable {
virtual ~PyBuiltInLen();
PyType* getType();
bool allowableArgCount(int count);
string callName();
string toString();

protected:
Expand Down
6 changes: 1 addition & 5 deletions PyBuiltInPrint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ PyObject* PyBuiltInPrint::__call__(vector<PyObject*>* args) {
return new PyNone();
}

string PyBuiltInPrint::callName() {
return "print";
}

string PyBuiltInPrint::toString() {
return callName();
return "print";
}
1 change: 0 additions & 1 deletion PyBuiltInPrint.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class PyBuiltInPrint : public PyCallable {
virtual ~PyBuiltInPrint();
PyType* getType();
bool allowableArgCount(int count);
string callName();
string toString();

private:
Expand Down
6 changes: 1 addition & 5 deletions PyBuiltInTPrint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,6 @@ PyObject* PyBuiltInTPrint::__call__(vector<PyObject*>* args) {
return new PyNone();
}

string PyBuiltInTPrint::callName() {
return "tprint";
}

string PyBuiltInTPrint::toString() {
return callName();
return "tprint";
}
1 change: 0 additions & 1 deletion PyBuiltInTPrint.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class PyBuiltInTPrint : public PyCallable {
virtual ~PyBuiltInTPrint();
PyType* getType();
bool allowableArgCount(int count);
string callName();
string toString();

protected:
Expand Down
1 change: 0 additions & 1 deletion PyCallable.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class PyCallable : public PyObject {
PyCallable();
PyCallable(const PyCallable& orig);
virtual ~PyCallable();
virtual string callName() = 0;

protected:
virtual PyObject* __call__(vector<PyObject*>* args);
Expand Down
8 changes: 4 additions & 4 deletions PyInt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,13 @@ PyObject* PyInt::__truediv__(vector<PyObject*>* args) {
case PyIntType:
x = (PyInt*) arg;
if (x->val == 0)
throw new PyException(PYILLEGALOPERATIONEXCEPTION, "Division By Zero Error");
throw new PyException(PYILLEGALOPERATIONEXCEPTION, "ZeroDivisionError: integer division or modulo by zero");
return new PyFloat(this->val / x->val);

case PyFloatType:
y = (PyFloat*) arg;
if (y->getVal() == 0)
throw new PyException(PYILLEGALOPERATIONEXCEPTION, "Division By Zero Error");
throw new PyException(PYILLEGALOPERATIONEXCEPTION, "ZeroDivisionError: integer division or modulo by zero");
return new PyFloat(this->val / y->getVal());

default:
Expand All @@ -182,13 +182,13 @@ PyObject* PyInt::__floordiv__(vector<PyObject*>* args) {
case PyIntType:
x = (PyInt*) arg;
if (x->val == 0)
throw new PyException(PYILLEGALOPERATIONEXCEPTION, "Division By Zero Error");
throw new PyException(PYILLEGALOPERATIONEXCEPTION, "ZeroDivisionError: integer division or modulo by zero");
return new PyInt(this->val / x->val);

case PyFloatType:
y = (PyFloat*) arg;
if (y->getVal() == 0)
throw new PyException(PYILLEGALOPERATIONEXCEPTION, "Division By Zero Error");
throw new PyException(PYILLEGALOPERATIONEXCEPTION, "ZeroDivisionError: integer division or modulo by zero");

return new PyFloat(floor(this->val / y->getVal()));

Expand Down
6 changes: 3 additions & 3 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ void sigHandler(int signum) {
cerr << "*********************************************************" << endl;
cerr << " An Uncaught Exception Occurred" << endl;
cerr << "*********************************************************" << endl;
cerr << "The exception was:\n";
cerr << "Signal: ";
switch (signum) {
case SIGABRT:
cerr << "Program Execution Aborted" << endl;
Expand Down Expand Up @@ -353,15 +353,15 @@ int main(int argc, char* argv[]) {
cerr << "*********************************************************" << endl;
cerr << " An Uncaught Exception Occurred" << endl;
cerr << "*********************************************************" << endl;
cerr << "The exception was: " << ex->toString() << endl;
cerr << ex->toString() << endl;
cerr << "---------------------------------------------------------" << endl;
cerr << " The Exception's Traceback" << endl;
cerr << "---------------------------------------------------------" << endl;
ex->printTraceBack();
cerr << "*********************************************************" << endl;
cerr << " An Uncaught Exception Occurred (See Above) " << endl;
cerr << "*********************************************************" << endl;
cerr << "The exception was: " << ex->toString() << endl;
cerr << ex->toString() << endl;
cerr << "*********************************************************" << endl;
}

Expand Down
8 changes: 8 additions & 0 deletions tests/testcall.casm
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Function: main/0
Constants: None, 5
Globals: print
BEGIN
LOAD_CONST 1
CALL_FUNCTION 0
RETURN_VALUE
END
9 changes: 9 additions & 0 deletions tests/testcall2.casm
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Function: main/0
Constants: None, 5, 0
Globals: print
BEGIN
LOAD_CONST 1
LOAD_CONST 2
BINARY_TRUE_DIVIDE
RETURN_VALUE
END
1 change: 1 addition & 0 deletions tests/testit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5 / 0

0 comments on commit 9cccfce

Please sign in to comment.