summaryrefslogtreecommitdiffstats
path: root/Sencha-lang/Elements
diff options
context:
space:
mode:
authorJustyna Ilczuk <justyna.ilczuk@gmail.com>2012-12-30 14:59:30 +0100
committerJustyna Ilczuk <justyna.ilczuk@gmail.com>2012-12-30 14:59:30 +0100
commit39794ea7111f2508e8dc7504de4396bc570da03e (patch)
tree45e28bf95007405037f3d0d464787f574e30a6de /Sencha-lang/Elements
parent93a63d43e950c53230c1658e86111ee962faf7f9 (diff)
downloadsencha-lang-39794ea7111f2508e8dc7504de4396bc570da03e.tar.gz
sencha-lang-39794ea7111f2508e8dc7504de4396bc570da03e.tar.bz2
sencha-lang-39794ea7111f2508e8dc7504de4396bc570da03e.tar.xz
sencha-lang-39794ea7111f2508e8dc7504de4396bc570da03e.zip
I began implementing function functionality and I apply some changes to
whole design.
Diffstat (limited to 'Sencha-lang/Elements')
-rw-r--r--Sencha-lang/Elements/Element.cpp20
-rw-r--r--Sencha-lang/Elements/Element.h18
-rw-r--r--Sencha-lang/Elements/SenchaFunction.cpp19
-rw-r--r--Sencha-lang/Elements/SenchaFunction.h32
-rw-r--r--Sencha-lang/Elements/SenchaObject.cpp399
-rw-r--r--Sencha-lang/Elements/SenchaObject.h70
6 files changed, 558 insertions, 0 deletions
diff --git a/Sencha-lang/Elements/Element.cpp b/Sencha-lang/Elements/Element.cpp
new file mode 100644
index 0000000..05241f3
--- /dev/null
+++ b/Sencha-lang/Elements/Element.cpp
@@ -0,0 +1,20 @@
+/*
+ * Element.cpp
+ *
+ * Created on: Dec 30, 2012
+ * Author: att
+ */
+
+#include "Element.h"
+
+Element::Element()
+{
+ // TODO Auto-generated constructor stub
+
+}
+
+Element::~Element()
+{
+ // TODO Auto-generated destructor stub
+}
+
diff --git a/Sencha-lang/Elements/Element.h b/Sencha-lang/Elements/Element.h
new file mode 100644
index 0000000..3377c9a
--- /dev/null
+++ b/Sencha-lang/Elements/Element.h
@@ -0,0 +1,18 @@
+/*
+ * Element.h
+ *
+ * Created on: Dec 30, 2012
+ * Author: att
+ */
+
+#ifndef ELEMENT_H_
+#define ELEMENT_H_
+
+class Element
+{
+public:
+ Element();
+ virtual ~Element();
+};
+
+#endif /* ELEMENT_H_ */
diff --git a/Sencha-lang/Elements/SenchaFunction.cpp b/Sencha-lang/Elements/SenchaFunction.cpp
new file mode 100644
index 0000000..dfbf428
--- /dev/null
+++ b/Sencha-lang/Elements/SenchaFunction.cpp
@@ -0,0 +1,19 @@
+/*
+ * SenchaFunction.cpp
+ *
+ * Created on: Dec 30, 2012
+ * Author: att
+ */
+
+#include "SenchaFunction.h"
+
+SenchaFunction::SenchaFunction(std::string name, std::vector<std::string> names_of_arguments, ASTNode * body, Context * context)
+ : name(name), names_of_arguments(names_of_arguments), body(body), context(context)
+{
+
+}
+
+SenchaFunction::~SenchaFunction() {
+
+}
+
diff --git a/Sencha-lang/Elements/SenchaFunction.h b/Sencha-lang/Elements/SenchaFunction.h
new file mode 100644
index 0000000..7185ebb
--- /dev/null
+++ b/Sencha-lang/Elements/SenchaFunction.h
@@ -0,0 +1,32 @@
+/*
+ * SenchaFunction.h
+ *
+ * Created on: Dec 30, 2012
+ * Author: att
+ */
+
+#ifndef SENCHAFUNCTION_H_
+#define SENCHAFUNCTION_H_
+#include <string>
+#include <iostream>
+#include <vector>
+#include <SenchaObject.h>
+#include "Element.h"
+#include "../Utils/to_string.h"
+#include "../Context.h"
+#include "../AST/ASTNode.h"
+
+
+class SenchaFunction : public Element
+{
+public:
+ std::string name;
+ std::vector<std::string> names_of_arguments;
+ ASTNode * body;
+ Context * context;
+
+ SenchaFunction(std::string name, std::vector<std::string> names_of_arguments, ASTNode * body, Context * context);
+ virtual ~SenchaFunction();
+};
+
+#endif /* SENCHAFUNCTION_H_ */
diff --git a/Sencha-lang/Elements/SenchaObject.cpp b/Sencha-lang/Elements/SenchaObject.cpp
new file mode 100644
index 0000000..56af04c
--- /dev/null
+++ b/Sencha-lang/Elements/SenchaObject.cpp
@@ -0,0 +1,399 @@
+/*
+ * SenchaObject.cpp
+ *
+ * Created on: Dec 5, 2012
+ * Author: attero
+ */
+
+#include "SenchaObject.h"
+
+SenchaObject::SenchaObject() {
+ set_null_value();
+}
+
+SenchaObject::~SenchaObject() {
+ // Do nothing
+}
+
+bool SenchaObject::is_true()
+{
+ if(type == invalid || type == null)
+ {
+ return false;
+ }
+ if(type == boolean) return truthy;
+ else return true;
+
+}
+
+void SenchaObject::set_value(std::string text)
+{
+ if(text[0] == '\"' && text[text.size()-1] == '\"')
+ {
+ this->text = text.substr(1, text.size()-2);
+ type = string_literal;
+ }
+}
+
+void SenchaObject::set_new_string(std::string text)
+{
+ this->text = text;
+ type = string_literal;
+}
+
+void SenchaObject::set_null_value()
+{
+ this->type = null;
+ this->integer = 0;
+ this->number = 0;
+ this->text = "";
+}
+
+void SenchaObject::set_value(int integer)
+{
+ this->integer = integer;
+ type = integer_number;
+}
+
+void SenchaObject::set_value(double number)
+{
+ this->number = number;
+ type = float_number;
+}
+
+void SenchaObject::set_value(bool logic)
+{
+ this->truthy = logic;
+ type = boolean;
+}
+
+std::string SenchaObject::repr()
+{
+ std::string representation = "";
+ switch(type){
+ case string_literal:
+ representation = "type: string\n";
+ representation += this->text;
+ break;
+ case integer_number:
+ representation = "type: integer\n";
+ representation += to_string(this->integer);
+ break;
+ case float_number:
+ representation = "type: float\n";
+ representation += to_string(this->number);
+ break;
+ case null:
+ representation = "type: null\n";
+ representation += "null";
+ break;
+ case symbol:
+ representation = "type: symbol\n";
+ representation += this->text;
+ break;
+ case invalid:
+ representation = "type: invalid\n";
+ representation += "some crap";
+ break;
+ case boolean:
+ 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;
+}
+
+SenchaObject SenchaObject::operator+(const SenchaObject& right)const
+{
+ SenchaObject result;
+ if(type == right.type)
+ {
+ switch(type){
+ case string_literal:
+ result.set_new_string(this->text + right.text);
+ 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;
+
+}
+
+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 == 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;
+}
+
+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 == 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;
+}
+
+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 == 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;
+}
+
+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;
+ }
+ }
+
+ result.truthy = value;
+ return result;
+ }
+
+SenchaObject SenchaObject::operator!=(const SenchaObject& right) const
+{
+ SenchaObject result;
+ result.type = boolean;
+
+ result = (*this == right);
+ if(result.truthy)
+ result.truthy = false;
+ else result.truthy = true;
+
+ return result;
+}
+
+
+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;
+ }
+ }
+ else if(type == float_number && right.type == integer_number )
+ {
+ value = (this->number > right.integer);
+ }
+ else if(type == integer_number && right.type == float_number)
+ {
+ value = (this->integer > right.number);
+ }
+
+ result.truthy = value;
+ return result;
+}
+
+SenchaObject SenchaObject::operator>= (const SenchaObject& right) const
+{
+ SenchaObject result;
+ bool value = false;
+ result.type = boolean;
+
+ if((*this == right).truthy || ((*this) > right).truthy)
+ {
+ value = true;
+ }
+ result.truthy = value;
+ return result;
+}
+
+SenchaObject SenchaObject::operator< (const SenchaObject& right) const
+{
+ SenchaObject result;
+ bool value = false;
+ result.type = boolean;
+
+ if(!((*this) >= right).truthy)
+ {
+ value = true;
+ }
+ result.truthy = value;
+ return result;
+}
+
+SenchaObject SenchaObject::operator<= (const SenchaObject& right) const
+{
+ SenchaObject result;
+ bool value = false;
+ result.type = boolean;
+
+ if(!((*this) > right).truthy)
+ {
+ value = true;
+ }
+ result.truthy = value;
+ return result;
+}
+
+//TODO change code above to something more generic
diff --git a/Sencha-lang/Elements/SenchaObject.h b/Sencha-lang/Elements/SenchaObject.h
new file mode 100644
index 0000000..58f7cf6
--- /dev/null
+++ b/Sencha-lang/Elements/SenchaObject.h
@@ -0,0 +1,70 @@
+/*
+ * SenchaObject.h
+ *
+ * Created on: Dec 5, 2012
+ * Author: attero
+ */
+
+#ifndef SENCHAOBJECT_H_
+#define SENCHAOBJECT_H_
+#include <string>
+#include <iostream>
+#include "../Utils/to_string.h"
+#include "Element.h"
+
+class SenchaObject : public Element {
+
+public:
+ typedef enum {
+ string_literal,
+ integer_number,
+ float_number,
+ null,
+ symbol,
+ boolean,
+ invalid
+ } Type;
+
+ Type type;
+
+ virtual std::string repr();
+ virtual std::string str();
+ virtual bool is_true();
+
+ std::string text;
+ std::string name;
+ bool truthy;
+ int integer;
+ double number;
+
+ void set_value(std::string text);
+ void set_new_string(std::string text);
+ void set_null_value();
+ void set_value(int integer);
+ void set_value(double number);
+ void set_value(bool logic);
+
+ SenchaObject();
+ SenchaObject(int integer) { set_value(integer); }
+ SenchaObject(bool truthy) {set_value(truthy); }
+ SenchaObject(double number) { set_value(number); }
+ SenchaObject(std::string text) { set_value(text); }
+
+
+ virtual SenchaObject operator< (const SenchaObject& right)const;
+ virtual SenchaObject operator> (const SenchaObject& right)const;
+ virtual SenchaObject operator<= (const SenchaObject& right)const;
+ virtual SenchaObject operator>= (const SenchaObject& right)const;
+ virtual SenchaObject operator+(const SenchaObject& right)const;
+ virtual SenchaObject operator-(const SenchaObject& right)const;
+ virtual SenchaObject operator*(const SenchaObject& right)const;
+ virtual SenchaObject operator/(const SenchaObject& right)const;
+ virtual SenchaObject operator==(const SenchaObject& right)const;
+ virtual SenchaObject operator!=(const SenchaObject& right)const;
+
+
+
+ virtual ~SenchaObject();
+};
+
+#endif /* SENCHAOBJECT_H_ */