Remove unnecessary type comparison in equation
This commit is contained in:
@@ -8,10 +8,8 @@ SET (CMAKE_BUILD_TYPE gdb)
|
|||||||
SET (CMAKE_C_FLAGS_GDB " -Wall -ggdb")
|
SET (CMAKE_C_FLAGS_GDB " -Wall -ggdb")
|
||||||
SET (CMAKE_CXX_FLAGS_GDB " -Wall -ggdb")
|
SET (CMAKE_CXX_FLAGS_GDB " -Wall -ggdb")
|
||||||
|
|
||||||
include_directories(dispatchkit langkit)
|
include_directories(dispatchkit)
|
||||||
|
|
||||||
add_subdirectory(langkit bin)
|
|
||||||
add_subdirectory(dispatchkit bin)
|
add_subdirectory(dispatchkit bin)
|
||||||
add_subdirectory(chaiscript bin)
|
add_subdirectory(chaiscript bin)
|
||||||
add_subdirectory(chaioop bin)
|
|
||||||
|
|
||||||
|
@@ -10,7 +10,7 @@ SET (CMAKE_CXX_FLAGS_GDB " -Wall -ggdb")
|
|||||||
find_package(Boost 1.36.0 COMPONENTS regex unit_test_framework)
|
find_package(Boost 1.36.0 COMPONENTS regex unit_test_framework)
|
||||||
if(Boost_FOUND)
|
if(Boost_FOUND)
|
||||||
include_directories(${Boost_INCLUDE_DIRS})
|
include_directories(${Boost_INCLUDE_DIRS})
|
||||||
include_directories(../langkit ../dispatchkit)
|
include_directories(../dispatchkit)
|
||||||
|
|
||||||
add_executable(chaiscript_test main.cpp)
|
add_executable(chaiscript_test main.cpp)
|
||||||
target_link_libraries(chaiscript_test ${Boost_LIBRARIES})
|
target_link_libraries(chaiscript_test ${Boost_LIBRARIES})
|
||||||
@@ -25,3 +25,4 @@ if(Boost_FOUND)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
|
@@ -78,28 +78,23 @@ namespace chaiscript
|
|||||||
for (i = node->children.size()-3; ((int)i) >= 0; i -= 2) {
|
for (i = node->children.size()-3; ((int)i) >= 0; i -= 2) {
|
||||||
if (node->children[i+1]->text == "=") {
|
if (node->children[i+1]->text == "=") {
|
||||||
dispatchkit::Boxed_Value lhs = eval_token(ss, node->children[i]);
|
dispatchkit::Boxed_Value lhs = eval_token(ss, node->children[i]);
|
||||||
if (lhs.is_unknown() || dispatchkit::Bootstrap::type_match(lhs, retval)) {
|
try {
|
||||||
|
if (lhs.is_unknown())
|
||||||
|
{
|
||||||
|
retval = dispatch(ss.get_function("clone"), dispatchkit::Param_List_Builder() << retval);
|
||||||
|
}
|
||||||
|
dispatchkit::Param_List_Builder plb;
|
||||||
|
plb << lhs;
|
||||||
|
plb << retval;
|
||||||
try {
|
try {
|
||||||
if (lhs.is_unknown())
|
retval = dispatch(ss.get_function(node->children[i+1]->text), plb);
|
||||||
{
|
|
||||||
retval = dispatch(ss.get_function("clone"), dispatchkit::Param_List_Builder() << retval);
|
|
||||||
}
|
|
||||||
dispatchkit::Param_List_Builder plb;
|
|
||||||
plb << lhs;
|
|
||||||
plb << retval;
|
|
||||||
try {
|
|
||||||
retval = dispatch(ss.get_function(node->children[i+1]->text), plb);
|
|
||||||
}
|
|
||||||
catch(const dispatchkit::dispatch_error &e){
|
|
||||||
throw EvalError("Can not find appropriate '" + node->children[i+1]->text + "'", node->children[i+1]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch(const dispatchkit::dispatch_error &e){
|
catch(const dispatchkit::dispatch_error &e){
|
||||||
throw EvalError("Can not clone right hand side of equation", node->children[i+1]);
|
throw EvalError("Can not find appropriate '" + node->children[i+1]->text + "'", node->children[i+1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
catch(const dispatchkit::dispatch_error &e){
|
||||||
throw EvalError("Mismatched types in equation", node->children[i+1]);
|
throw EvalError("Can not clone right hand side of equation", node->children[i+1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (node->children[i+1]->text == ":=") {
|
else if (node->children[i+1]->text == ":=") {
|
||||||
|
@@ -20,6 +20,8 @@ def puts(x) { \n\
|
|||||||
def print(x) { \n\
|
def print(x) { \n\
|
||||||
println_string(x.to_string()) \n\
|
println_string(x.to_string()) \n\
|
||||||
}; \n\
|
}; \n\
|
||||||
|
def max(a, b) { if (a>b) { a } else { b } } \n\
|
||||||
|
def min(a, b) { if (a<b) { a } else { b } } \n\
|
||||||
def for_each(container, func) : call_exists(range, container) { \n\
|
def for_each(container, func) : call_exists(range, container) { \n\
|
||||||
var range = range(container); \n\
|
var range = range(container); \n\
|
||||||
while (!range.empty()) { \n\
|
while (!range.empty()) { \n\
|
||||||
@@ -45,8 +47,8 @@ def foldl(container, func, initial) : call_exists(range, container){ \n\
|
|||||||
} \n\
|
} \n\
|
||||||
retval \n\
|
retval \n\
|
||||||
} \n\
|
} \n\
|
||||||
def sum(x) { foldl(x, `+`, 0) } \n\
|
def sum(container) { foldl(container, `+`, 0) } \n\
|
||||||
def product(x) { foldl(x, `*`, 1) } \n\
|
def product(container) { foldl(container, `*`, 1) } \n\
|
||||||
def take(container, num) : call_exists(range, container) { \n\
|
def take(container, num) : call_exists(range, container) { \n\
|
||||||
var r = range(container); \n\
|
var r = range(container); \n\
|
||||||
var i = num; \n\
|
var i = num; \n\
|
||||||
@@ -105,8 +107,6 @@ def reduce(container, func) : container.size() >= 2 && call_exists(range, contai
|
|||||||
} \n\
|
} \n\
|
||||||
retval \n\
|
retval \n\
|
||||||
} \n\
|
} \n\
|
||||||
def max(a, b) { if (a>b) { a } else { b } } \n\
|
|
||||||
def min(a, b) { if (a<b) { a } else { b } } \n\
|
|
||||||
def join(container, delim) { \n\
|
def join(container, delim) { \n\
|
||||||
var retval = \"\" \n\
|
var retval = \"\" \n\
|
||||||
var range = range(container) \n\
|
var range = range(container) \n\
|
||||||
@@ -121,9 +121,9 @@ def join(container, delim) { \n\
|
|||||||
} \n\
|
} \n\
|
||||||
retval \n\
|
retval \n\
|
||||||
} \n\
|
} \n\
|
||||||
def filter(a, f) : call_exists(range, a) { \n\
|
def filter(container, f) : call_exists(range, container) { \n\
|
||||||
var retval = Vector(); \n\
|
var retval = Vector(); \n\
|
||||||
var r = range(a); \n\
|
var r = range(container); \n\
|
||||||
while (!r.empty()) { \n\
|
while (!r.empty()) { \n\
|
||||||
if (f(r.front())) { \n\
|
if (f(r.front())) { \n\
|
||||||
retval.push_back(r.front()); \n\
|
retval.push_back(r.front()); \n\
|
||||||
|
Reference in New Issue
Block a user