Remove unnecessary type comparison in equation

This commit is contained in:
Jonathan Turner
2009-07-03 14:52:05 +00:00
parent bce2a1ffdb
commit 294d22ac5b
4 changed files with 21 additions and 27 deletions

View File

@@ -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)

View File

@@ -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()

View File

@@ -78,7 +78,6 @@ 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 { try {
if (lhs.is_unknown()) if (lhs.is_unknown())
{ {
@@ -98,10 +97,6 @@ namespace chaiscript
throw EvalError("Can not clone right hand side of equation", node->children[i+1]); throw EvalError("Can not clone right hand side of equation", node->children[i+1]);
} }
} }
else {
throw EvalError("Mismatched types in equation", node->children[i+1]);
}
}
else if (node->children[i+1]->text == ":=") { else 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)) { if (lhs.is_unknown() || dispatchkit::Bootstrap::type_match(lhs, retval)) {

View File

@@ -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\