-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
402 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// Cruxcallable.h contains function definations that is overridden | ||
// by CruxFunction and Crux Class | ||
// | ||
// | ||
#pragma once | ||
|
||
#include "utls/Object.h" | ||
#include <string> | ||
#include <vector> | ||
|
||
class Interpreter; | ||
|
||
class CruxCallable { | ||
public: | ||
virtual int arity() = 0; | ||
virtual Object call(Interpreter *interpreter, std::vector<Object>) = 0; | ||
virtual std::string str() = 0; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#ifndef FUNCTION_H | ||
#define FUNCTION_H | ||
|
||
#include "CruxCallable.h" | ||
#include "Statement.h" | ||
|
||
class CruxFunction : public CruxCallable { | ||
public: | ||
Function *declaration; | ||
CruxFunction(Function *declaration); | ||
virtual int arity() override; | ||
virtual Object call(Interpreter *interpreter, std::vector<Object>) override; | ||
virtual std::string str() override; | ||
}; | ||
|
||
#endif // FUNCTION_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#pragma once | ||
|
||
#include "CruxCallable.h" | ||
#include <chrono> | ||
#include <string> | ||
#include <vector> | ||
class Interpreter; | ||
|
||
class ClockFunction : public CruxCallable { | ||
virtual int arity() override { return 0; } | ||
|
||
virtual Object call(Interpreter *interpreter, std::vector<Object>) override { | ||
auto millisec_since_epoch = | ||
std::chrono::duration_cast<std::chrono::milliseconds>( | ||
std::chrono::system_clock::now().time_since_epoch()) | ||
.count(); | ||
|
||
Object value((double)millisec_since_epoch / 1000.0); | ||
return value; | ||
} | ||
|
||
virtual std::string str() override { return "<native fn>"; } | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#include "utls/Object.h" | ||
|
||
struct ReturnValue { | ||
Object value; | ||
ReturnValue(Object value) : value(value){}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ set(Sources Error.cpp | |
AstPrinter.cpp | ||
Interpreter.cpp | ||
Statement.cpp | ||
Function.cpp | ||
env/Env.cpp | ||
) | ||
|
||
|
Oops, something went wrong.