Add chaiscript namespace
This commit is contained in:
parent
785263628b
commit
ae67be1ecd
@ -12,6 +12,9 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
|
namespace chaiscript
|
||||||
|
{
|
||||||
|
|
||||||
class TokenType { public: enum Type { File, Whitespace, Identifier, Integer, Operator, Parens_Open, Parens_Close,
|
class TokenType { public: enum Type { File, Whitespace, Identifier, Integer, Operator, Parens_Open, Parens_Close,
|
||||||
Square_Open, Square_Close, Curly_Open, Curly_Close, Comma, Quoted_String, Single_Quoted_String, Carriage_Return, Semicolon,
|
Square_Open, Square_Close, Curly_Open, Curly_Close, Comma, Quoted_String, Single_Quoted_String, Carriage_Return, Semicolon,
|
||||||
Function_Def, Lambda_Def, Scoped_Block, Statement, Equation, Return, Expression, Term, Factor, Negate, Not, Comment,
|
Function_Def, Lambda_Def, Scoped_Block, Statement, Equation, Return, Expression, Term, Factor, Negate, Not, Comment,
|
||||||
@ -27,6 +30,7 @@ const char *tokentype_to_string(int tokentype) {
|
|||||||
|
|
||||||
return token_types[tokentype];
|
return token_types[tokentype];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#include "dispatchkit.hpp"
|
#include "dispatchkit.hpp"
|
||||||
#include "bootstrap.hpp"
|
#include "bootstrap.hpp"
|
||||||
|
@ -6,8 +6,8 @@
|
|||||||
|
|
||||||
#include <exception>
|
#include <exception>
|
||||||
|
|
||||||
//A function that prints any string passed to it
|
namespace chaiscript
|
||||||
|
{
|
||||||
template <typename Eval_Engine>
|
template <typename Eval_Engine>
|
||||||
class ChaiScript_System {
|
class ChaiScript_System {
|
||||||
langkit::Lexer lexer;
|
langkit::Lexer lexer;
|
||||||
@ -268,6 +268,6 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
typedef ChaiScript_System<dispatchkit::Dispatch_Engine> ChaiScript_Engine;
|
typedef ChaiScript_System<dispatchkit::Dispatch_Engine> ChaiScript_Engine;
|
||||||
|
}
|
||||||
#endif /* CHAISCRIPT_ENGINE_HPP_ */
|
#endif /* CHAISCRIPT_ENGINE_HPP_ */
|
||||||
|
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
|
namespace chaiscript
|
||||||
|
{
|
||||||
struct ParserError {
|
struct ParserError {
|
||||||
std::string reason;
|
std::string reason;
|
||||||
langkit::TokenPtr location;
|
langkit::TokenPtr location;
|
||||||
@ -446,5 +448,5 @@ dispatchkit::Boxed_Value eval_token(Eval_System &ss, langkit::TokenPtr node) {
|
|||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#endif /* CHAISCRIPT_EVAL_HPP_ */
|
#endif /* CHAISCRIPT_EVAL_HPP_ */
|
||||||
|
@ -3,25 +3,27 @@
|
|||||||
#include "chaiscript.hpp"
|
#include "chaiscript.hpp"
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
using namespace dispatchkit;
|
|
||||||
|
|
||||||
std::string input;
|
std::string input;
|
||||||
|
|
||||||
ChaiScript_Engine chai;
|
chaiscript::ChaiScript_Engine chai;
|
||||||
|
|
||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
std::cout << "eval> ";
|
std::cout << "eval> ";
|
||||||
std::getline(std::cin, input);
|
std::getline(std::cin, input);
|
||||||
while (input != "quit") {
|
while (input != "quit") {
|
||||||
Boxed_Value val;
|
dispatchkit::Boxed_Value val;
|
||||||
|
|
||||||
val = chai.evaluate_string(input);
|
val = chai.evaluate_string(input);
|
||||||
|
|
||||||
if (val.get_type_info().m_bare_type_info && *(val.get_type_info().m_bare_type_info) != typeid(void)) {
|
if (val.get_type_info().m_bare_type_info && *(val.get_type_info().m_bare_type_info) != typeid(void)) {
|
||||||
try {
|
try {
|
||||||
Boxed_Value printeval = dispatch(chai.get_eval_engine().get_function("to_string"), Param_List_Builder() << val);
|
dispatchkit::Boxed_Value printeval
|
||||||
|
= dispatchkit::dispatch(chai.get_eval_engine().get_function("to_string"),
|
||||||
|
dispatchkit::Param_List_Builder() << val);
|
||||||
std::cout << "result: ";
|
std::cout << "result: ";
|
||||||
dispatch(chai.get_eval_engine().get_function("print"), Param_List_Builder() << printeval);
|
dispatchkit::dispatch(chai.get_eval_engine().get_function("print"),
|
||||||
|
dispatchkit::Param_List_Builder() << printeval);
|
||||||
} catch (const std::runtime_error &e) {
|
} catch (const std::runtime_error &e) {
|
||||||
std::cout << "result: object #" << &val << std::endl;
|
std::cout << "result: object #" << &val << std::endl;
|
||||||
}
|
}
|
||||||
@ -33,7 +35,7 @@ int main(int argc, char *argv[]) {
|
|||||||
else {
|
else {
|
||||||
for (int i = 1; i < argc; ++i) {
|
for (int i = 1; i < argc; ++i) {
|
||||||
try {
|
try {
|
||||||
Boxed_Value val = chai.evaluate_file(argv[i]);
|
dispatchkit::Boxed_Value val = chai.evaluate_file(argv[i]);
|
||||||
}
|
}
|
||||||
catch (std::exception &e) {
|
catch (std::exception &e) {
|
||||||
std::cerr << "Could not open: " << argv[i] << std::endl;
|
std::cerr << "Could not open: " << argv[i] << std::endl;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user