summaryrefslogtreecommitdiffstats
path: root/Sencha-lang
diff options
context:
space:
mode:
authorJustyna Ilczuk <justyna.ilczuk@gmail.com>2012-12-22 11:40:57 +0100
committerJustyna Ilczuk <justyna.ilczuk@gmail.com>2012-12-22 11:40:57 +0100
commitb75236096e2b8077ed5b8f2107575a075d657f14 (patch)
tree5547a77013da6885aa0be73eb9175d68e7b7a49b /Sencha-lang
parentf0bc0e235ba712809cd72559527c194f480a62bc (diff)
downloadsencha-lang-b75236096e2b8077ed5b8f2107575a075d657f14.tar.gz
sencha-lang-b75236096e2b8077ed5b8f2107575a075d657f14.tar.bz2
sencha-lang-b75236096e2b8077ed5b8f2107575a075d657f14.zip
Mixing floats and ints is possible now!
Diffstat (limited to 'Sencha-lang')
-rw-r--r--Sencha-lang/AST/SenchaObject.cpp249
1 files changed, 141 insertions, 108 deletions
diff --git a/Sencha-lang/AST/SenchaObject.cpp b/Sencha-lang/AST/SenchaObject.cpp
index 3edd088..81d859a 100644
--- a/Sencha-lang/AST/SenchaObject.cpp
+++ b/Sencha-lang/AST/SenchaObject.cpp
@@ -30,63 +30,63 @@ std::string SenchaObject::repr()
std::string representation = "";
switch(type){
case string_literal:
- representation = "type: string\n";
- representation += this->text;
- break;
+ representation = "type: string\n";
+ representation += this->text;
+ break;
case integer_number:
- representation = "type: integer\n";
- representation += to_string(this->integer);
- break;
+ representation = "type: integer\n";
+ representation += to_string(this->integer);
+ break;
case float_number:
- representation = "type: float\n";
- representation += to_string(this->number);
- break;
+ representation = "type: float\n";
+ representation += to_string(this->number);
+ break;
case null:
- representation = "type: null\n";
- representation += "null";
- break;
+ representation = "type: null\n";
+ representation += "null";
+ break;
case symbol:
- representation = "type: symbol\n";
- representation += this->text;
- break;
+ representation = "type: symbol\n";
+ representation += this->text;
+ break;
case invalid:
- representation = "type: invalid\n";
- representation += "some crap";
- break;
+ representation = "type: invalid\n";
+ representation += "some crap";
+ break;
case boolean:
- representation = "type: boolean\n";
- representation += to_string(this->truthy);
- break;
+ representation = "type: boolean\n";
+ representation += to_string(this->truthy);
+ break;
}
return representation;
}
std::string SenchaObject::str()
{
std::string representation = "";
- switch(type){
- case string_literal:
- representation += this->text;
- break;
- case integer_number:
- representation += to_string(this->integer);
- break;
- case float_number:
- representation += to_string(this->number);
- break;
- case null:
- representation += "null";
- break;
- case symbol:
- representation += this->text;
- break;
- case invalid:
- representation += "some crap";
- break;
- case boolean:
- representation += to_string(this->truthy);
- break;
- }
- return representation;
+ switch(type){
+ case string_literal:
+ representation += this->text;
+ break;
+ case integer_number:
+ representation += to_string(this->integer);
+ break;
+ case float_number:
+ representation += to_string(this->number);
+ break;
+ case null:
+ representation += "null";
+ break;
+ case symbol:
+ representation += this->text;
+ break;
+ case invalid:
+ representation += "some crap";
+ break;
+ case boolean:
+ representation += to_string(this->truthy);
+ break;
+ }
+ return representation;
}
SenchaObject SenchaObject::operator+(const SenchaObject& right)const
@@ -106,6 +106,14 @@ SenchaObject SenchaObject::operator+(const SenchaObject& right)const
break;
}
}
+ else if(type == float_number && right.type == integer_number )
+ {
+ result.set_value(this->number + right.integer);
+ }
+ else if(type == integer_number && right.type == float_number)
+ {
+ result.set_value(this->integer + right.number);
+ }
else
{
result.type = invalid;
@@ -118,51 +126,67 @@ SenchaObject SenchaObject::operator+(const SenchaObject& right)const
SenchaObject SenchaObject::operator-(const SenchaObject& right)const
{
SenchaObject result;
- if(type == right.type)
- {
- switch(type){
- case string_literal:
- result.type = invalid;
- break;
- case integer_number:
- result.set_value(this->integer - right.integer);
- break;
- case float_number:
- result.set_value(this->number - right.number);
- break;
- }
- }
- else
- {
+ if(type == right.type)
+ {
+ switch(type){
+ case string_literal:
result.type = invalid;
+ break;
+ case integer_number:
+ result.set_value(this->integer - right.integer);
+ break;
+ case float_number:
+ result.set_value(this->number - right.number);
+ break;
}
+ }
+ else if(type == float_number && right.type == integer_number )
+ {
+ result.set_value(this->number - right.integer);
+ }
+ else if(type == integer_number && right.type == float_number)
+ {
+ result.set_value(this->integer - right.number);
+ }
+ else
+ {
+ result.type = invalid;
+ }
- return result;
+ return result;
}
SenchaObject SenchaObject::operator*(const SenchaObject& right)const
{
SenchaObject result;
- if(type == right.type)
- {
- switch(type){
- case string_literal:
- result.type = invalid;
- break;
- case integer_number:
- result.set_value(this->integer * right.integer);
- break;
- case float_number:
- result.set_value(this->number * right.number);
- break;
- }
- }
- else
- {
- result.type = invalid;
- }
+ if(type == right.type)
+ {
+ switch(type){
+ case string_literal:
+ result.type = invalid;
+ break;
+ case integer_number:
+ result.set_value(this->integer * right.integer);
+ break;
+ case float_number:
+ result.set_value(this->number * right.number);
+ break;
+ }
+ }
+ else if(type == float_number && right.type == integer_number )
+ {
+ result.set_value(this->number * right.integer);
+ }
+ else if(type == integer_number && right.type == float_number)
+ {
+ result.set_value(this->integer * right.number);
+ }
+ else
+ {
+ result.type = invalid;
+ }
- return result;
+ return result;
}
SenchaObject SenchaObject::operator/(const SenchaObject& right)const
@@ -182,6 +206,14 @@ SenchaObject SenchaObject::operator/(const SenchaObject& right)const
break;
}
}
+ else if(type == float_number && right.type == integer_number )
+ {
+ result.set_value(this->number / right.integer);
+ }
+ else if(type == integer_number && right.type == float_number)
+ {
+ result.set_value(this->integer / right.number);
+ }
else
{
result.type = invalid;
@@ -191,40 +223,41 @@ SenchaObject SenchaObject::operator/(const SenchaObject& right)const
}
SenchaObject SenchaObject::operator==(const SenchaObject& right)const
-{
+ {
SenchaObject result;
bool value = false;
result.type = boolean;
- if(type == right.type)
- {
- switch(type){
- case string_literal:
- if(this->text == right.text)
- {
- value = true;
- }
- break;
- case integer_number:
- if(this->integer == right.integer)
- {
- value = true;
- }
- break;
- case float_number:
- if(this->number == right.number)
- {
- value = true;
- }
- break;
+ if(type == right.type)
+ {
+ switch(type){
+ case string_literal:
+ if(this->text == right.text)
+ {
+ value = true;
+ }
+ break;
+ case integer_number:
+ if(this->integer == right.integer)
+ {
+ value = true;
+ }
+ break;
+ case float_number:
+ if(this->number == right.number)
+ {
+ value = true;
}
+ break;
+ }
+ }
+
+ result.truthy = value;
+ return result;
}
- result.truthy = value;
- return result;
-}
SenchaObject SenchaObject::operator!=(const SenchaObject& right)const
-{
+ {
SenchaObject result;
result.type = boolean;
@@ -234,6 +267,6 @@ SenchaObject SenchaObject::operator!=(const SenchaObject& right)const
else result.truthy = true;
return result;
-}
+ }
//TODO change code above to something more generic