summaryrefslogtreecommitdiffstats
path: root/Sencha-lang/basic_native_functions.h
blob: 37ac5e32ebe51fad4d28ca6be3e3b3901309e3ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
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;
}