Sleep function enabled.

functions
Justyna Ilczuk 2012-12-22 12:20:23 +01:00
parent b75236096e
commit c6e3678f15
1 changed files with 23 additions and 1 deletions

View File

@ -8,7 +8,9 @@
#include "Tests/TestLexer.h"
#include "Context.h"
#include "ASTInspector.h"
#include "Tests/tests.h"
#include "Tests/tests.h"
#include <unistd.h>
using namespace std;
@ -25,6 +27,24 @@ dupa"); declaration? hello? It's probably temporary effect of searching for this
>>
*/
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)
@ -130,6 +150,7 @@ void interactive()
context.register_function("sin", s_sin);
context.register_function("cos", s_cos);
context.register_function("tan", s_tan);
context.register_function("sleep", sleep);
Parser parser(&context);
ASTInspector inspector;
@ -188,6 +209,7 @@ int main(int argc, char *argv[])
context.register_function("sin", s_sin);
context.register_function("cos", s_cos);
context.register_function("tan", s_tan);
context.register_function("sleep", sleep);
Parser parser(&context);