summaryrefslogtreecommitdiffstats
path: root/Sencha-lang/basic_native_functions.h
diff options
context:
space:
mode:
authorJustyna Ilczuk <justyna.ilczuk@gmail.com>2013-01-13 17:36:38 +0100
committerJustyna Ilczuk <justyna.ilczuk@gmail.com>2013-01-13 17:36:38 +0100
commit058a18c612c6d4f33779058b07ba80b3854f2275 (patch)
tree6fcb75fb0ba30fc6104e83863aa93f3e15375c1e /Sencha-lang/basic_native_functions.h
parent837d4c4bce813919f6713f76c7c24404951751f6 (diff)
downloadsencha-lang-master.tar.gz
sencha-lang-master.tar.bz2
sencha-lang-master.zip
More documentaaaaation.HEADmaster
Diffstat (limited to 'Sencha-lang/basic_native_functions.h')
-rw-r--r--Sencha-lang/basic_native_functions.h121
1 files changed, 121 insertions, 0 deletions
diff --git a/Sencha-lang/basic_native_functions.h b/Sencha-lang/basic_native_functions.h
new file mode 100644
index 0000000..37ac5e3
--- /dev/null
+++ b/Sencha-lang/basic_native_functions.h
@@ -0,0 +1,121 @@
+#include <iostream>
+#include <string>
+#include <vector>
+#include <math.h>
+#include "AST/AllTypesOfASTNodes.h"
+
+using namespace std;
+
+SenchaObject sleep(vector<ASTExpression *> arguments)
+{
+ SenchaObject argument = arguments[0]->evaluate();
+ if(argument.type == SenchaObject::integer_number && argument.integer >= 0)
+ {
+ cout << "valid argument for sleep: " << argument.integer << endl;
+ usleep(1000 * argument.integer);
+ return SenchaObject();
+ }
+ else
+ {
+ cout << "invalid argument for sleep";
+ argument.type = SenchaObject::invalid;
+ return argument;
+ }
+
+}
+
+SenchaObject print(vector<ASTExpression *> arguments)
+{
+ for (auto argument: arguments)
+ {
+ auto value = argument->evaluate();
+
+ std::cout << value.str();
+
+ }
+ return SenchaObject();
+}
+
+SenchaObject println(vector<ASTExpression *> arguments)
+{
+ for (auto argument: arguments)
+ {
+ auto value = argument->evaluate();
+
+ std::cout << value.str();
+
+ }
+ std::cout << std::endl;
+ return SenchaObject();
+}
+
+SenchaObject s_sin(vector<ASTExpression *> arguments)
+{
+ SenchaObject result;
+ SenchaObject sin_argument = arguments[0]->evaluate();
+ if(sin_argument.type == SenchaObject::integer_number)
+ {
+ result = SenchaObject(sin(sin_argument.integer));
+ }
+ else if(sin_argument.type == SenchaObject::float_number)
+ {
+ result = SenchaObject(sin(sin_argument.number));
+ }
+ else
+ {
+ result.type = SenchaObject::invalid;
+ }
+
+ return result;
+}
+
+SenchaObject s_cos(vector<ASTExpression *> arguments)
+{
+ SenchaObject result;
+ SenchaObject cos_argument = arguments[0]->evaluate();
+ if(cos_argument.type == SenchaObject::integer_number)
+ {
+ result = SenchaObject(cos(cos_argument.integer));
+ }
+ else if(cos_argument.type == SenchaObject::float_number)
+ {
+ result = SenchaObject(cos(cos_argument.number));
+ }
+ else
+ {
+ result.type = SenchaObject::invalid;
+ }
+
+ return result;
+}
+
+SenchaObject s_tan(vector<ASTExpression *> arguments)
+{
+ SenchaObject result;
+ SenchaObject tan_argument = arguments[0]->evaluate();
+ if(tan_argument.type == SenchaObject::integer_number)
+ {
+ result = SenchaObject(tan(tan_argument.integer));
+ }
+ else if(tan_argument.type == SenchaObject::float_number)
+ {
+ result = SenchaObject(tan(tan_argument.number));
+ }
+ else
+ {
+ result.type = SenchaObject::invalid;
+ }
+
+ return result;
+}
+
+SenchaObject len(vector<ASTExpression *> arguments)
+{
+ SenchaObject result;
+ SenchaObject argument = arguments[0]->evaluate();
+ if(argument.type == SenchaObject::string_literal)
+ {
+ result = SenchaObject(int(argument.text.size()));
+ }
+ return result;
+}