Compare commits
17 Commits
attempt_gl
...
v5.8.6
Author | SHA1 | Date | |
---|---|---|---|
![]() |
2c99e6cd32 | ||
![]() |
a38b254a98 | ||
![]() |
77231461ca | ||
![]() |
0d4a99af82 | ||
![]() |
9f30d84f39 | ||
![]() |
508729ec77 | ||
![]() |
ab07872857 | ||
![]() |
23c13e6570 | ||
![]() |
7339ff2c2f | ||
![]() |
665125665a | ||
![]() |
d1c7645a4e | ||
![]() |
58faea1cf2 | ||
![]() |
8b7fe33bf1 | ||
![]() |
21495ebb40 | ||
![]() |
bec1b91b7b | ||
![]() |
4b81a24a0a | ||
![]() |
cefb4d3c78 |
@@ -1,12 +1,12 @@
|
|||||||
compilers:
|
compilers:
|
||||||
- name: "clang"
|
- name: "clang"
|
||||||
version: "3.6"
|
version: "3.5"
|
||||||
skip_packaging: true
|
skip_packaging: true
|
||||||
cmake_extra_flags: -DUSE_LIBCXX:BOOL=OFF -DBUILD_SAMPLES:BOOL=ON -DBUILD_PACKAGE:BOOL=ON -DBUILD_TESTING:BOOL=ON -DRUN_PERFORMANCE_TESTS:BOOL=ON
|
cmake_extra_flags: -DUSE_LIBCXX:BOOL=OFF -DBUILD_SAMPLES:BOOL=ON -DBUILD_PACKAGE:BOOL=ON -DBUILD_TESTING:BOOL=ON -DRUN_PERFORMANCE_TESTS:BOOL=ON
|
||||||
collect_performance_results: true
|
collect_performance_results: true
|
||||||
- name: "clang"
|
- name: "clang"
|
||||||
build_tag: "LibC++"
|
build_tag: "LibC++"
|
||||||
version: "3.6"
|
version: "3.5"
|
||||||
skip_packaging: true
|
skip_packaging: true
|
||||||
cmake_extra_flags: -DUSE_LIBCXX:BOOL=ON -DBUILD_SAMPLES:BOOL=ON -DBUILD_PACKAGE:BOOL=ON -DBUILD_TESTING:BOOL=ON
|
cmake_extra_flags: -DUSE_LIBCXX:BOOL=ON -DBUILD_SAMPLES:BOOL=ON -DBUILD_PACKAGE:BOOL=ON -DBUILD_TESTING:BOOL=ON
|
||||||
- name: "clang"
|
- name: "clang"
|
||||||
@@ -19,28 +19,17 @@ compilers:
|
|||||||
version: "3.6"
|
version: "3.6"
|
||||||
skip_packaging: true
|
skip_packaging: true
|
||||||
cmake_extra_flags: -DUSE_LIBCXX:BOOL=OFF -DBUILD_SAMPLES:BOOL=ON -DBUILD_PACKAGE:BOOL=ON -DBUILD_TESTING:BOOL=ON -DENABLE_THREAD_SANITIZER:BOOL=ON
|
cmake_extra_flags: -DUSE_LIBCXX:BOOL=OFF -DBUILD_SAMPLES:BOOL=ON -DBUILD_PACKAGE:BOOL=ON -DBUILD_TESTING:BOOL=ON -DENABLE_THREAD_SANITIZER:BOOL=ON
|
||||||
- name: "clang"
|
|
||||||
version: "3.7"
|
|
||||||
skip_packaging: true
|
|
||||||
cmake_extra_flags: -DUSE_LIBCXX:BOOL=OFF -DBUILD_SAMPLES:BOOL=ON -DBUILD_PACKAGE:BOOL=ON -DBUILD_TESTING:BOOL=ON -DRUN_PERFORMANCE_TESTS:BOOL=ON
|
|
||||||
collect_performance_results: true
|
|
||||||
- name: "clang"
|
|
||||||
build_tag: "LibC++"
|
|
||||||
version: "3.7"
|
|
||||||
skip_packaging: true
|
|
||||||
cmake_extra_flags: -DUSE_LIBCXX:BOOL=ON -DBUILD_SAMPLES:BOOL=ON -DBUILD_PACKAGE:BOOL=ON -DBUILD_TESTING:BOOL=ON
|
|
||||||
- name: "gcc"
|
- name: "gcc"
|
||||||
version: "4.9"
|
version: "4.8"
|
||||||
cmake_extra_flags: -DBUILD_PACKAGE:BOOL=ON -DBUILD_TESTING:BOOL=ON -DBUILD_TESTING:BOOL=ON -DRUN_PERFORMANCE_TESTS:BOOL=ON
|
|
||||||
collect_performance_results: true
|
|
||||||
- name: "gcc"
|
|
||||||
version: "4.9"
|
|
||||||
skip_packaging: true
|
|
||||||
build_tag: "NoThreads"
|
build_tag: "NoThreads"
|
||||||
cmake_extra_flags: -DBUILD_PACKAGE:BOOL=ON -DBUILD_TESTING:BOOL=ON -DBUILD_TESTING:BOOL=ON -DRUN_PERFORMANCE_TESTS:BOOL=ON -DMULTITHREAD_SUPPORT_ENABLED:BOOL=OFF
|
cmake_extra_flags: -DBUILD_PACKAGE:BOOL=ON -DBUILD_TESTING:BOOL=ON -DBUILD_TESTING:BOOL=ON -DRUN_PERFORMANCE_TESTS:BOOL=ON -DMULTITHREAD_SUPPORT_ENABLED:BOOL=OFF
|
||||||
collect_performance_results: true
|
collect_performance_results: true
|
||||||
- name: "gcc"
|
- name: "gcc"
|
||||||
version: "5"
|
version: "4.8"
|
||||||
|
cmake_extra_flags: -DBUILD_PACKAGE:BOOL=ON -DBUILD_TESTING:BOOL=ON -DBUILD_TESTING:BOOL=ON -DRUN_PERFORMANCE_TESTS:BOOL=ON
|
||||||
|
collect_performance_results: true
|
||||||
|
- name: "gcc"
|
||||||
|
version: "4.6"
|
||||||
skip_packaging: true
|
skip_packaging: true
|
||||||
cmake_extra_flags: -DBUILD_SAMPLES:BOOL=ON -DBUILD_PACKAGE:BOOL=ON -DBUILD_TESTING:BOOL=ON -DRUN_PERFORMANCE_TESTS:BOOL=ON
|
cmake_extra_flags: -DBUILD_SAMPLES:BOOL=ON -DBUILD_PACKAGE:BOOL=ON -DBUILD_TESTING:BOOL=ON -DRUN_PERFORMANCE_TESTS:BOOL=ON
|
||||||
collect_performance_results: true
|
collect_performance_results: true
|
||||||
|
@@ -10,6 +10,13 @@ compilers:
|
|||||||
cmake_extra_flags: -DBUILD_SAMPLES:BOOL=ON -DBUILD_PACKAGE:BOOL=ON -DBUILD_TESTING:BOOL=ON -DCOMMIT_SHA=%COMMIT_SHA%
|
cmake_extra_flags: -DBUILD_SAMPLES:BOOL=ON -DBUILD_PACKAGE:BOOL=ON -DBUILD_TESTING:BOOL=ON -DCOMMIT_SHA=%COMMIT_SHA%
|
||||||
compiler_extra_flags: /analyze
|
compiler_extra_flags: /analyze
|
||||||
skip_packaging: true
|
skip_packaging: true
|
||||||
|
- name: Visual Studio
|
||||||
|
version: 12
|
||||||
|
cmake_extra_flags: -DBUILD_SAMPLES:BOOL=ON -DBUILD_PACKAGE:BOOL=ON -DBUILD_TESTING:BOOL=ON -DCOMMIT_SHA=%COMMIT_SHA%
|
||||||
|
- name: Visual Studio
|
||||||
|
version: 12
|
||||||
|
architecture: Win64
|
||||||
|
cmake_extra_flags: -DBUILD_SAMPLES:BOOL=ON -DBUILD_PACKAGE:BOOL=ON -DBUILD_TESTING:BOOL=ON -DCOMMIT_SHA=%COMMIT_SHA%
|
||||||
- name: Visual Studio
|
- name: Visual Studio
|
||||||
version: 14
|
version: 14
|
||||||
build_type: Debug
|
build_type: Debug
|
||||||
@@ -18,4 +25,3 @@ compilers:
|
|||||||
compiler_extra_flags: /analyze
|
compiler_extra_flags: /analyze
|
||||||
skip_packaging: true
|
skip_packaging: true
|
||||||
|
|
||||||
|
|
||||||
|
@@ -3,8 +3,8 @@ compiler:
|
|||||||
- gcc
|
- gcc
|
||||||
env:
|
env:
|
||||||
matrix:
|
matrix:
|
||||||
- GCC_VER="4.9"
|
- GCC_VER="4.6"
|
||||||
- GCC_VER="5"
|
- GCC_VER="4.8"
|
||||||
|
|
||||||
global:
|
global:
|
||||||
- secure: eiaR6pXiiEpyB8+LLQ1NvZdl0Yylru1BLy9lMoHl+IpUNGGQGywmW/2WAn77rFfmR1OPA2qWQLfgPwgK0HxUA9HHlot9tre5QhiN2Lw8NOT8tCZ6tTm2+QntDBjBGJyal/knRvQkn/6qs6GxlXRerz4ArnnuPL1vESt3zwB0YtU=
|
- secure: eiaR6pXiiEpyB8+LLQ1NvZdl0Yylru1BLy9lMoHl+IpUNGGQGywmW/2WAn77rFfmR1OPA2qWQLfgPwgK0HxUA9HHlot9tre5QhiN2Lw8NOT8tCZ6tTm2+QntDBjBGJyal/knRvQkn/6qs6GxlXRerz4ArnnuPL1vESt3zwB0YtU=
|
||||||
@@ -13,7 +13,7 @@ env:
|
|||||||
|
|
||||||
before_install:
|
before_install:
|
||||||
- export CXX="g++-$GCC_VER" CC="gcc-$GCC_VER" GCOV="gcov-$GCC_VER"
|
- export CXX="g++-$GCC_VER" CC="gcc-$GCC_VER" GCOV="gcov-$GCC_VER"
|
||||||
- if [ "$GCC_VER" = "5" ]; then export COVERAGE=1 CPPCHECK=1; fi
|
- if [ "$GCC_VER" = "4.8" ]; then export COVERAGE=1 CPPCHECK=1; fi
|
||||||
- if [ ${COVERAGE} = 1 ]; then export FUZZY_CMD="-D RUN_FUZZY_TESTS:BOOL=TRUE"; fi
|
- if [ ${COVERAGE} = 1 ]; then export FUZZY_CMD="-D RUN_FUZZY_TESTS:BOOL=TRUE"; fi
|
||||||
- sudo pip install cpp-coveralls
|
- sudo pip install cpp-coveralls
|
||||||
- sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
|
- sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
|
||||||
|
@@ -101,9 +101,9 @@ set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/license.txt")
|
|||||||
set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/readme.md")
|
set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/readme.md")
|
||||||
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/description.txt")
|
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/description.txt")
|
||||||
|
|
||||||
set(CPACK_PACKAGE_VERSION_MAJOR 6)
|
set(CPACK_PACKAGE_VERSION_MAJOR 5)
|
||||||
set(CPACK_PACKAGE_VERSION_MINOR 0)
|
set(CPACK_PACKAGE_VERSION_MINOR 8)
|
||||||
set(CPACK_PACKAGE_VERSION_PATCH 0)
|
set(CPACK_PACKAGE_VERSION_PATCH 6)
|
||||||
|
|
||||||
set(CPACK_PACKAGE_EXECUTABLES "chai;ChaiScript Eval")
|
set(CPACK_PACKAGE_EXECUTABLES "chai;ChaiScript Eval")
|
||||||
set(CPACK_PACKAGE_VENDOR "ChaiScript.com")
|
set(CPACK_PACKAGE_VENDOR "ChaiScript.com")
|
||||||
@@ -148,13 +148,13 @@ endif()
|
|||||||
if(CMAKE_COMPILER_IS_GNUCC)
|
if(CMAKE_COMPILER_IS_GNUCC)
|
||||||
execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
|
execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
|
||||||
|
|
||||||
if(GCC_VERSION VERSION_LESS 4.9)
|
if(GCC_VERSION VERSION_LESS 4.8)
|
||||||
set(CPP11_FLAG "-std=c++1y")
|
set(CPP11_FLAG "-std=c++0x")
|
||||||
else()
|
else()
|
||||||
set(CPP11_FLAG "-std=c++14")
|
set(CPP11_FLAG "-std=c++11")
|
||||||
endif()
|
endif()
|
||||||
else()
|
else()
|
||||||
set(CPP11_FLAG "-std=c++14")
|
set(CPP11_FLAG "-std=c++11")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(MSVC)
|
if(MSVC)
|
||||||
@@ -213,7 +213,7 @@ endif()
|
|||||||
include_directories(include)
|
include_directories(include)
|
||||||
|
|
||||||
|
|
||||||
set(Chai_INCLUDES include/chaiscript/chaiscript.hpp include/chaiscript/chaiscript_threading.hpp include/chaiscript/dispatchkit/bad_boxed_cast.hpp include/chaiscript/dispatchkit/bind_first.hpp include/chaiscript/dispatchkit/bootstrap.hpp include/chaiscript/dispatchkit/bootstrap_stl.hpp include/chaiscript/dispatchkit/boxed_cast.hpp include/chaiscript/dispatchkit/boxed_cast_helper.hpp include/chaiscript/dispatchkit/boxed_number.hpp include/chaiscript/dispatchkit/boxed_value.hpp include/chaiscript/dispatchkit/dispatchkit.hpp include/chaiscript/dispatchkit/type_conversions.hpp include/chaiscript/dispatchkit/dynamic_object.hpp include/chaiscript/dispatchkit/exception_specification.hpp include/chaiscript/dispatchkit/function_call.hpp include/chaiscript/dispatchkit/function_call_detail.hpp include/chaiscript/dispatchkit/handle_return.hpp include/chaiscript/dispatchkit/operators.hpp include/chaiscript/dispatchkit/proxy_constructors.hpp include/chaiscript/dispatchkit/proxy_functions.hpp include/chaiscript/dispatchkit/proxy_functions_detail.hpp include/chaiscript/dispatchkit/register_function.hpp include/chaiscript/dispatchkit/type_info.hpp include/chaiscript/language/chaiscript_algebraic.hpp include/chaiscript/language/chaiscript_common.hpp include/chaiscript/language/chaiscript_engine.hpp include/chaiscript/language/chaiscript_eval.hpp include/chaiscript/language/chaiscript_parser.hpp include/chaiscript/language/chaiscript_prelude.hpp include/chaiscript/language/chaiscript_prelude_docs.hpp include/chaiscript/utility/utility.hpp include/chaiscript/utility/json.hpp include/chaiscript/utility/json_wrap.hpp)
|
set(Chai_INCLUDES include/chaiscript/chaiscript.hpp include/chaiscript/chaiscript_threading.hpp include/chaiscript/dispatchkit/bad_boxed_cast.hpp include/chaiscript/dispatchkit/bind_first.hpp include/chaiscript/dispatchkit/bootstrap.hpp include/chaiscript/dispatchkit/bootstrap_stl.hpp include/chaiscript/dispatchkit/boxed_cast.hpp include/chaiscript/dispatchkit/boxed_cast_helper.hpp include/chaiscript/dispatchkit/boxed_number.hpp include/chaiscript/dispatchkit/boxed_value.hpp include/chaiscript/dispatchkit/dispatchkit.hpp include/chaiscript/dispatchkit/type_conversions.hpp include/chaiscript/dispatchkit/dynamic_object.hpp include/chaiscript/dispatchkit/exception_specification.hpp include/chaiscript/dispatchkit/function_call.hpp include/chaiscript/dispatchkit/function_call_detail.hpp include/chaiscript/dispatchkit/handle_return.hpp include/chaiscript/dispatchkit/operators.hpp include/chaiscript/dispatchkit/proxy_constructors.hpp include/chaiscript/dispatchkit/proxy_functions.hpp include/chaiscript/dispatchkit/proxy_functions_detail.hpp include/chaiscript/dispatchkit/register_function.hpp include/chaiscript/dispatchkit/type_info.hpp include/chaiscript/language/chaiscript_algebraic.hpp include/chaiscript/language/chaiscript_common.hpp include/chaiscript/language/chaiscript_engine.hpp include/chaiscript/language/chaiscript_eval.hpp include/chaiscript/language/chaiscript_parser.hpp include/chaiscript/language/chaiscript_prelude.chai include/chaiscript/language/chaiscript_prelude_docs.hpp include/chaiscript/utility/utility.hpp include/chaiscript/utility/json.hpp include/chaiscript/utility/json_wrap.hpp)
|
||||||
|
|
||||||
set_source_files_properties(${Chai_INCLUDES} PROPERTIES HEADER_FILE_ONLY TRUE)
|
set_source_files_properties(${Chai_INCLUDES} PROPERTIES HEADER_FILE_ONLY TRUE)
|
||||||
|
|
||||||
@@ -274,9 +274,6 @@ endif()
|
|||||||
|
|
||||||
|
|
||||||
if(BUILD_MODULES)
|
if(BUILD_MODULES)
|
||||||
add_library(test_module MODULE src/test_module.cpp)
|
|
||||||
target_link_libraries(test_module ${LIBS})
|
|
||||||
|
|
||||||
add_library(stl_extra MODULE src/stl_extra.cpp)
|
add_library(stl_extra MODULE src/stl_extra.cpp)
|
||||||
target_link_libraries(stl_extra ${LIBS})
|
target_link_libraries(stl_extra ${LIBS})
|
||||||
|
|
||||||
@@ -462,6 +459,9 @@ if(BUILD_TESTING)
|
|||||||
target_link_libraries(multifile_test ${LIBS})
|
target_link_libraries(multifile_test ${LIBS})
|
||||||
add_test(NAME MultiFile_Test COMMAND multifile_test)
|
add_test(NAME MultiFile_Test COMMAND multifile_test)
|
||||||
|
|
||||||
|
add_library(test_module MODULE src/test_module.cpp)
|
||||||
|
target_link_libraries(test_module ${LIBS})
|
||||||
|
|
||||||
install(TARGETS test_module RUNTIME DESTINATION bin LIBRARY DESTINATION lib/chaiscript)
|
install(TARGETS test_module RUNTIME DESTINATION bin LIBRARY DESTINATION lib/chaiscript)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
version: 5.8.x.{build}
|
version: 5.7.2.{build}
|
||||||
os: Visual Studio 2015
|
os: Visual Studio 2015
|
||||||
environment:
|
environment:
|
||||||
matrix:
|
matrix:
|
||||||
@@ -14,9 +14,3 @@ build_script:
|
|||||||
cmake --build . --config Debug
|
cmake --build . --config Debug
|
||||||
test_script:
|
test_script:
|
||||||
- cmd: ctest -C Debug
|
- cmd: ctest -C Debug
|
||||||
notifications:
|
|
||||||
- provider: Webhook
|
|
||||||
url: https://webhooks.gitter.im/e/9ff725a985b5679d1d5d
|
|
||||||
on_build_success: true
|
|
||||||
on_build_failure: true
|
|
||||||
on_build_status_changed: false
|
|
||||||
|
@@ -84,6 +84,33 @@ chai.add(chaiscript::user_type<MyClass>(), "MyClass");
|
|||||||
|
|
||||||
User defined type conversions are possible, defined in either script or in C++.
|
User defined type conversions are possible, defined in either script or in C++.
|
||||||
|
|
||||||
|
|
||||||
|
### ChaiScript Defined Conversions
|
||||||
|
|
||||||
|
Function objects (including lambdas) can be used to add type conversions
|
||||||
|
from inside of ChaiScript:
|
||||||
|
|
||||||
|
```
|
||||||
|
add_type_conversion(type("string"), type("Type_Info"), fun(s) { return type(s); });
|
||||||
|
```
|
||||||
|
|
||||||
|
### C++ Defined Conversions
|
||||||
|
|
||||||
|
Invoking a C++ type conversion possible with `static_cast`
|
||||||
|
|
||||||
|
```
|
||||||
|
chai.add(chaiscript::type_conversion<T, bool>());
|
||||||
|
```
|
||||||
|
|
||||||
|
Calling a user defined type conversion that takes a lambda
|
||||||
|
|
||||||
|
```
|
||||||
|
chai.add(chaiscript::type_conversion<TestBaseType, Type2>([](const TestBaseType &t_bt) { /* return converted thing */ }));
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
### Helpers
|
||||||
|
|
||||||
A helper function exists for strongly typed and ChaiScript `Vector` function conversion definition:
|
A helper function exists for strongly typed and ChaiScript `Vector` function conversion definition:
|
||||||
|
|
||||||
```
|
```
|
||||||
@@ -97,6 +124,7 @@ chai.add(chaiscript::map_conversion<std::map<std::string, int>>());
|
|||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
This allows you to pass a ChaiScript function to a function requiring `std::vector<int>`
|
This allows you to pass a ChaiScript function to a function requiring `std::vector<int>`
|
||||||
|
|
||||||
## Adding Objects
|
## Adding Objects
|
||||||
|
@@ -1,61 +0,0 @@
|
|||||||
# My dict
|
|
||||||
|
|
||||||
|
|
||||||
for="for"
|
|
||||||
while="while"
|
|
||||||
def="def"
|
|
||||||
fun="fun"
|
|
||||||
if="if"
|
|
||||||
else="else"
|
|
||||||
and="&&"
|
|
||||||
or="||"
|
|
||||||
auto="auto"
|
|
||||||
var="var"
|
|
||||||
begin_block="{"
|
|
||||||
end_block="}"
|
|
||||||
empty_vec="[]"
|
|
||||||
string="string"
|
|
||||||
vector="Vector"
|
|
||||||
map="Map"
|
|
||||||
return="return"
|
|
||||||
break="break"
|
|
||||||
true="true"
|
|
||||||
false="false"
|
|
||||||
class="class"
|
|
||||||
attr="attr"
|
|
||||||
var="var"
|
|
||||||
global="global"
|
|
||||||
empty_lambda=" fun(){} "
|
|
||||||
empty_fun=" def empty_fun() {} "
|
|
||||||
continue="continue"
|
|
||||||
float=" 1.1f "
|
|
||||||
double=" 2.2 "
|
|
||||||
long_double=" 2.2ll "
|
|
||||||
unsigned=" 3u "
|
|
||||||
unsigned_long=" 4ul "
|
|
||||||
unsigned_long_long=" 4ull "
|
|
||||||
long_long=" 5ll "
|
|
||||||
attr="attr"
|
|
||||||
reference_del="auto &"
|
|
||||||
int8=" int8_t(1) "
|
|
||||||
int16=" int16_t(2) "
|
|
||||||
int32=" int32_t(3) "
|
|
||||||
int64=" int64_t(4) "
|
|
||||||
uint8=" uint8_t(1) "
|
|
||||||
uint16=" uint16_t(2) "
|
|
||||||
uint32=" uint32_t(3) "
|
|
||||||
uint64=" uint64_t(4) "
|
|
||||||
int8t="int8_t"
|
|
||||||
int16t="int16_t"
|
|
||||||
int32t="int32_t"
|
|
||||||
int64t="int64_t"
|
|
||||||
uint8t="uint8_t"
|
|
||||||
uint16t="uint16_t"
|
|
||||||
uint32t="uint32_t"
|
|
||||||
uint64t="uint64_t"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@@ -1,17 +0,0 @@
|
|||||||
Command line used to find this crash:
|
|
||||||
|
|
||||||
../../Downloads/afl-1.80b/afl-fuzz -i- -o findings -x chaiscript.dict -- ../a.out unit_test.inc @@
|
|
||||||
|
|
||||||
If you can't reproduce a bug outside of afl-fuzz, be sure to set the same
|
|
||||||
memory limit. The limit used for this fuzzing session was 50.0 MB.
|
|
||||||
|
|
||||||
Need a tool to minimize test cases before investigating the crashes or sending
|
|
||||||
them to a vendor? Check out the afl-tmin that comes with the fuzzer!
|
|
||||||
|
|
||||||
Found any cool bugs in open-source tools using afl-fuzz? If yes, please drop
|
|
||||||
me a mail at <lcamtuf@coredump.cx> once the issues are fixed - I'd love to
|
|
||||||
add your finds to the gallery at:
|
|
||||||
|
|
||||||
http://lcamtuf.coredump.cx/afl/
|
|
||||||
|
|
||||||
Thanks :-)
|
|
@@ -1,5 +0,0 @@
|
|||||||
def greet {
|
|
||||||
return("hello")
|
|
||||||
}
|
|
||||||
|
|
||||||
fun(){ "world" }
|
|
@@ -695,10 +695,11 @@
|
|||||||
/// Begins a function or method definition
|
/// Begins a function or method definition
|
||||||
///
|
///
|
||||||
/// ~~~~~~~~
|
/// ~~~~~~~~
|
||||||
/// Function Definition ::= "def" identifier "(" [[type] arg ("," [type] arg)*] ")" [":" guard] block
|
/// Function Definition ::= [annotation + CR/LF] "def" identifier "(" [[type] arg ("," [type] arg)*] ")" [":" guard] block
|
||||||
/// Method Definition ::= "def" class_name "::" method_name "(" [[type] arg ("," [type] arg)*] ")" [":" guard] block
|
/// Method Definition ::= [annotation + CR/LF] "def" class_name "::" method_name "(" [[type] arg ("," [type] arg)*] ")" [":" guard] block
|
||||||
/// ~~~~~~~~
|
/// ~~~~~~~~
|
||||||
///
|
///
|
||||||
|
/// annotation: meta-annotation on function, currently used as documentation. Optional.
|
||||||
/// identifier: name of function. Required.
|
/// identifier: name of function. Required.
|
||||||
/// args: comma-delimited list of parameter names with optional type specifiers. Optional.
|
/// args: comma-delimited list of parameter names with optional type specifiers. Optional.
|
||||||
/// guards: guarding statement that act as a prerequisite for the function. Optional.
|
/// guards: guarding statement that act as a prerequisite for the function. Optional.
|
||||||
|
@@ -12,10 +12,17 @@
|
|||||||
#define CHAISCRIPT_COMPILER_VERSION CHAISCRIPT_STRINGIZE(_MSC_FULL_VER)
|
#define CHAISCRIPT_COMPILER_VERSION CHAISCRIPT_STRINGIZE(_MSC_FULL_VER)
|
||||||
#define CHAISCRIPT_MSVC _MSC_VER
|
#define CHAISCRIPT_MSVC _MSC_VER
|
||||||
#define CHAISCRIPT_HAS_DECLSPEC
|
#define CHAISCRIPT_HAS_DECLSPEC
|
||||||
|
#if _MSC_VER <= 1800
|
||||||
|
#define CHAISCRIPT_MSVC_12
|
||||||
|
#endif
|
||||||
#else
|
#else
|
||||||
#define CHAISCRIPT_COMPILER_VERSION __VERSION__
|
#define CHAISCRIPT_COMPILER_VERSION __VERSION__
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef CHAISCRIPT_MSVC_12
|
||||||
|
#define CHAISCRIPT_HAS_MAGIC_STATICS
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#if defined( _LIBCPP_VERSION )
|
#if defined( _LIBCPP_VERSION )
|
||||||
@@ -44,15 +51,26 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(CHAISCRIPT_MSVC) || (defined(__GNUC__) && __GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) || (defined(__llvm__) && !defined(CHAISCRIPT_LIBCPP))
|
#if (defined(CHAISCRIPT_MSVC) && !defined(CHAISCRIPT_MSVC_12)) || (defined(__GNUC__) && __GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) || (defined(__llvm__) && !defined(CHAISCRIPT_LIBCPP))
|
||||||
|
/// Currently only g++>=4.8 supports this natively
|
||||||
/// \todo Make this support other compilers when possible
|
/// \todo Make this support other compilers when possible
|
||||||
#define CHAISCRIPT_HAS_THREAD_LOCAL
|
#define CHAISCRIPT_HAS_THREAD_LOCAL
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if (defined(__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ == 6)
|
||||||
|
#define CHAISCRIPT_GCC_4_6
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(__llvm__)
|
#if defined(__llvm__)
|
||||||
#define CHAISCRIPT_CLANG
|
#define CHAISCRIPT_CLANG
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if (defined(__GNUC__) && __GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7) || defined(CHAISCRIPT_MSVC) || defined(CHAISCRIPT_CLANG)
|
||||||
|
#define CHAISCRIPT_OVERRIDE override
|
||||||
|
#else
|
||||||
|
#define CHAISCRIPT_OVERRIDE
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifdef CHAISCRIPT_HAS_DECLSPEC
|
#ifdef CHAISCRIPT_HAS_DECLSPEC
|
||||||
#define CHAISCRIPT_MODULE_EXPORT extern "C" __declspec(dllexport)
|
#define CHAISCRIPT_MODULE_EXPORT extern "C" __declspec(dllexport)
|
||||||
@@ -60,6 +78,14 @@
|
|||||||
#define CHAISCRIPT_MODULE_EXPORT extern "C"
|
#define CHAISCRIPT_MODULE_EXPORT extern "C"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef CHAISCRIPT_MSVC_12
|
||||||
|
#define CHAISCRIPT_NOEXCEPT throw()
|
||||||
|
#define CHAISCRIPT_CONSTEXPR
|
||||||
|
#else
|
||||||
|
#define CHAISCRIPT_NOEXCEPT noexcept
|
||||||
|
#define CHAISCRIPT_CONSTEXPR constexpr
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
#define CHAISCRIPT_DEBUG true
|
#define CHAISCRIPT_DEBUG true
|
||||||
#else
|
#else
|
||||||
@@ -71,9 +97,9 @@
|
|||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
namespace chaiscript {
|
namespace chaiscript {
|
||||||
static const int version_major = 6;
|
static const int version_major = 5;
|
||||||
static const int version_minor = 0;
|
static const int version_minor = 8;
|
||||||
static const int version_patch = 0;
|
static const int version_patch = 6;
|
||||||
|
|
||||||
static const char *compiler_version = CHAISCRIPT_COMPILER_VERSION;
|
static const char *compiler_version = CHAISCRIPT_COMPILER_VERSION;
|
||||||
static const char *compiler_name = CHAISCRIPT_COMPILER_NAME;
|
static const char *compiler_name = CHAISCRIPT_COMPILER_NAME;
|
||||||
@@ -89,54 +115,6 @@ namespace chaiscript {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Build_Info {
|
|
||||||
static int version_major()
|
|
||||||
{
|
|
||||||
return chaiscript::version_major;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int version_minor()
|
|
||||||
{
|
|
||||||
return chaiscript::version_minor;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int version_patch()
|
|
||||||
{
|
|
||||||
return chaiscript::version_patch;
|
|
||||||
}
|
|
||||||
|
|
||||||
static std::string version()
|
|
||||||
{
|
|
||||||
return std::to_string(version_major()) + '.' + std::to_string(version_minor()) + '.' + std::to_string(version_patch());
|
|
||||||
}
|
|
||||||
|
|
||||||
static std::string compiler_id()
|
|
||||||
{
|
|
||||||
return compiler_name() + '-' + compiler_version();
|
|
||||||
}
|
|
||||||
|
|
||||||
static std::string build_id()
|
|
||||||
{
|
|
||||||
return compiler_id() + (debug_build()?"-Debug":"-Release");
|
|
||||||
}
|
|
||||||
|
|
||||||
static std::string compiler_version()
|
|
||||||
{
|
|
||||||
return chaiscript::compiler_version;
|
|
||||||
}
|
|
||||||
|
|
||||||
static std::string compiler_name()
|
|
||||||
{
|
|
||||||
return chaiscript::compiler_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool debug_build()
|
|
||||||
{
|
|
||||||
return chaiscript::debug_build;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
template<typename Iter, typename Distance>
|
template<typename Iter, typename Distance>
|
||||||
Iter advance_copy(Iter iter, Distance distance) {
|
Iter advance_copy(Iter iter, Distance distance) {
|
||||||
std::advance(iter, static_cast<typename std::iterator_traits<Iter>::difference_type>(distance));
|
std::advance(iter, static_cast<typename std::iterator_traits<Iter>::difference_type>(distance));
|
||||||
|
@@ -14,15 +14,11 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "chaiscript_defines.hpp"
|
#include "chaiscript_defines.hpp"
|
||||||
#include "language/chaiscript_common.hpp"
|
#include "dispatchkit/dispatchkit.hpp"
|
||||||
|
|
||||||
//#include "dispatchkit/dispatchkit.hpp"
|
|
||||||
#include "dispatchkit/operators.hpp"
|
|
||||||
#include "dispatchkit/bootstrap.hpp"
|
#include "dispatchkit/bootstrap.hpp"
|
||||||
#include "dispatchkit/bootstrap_stl.hpp"
|
#include "dispatchkit/bootstrap_stl.hpp"
|
||||||
//#include "dispatchkit/boxed_value.hpp"
|
#include "dispatchkit/boxed_value.hpp"
|
||||||
#include "language/chaiscript_prelude.hpp"
|
#include "language/chaiscript_prelude.chai"
|
||||||
#include "dispatchkit/register_function.hpp"
|
|
||||||
#include "utility/json_wrap.hpp"
|
#include "utility/json_wrap.hpp"
|
||||||
|
|
||||||
#ifndef CHAISCRIPT_NO_THREADS
|
#ifndef CHAISCRIPT_NO_THREADS
|
||||||
@@ -42,22 +38,21 @@ namespace chaiscript
|
|||||||
|
|
||||||
static ModulePtr library()
|
static ModulePtr library()
|
||||||
{
|
{
|
||||||
// using namespace bootstrap;
|
using namespace bootstrap;
|
||||||
|
|
||||||
auto lib = std::make_shared<Module>();
|
ModulePtr lib = Bootstrap::bootstrap();
|
||||||
bootstrap::Bootstrap::bootstrap(*lib);
|
|
||||||
|
|
||||||
bootstrap::standard_library::vector_type<std::vector<Boxed_Value> >("Vector", *lib);
|
lib->add(standard_library::vector_type<std::vector<Boxed_Value> >("Vector"));
|
||||||
bootstrap::standard_library::string_type<std::string>("string", *lib);
|
lib->add(standard_library::string_type<std::string>("string"));
|
||||||
bootstrap::standard_library::map_type<std::map<std::string, Boxed_Value> >("Map", *lib);
|
lib->add(standard_library::map_type<std::map<std::string, Boxed_Value> >("Map"));
|
||||||
bootstrap::standard_library::pair_type<std::pair<Boxed_Value, Boxed_Value > >("Pair", *lib);
|
lib->add(standard_library::pair_type<std::pair<Boxed_Value, Boxed_Value > >("Pair"));
|
||||||
|
|
||||||
#ifndef CHAISCRIPT_NO_THREADS
|
#ifndef CHAISCRIPT_NO_THREADS
|
||||||
bootstrap::standard_library::future_type<std::future<chaiscript::Boxed_Value>>("future", *lib);
|
lib->add(standard_library::future_type<std::future<chaiscript::Boxed_Value>>("future"));
|
||||||
lib->add(chaiscript::fun([](const std::function<chaiscript::Boxed_Value ()> &t_func){ return std::async(std::launch::async, t_func);}), "async");
|
lib->add(chaiscript::fun([](const std::function<chaiscript::Boxed_Value ()> &t_func){ return std::async(std::launch::async, t_func);}), "async");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
json_wrap::library(*lib);
|
lib->add(json_wrap::library());
|
||||||
|
|
||||||
lib->eval(ChaiScript_Prelude::chaiscript_prelude() /*, "standard prelude"*/ );
|
lib->eval(ChaiScript_Prelude::chaiscript_prelude() /*, "standard prelude"*/ );
|
||||||
|
|
||||||
|
@@ -42,16 +42,28 @@ namespace chaiscript
|
|||||||
#ifndef CHAISCRIPT_NO_THREADS
|
#ifndef CHAISCRIPT_NO_THREADS
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
using unique_lock = std::unique_lock<T>;
|
class unique_lock : public std::unique_lock<T>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit unique_lock(T &t) : std::unique_lock<T>(t) {}
|
||||||
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
using shared_lock = std::unique_lock<T>;
|
class shared_lock : public std::unique_lock<T>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit shared_lock(T &t) : std::unique_lock<T>(t) {}
|
||||||
|
void unlock() {}
|
||||||
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
using lock_guard = std::lock_guard<T>;
|
class lock_guard : public std::lock_guard<T>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit lock_guard(T &t) : std::lock_guard<T>(t) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
class shared_mutex : public std::mutex { };
|
||||||
using shared_mutex = std::mutex;
|
|
||||||
|
|
||||||
using std::mutex;
|
using std::mutex;
|
||||||
|
|
||||||
@@ -108,9 +120,6 @@ namespace chaiscript
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#pragma message ("Threading without thread_local support is not well supported.")
|
|
||||||
|
|
||||||
|
|
||||||
/// Typesafe thread specific storage. If threading is enabled, this class uses a mutex protected map. If
|
/// Typesafe thread specific storage. If threading is enabled, this class uses a mutex protected map. If
|
||||||
/// threading is not enabled, the class always returns the same data, regardless of which thread it is called from.
|
/// threading is not enabled, the class always returns the same data, regardless of which thread it is called from.
|
||||||
///
|
///
|
||||||
|
@@ -21,17 +21,17 @@ namespace chaiscript {
|
|||||||
class bad_any_cast : public std::bad_cast
|
class bad_any_cast : public std::bad_cast
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
bad_any_cast() noexcept
|
bad_any_cast() CHAISCRIPT_NOEXCEPT
|
||||||
: m_what("bad any cast")
|
: m_what("bad any cast")
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bad_any_cast(const bad_any_cast &) = default;
|
bad_any_cast(const bad_any_cast &) = default;
|
||||||
|
|
||||||
~bad_any_cast() noexcept override = default;
|
virtual ~bad_any_cast() CHAISCRIPT_NOEXCEPT {}
|
||||||
|
|
||||||
/// \brief Description of what error occurred
|
/// \brief Description of what error occurred
|
||||||
const char * what() const noexcept override
|
virtual const char * what() const CHAISCRIPT_NOEXCEPT CHAISCRIPT_OVERRIDE
|
||||||
{
|
{
|
||||||
return m_what.c_str();
|
return m_what.c_str();
|
||||||
}
|
}
|
||||||
@@ -53,10 +53,9 @@ namespace chaiscript {
|
|||||||
|
|
||||||
Data &operator=(const Data &) = delete;
|
Data &operator=(const Data &) = delete;
|
||||||
|
|
||||||
virtual ~Data() = default;
|
virtual ~Data() {}
|
||||||
|
|
||||||
virtual void *data() = 0;
|
virtual void *data() = 0;
|
||||||
|
|
||||||
const std::type_info &type() const
|
const std::type_info &type() const
|
||||||
{
|
{
|
||||||
return m_type;
|
return m_type;
|
||||||
@@ -75,12 +74,14 @@ namespace chaiscript {
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void *data() override
|
virtual ~Data_Impl() {}
|
||||||
|
|
||||||
|
virtual void *data() CHAISCRIPT_OVERRIDE
|
||||||
{
|
{
|
||||||
return &m_data;
|
return &m_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<Data> clone() const override
|
std::unique_ptr<Data> clone() const CHAISCRIPT_OVERRIDE
|
||||||
{
|
{
|
||||||
return std::unique_ptr<Data>(new Data_Impl<T>(m_data));
|
return std::unique_ptr<Data>(new Data_Impl<T>(m_data));
|
||||||
}
|
}
|
||||||
@@ -95,8 +96,6 @@ namespace chaiscript {
|
|||||||
public:
|
public:
|
||||||
// construct/copy/destruct
|
// construct/copy/destruct
|
||||||
Any() = default;
|
Any() = default;
|
||||||
Any(Any &&) = default;
|
|
||||||
Any &operator=(Any &&t_any) = default;
|
|
||||||
|
|
||||||
Any(const Any &t_any)
|
Any(const Any &t_any)
|
||||||
{
|
{
|
||||||
@@ -108,6 +107,10 @@ namespace chaiscript {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !defined(_MSC_VER) || _MSC_VER != 1800
|
||||||
|
Any(Any &&) = default;
|
||||||
|
Any &operator=(Any &&t_any) = default;
|
||||||
|
#endif
|
||||||
|
|
||||||
template<typename ValueType,
|
template<typename ValueType,
|
||||||
typename = typename std::enable_if<!std::is_same<Any, typename std::decay<ValueType>::type>::value>::type>
|
typename = typename std::enable_if<!std::is_same<Any, typename std::decay<ValueType>::type>::value>::type>
|
||||||
@@ -136,6 +139,10 @@ namespace chaiscript {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
~Any()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
// modifiers
|
// modifiers
|
||||||
Any & swap(Any &t_other)
|
Any & swap(Any &t_other)
|
||||||
{
|
{
|
||||||
|
@@ -30,7 +30,7 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
bad_boxed_cast(Type_Info t_from, const std::type_info &t_to,
|
bad_boxed_cast(Type_Info t_from, const std::type_info &t_to,
|
||||||
std::string t_what) noexcept
|
std::string t_what) CHAISCRIPT_NOEXCEPT
|
||||||
: from(std::move(t_from)), to(&t_to), m_what(std::move(t_what))
|
: from(std::move(t_from)), to(&t_to), m_what(std::move(t_what))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -40,16 +40,16 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
explicit bad_boxed_cast(std::string t_what) noexcept
|
explicit bad_boxed_cast(std::string t_what) CHAISCRIPT_NOEXCEPT
|
||||||
: to(nullptr), m_what(std::move(t_what))
|
: to(nullptr), m_what(std::move(t_what))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bad_boxed_cast(const bad_boxed_cast &) = default;
|
bad_boxed_cast(const bad_boxed_cast &) = default;
|
||||||
virtual ~bad_boxed_cast() noexcept = default;
|
virtual ~bad_boxed_cast() CHAISCRIPT_NOEXCEPT {}
|
||||||
|
|
||||||
/// \brief Description of what error occurred
|
/// \brief Description of what error occurred
|
||||||
virtual const char * what() const noexcept override
|
virtual const char * what() const CHAISCRIPT_NOEXCEPT CHAISCRIPT_OVERRIDE
|
||||||
{
|
{
|
||||||
return m_what.c_str();
|
return m_what.c_str();
|
||||||
}
|
}
|
||||||
|
@@ -27,52 +27,45 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename O, typename Ret, typename P1, typename ... Param>
|
template<typename O, typename Ret, typename P1, typename ... Param>
|
||||||
auto bind_first(Ret (*f)(P1, Param...), O&& o)
|
std::function<Ret (Param...)> bind_first(Ret (*f)(P1, Param...), O&& o)
|
||||||
{
|
{
|
||||||
return [f, o](Param...param) -> Ret {
|
return std::function<Ret (Param...)>(
|
||||||
return f(std::forward<O>(o), std::forward<Param>(param)...);
|
[f, o](Param...param) -> Ret {
|
||||||
};
|
return f(std::forward<O>(o), std::forward<Param>(param)...);
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename O, typename Ret, typename Class, typename ... Param>
|
template<typename O, typename Ret, typename Class, typename ... Param>
|
||||||
auto bind_first(Ret (Class::*f)(Param...), O&& o)
|
std::function<Ret (Param...)> bind_first(Ret (Class::*f)(Param...), O&& o)
|
||||||
{
|
{
|
||||||
return [f, o](Param...param) -> Ret {
|
return std::function<Ret (Param...)>(
|
||||||
return (get_pointer(o)->*f)(std::forward<Param>(param)...);
|
[f, o](Param...param) -> Ret {
|
||||||
};
|
return (get_pointer(o)->*f)(std::forward<Param>(param)...);
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename O, typename Ret, typename Class, typename ... Param>
|
template<typename O, typename Ret, typename Class, typename ... Param>
|
||||||
auto bind_first(Ret (Class::*f)(Param...) const, O&& o)
|
std::function<Ret (Param...)> bind_first(Ret (Class::*f)(Param...) const, O&& o)
|
||||||
{
|
{
|
||||||
return [f, o](Param...param) -> Ret {
|
return std::function<Ret (Param...)>(
|
||||||
return (get_pointer(o)->*f)(std::forward<Param>(param)...);
|
[f, o](Param...param) -> Ret {
|
||||||
};
|
return (get_pointer(o)->*f)(std::forward<Param>(param)...);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename O, typename Ret, typename P1, typename ... Param>
|
template<typename O, typename Ret, typename P1, typename ... Param>
|
||||||
auto bind_first(const std::function<Ret (P1, Param...)> &f, O&& o)
|
std::function<Ret (Param...)> bind_first(const std::function<Ret (P1, Param...)> &f, O&& o)
|
||||||
{
|
{
|
||||||
return [f, o](Param...param) -> Ret {
|
return std::function<Ret (Param...)>(
|
||||||
return f(o, std::forward<Param>(param)...);
|
[f, o](Param...param) -> Ret {
|
||||||
};
|
return f(o, std::forward<Param>(param)...);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename F, typename O, typename Ret, typename Class, typename P1, typename ... Param>
|
|
||||||
auto bind_first(const F &fo, O&& o, Ret (Class::*f)(P1, Param...) const)
|
|
||||||
{
|
|
||||||
return [fo, o, f](Param ...param) -> Ret {
|
|
||||||
return (fo.*f)(o, std::forward<Param>(param)...);
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename F, typename O>
|
|
||||||
auto bind_first(const F &f, O&& o)
|
|
||||||
{
|
|
||||||
return bind_first(f, std::forward<O>(o), &F::operator());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -7,8 +7,32 @@
|
|||||||
#ifndef CHAISCRIPT_BOOTSTRAP_HPP_
|
#ifndef CHAISCRIPT_BOOTSTRAP_HPP_
|
||||||
#define CHAISCRIPT_BOOTSTRAP_HPP_
|
#define CHAISCRIPT_BOOTSTRAP_HPP_
|
||||||
|
|
||||||
#include "../utility/utility.hpp"
|
#include <cstdint>
|
||||||
|
#include <exception>
|
||||||
|
#include <functional>
|
||||||
|
#include <memory>
|
||||||
|
#include <sstream>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <string>
|
||||||
|
#include <type_traits>
|
||||||
|
#include <vector>
|
||||||
|
#include <iterator>
|
||||||
|
|
||||||
|
#include "bad_boxed_cast.hpp"
|
||||||
|
#include "boxed_cast.hpp"
|
||||||
|
#include "boxed_number.hpp"
|
||||||
|
#include "boxed_value.hpp"
|
||||||
|
#include "dispatchkit.hpp"
|
||||||
|
#include "type_conversions.hpp"
|
||||||
|
#include "dynamic_object.hpp"
|
||||||
|
#include "operators.hpp"
|
||||||
|
#include "proxy_constructors.hpp"
|
||||||
|
#include "proxy_functions.hpp"
|
||||||
|
#include "proxy_functions_detail.hpp"
|
||||||
#include "register_function.hpp"
|
#include "register_function.hpp"
|
||||||
|
#include "type_info.hpp"
|
||||||
|
#include "../utility/utility.hpp"
|
||||||
|
#include "../language/chaiscript_common.hpp"
|
||||||
|
|
||||||
namespace chaiscript
|
namespace chaiscript
|
||||||
{
|
{
|
||||||
@@ -28,12 +52,12 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, typename = typename std::enable_if<std::is_array<T>::value>::type >
|
template<typename T, typename = typename std::enable_if<std::is_array<T>::value>::type >
|
||||||
void array(const std::string &type, Module& m)
|
ModulePtr array(const std::string &type, ModulePtr m = std::make_shared<Module>())
|
||||||
{
|
{
|
||||||
typedef typename std::remove_extent<T>::type ReturnType;
|
typedef typename std::remove_extent<T>::type ReturnType;
|
||||||
const auto extent = std::extent<T>::value;
|
const auto extent = std::extent<T>::value;
|
||||||
m.add(user_type<T>(), type);
|
m->add(user_type<T>(), type);
|
||||||
m.add(fun(
|
m->add(fun(
|
||||||
[extent](T& t, size_t index)->ReturnType &{
|
[extent](T& t, size_t index)->ReturnType &{
|
||||||
if (extent > 0 && index >= extent) {
|
if (extent > 0 && index >= extent) {
|
||||||
throw std::range_error("Array index out of range. Received: " + std::to_string(index) + " expected < " + std::to_string(extent));
|
throw std::range_error("Array index out of range. Received: " + std::to_string(index) + " expected < " + std::to_string(extent));
|
||||||
@@ -44,7 +68,7 @@ namespace chaiscript
|
|||||||
), "[]"
|
), "[]"
|
||||||
);
|
);
|
||||||
|
|
||||||
m.add(fun(
|
m->add(fun(
|
||||||
[extent](const T &t, size_t index)->const ReturnType &{
|
[extent](const T &t, size_t index)->const ReturnType &{
|
||||||
if (extent > 0 && index >= extent) {
|
if (extent > 0 && index >= extent) {
|
||||||
throw std::range_error("Array index out of range. Received: " + std::to_string(index) + " expected < " + std::to_string(extent));
|
throw std::range_error("Array index out of range. Received: " + std::to_string(index) + " expected < " + std::to_string(extent));
|
||||||
@@ -55,29 +79,33 @@ namespace chaiscript
|
|||||||
), "[]"
|
), "[]"
|
||||||
);
|
);
|
||||||
|
|
||||||
m.add(fun(
|
m->add(fun(
|
||||||
[extent](const T &) {
|
[extent](const T &) {
|
||||||
return extent;
|
return extent;
|
||||||
}), "size");
|
}), "size");
|
||||||
|
|
||||||
|
|
||||||
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \brief Adds a copy constructor for the given type to the given Model
|
/// \brief Adds a copy constructor for the given type to the given Model
|
||||||
/// \param[in] type The name of the type. The copy constructor will be named "type".
|
/// \param[in] type The name of the type. The copy constructor will be named "type".
|
||||||
/// \param[in,out] m The Module to add the copy constructor to
|
/// \param[in,out] m The Module to add the copy constructor to
|
||||||
/// \tparam T The type to add a copy constructor for
|
/// \tparam T The type to add a copy constructor for
|
||||||
/// \returns The passed in Module
|
/// \returns The passed in ModulePtr, or the newly constructed one if the default param is used
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void copy_constructor(const std::string &type, Module& m)
|
ModulePtr copy_constructor(const std::string &type, ModulePtr m = std::make_shared<Module>())
|
||||||
{
|
{
|
||||||
m.add(constructor<T (const T &)>(), type);
|
m->add(constructor<T (const T &)>(), type);
|
||||||
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \brief Add all comparison operators for the templated type. Used during bootstrap, also available to users.
|
/// \brief Add all comparison operators for the templated type. Used during bootstrap, also available to users.
|
||||||
/// \tparam T Type to create comparison operators for
|
/// \tparam T Type to create comparison operators for
|
||||||
/// \param[in,out] m module to add comparison operators to
|
/// \param[in,out] m module to add comparison operators to
|
||||||
/// \returns the passed in Module.
|
/// \returns the passed in ModulePtr or the newly constructed one if the default params are used.
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void opers_comparison(Module& m)
|
ModulePtr opers_comparison(ModulePtr m = std::make_shared<Module>())
|
||||||
{
|
{
|
||||||
operators::equal<T>(m);
|
operators::equal<T>(m);
|
||||||
operators::greater_than<T>(m);
|
operators::greater_than<T>(m);
|
||||||
@@ -85,6 +113,7 @@ namespace chaiscript
|
|||||||
operators::less_than<T>(m);
|
operators::less_than<T>(m);
|
||||||
operators::less_than_equal<T>(m);
|
operators::less_than_equal<T>(m);
|
||||||
operators::not_equal<T>(m);
|
operators::not_equal<T>(m);
|
||||||
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -93,14 +122,15 @@ namespace chaiscript
|
|||||||
/// \param[in] type The name of the type to add the constructors for.
|
/// \param[in] type The name of the type to add the constructors for.
|
||||||
/// \param[in,out] m The Module to add the basic constructors to
|
/// \param[in,out] m The Module to add the basic constructors to
|
||||||
/// \tparam T Type to generate basic constructors for
|
/// \tparam T Type to generate basic constructors for
|
||||||
/// \returns The passed in Module
|
/// \returns The passed in ModulePtr, or the newly constructed one if the default param is used
|
||||||
/// \sa copy_constructor
|
/// \sa copy_constructor
|
||||||
/// \sa constructor
|
/// \sa constructor
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void basic_constructors(const std::string &type, Module& m)
|
ModulePtr basic_constructors(const std::string &type, ModulePtr m = std::make_shared<Module>())
|
||||||
{
|
{
|
||||||
m.add(constructor<T ()>(), type);
|
m->add(constructor<T ()>(), type);
|
||||||
copy_constructor<T>(type, m);
|
copy_constructor<T>(type, m);
|
||||||
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \brief Adds a constructor for a POD type
|
/// \brief Adds a constructor for a POD type
|
||||||
@@ -108,12 +138,22 @@ namespace chaiscript
|
|||||||
/// \param[in] type The name of the type
|
/// \param[in] type The name of the type
|
||||||
/// \param[in,out] m The Module to add the constructor to
|
/// \param[in,out] m The Module to add the constructor to
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void construct_pod(const std::string &type, Module& m)
|
ModulePtr construct_pod(const std::string &type, ModulePtr m = std::make_shared<Module>())
|
||||||
{
|
{
|
||||||
m.add(fun(&detail::construct_pod<T>), type);
|
m->add(fun(&detail::construct_pod<T>), type);
|
||||||
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// to_string function for internal use. Uses ostream operator<<
|
||||||
|
template<typename Input>
|
||||||
|
std::string to_string(Input i)
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << i;
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
|
||||||
/// Internal function for converting from a string to a value
|
/// Internal function for converting from a string to a value
|
||||||
/// uses ostream operator >> to perform the conversion
|
/// uses ostream operator >> to perform the conversion
|
||||||
template<typename Input>
|
template<typename Input>
|
||||||
@@ -145,13 +185,14 @@ namespace chaiscript
|
|||||||
/// Add all common functions for a POD type. All operators, and
|
/// Add all common functions for a POD type. All operators, and
|
||||||
/// common conversions
|
/// common conversions
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void bootstrap_pod_type(const std::string &name, Module& m)
|
ModulePtr bootstrap_pod_type(const std::string &name, ModulePtr m = std::make_shared<Module>())
|
||||||
{
|
{
|
||||||
m.add(user_type<T>(), name);
|
m->add(user_type<T>(), name);
|
||||||
m.add(constructor<T()>(), name);
|
m->add(constructor<T()>(), name);
|
||||||
construct_pod<T>(name, m);
|
construct_pod<T>(name, m);
|
||||||
|
|
||||||
m.add(fun(&parse_string<T>), "to_" + name);
|
m->add(fun(&parse_string<T>), "to_" + name);
|
||||||
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -220,41 +261,43 @@ namespace chaiscript
|
|||||||
|
|
||||||
|
|
||||||
/// Add all arithmetic operators for PODs
|
/// Add all arithmetic operators for PODs
|
||||||
static void opers_arithmetic_pod(Module& m)
|
static void opers_arithmetic_pod(ModulePtr m = std::make_shared<Module>())
|
||||||
{
|
{
|
||||||
m.add(fun(&Boxed_Number::equals), "==");
|
m->add(fun(&Boxed_Number::equals), "==");
|
||||||
m.add(fun(&Boxed_Number::less_than), "<");
|
m->add(fun(&Boxed_Number::less_than), "<");
|
||||||
m.add(fun(&Boxed_Number::greater_than), ">");
|
m->add(fun(&Boxed_Number::greater_than), ">");
|
||||||
m.add(fun(&Boxed_Number::greater_than_equal), ">=");
|
m->add(fun(&Boxed_Number::greater_than_equal), ">=");
|
||||||
m.add(fun(&Boxed_Number::less_than_equal), "<=");
|
m->add(fun(&Boxed_Number::less_than_equal), "<=");
|
||||||
m.add(fun(&Boxed_Number::not_equal), "!=");
|
m->add(fun(&Boxed_Number::not_equal), "!=");
|
||||||
|
|
||||||
|
m->add(fun(&Boxed_Number::pre_decrement), "--");
|
||||||
|
m->add(fun(&Boxed_Number::pre_increment), "++");
|
||||||
|
m->add(fun(&Boxed_Number::sum), "+");
|
||||||
|
m->add(fun(&Boxed_Number::unary_plus), "+");
|
||||||
|
m->add(fun(&Boxed_Number::unary_minus), "-");
|
||||||
|
m->add(fun(&Boxed_Number::difference), "-");
|
||||||
|
m->add(fun(&Boxed_Number::assign_bitwise_and), "&=");
|
||||||
|
m->add(fun(&Boxed_Number::assign), "=");
|
||||||
|
m->add(fun(&Boxed_Number::assign_bitwise_or), "|=");
|
||||||
|
m->add(fun(&Boxed_Number::assign_bitwise_xor), "^=");
|
||||||
|
m->add(fun(&Boxed_Number::assign_remainder), "%=");
|
||||||
|
m->add(fun(&Boxed_Number::assign_shift_left), "<<=");
|
||||||
|
m->add(fun(&Boxed_Number::assign_shift_right), ">>=");
|
||||||
|
m->add(fun(&Boxed_Number::bitwise_and), "&");
|
||||||
|
m->add(fun(&Boxed_Number::bitwise_complement), "~");
|
||||||
|
m->add(fun(&Boxed_Number::bitwise_xor), "^");
|
||||||
|
m->add(fun(&Boxed_Number::bitwise_or), "|");
|
||||||
|
m->add(fun(&Boxed_Number::assign_product), "*=");
|
||||||
|
m->add(fun(&Boxed_Number::assign_quotient), "/=");
|
||||||
|
m->add(fun(&Boxed_Number::assign_sum), "+=");
|
||||||
|
m->add(fun(&Boxed_Number::assign_difference), "-=");
|
||||||
|
m->add(fun(&Boxed_Number::quotient), "/");
|
||||||
|
m->add(fun(&Boxed_Number::shift_left), "<<");
|
||||||
|
m->add(fun(&Boxed_Number::product), "*");
|
||||||
|
m->add(fun(&Boxed_Number::remainder), "%");
|
||||||
|
m->add(fun(&Boxed_Number::shift_right), ">>");
|
||||||
|
|
||||||
|
|
||||||
m.add(fun(&Boxed_Number::pre_decrement), "--");
|
|
||||||
m.add(fun(&Boxed_Number::pre_increment), "++");
|
|
||||||
m.add(fun(&Boxed_Number::sum), "+");
|
|
||||||
m.add(fun(&Boxed_Number::unary_plus), "+");
|
|
||||||
m.add(fun(&Boxed_Number::unary_minus), "-");
|
|
||||||
m.add(fun(&Boxed_Number::difference), "-");
|
|
||||||
m.add(fun(&Boxed_Number::assign_bitwise_and), "&=");
|
|
||||||
m.add(fun(&Boxed_Number::assign), "=");
|
|
||||||
m.add(fun(&Boxed_Number::assign_bitwise_or), "|=");
|
|
||||||
m.add(fun(&Boxed_Number::assign_bitwise_xor), "^=");
|
|
||||||
m.add(fun(&Boxed_Number::assign_remainder), "%=");
|
|
||||||
m.add(fun(&Boxed_Number::assign_shift_left), "<<=");
|
|
||||||
m.add(fun(&Boxed_Number::assign_shift_right), ">>=");
|
|
||||||
m.add(fun(&Boxed_Number::bitwise_and), "&");
|
|
||||||
m.add(fun(&Boxed_Number::bitwise_complement), "~");
|
|
||||||
m.add(fun(&Boxed_Number::bitwise_xor), "^");
|
|
||||||
m.add(fun(&Boxed_Number::bitwise_or), "|");
|
|
||||||
m.add(fun(&Boxed_Number::assign_product), "*=");
|
|
||||||
m.add(fun(&Boxed_Number::assign_quotient), "/=");
|
|
||||||
m.add(fun(&Boxed_Number::assign_sum), "+=");
|
|
||||||
m.add(fun(&Boxed_Number::assign_difference), "-=");
|
|
||||||
m.add(fun(&Boxed_Number::quotient), "/");
|
|
||||||
m.add(fun(&Boxed_Number::shift_left), "<<");
|
|
||||||
m.add(fun(&Boxed_Number::product), "*");
|
|
||||||
m.add(fun(&Boxed_Number::remainder), "%");
|
|
||||||
m.add(fun(&Boxed_Number::shift_right), ">>");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a bound function object. The first param is the function to bind
|
/// Create a bound function object. The first param is the function to bind
|
||||||
@@ -294,6 +337,26 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void throw_exception(const Boxed_Value &bv) {
|
||||||
|
throw bv;
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::string what(const std::exception &e)
|
||||||
|
{
|
||||||
|
return e.what();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Boolean specialization of internal to_string function
|
||||||
|
static std::string bool_to_string(bool b)
|
||||||
|
{
|
||||||
|
if (b)
|
||||||
|
{
|
||||||
|
return "true";
|
||||||
|
} else {
|
||||||
|
return "false";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
template<typename FunctionType>
|
template<typename FunctionType>
|
||||||
static std::vector<Boxed_Value> do_return_boxed_value_vector(FunctionType f,
|
static std::vector<Boxed_Value> do_return_boxed_value_vector(FunctionType f,
|
||||||
const dispatch::Proxy_Function_Base *b)
|
const dispatch::Proxy_Function_Base *b)
|
||||||
@@ -329,7 +392,7 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename Function>
|
template<typename Function>
|
||||||
static auto return_boxed_value_vector(const Function &f)
|
static std::function<std::vector<Boxed_Value> (const dispatch::Proxy_Function_Base*)> return_boxed_value_vector(const Function &f)
|
||||||
{
|
{
|
||||||
return [f](const dispatch::Proxy_Function_Base *b) {
|
return [f](const dispatch::Proxy_Function_Base *b) {
|
||||||
return do_return_boxed_value_vector(f, b);
|
return do_return_boxed_value_vector(f, b);
|
||||||
@@ -340,123 +403,94 @@ namespace chaiscript
|
|||||||
public:
|
public:
|
||||||
/// \brief perform all common bootstrap functions for std::string, void and POD types
|
/// \brief perform all common bootstrap functions for std::string, void and POD types
|
||||||
/// \param[in,out] m Module to add bootstrapped functions to
|
/// \param[in,out] m Module to add bootstrapped functions to
|
||||||
/// \returns passed in Module
|
/// \returns passed in ModulePtr, or newly created one if default argument is used
|
||||||
static void bootstrap(Module& m)
|
static ModulePtr bootstrap(ModulePtr m = std::make_shared<Module>())
|
||||||
{
|
{
|
||||||
m.add(user_type<void>(), "void");
|
m->add(user_type<void>(), "void");
|
||||||
m.add(user_type<bool>(), "bool");
|
m->add(user_type<bool>(), "bool");
|
||||||
m.add(user_type<Boxed_Value>(), "Object");
|
m->add(user_type<Boxed_Value>(), "Object");
|
||||||
m.add(user_type<Boxed_Number>(), "Number");
|
m->add(user_type<Boxed_Number>(), "Number");
|
||||||
m.add(user_type<Proxy_Function>(), "Function");
|
m->add(user_type<Proxy_Function>(), "Function");
|
||||||
m.add(user_type<dispatch::Assignable_Proxy_Function>(), "Assignable_Function");
|
m->add(user_type<dispatch::Assignable_Proxy_Function>(), "Assignable_Function");
|
||||||
m.add(user_type<std::exception>(), "exception");
|
m->add(user_type<std::exception>(), "exception");
|
||||||
|
|
||||||
m.add(fun(&dispatch::Proxy_Function_Base::get_arity), "get_arity");
|
m->add(fun(&dispatch::Proxy_Function_Base::get_arity), "get_arity");
|
||||||
m.add(fun(&dispatch::Proxy_Function_Base::operator==), "==");
|
m->add(fun(&dispatch::Proxy_Function_Base::annotation), "get_annotation");
|
||||||
|
m->add(fun(&dispatch::Proxy_Function_Base::operator==), "==");
|
||||||
|
|
||||||
|
|
||||||
m.add(fun(return_boxed_value_vector(&dispatch::Proxy_Function_Base::get_param_types)), "get_param_types");
|
m->add(fun(return_boxed_value_vector(&dispatch::Proxy_Function_Base::get_param_types)), "get_param_types");
|
||||||
m.add(fun(return_boxed_value_vector(&dispatch::Proxy_Function_Base::get_contained_functions)), "get_contained_functions");
|
m->add(fun(return_boxed_value_vector(&dispatch::Proxy_Function_Base::get_contained_functions)), "get_contained_functions");
|
||||||
|
|
||||||
m.add(fun([](const std::exception &e){ return std::string(e.what()); }), "what");
|
|
||||||
|
|
||||||
m.add(user_type<std::out_of_range>(), "out_of_range");
|
m->add(user_type<std::out_of_range>(), "out_of_range");
|
||||||
m.add(user_type<std::logic_error>(), "logic_error");
|
m->add(user_type<std::logic_error>(), "logic_error");
|
||||||
m.add(chaiscript::base_class<std::exception, std::logic_error>());
|
m->add(chaiscript::base_class<std::exception, std::logic_error>());
|
||||||
m.add(chaiscript::base_class<std::logic_error, std::out_of_range>());
|
m->add(chaiscript::base_class<std::logic_error, std::out_of_range>());
|
||||||
m.add(chaiscript::base_class<std::exception, std::out_of_range>());
|
m->add(chaiscript::base_class<std::exception, std::out_of_range>());
|
||||||
|
|
||||||
m.add(user_type<std::runtime_error>(), "runtime_error");
|
m->add(user_type<std::runtime_error>(), "runtime_error");
|
||||||
m.add(chaiscript::base_class<std::exception, std::runtime_error>());
|
m->add(chaiscript::base_class<std::exception, std::runtime_error>());
|
||||||
|
|
||||||
m.add(constructor<std::runtime_error (const std::string &)>(), "runtime_error");
|
m->add(constructor<std::runtime_error (const std::string &)>(), "runtime_error");
|
||||||
|
m->add(fun(std::function<std::string (const std::runtime_error &)>(&what)), "what");
|
||||||
|
|
||||||
m.add(user_type<dispatch::Dynamic_Object>(), "Dynamic_Object");
|
m->add(user_type<dispatch::Dynamic_Object>(), "Dynamic_Object");
|
||||||
m.add(constructor<dispatch::Dynamic_Object (const std::string &)>(), "Dynamic_Object");
|
m->add(constructor<dispatch::Dynamic_Object (const std::string &)>(), "Dynamic_Object");
|
||||||
m.add(constructor<dispatch::Dynamic_Object ()>(), "Dynamic_Object");
|
m->add(constructor<dispatch::Dynamic_Object ()>(), "Dynamic_Object");
|
||||||
m.add(fun(&dispatch::Dynamic_Object::get_type_name), "get_type_name");
|
m->add(fun(&dispatch::Dynamic_Object::get_type_name), "get_type_name");
|
||||||
m.add(fun(&dispatch::Dynamic_Object::get_attrs), "get_attrs");
|
m->add(fun(&dispatch::Dynamic_Object::get_attrs), "get_attrs");
|
||||||
m.add(fun(&dispatch::Dynamic_Object::set_explicit), "set_explicit");
|
m->add(fun(&dispatch::Dynamic_Object::set_explicit), "set_explicit");
|
||||||
m.add(fun(&dispatch::Dynamic_Object::is_explicit), "is_explicit");
|
m->add(fun(&dispatch::Dynamic_Object::is_explicit), "is_explicit");
|
||||||
m.add(fun(&dispatch::Dynamic_Object::has_attr), "has_attr");
|
|
||||||
|
|
||||||
m.add(fun(static_cast<Boxed_Value & (dispatch::Dynamic_Object::*)(const std::string &)>(&dispatch::Dynamic_Object::get_attr)), "get_attr");
|
m->add(fun(static_cast<Boxed_Value & (dispatch::Dynamic_Object::*)(const std::string &)>(&dispatch::Dynamic_Object::get_attr)), "get_attr");
|
||||||
m.add(fun(static_cast<const Boxed_Value & (dispatch::Dynamic_Object::*)(const std::string &) const>(&dispatch::Dynamic_Object::get_attr)), "get_attr");
|
m->add(fun(static_cast<const Boxed_Value & (dispatch::Dynamic_Object::*)(const std::string &) const>(&dispatch::Dynamic_Object::get_attr)), "get_attr");
|
||||||
|
|
||||||
m.add(fun(static_cast<Boxed_Value & (dispatch::Dynamic_Object::*)(const std::string &)>(&dispatch::Dynamic_Object::method_missing)), "method_missing");
|
m->add(fun(static_cast<Boxed_Value & (dispatch::Dynamic_Object::*)(const std::string &)>(&dispatch::Dynamic_Object::method_missing)), "method_missing");
|
||||||
m.add(fun(static_cast<const Boxed_Value & (dispatch::Dynamic_Object::*)(const std::string &) const>(&dispatch::Dynamic_Object::method_missing)), "method_missing");
|
m->add(fun(static_cast<const Boxed_Value & (dispatch::Dynamic_Object::*)(const std::string &) const>(&dispatch::Dynamic_Object::method_missing)), "method_missing");
|
||||||
|
|
||||||
m.add(fun(static_cast<Boxed_Value & (dispatch::Dynamic_Object::*)(const std::string &)>(&dispatch::Dynamic_Object::get_attr)), "[]");
|
m->add(fun(static_cast<Boxed_Value & (dispatch::Dynamic_Object::*)(const std::string &)>(&dispatch::Dynamic_Object::get_attr)), "[]");
|
||||||
m.add(fun(static_cast<const Boxed_Value & (dispatch::Dynamic_Object::*)(const std::string &) const>(&dispatch::Dynamic_Object::get_attr)), "[]");
|
m->add(fun(static_cast<const Boxed_Value & (dispatch::Dynamic_Object::*)(const std::string &) const>(&dispatch::Dynamic_Object::get_attr)), "[]");
|
||||||
|
|
||||||
m.eval(R"chaiscript(
|
m->eval(R""(
|
||||||
def Dynamic_Object::clone() {
|
def Dynamic_Object::clone() {
|
||||||
auto &new_o = Dynamic_Object(this.get_type_name());
|
auto &new_o = Dynamic_Object(this.get_type_name());
|
||||||
for_each(this.get_attrs(), fun[new_o](x) { new_o.get_attr(x.first) = x.second; } );
|
for_each(this.get_attrs(), fun[new_o](x) { new_o.get_attr(x.first) = x.second; } );
|
||||||
new_o;
|
new_o;
|
||||||
}
|
}
|
||||||
|
)"");
|
||||||
|
|
||||||
def `=`(Dynamic_Object lhs, Dynamic_Object rhs) : lhs.get_type_name() == rhs.get_type_name()
|
m->add(fun(&has_guard), "has_guard");
|
||||||
{
|
m->add(fun(&get_guard), "get_guard");
|
||||||
for_each(rhs.get_attrs(), fun[lhs](x) { lhs.get_attr(x.first) = clone(x.second); } );
|
|
||||||
}
|
|
||||||
|
|
||||||
def `!=`(Dynamic_Object lhs, Dynamic_Object rhs) : lhs.get_type_name() == rhs.get_type_name()
|
m->add(fun(&Boxed_Value::is_undef), "is_var_undef");
|
||||||
{
|
m->add(fun(&Boxed_Value::is_null), "is_var_null");
|
||||||
var rhs_attrs := rhs.get_attrs();
|
m->add(fun(&Boxed_Value::is_const), "is_var_const");
|
||||||
var lhs_attrs := lhs.get_attrs();
|
m->add(fun(&Boxed_Value::is_ref), "is_var_reference");
|
||||||
|
m->add(fun(&Boxed_Value::is_pointer), "is_var_pointer");
|
||||||
|
m->add(fun(&Boxed_Value::is_return_value), "is_var_return_value");
|
||||||
|
m->add(fun(&Boxed_Value::reset_return_value), "reset_var_return_value");
|
||||||
|
m->add(fun(&Boxed_Value::is_type), "is_type");
|
||||||
|
m->add(fun(&Boxed_Value::get_attr), "get_var_attr");
|
||||||
|
m->add(fun(&Boxed_Value::copy_attrs), "copy_var_attrs");
|
||||||
|
m->add(fun(&Boxed_Value::clone_attrs), "clone_var_attrs");
|
||||||
|
|
||||||
if (rhs_attrs.size() != lhs_attrs.size()) {
|
m->add(fun(&Boxed_Value::get_type_info), "get_type_info");
|
||||||
true;
|
m->add(user_type<Type_Info>(), "Type_Info");
|
||||||
} else {
|
m->add(constructor<Type_Info (const Type_Info &)>(), "Type_Info");
|
||||||
return any_of(rhs_attrs, fun[lhs](x) { !lhs.has_attr(x.first) || lhs.get_attr(x.first) != x.second; } );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def `==`(Dynamic_Object lhs, Dynamic_Object rhs) : lhs.get_type_name() == rhs.get_type_name()
|
|
||||||
{
|
|
||||||
var rhs_attrs := rhs.get_attrs();
|
|
||||||
var lhs_attrs := lhs.get_attrs();
|
|
||||||
|
|
||||||
if (rhs_attrs.size() != lhs_attrs.size()) {
|
|
||||||
false;
|
|
||||||
} else {
|
|
||||||
return all_of(rhs_attrs, fun[lhs](x) { lhs.has_attr(x.first) && lhs.get_attr(x.first) == x.second; } );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)chaiscript");
|
|
||||||
|
|
||||||
m.add(fun(&has_guard), "has_guard");
|
|
||||||
m.add(fun(&get_guard), "get_guard");
|
|
||||||
|
|
||||||
m.add(fun(&Boxed_Value::is_undef), "is_var_undef");
|
|
||||||
m.add(fun(&Boxed_Value::is_null), "is_var_null");
|
|
||||||
m.add(fun(&Boxed_Value::is_const), "is_var_const");
|
|
||||||
m.add(fun(&Boxed_Value::is_ref), "is_var_reference");
|
|
||||||
m.add(fun(&Boxed_Value::is_pointer), "is_var_pointer");
|
|
||||||
m.add(fun(&Boxed_Value::is_return_value), "is_var_return_value");
|
|
||||||
m.add(fun(&Boxed_Value::reset_return_value), "reset_var_return_value");
|
|
||||||
m.add(fun(&Boxed_Value::is_type), "is_type");
|
|
||||||
m.add(fun(&Boxed_Value::get_attr), "get_var_attr");
|
|
||||||
m.add(fun(&Boxed_Value::copy_attrs), "copy_var_attrs");
|
|
||||||
m.add(fun(&Boxed_Value::clone_attrs), "clone_var_attrs");
|
|
||||||
|
|
||||||
m.add(fun(&Boxed_Value::get_type_info), "get_type_info");
|
|
||||||
m.add(user_type<Type_Info>(), "Type_Info");
|
|
||||||
m.add(constructor<Type_Info (const Type_Info &)>(), "Type_Info");
|
|
||||||
|
|
||||||
|
|
||||||
operators::equal<Type_Info>(m);
|
operators::equal<Type_Info>(m);
|
||||||
|
|
||||||
m.add(fun(&Type_Info::is_const), "is_type_const");
|
m->add(fun(&Type_Info::is_const), "is_type_const");
|
||||||
m.add(fun(&Type_Info::is_reference), "is_type_reference");
|
m->add(fun(&Type_Info::is_reference), "is_type_reference");
|
||||||
m.add(fun(&Type_Info::is_void), "is_type_void");
|
m->add(fun(&Type_Info::is_void), "is_type_void");
|
||||||
m.add(fun(&Type_Info::is_undef), "is_type_undef");
|
m->add(fun(&Type_Info::is_undef), "is_type_undef");
|
||||||
m.add(fun(&Type_Info::is_pointer), "is_type_pointer");
|
m->add(fun(&Type_Info::is_pointer), "is_type_pointer");
|
||||||
m.add(fun(&Type_Info::is_arithmetic), "is_type_arithmetic");
|
m->add(fun(&Type_Info::is_arithmetic), "is_type_arithmetic");
|
||||||
m.add(fun(&Type_Info::name), "cpp_name");
|
m->add(fun(&Type_Info::name), "cpp_name");
|
||||||
m.add(fun(&Type_Info::bare_name), "cpp_bare_name");
|
m->add(fun(&Type_Info::bare_name), "cpp_bare_name");
|
||||||
m.add(fun(&Type_Info::bare_equal), "bare_equal");
|
m->add(fun(&Type_Info::bare_equal), "bare_equal");
|
||||||
|
|
||||||
|
|
||||||
basic_constructors<bool>("bool", m);
|
basic_constructors<bool>("bool", m);
|
||||||
@@ -464,15 +498,15 @@ namespace chaiscript
|
|||||||
operators::equal<bool>(m);
|
operators::equal<bool>(m);
|
||||||
operators::not_equal<bool>(m);
|
operators::not_equal<bool>(m);
|
||||||
|
|
||||||
m.add(fun([](const std::string &s) { return s; }), "to_string");
|
m->add(fun([](const std::string &s) -> std::string { return s; }), "to_string");
|
||||||
m.add(fun([](const bool b) { return std::string(b?"true":"false"); }), "to_string");
|
m->add(fun(&Bootstrap::bool_to_string), "to_string");
|
||||||
m.add(fun(&unknown_assign), "=");
|
m->add(fun(&unknown_assign), "=");
|
||||||
m.add(fun([](const Boxed_Value &bv) { throw bv; }), "throw");
|
m->add(fun(&throw_exception), "throw");
|
||||||
|
m->add(fun(&what), "what");
|
||||||
|
|
||||||
m.add(fun([](const char c) { return std::string(1, c); }), "to_string");
|
m->add(fun(&to_string<char>), "to_string");
|
||||||
m.add(fun(&Boxed_Number::to_string), "to_string");
|
m->add(fun(&Boxed_Number::to_string), "to_string");
|
||||||
|
|
||||||
|
|
||||||
bootstrap_pod_type<double>("double", m);
|
bootstrap_pod_type<double>("double", m);
|
||||||
bootstrap_pod_type<long double>("long_double", m);
|
bootstrap_pod_type<long double>("long_double", m);
|
||||||
bootstrap_pod_type<float>("float", m);
|
bootstrap_pod_type<float>("float", m);
|
||||||
@@ -496,71 +530,58 @@ namespace chaiscript
|
|||||||
bootstrap_pod_type<std::uint32_t>("uint32_t", m);
|
bootstrap_pod_type<std::uint32_t>("uint32_t", m);
|
||||||
bootstrap_pod_type<std::uint64_t>("uint64_t", m);
|
bootstrap_pod_type<std::uint64_t>("uint64_t", m);
|
||||||
|
|
||||||
|
|
||||||
operators::logical_compliment<bool>(m);
|
operators::logical_compliment<bool>(m);
|
||||||
|
|
||||||
opers_arithmetic_pod(m);
|
opers_arithmetic_pod(m);
|
||||||
|
|
||||||
|
|
||||||
m.add(fun(&Build_Info::version_major), "version_major");
|
|
||||||
m.add(fun(&Build_Info::version_minor), "version_minor");
|
|
||||||
m.add(fun(&Build_Info::version_patch), "version_patch");
|
|
||||||
m.add(fun(&Build_Info::version), "version");
|
|
||||||
m.add(fun(&Build_Info::compiler_version), "compiler_version");
|
|
||||||
m.add(fun(&Build_Info::compiler_name), "compiler_name");
|
|
||||||
m.add(fun(&Build_Info::compiler_id), "compiler_id");
|
|
||||||
m.add(fun(&Build_Info::debug_build), "debug_build");
|
|
||||||
|
|
||||||
|
m->add(fun(&print), "print_string");
|
||||||
|
m->add(fun(&println), "println_string");
|
||||||
|
|
||||||
m.add(fun(&print), "print_string");
|
m->add(dispatch::make_dynamic_proxy_function(&bind_function), "bind");
|
||||||
m.add(fun(&println), "println_string");
|
|
||||||
|
|
||||||
m.add(dispatch::make_dynamic_proxy_function(&bind_function), "bind");
|
m->add(fun(&shared_ptr_unconst_clone<dispatch::Proxy_Function_Base>), "clone");
|
||||||
|
m->add(fun(&ptr_assign<std::remove_const<dispatch::Proxy_Function_Base>::type>), "=");
|
||||||
m.add(fun(&shared_ptr_unconst_clone<dispatch::Proxy_Function_Base>), "clone");
|
m->add(fun(&ptr_assign<std::add_const<dispatch::Proxy_Function_Base>::type>), "=");
|
||||||
m.add(fun(&ptr_assign<std::remove_const<dispatch::Proxy_Function_Base>::type>), "=");
|
m->add(chaiscript::base_class<dispatch::Proxy_Function_Base, dispatch::Assignable_Proxy_Function>());
|
||||||
m.add(fun(&ptr_assign<std::add_const<dispatch::Proxy_Function_Base>::type>), "=");
|
m->add(fun(
|
||||||
m.add(chaiscript::base_class<dispatch::Proxy_Function_Base, dispatch::Assignable_Proxy_Function>());
|
|
||||||
m.add(fun(
|
|
||||||
[](dispatch::Assignable_Proxy_Function &t_lhs, const std::shared_ptr<const dispatch::Proxy_Function_Base> &t_rhs) {
|
[](dispatch::Assignable_Proxy_Function &t_lhs, const std::shared_ptr<const dispatch::Proxy_Function_Base> &t_rhs) {
|
||||||
t_lhs.assign(t_rhs);
|
t_lhs.assign(t_rhs);
|
||||||
}
|
}
|
||||||
), "="
|
), "="
|
||||||
);
|
);
|
||||||
|
|
||||||
m.add(fun(&Boxed_Value::type_match), "type_match");
|
m->add(fun(&Boxed_Value::type_match), "type_match");
|
||||||
|
|
||||||
|
|
||||||
m.add(chaiscript::fun(&has_parse_tree), "has_parse_tree");
|
m->add(chaiscript::fun(&has_parse_tree), "has_parse_tree");
|
||||||
m.add(chaiscript::fun(&get_parse_tree), "get_parse_tree");
|
m->add(chaiscript::fun(&get_parse_tree), "get_parse_tree");
|
||||||
|
|
||||||
m.add(chaiscript::base_class<std::runtime_error, chaiscript::exception::eval_error>());
|
m->add(chaiscript::base_class<std::runtime_error, chaiscript::exception::eval_error>());
|
||||||
m.add(chaiscript::base_class<std::exception, chaiscript::exception::eval_error>());
|
|
||||||
|
|
||||||
m.add(chaiscript::user_type<chaiscript::exception::arithmetic_error>(), "arithmetic_error");
|
m->add(chaiscript::user_type<chaiscript::exception::arithmetic_error>(), "arithmetic_error");
|
||||||
m.add(chaiscript::base_class<std::runtime_error, chaiscript::exception::arithmetic_error>());
|
m->add(chaiscript::base_class<std::runtime_error, chaiscript::exception::arithmetic_error>());
|
||||||
m.add(chaiscript::base_class<std::exception, chaiscript::exception::arithmetic_error>());
|
|
||||||
|
|
||||||
|
|
||||||
// chaiscript::bootstrap::standard_library::vector_type<std::vector<std::shared_ptr<chaiscript::AST_Node> > >("AST_NodeVector", m);
|
// chaiscript::bootstrap::standard_library::vector_type<std::vector<std::shared_ptr<chaiscript::AST_Node> > >("AST_NodeVector", m);
|
||||||
|
|
||||||
|
|
||||||
chaiscript::utility::add_class<chaiscript::exception::eval_error>(m,
|
chaiscript::utility::add_class<chaiscript::exception::eval_error>(*m,
|
||||||
"eval_error",
|
"eval_error",
|
||||||
{ },
|
{ },
|
||||||
{ {fun(&chaiscript::exception::eval_error::reason), "reason"},
|
{ {fun(&chaiscript::exception::eval_error::reason), "reason"},
|
||||||
{fun(&chaiscript::exception::eval_error::pretty_print), "pretty_print"},
|
{fun(&chaiscript::exception::eval_error::pretty_print), "pretty_print"},
|
||||||
{fun([](const chaiscript::exception::eval_error &t_eval_error) {
|
{fun(std::function<std::vector<Boxed_Value> (const chaiscript::exception::eval_error &t_eval_error)>([](const chaiscript::exception::eval_error &t_eval_error) -> std::vector<Boxed_Value> {
|
||||||
std::vector<Boxed_Value> retval;
|
std::vector<Boxed_Value> retval;
|
||||||
std::transform(t_eval_error.call_stack.begin(), t_eval_error.call_stack.end(),
|
std::transform(t_eval_error.call_stack.begin(), t_eval_error.call_stack.end(),
|
||||||
std::back_inserter(retval),
|
std::back_inserter(retval),
|
||||||
&chaiscript::var<const std::shared_ptr<const chaiscript::AST_Node> &>);
|
&chaiscript::var<const std::shared_ptr<const chaiscript::AST_Node> &>);
|
||||||
return retval;
|
return retval;
|
||||||
}), "call_stack"} }
|
})), "call_stack"} }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
chaiscript::utility::add_class<chaiscript::File_Position>(m,
|
chaiscript::utility::add_class<chaiscript::File_Position>(*m,
|
||||||
"File_Position",
|
"File_Position",
|
||||||
{ constructor<File_Position()>(),
|
{ constructor<File_Position()>(),
|
||||||
constructor<File_Position(int, int)>() },
|
constructor<File_Position(int, int)>() },
|
||||||
@@ -569,7 +590,7 @@ namespace chaiscript
|
|||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
chaiscript::utility::add_class<AST_Node>(m,
|
chaiscript::utility::add_class<AST_Node>(*m,
|
||||||
"AST_Node",
|
"AST_Node",
|
||||||
{ },
|
{ },
|
||||||
{ {fun(&AST_Node::text), "text"},
|
{ {fun(&AST_Node::text), "text"},
|
||||||
@@ -578,17 +599,28 @@ namespace chaiscript
|
|||||||
{fun(&AST_Node::start), "start"},
|
{fun(&AST_Node::start), "start"},
|
||||||
{fun(&AST_Node::end), "end"},
|
{fun(&AST_Node::end), "end"},
|
||||||
{fun(&AST_Node::to_string), "to_string"},
|
{fun(&AST_Node::to_string), "to_string"},
|
||||||
{fun([](const chaiscript::AST_Node &t_node) -> std::vector<Boxed_Value> {
|
{fun(std::function<std::vector<Boxed_Value> (const chaiscript::AST_Node &t_node)>([](const chaiscript::AST_Node &t_node) -> std::vector<Boxed_Value> {
|
||||||
std::vector<Boxed_Value> retval;
|
std::vector<Boxed_Value> retval;
|
||||||
const auto children = t_node.get_children();
|
std::transform(t_node.children.begin(), t_node.children.end(),
|
||||||
std::transform(children.begin(), children.end(),
|
|
||||||
std::back_inserter(retval),
|
std::back_inserter(retval),
|
||||||
&chaiscript::var<const std::shared_ptr<chaiscript::AST_Node> &>);
|
&chaiscript::var<const std::shared_ptr<chaiscript::AST_Node> &>);
|
||||||
return retval;
|
return retval;
|
||||||
}), "children"}
|
})), "children"},
|
||||||
|
{fun(&AST_Node::replace_child), "replace_child"}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
chaiscript::utility::add_class<parser::ChaiScript_Parser>(*m,
|
||||||
|
"ChaiScript_Parser",
|
||||||
|
{ constructor<parser::ChaiScript_Parser ()>() },
|
||||||
|
{ {fun(&parser::ChaiScript_Parser::parse), "parse"},
|
||||||
|
{fun(&parser::ChaiScript_Parser::ast), "ast"} }
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return m;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@@ -177,20 +177,22 @@ namespace chaiscript
|
|||||||
|
|
||||||
/// Add Bidir_Range support for the given ContainerType
|
/// Add Bidir_Range support for the given ContainerType
|
||||||
template<typename Bidir_Type>
|
template<typename Bidir_Type>
|
||||||
void input_range_type_impl(const std::string &type, Module& m)
|
ModulePtr input_range_type_impl(const std::string &type, ModulePtr m = std::make_shared<Module>())
|
||||||
{
|
{
|
||||||
m.add(user_type<Bidir_Type>(), type + "_Range");
|
m->add(user_type<Bidir_Type>(), type + "_Range");
|
||||||
|
|
||||||
copy_constructor<Bidir_Type>(type + "_Range", m);
|
copy_constructor<Bidir_Type>(type + "_Range", m);
|
||||||
|
|
||||||
m.add(constructor<Bidir_Type (typename Bidir_Type::container_type &)>(), "range_internal");
|
m->add(constructor<Bidir_Type (typename Bidir_Type::container_type &)>(), "range_internal");
|
||||||
|
|
||||||
m.add(fun(&Bidir_Type::empty), "empty");
|
m->add(fun(&Bidir_Type::empty), "empty");
|
||||||
m.add(fun(&Bidir_Type::pop_front), "pop_front");
|
m->add(fun(&Bidir_Type::pop_front), "pop_front");
|
||||||
m.add(fun(&Bidir_Type::front), "front");
|
m->add(fun(&Bidir_Type::front), "front");
|
||||||
m.add(fun(&Bidir_Type::pop_back), "pop_back");
|
m->add(fun(&Bidir_Type::pop_back), "pop_back");
|
||||||
m.add(fun(&Bidir_Type::back), "back");
|
m->add(fun(&Bidir_Type::back), "back");
|
||||||
}
|
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Algorithm for inserting at a specific position into a container
|
/// Algorithm for inserting at a specific position into a container
|
||||||
@@ -228,16 +230,10 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename ContainerType>
|
template<typename ContainerType>
|
||||||
void input_range_type(const std::string &type, Module& m)
|
ModulePtr input_range_type(const std::string &type, ModulePtr m = std::make_shared<Module>())
|
||||||
{
|
{
|
||||||
detail::input_range_type_impl<Bidir_Range<ContainerType> >(type,m);
|
detail::input_range_type_impl<Bidir_Range<ContainerType> >(type,m);
|
||||||
detail::input_range_type_impl<Const_Bidir_Range<ContainerType> >("Const_" + type, m);
|
detail::input_range_type_impl<Const_Bidir_Range<ContainerType> >("Const_" + type, m);
|
||||||
}
|
|
||||||
template<typename ContainerType>
|
|
||||||
ModulePtr input_range_type(const std::string &type)
|
|
||||||
{
|
|
||||||
auto m = std::make_shared<Module>();
|
|
||||||
input_range_type<ContainerType>(type, *m);
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -245,11 +241,11 @@ namespace chaiscript
|
|||||||
/// Add random_access_container concept to the given ContainerType
|
/// Add random_access_container concept to the given ContainerType
|
||||||
/// http://www.sgi.com/tech/stl/RandomAccessContainer.html
|
/// http://www.sgi.com/tech/stl/RandomAccessContainer.html
|
||||||
template<typename ContainerType>
|
template<typename ContainerType>
|
||||||
void random_access_container_type(const std::string &/*type*/, Module& m)
|
ModulePtr random_access_container_type(const std::string &/*type*/, ModulePtr m = std::make_shared<Module>())
|
||||||
{
|
{
|
||||||
//In the interest of runtime safety for the m, we prefer the at() method for [] access,
|
//In the interest of runtime safety for the m, we prefer the at() method for [] access,
|
||||||
//to throw an exception in an out of bounds condition.
|
//to throw an exception in an out of bounds condition.
|
||||||
m.add(
|
m->add(
|
||||||
fun(
|
fun(
|
||||||
[](ContainerType &c, int index) -> typename ContainerType::reference {
|
[](ContainerType &c, int index) -> typename ContainerType::reference {
|
||||||
/// \todo we are prefering to keep the key as 'int' to avoid runtime conversions
|
/// \todo we are prefering to keep the key as 'int' to avoid runtime conversions
|
||||||
@@ -257,71 +253,25 @@ namespace chaiscript
|
|||||||
return c.at(static_cast<typename ContainerType::size_type>(index));
|
return c.at(static_cast<typename ContainerType::size_type>(index));
|
||||||
}), "[]");
|
}), "[]");
|
||||||
|
|
||||||
m.add(
|
m->add(
|
||||||
fun(
|
fun(
|
||||||
[](const ContainerType &c, int index) -> typename ContainerType::const_reference {
|
[](const ContainerType &c, int index) -> typename ContainerType::const_reference {
|
||||||
/// \todo we are prefering to keep the key as 'int' to avoid runtime conversions
|
/// \todo we are prefering to keep the key as 'int' to avoid runtime conversions
|
||||||
/// during dispatch. reevaluate
|
/// during dispatch. reevaluate
|
||||||
return c.at(static_cast<typename ContainerType::size_type>(index));
|
return c.at(static_cast<typename ContainerType::size_type>(index));
|
||||||
}), "[]");
|
}), "[]");
|
||||||
}
|
|
||||||
template<typename ContainerType>
|
|
||||||
ModulePtr random_access_container_type(const std::string &type)
|
|
||||||
{
|
|
||||||
auto m = std::make_shared<Module>();
|
|
||||||
random_access_container_type<ContainerType>(type, *m);
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// Add assignable concept to the given ContainerType
|
/// Add assignable concept to the given ContainerType
|
||||||
/// http://www.sgi.com/tech/stl/Assignable.html
|
/// http://www.sgi.com/tech/stl/Assignable.html
|
||||||
template<typename ContainerType>
|
template<typename ContainerType>
|
||||||
void assignable_type(const std::string &type, Module& m)
|
ModulePtr assignable_type(const std::string &type, ModulePtr m = std::make_shared<Module>())
|
||||||
{
|
{
|
||||||
copy_constructor<ContainerType>(type, m);
|
copy_constructor<ContainerType>(type, m);
|
||||||
operators::assign<ContainerType>(m);
|
operators::assign<ContainerType>(m);
|
||||||
}
|
|
||||||
template<typename ContainerType>
|
|
||||||
ModulePtr assignable_type(const std::string &type)
|
|
||||||
{
|
|
||||||
auto m = std::make_shared<Module>();
|
|
||||||
assignable_type<ContainerType>(type, *m);
|
|
||||||
return m;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// Add container resize concept to the given ContainerType
|
|
||||||
/// http://www.cplusplus.com/reference/stl/
|
|
||||||
template<typename ContainerType>
|
|
||||||
void resizable_type(const std::string &/*type*/, Module& m)
|
|
||||||
{
|
|
||||||
m.add(fun([](ContainerType *a, typename ContainerType::size_type n, const typename ContainerType::value_type& val) { return a->resize(n, val); } ), "resize");
|
|
||||||
m.add(fun([](ContainerType *a, typename ContainerType::size_type n) { return a->resize(n); } ), "resize");
|
|
||||||
}
|
|
||||||
template<typename ContainerType>
|
|
||||||
ModulePtr resizable_type(const std::string &type)
|
|
||||||
{
|
|
||||||
auto m = std::make_shared<Module>();
|
|
||||||
resizable_type<ContainerType>(type, *m);
|
|
||||||
return m;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// Add container reserve concept to the given ContainerType
|
|
||||||
/// http://www.cplusplus.com/reference/stl/
|
|
||||||
template<typename ContainerType>
|
|
||||||
void reservable_type(const std::string &/*type*/, Module& m)
|
|
||||||
{
|
|
||||||
m.add(fun([](ContainerType *a, typename ContainerType::size_type n) { return a->reserve(n); } ), "reserve");
|
|
||||||
m.add(fun([](const ContainerType *a) { return a->capacity(); } ), "capacity");
|
|
||||||
}
|
|
||||||
template<typename ContainerType>
|
|
||||||
ModulePtr reservable_type(const std::string &type)
|
|
||||||
{
|
|
||||||
auto m = std::make_shared<Module>();
|
|
||||||
reservable_type<ContainerType>(type, *m);
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -329,44 +279,33 @@ namespace chaiscript
|
|||||||
/// Add container concept to the given ContainerType
|
/// Add container concept to the given ContainerType
|
||||||
/// http://www.sgi.com/tech/stl/Container.html
|
/// http://www.sgi.com/tech/stl/Container.html
|
||||||
template<typename ContainerType>
|
template<typename ContainerType>
|
||||||
void container_type(const std::string &/*type*/, Module& m)
|
ModulePtr container_type(const std::string &/*type*/, ModulePtr m = std::make_shared<Module>())
|
||||||
{
|
{
|
||||||
m.add(fun([](const ContainerType *a) { return a->size(); } ), "size");
|
m->add(fun([](const ContainerType *a) { return a->size(); } ), "size");
|
||||||
m.add(fun([](const ContainerType *a) { return a->empty(); } ), "empty");
|
m->add(fun([](const ContainerType *a) { return a->empty(); } ), "empty");
|
||||||
m.add(fun([](ContainerType *a) { a->clear(); } ), "clear");
|
m->add(fun([](ContainerType *a) { a->clear(); } ), "clear");
|
||||||
|
return m;
|
||||||
}
|
}
|
||||||
template <typename ContainerType>
|
|
||||||
ModulePtr container_type(const std::string& type)
|
|
||||||
{
|
|
||||||
auto m = std::make_shared<Module>();
|
|
||||||
container_type<ContainerType>(type, *m);
|
|
||||||
return m;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// Add default constructable concept to the given Type
|
/// Add default constructable concept to the given Type
|
||||||
/// http://www.sgi.com/tech/stl/DefaultConstructible.html
|
/// http://www.sgi.com/tech/stl/DefaultConstructible.html
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
void default_constructible_type(const std::string &type, Module& m)
|
ModulePtr default_constructible_type(const std::string &type, ModulePtr m = std::make_shared<Module>())
|
||||||
{
|
{
|
||||||
m.add(constructor<Type ()>(), type);
|
m->add(constructor<Type ()>(), type);
|
||||||
}
|
|
||||||
template <typename Type>
|
|
||||||
ModulePtr default_constructible_type(const std::string& type)
|
|
||||||
{
|
|
||||||
auto m = std::make_shared<Module>();
|
|
||||||
default_constructible_type<Type>(type, *m);
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// Add sequence concept to the given ContainerType
|
/// Add sequence concept to the given ContainerType
|
||||||
/// http://www.sgi.com/tech/stl/Sequence.html
|
/// http://www.sgi.com/tech/stl/Sequence.html
|
||||||
template<typename ContainerType>
|
template<typename ContainerType>
|
||||||
void sequence_type(const std::string &/*type*/, Module& m)
|
ModulePtr sequence_type(const std::string &/*type*/, ModulePtr m = std::make_shared<Module>())
|
||||||
{
|
{
|
||||||
m.add(fun(&detail::insert_at<ContainerType>),
|
m->add(fun(&detail::insert_at<ContainerType>),
|
||||||
[]()->std::string{
|
[]()->std::string{
|
||||||
if (typeid(typename ContainerType::value_type) == typeid(Boxed_Value)) {
|
if (typeid(typename ContainerType::value_type) == typeid(Boxed_Value)) {
|
||||||
return "insert_ref_at";
|
return "insert_ref_at";
|
||||||
@@ -375,31 +314,27 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
}());
|
}());
|
||||||
|
|
||||||
m.add(fun(&detail::erase_at<ContainerType>), "erase_at");
|
m->add(fun(&detail::erase_at<ContainerType>), "erase_at");
|
||||||
}
|
|
||||||
template <typename ContainerType>
|
|
||||||
ModulePtr sequence_type(const std::string &type)
|
|
||||||
{
|
|
||||||
auto m = std::make_shared<Module>();
|
|
||||||
sequence_type<ContainerType>(type, *m);
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Add back insertion sequence concept to the given ContainerType
|
/// Add back insertion sequence concept to the given ContainerType
|
||||||
/// http://www.sgi.com/tech/stl/BackInsertionSequence.html
|
/// http://www.sgi.com/tech/stl/BackInsertionSequence.html
|
||||||
template<typename ContainerType>
|
template<typename ContainerType>
|
||||||
void back_insertion_sequence_type(const std::string &type, Module& m)
|
ModulePtr back_insertion_sequence_type(const std::string &type, ModulePtr m = std::make_shared<Module>())
|
||||||
{
|
{
|
||||||
typedef typename ContainerType::reference (ContainerType::*backptr)();
|
typedef typename ContainerType::reference (ContainerType::*backptr)();
|
||||||
|
|
||||||
m.add(fun(static_cast<backptr>(&ContainerType::back)), "back");
|
m->add(fun(static_cast<backptr>(&ContainerType::back)), "back");
|
||||||
|
|
||||||
|
|
||||||
typedef void (ContainerType::*push_back)(const typename ContainerType::value_type &);
|
typedef void (ContainerType::*push_back)(const typename ContainerType::value_type &);
|
||||||
m.add(fun(static_cast<push_back>(&ContainerType::push_back)),
|
m->add(fun(static_cast<push_back>(&ContainerType::push_back)),
|
||||||
[&]()->std::string{
|
[&]()->std::string{
|
||||||
if (typeid(typename ContainerType::value_type) == typeid(Boxed_Value)) {
|
if (typeid(typename ContainerType::value_type) == typeid(Boxed_Value)) {
|
||||||
m.eval(
|
m->eval(
|
||||||
"# Pushes the second value onto the container while making a clone of the value\n"
|
"# Pushes the second value onto the container while making a clone of the value\n"
|
||||||
"def push_back(" + type + " container, x)\n"
|
"def push_back(" + type + " container, x)\n"
|
||||||
"{ \n"
|
"{ \n"
|
||||||
@@ -418,13 +353,7 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
}());
|
}());
|
||||||
|
|
||||||
m.add(fun(&ContainerType::pop_back), "pop_back");
|
m->add(fun(&ContainerType::pop_back), "pop_back");
|
||||||
}
|
|
||||||
template<typename ContainerType>
|
|
||||||
ModulePtr back_insertion_sequence_type(const std::string &type)
|
|
||||||
{
|
|
||||||
auto m = std::make_shared<Module>();
|
|
||||||
back_insertion_sequence_type<ContainerType>(type, *m);
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -433,20 +362,20 @@ namespace chaiscript
|
|||||||
/// Front insertion sequence
|
/// Front insertion sequence
|
||||||
/// http://www.sgi.com/tech/stl/FrontInsertionSequence.html
|
/// http://www.sgi.com/tech/stl/FrontInsertionSequence.html
|
||||||
template<typename ContainerType>
|
template<typename ContainerType>
|
||||||
void front_insertion_sequence_type(const std::string &type, Module& m)
|
ModulePtr front_insertion_sequence_type(const std::string &type, ModulePtr m = std::make_shared<Module>())
|
||||||
{
|
{
|
||||||
typedef typename ContainerType::reference (ContainerType::*front_ptr)();
|
typedef typename ContainerType::reference (ContainerType::*front_ptr)();
|
||||||
typedef typename ContainerType::const_reference (ContainerType::*const_front_ptr)() const;
|
typedef typename ContainerType::const_reference (ContainerType::*const_front_ptr)() const;
|
||||||
typedef void (ContainerType::*push_ptr)(typename ContainerType::const_reference);
|
typedef void (ContainerType::*push_ptr)(typename ContainerType::const_reference);
|
||||||
typedef void (ContainerType::*pop_ptr)();
|
typedef void (ContainerType::*pop_ptr)();
|
||||||
|
|
||||||
m.add(fun(static_cast<front_ptr>(&ContainerType::front)), "front");
|
m->add(fun(static_cast<front_ptr>(&ContainerType::front)), "front");
|
||||||
m.add(fun(static_cast<const_front_ptr>(&ContainerType::front)), "front");
|
m->add(fun(static_cast<const_front_ptr>(&ContainerType::front)), "front");
|
||||||
|
|
||||||
m.add(fun(static_cast<push_ptr>(&ContainerType::push_front)),
|
m->add(fun(static_cast<push_ptr>(&ContainerType::push_front)),
|
||||||
[&]()->std::string{
|
[&]()->std::string{
|
||||||
if (typeid(typename ContainerType::value_type) == typeid(Boxed_Value)) {
|
if (typeid(typename ContainerType::value_type) == typeid(Boxed_Value)) {
|
||||||
m.eval(
|
m->eval(
|
||||||
"# Pushes the second value onto the front of container while making a clone of the value\n"
|
"# Pushes the second value onto the front of container while making a clone of the value\n"
|
||||||
"def push_front(" + type + " container, x)\n"
|
"def push_front(" + type + " container, x)\n"
|
||||||
"{ \n"
|
"{ \n"
|
||||||
@@ -464,13 +393,7 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
}());
|
}());
|
||||||
|
|
||||||
m.add(fun(static_cast<pop_ptr>(&ContainerType::pop_front)), "pop_front");
|
m->add(fun(static_cast<pop_ptr>(&ContainerType::pop_front)), "pop_front");
|
||||||
}
|
|
||||||
template<typename ContainerType>
|
|
||||||
ModulePtr front_insertion_sequence_type(const std::string &type)
|
|
||||||
{
|
|
||||||
auto m = std::make_shared<Module>();
|
|
||||||
front_insertion_sequence_type<ContainerType>(type, *m);
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -478,25 +401,20 @@ namespace chaiscript
|
|||||||
/// bootstrap a given PairType
|
/// bootstrap a given PairType
|
||||||
/// http://www.sgi.com/tech/stl/pair.html
|
/// http://www.sgi.com/tech/stl/pair.html
|
||||||
template<typename PairType>
|
template<typename PairType>
|
||||||
void pair_type(const std::string &type, Module& m)
|
ModulePtr pair_type(const std::string &type, ModulePtr m = std::make_shared<Module>())
|
||||||
{
|
{
|
||||||
m.add(user_type<PairType>(), type);
|
m->add(user_type<PairType>(), type);
|
||||||
|
|
||||||
|
|
||||||
typename PairType::first_type PairType::* f = &PairType::first;
|
typename PairType::first_type PairType::* f = &PairType::first;
|
||||||
typename PairType::second_type PairType::* s = &PairType::second;
|
typename PairType::second_type PairType::* s = &PairType::second;
|
||||||
|
|
||||||
m.add(fun(f), "first");
|
m->add(fun(f), "first");
|
||||||
m.add(fun(s), "second");
|
m->add(fun(s), "second");
|
||||||
|
|
||||||
basic_constructors<PairType>(type, m);
|
basic_constructors<PairType>(type, m);
|
||||||
m.add(constructor<PairType (const typename PairType::first_type &, const typename PairType::second_type &)>(), type);
|
m->add(constructor<PairType (const typename PairType::first_type &, const typename PairType::second_type &)>(), type);
|
||||||
}
|
|
||||||
template<typename PairType>
|
|
||||||
ModulePtr pair_type(const std::string &type)
|
|
||||||
{
|
|
||||||
auto m = std::make_shared<Module>();
|
|
||||||
pair_type<PairType>(type, *m);
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -506,15 +424,10 @@ namespace chaiscript
|
|||||||
/// http://www.sgi.com/tech/stl/PairAssociativeContainer.html
|
/// http://www.sgi.com/tech/stl/PairAssociativeContainer.html
|
||||||
|
|
||||||
template<typename ContainerType>
|
template<typename ContainerType>
|
||||||
void pair_associative_container_type(const std::string &type, Module& m)
|
ModulePtr pair_associative_container_type(const std::string &type, ModulePtr m = std::make_shared<Module>())
|
||||||
{
|
{
|
||||||
pair_type<typename ContainerType::value_type>(type + "_Pair", m);
|
pair_type<typename ContainerType::value_type>(type + "_Pair", m);
|
||||||
}
|
|
||||||
template<typename ContainerType>
|
|
||||||
ModulePtr pair_associative_container_type(const std::string &type)
|
|
||||||
{
|
|
||||||
auto m = std::make_shared<Module>();
|
|
||||||
pair_associative_container_type<ContainerType>(type, *m);
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -522,17 +435,17 @@ namespace chaiscript
|
|||||||
/// Add unique associative container concept to the given ContainerType
|
/// Add unique associative container concept to the given ContainerType
|
||||||
/// http://www.sgi.com/tech/stl/UniqueAssociativeContainer.html
|
/// http://www.sgi.com/tech/stl/UniqueAssociativeContainer.html
|
||||||
template<typename ContainerType>
|
template<typename ContainerType>
|
||||||
void unique_associative_container_type(const std::string &/*type*/, Module& m)
|
ModulePtr unique_associative_container_type(const std::string &/*type*/, ModulePtr m = std::make_shared<Module>())
|
||||||
{
|
{
|
||||||
m.add(fun(detail::count<ContainerType>), "count");
|
m->add(fun(detail::count<ContainerType>), "count");
|
||||||
|
|
||||||
typedef size_t (ContainerType::*erase_ptr)(const typename ContainerType::key_type &);
|
typedef size_t (ContainerType::*erase_ptr)(const typename ContainerType::key_type &);
|
||||||
|
|
||||||
m.add(fun(static_cast<erase_ptr>(&ContainerType::erase)), "erase");
|
m->add(fun(static_cast<erase_ptr>(&ContainerType::erase)), "erase");
|
||||||
|
|
||||||
m.add(fun(&detail::insert<ContainerType>), "insert");
|
m->add(fun(&detail::insert<ContainerType>), "insert");
|
||||||
|
|
||||||
m.add(fun(&detail::insert_ref<ContainerType>),
|
m->add(fun(&detail::insert_ref<ContainerType>),
|
||||||
[]()->std::string{
|
[]()->std::string{
|
||||||
if (typeid(typename ContainerType::mapped_type) == typeid(Boxed_Value)) {
|
if (typeid(typename ContainerType::mapped_type) == typeid(Boxed_Value)) {
|
||||||
return "insert_ref";
|
return "insert_ref";
|
||||||
@@ -540,12 +453,8 @@ namespace chaiscript
|
|||||||
return "insert";
|
return "insert";
|
||||||
}
|
}
|
||||||
}());
|
}());
|
||||||
}
|
|
||||||
template<typename ContainerType>
|
|
||||||
ModulePtr unique_associative_container_type(const std::string &type)
|
|
||||||
{
|
|
||||||
auto m = std::make_shared<Module>();
|
|
||||||
unique_associative_container_type<ContainerType>(type, *m);
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -553,21 +462,21 @@ namespace chaiscript
|
|||||||
/// Add a MapType container
|
/// Add a MapType container
|
||||||
/// http://www.sgi.com/tech/stl/Map.html
|
/// http://www.sgi.com/tech/stl/Map.html
|
||||||
template<typename MapType>
|
template<typename MapType>
|
||||||
void map_type(const std::string &type, Module& m)
|
ModulePtr map_type(const std::string &type, ModulePtr m = std::make_shared<Module>())
|
||||||
{
|
{
|
||||||
m.add(user_type<MapType>(), type);
|
m->add(user_type<MapType>(), type);
|
||||||
|
|
||||||
typedef typename MapType::mapped_type &(MapType::*elem_access)(const typename MapType::key_type &);
|
typedef typename MapType::mapped_type &(MapType::*elem_access)(const typename MapType::key_type &);
|
||||||
typedef const typename MapType::mapped_type &(MapType::*const_elem_access)(const typename MapType::key_type &) const;
|
typedef const typename MapType::mapped_type &(MapType::*const_elem_access)(const typename MapType::key_type &) const;
|
||||||
|
|
||||||
m.add(fun(static_cast<elem_access>(&MapType::operator[])), "[]");
|
m->add(fun(static_cast<elem_access>(&MapType::operator[])), "[]");
|
||||||
|
|
||||||
m.add(fun(static_cast<elem_access>(&MapType::at)), "at");
|
m->add(fun(static_cast<elem_access>(&MapType::at)), "at");
|
||||||
m.add(fun(static_cast<const_elem_access>(&MapType::at)), "at");
|
m->add(fun(static_cast<const_elem_access>(&MapType::at)), "at");
|
||||||
|
|
||||||
if (typeid(MapType) == typeid(std::map<std::string, Boxed_Value>))
|
if (typeid(MapType) == typeid(std::map<std::string, Boxed_Value>))
|
||||||
{
|
{
|
||||||
m.eval(R"(
|
m->eval(R"(
|
||||||
def Map::`==`(Map rhs) {
|
def Map::`==`(Map rhs) {
|
||||||
if ( rhs.size() != this.size() ) {
|
if ( rhs.size() != this.size() ) {
|
||||||
return false;
|
return false;
|
||||||
@@ -595,12 +504,7 @@ namespace chaiscript
|
|||||||
unique_associative_container_type<MapType>(type, m);
|
unique_associative_container_type<MapType>(type, m);
|
||||||
pair_associative_container_type<MapType>(type, m);
|
pair_associative_container_type<MapType>(type, m);
|
||||||
input_range_type<MapType>(type, m);
|
input_range_type<MapType>(type, m);
|
||||||
}
|
|
||||||
template<typename MapType>
|
|
||||||
ModulePtr map_type(const std::string &type)
|
|
||||||
{
|
|
||||||
auto m = std::make_shared<Module>();
|
|
||||||
map_type<MapType>(type, *m);
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -608,24 +512,18 @@ namespace chaiscript
|
|||||||
/// hopefully working List type
|
/// hopefully working List type
|
||||||
/// http://www.sgi.com/tech/stl/List.html
|
/// http://www.sgi.com/tech/stl/List.html
|
||||||
template<typename ListType>
|
template<typename ListType>
|
||||||
void list_type(const std::string &type, Module& m)
|
ModulePtr list_type(const std::string &type, ModulePtr m = std::make_shared<Module>())
|
||||||
{
|
{
|
||||||
m.add(user_type<ListType>(), type);
|
m->add(user_type<ListType>(), type);
|
||||||
|
|
||||||
front_insertion_sequence_type<ListType>(type, m);
|
front_insertion_sequence_type<ListType>(type, m);
|
||||||
back_insertion_sequence_type<ListType>(type, m);
|
back_insertion_sequence_type<ListType>(type, m);
|
||||||
sequence_type<ListType>(type, m);
|
sequence_type<ListType>(type, m);
|
||||||
resizable_type<ListType>(type, m);
|
|
||||||
container_type<ListType>(type, m);
|
container_type<ListType>(type, m);
|
||||||
default_constructible_type<ListType>(type, m);
|
default_constructible_type<ListType>(type, m);
|
||||||
assignable_type<ListType>(type, m);
|
assignable_type<ListType>(type, m);
|
||||||
input_range_type<ListType>(type, m);
|
input_range_type<ListType>(type, m);
|
||||||
}
|
|
||||||
template<typename ListType>
|
|
||||||
ModulePtr list_type(const std::string &type)
|
|
||||||
{
|
|
||||||
auto m = std::make_shared<Module>();
|
|
||||||
list_type<ListType>(type, m);
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -633,22 +531,20 @@ namespace chaiscript
|
|||||||
/// Create a vector type with associated concepts
|
/// Create a vector type with associated concepts
|
||||||
/// http://www.sgi.com/tech/stl/Vector.html
|
/// http://www.sgi.com/tech/stl/Vector.html
|
||||||
template<typename VectorType>
|
template<typename VectorType>
|
||||||
void vector_type(const std::string &type, Module& m)
|
ModulePtr vector_type(const std::string &type, ModulePtr m = std::make_shared<Module>())
|
||||||
{
|
{
|
||||||
m.add(user_type<VectorType>(), type);
|
m->add(user_type<VectorType>(), type);
|
||||||
|
|
||||||
typedef typename VectorType::reference (VectorType::*frontptr)();
|
typedef typename VectorType::reference (VectorType::*frontptr)();
|
||||||
typedef typename VectorType::const_reference (VectorType::*constfrontptr)() const;
|
typedef typename VectorType::const_reference (VectorType::*constfrontptr)() const;
|
||||||
|
|
||||||
m.add(fun(static_cast<frontptr>(&VectorType::front)), "front");
|
m->add(fun(static_cast<frontptr>(&VectorType::front)), "front");
|
||||||
m.add(fun(static_cast<constfrontptr>(&VectorType::front)), "front");
|
m->add(fun(static_cast<constfrontptr>(&VectorType::front)), "front");
|
||||||
|
|
||||||
|
|
||||||
back_insertion_sequence_type<VectorType>(type, m);
|
back_insertion_sequence_type<VectorType>(type, m);
|
||||||
sequence_type<VectorType>(type, m);
|
sequence_type<VectorType>(type, m);
|
||||||
random_access_container_type<VectorType>(type, m);
|
random_access_container_type<VectorType>(type, m);
|
||||||
resizable_type<VectorType>(type, m);
|
|
||||||
reservable_type<VectorType>(type, m);
|
|
||||||
container_type<VectorType>(type, m);
|
container_type<VectorType>(type, m);
|
||||||
default_constructible_type<VectorType>(type, m);
|
default_constructible_type<VectorType>(type, m);
|
||||||
assignable_type<VectorType>(type, m);
|
assignable_type<VectorType>(type, m);
|
||||||
@@ -656,7 +552,7 @@ namespace chaiscript
|
|||||||
|
|
||||||
if (typeid(VectorType) == typeid(std::vector<Boxed_Value>))
|
if (typeid(VectorType) == typeid(std::vector<Boxed_Value>))
|
||||||
{
|
{
|
||||||
m.eval(R"(
|
m->eval(R"(
|
||||||
def Vector::`==`(Vector rhs) {
|
def Vector::`==`(Vector rhs) {
|
||||||
if ( rhs.size() != this.size() ) {
|
if ( rhs.size() != this.size() ) {
|
||||||
return false;
|
return false;
|
||||||
@@ -677,21 +573,16 @@ namespace chaiscript
|
|||||||
} )"
|
} )"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
template<typename VectorType>
|
|
||||||
ModulePtr vector_type(const std::string &type)
|
|
||||||
{
|
|
||||||
auto m = std::make_shared<Module>();
|
|
||||||
vector_type<VectorType>(type, *m);
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add a String container
|
/// Add a String container
|
||||||
/// http://www.sgi.com/tech/stl/basic_string.html
|
/// http://www.sgi.com/tech/stl/basic_string.html
|
||||||
template<typename String>
|
template<typename String>
|
||||||
void string_type(const std::string &type, Module& m)
|
ModulePtr string_type(const std::string &type, ModulePtr m = std::make_shared<Module>())
|
||||||
{
|
{
|
||||||
m.add(user_type<String>(), type);
|
m->add(user_type<String>(), type);
|
||||||
operators::addition<String>(m);
|
operators::addition<String>(m);
|
||||||
operators::assign_sum<String>(m);
|
operators::assign_sum<String>(m);
|
||||||
opers_comparison<String>(m);
|
opers_comparison<String>(m);
|
||||||
@@ -703,7 +594,7 @@ namespace chaiscript
|
|||||||
input_range_type<String>(type, m);
|
input_range_type<String>(type, m);
|
||||||
|
|
||||||
//Special case: add push_back to string (which doesn't support other back_insertion operations
|
//Special case: add push_back to string (which doesn't support other back_insertion operations
|
||||||
m.add(fun(&String::push_back),
|
m->add(fun(&String::push_back),
|
||||||
[]()->std::string{
|
[]()->std::string{
|
||||||
if (typeid(typename String::value_type) == typeid(Boxed_Value)) {
|
if (typeid(typename String::value_type) == typeid(Boxed_Value)) {
|
||||||
return "push_back_ref";
|
return "push_back_ref";
|
||||||
@@ -713,26 +604,21 @@ namespace chaiscript
|
|||||||
}());
|
}());
|
||||||
|
|
||||||
|
|
||||||
m.add(fun([](const String *s, const String &f, size_t pos) { return s->find(f, pos); } ), "find");
|
m->add(fun([](const String *s, const String &f, size_t pos) { return s->find(f, pos); } ), "find");
|
||||||
m.add(fun([](const String *s, const String &f, size_t pos) { return s->rfind(f, pos); } ), "rfind");
|
m->add(fun([](const String *s, const String &f, size_t pos) { return s->rfind(f, pos); } ), "rfind");
|
||||||
m.add(fun([](const String *s, const String &f, size_t pos) { return s->find_first_of(f, pos); } ), "find_first_of");
|
m->add(fun([](const String *s, const String &f, size_t pos) { return s->find_first_of(f, pos); } ), "find_first_of");
|
||||||
m.add(fun([](const String *s, const String &f, size_t pos) { return s->find_last_of(f, pos); } ), "find_last_of");
|
m->add(fun([](const String *s, const String &f, size_t pos) { return s->find_last_of(f, pos); } ), "find_last_of");
|
||||||
m.add(fun([](const String *s, const String &f, size_t pos) { return s->find_last_not_of(f, pos); } ), "find_last_not_of");
|
m->add(fun([](const String *s, const String &f, size_t pos) { return s->find_last_not_of(f, pos); } ), "find_last_not_of");
|
||||||
m.add(fun([](const String *s, const String &f, size_t pos) { return s->find_first_not_of(f, pos); } ), "find_first_not_of");
|
m->add(fun([](const String *s, const String &f, size_t pos) { return s->find_first_not_of(f, pos); } ), "find_first_not_of");
|
||||||
|
|
||||||
m.add(fun([](String *s) { s->clear(); } ), "clear");
|
m->add(fun([](String *s) { s->clear(); } ), "clear");
|
||||||
m.add(fun([](const String *s) { return s->empty(); } ), "empty");
|
m->add(fun([](const String *s) { return s->empty(); } ), "empty");
|
||||||
m.add(fun([](const String *s) { return s->size(); } ), "size");
|
m->add(fun([](const String *s) { return s->size(); } ), "size");
|
||||||
|
|
||||||
|
m->add(fun([](const String *s) { return s->c_str(); } ), "c_str");
|
||||||
|
m->add(fun([](const String *s) { return s->data(); } ), "data");
|
||||||
|
m->add(fun([](const String *s, size_t pos, size_t len) { return s->substr(pos, len); } ), "substr");
|
||||||
|
|
||||||
m.add(fun([](const String *s) { return s->c_str(); } ), "c_str");
|
|
||||||
m.add(fun([](const String *s) { return s->data(); } ), "data");
|
|
||||||
m.add(fun([](const String *s, size_t pos, size_t len) { return s->substr(pos, len); } ), "substr");
|
|
||||||
}
|
|
||||||
template<typename String>
|
|
||||||
ModulePtr string_type(const std::string &type)
|
|
||||||
{
|
|
||||||
auto m = std::make_shared<Module>();
|
|
||||||
string_type<String>(type, *m);
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -741,19 +627,14 @@ namespace chaiscript
|
|||||||
/// Add a MapType container
|
/// Add a MapType container
|
||||||
/// http://www.sgi.com/tech/stl/Map.html
|
/// http://www.sgi.com/tech/stl/Map.html
|
||||||
template<typename FutureType>
|
template<typename FutureType>
|
||||||
void future_type(const std::string &type, Module& m)
|
ModulePtr future_type(const std::string &type, ModulePtr m = std::make_shared<Module>())
|
||||||
{
|
{
|
||||||
m.add(user_type<FutureType>(), type);
|
m->add(user_type<FutureType>(), type);
|
||||||
|
|
||||||
|
m->add(fun([](const FutureType &t) { return t.valid(); }), "valid");
|
||||||
|
m->add(fun(&FutureType::get), "get");
|
||||||
|
m->add(fun(&FutureType::wait), "wait");
|
||||||
|
|
||||||
m.add(fun([](const FutureType &t) { return t.valid(); }), "valid");
|
|
||||||
m.add(fun(&FutureType::get), "get");
|
|
||||||
m.add(fun(&FutureType::wait), "wait");
|
|
||||||
}
|
|
||||||
template<typename FutureType>
|
|
||||||
ModulePtr future_type(const std::string &type)
|
|
||||||
{
|
|
||||||
auto m = std::make_shared<Module>();
|
|
||||||
future_type<FutureType>(type, *m);
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -69,11 +69,11 @@ namespace chaiscript
|
|||||||
/// assert(i == 5);
|
/// assert(i == 5);
|
||||||
/// \endcode
|
/// \endcode
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
decltype(auto) boxed_cast(const Boxed_Value &bv, const Type_Conversions_State *t_conversions = nullptr)
|
typename detail::Cast_Helper<Type>::Result_Type boxed_cast(const Boxed_Value &bv, const Type_Conversions_State *t_conversions = nullptr)
|
||||||
{
|
{
|
||||||
if (!t_conversions || bv.get_type_info().bare_equal(user_type<Type>()) || (t_conversions && !(*t_conversions)->convertable_type<Type>())) {
|
if (!t_conversions || bv.get_type_info().bare_equal(user_type<Type>()) || (t_conversions && !(*t_conversions)->convertable_type<Type>())) {
|
||||||
try {
|
try {
|
||||||
return(detail::Cast_Helper<Type>::cast(bv, t_conversions));
|
return detail::Cast_Helper<Type>::cast(bv, t_conversions);
|
||||||
} catch (const chaiscript::detail::exception::bad_any_cast &) {
|
} catch (const chaiscript::detail::exception::bad_any_cast &) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -82,19 +82,21 @@ namespace chaiscript
|
|||||||
if (t_conversions && (*t_conversions)->convertable_type<Type>())
|
if (t_conversions && (*t_conversions)->convertable_type<Type>())
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
// std::cout << "trying an up conversion " << typeid(Type).name() << '\n';
|
||||||
// We will not catch any bad_boxed_dynamic_cast that is thrown, let the user get it
|
// We will not catch any bad_boxed_dynamic_cast that is thrown, let the user get it
|
||||||
// either way, we are not responsible if it doesn't work
|
// either way, we are not responsible if it doesn't work
|
||||||
return(detail::Cast_Helper<Type>::cast((*t_conversions)->boxed_type_conversion<Type>(t_conversions->saves(), bv), t_conversions));
|
return detail::Cast_Helper<Type>::cast((*t_conversions)->boxed_type_conversion<Type>(t_conversions->saves(), bv), t_conversions);
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
try {
|
try {
|
||||||
// try going the other way
|
// std::cout << "trying a down conversion " << typeid(Type).name() << '\n';
|
||||||
return(detail::Cast_Helper<Type>::cast((*t_conversions)->boxed_type_down_conversion<Type>(t_conversions->saves(), bv), t_conversions));
|
// try going the other way - down the inheritance graph
|
||||||
|
return detail::Cast_Helper<Type>::cast((*t_conversions)->boxed_type_down_conversion<Type>(t_conversions->saves(), bv), t_conversions);
|
||||||
} catch (const chaiscript::detail::exception::bad_any_cast &) {
|
} catch (const chaiscript::detail::exception::bad_any_cast &) {
|
||||||
throw exception::bad_boxed_cast(bv.get_type_info(), typeid(Type));
|
throw exception::bad_boxed_cast(bv.get_type_info(), typeid(Type));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// If it's not convertable, just throw the error, don't waste the time on the
|
// If it's not polymorphic, just throw the error, don't waste the time on the
|
||||||
// attempted dynamic_cast
|
// attempted dynamic_cast
|
||||||
throw exception::bad_boxed_cast(bv.get_type_info(), typeid(Type));
|
throw exception::bad_boxed_cast(bv.get_type_info(), typeid(Type));
|
||||||
}
|
}
|
||||||
|
@@ -29,50 +29,21 @@ namespace chaiscript
|
|||||||
throw std::runtime_error("Attempted to dereference null Boxed_Value");
|
throw std::runtime_error("Attempted to dereference null Boxed_Value");
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
static const T *verify_type_no_throw(const Boxed_Value &ob, const std::type_info &ti, const T *ptr) {
|
|
||||||
if (ob.get_type_info() == ti) {
|
|
||||||
return ptr;
|
|
||||||
} else {
|
|
||||||
throw chaiscript::detail::exception::bad_any_cast();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
static T *verify_type_no_throw(const Boxed_Value &ob, const std::type_info &ti, T *ptr) {
|
|
||||||
if (!ob.is_const() && ob.get_type_info() == ti) {
|
|
||||||
return ptr;
|
|
||||||
} else {
|
|
||||||
throw chaiscript::detail::exception::bad_any_cast();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
static const T *verify_type(const Boxed_Value &ob, const std::type_info &ti, const T *ptr) {
|
|
||||||
if (ob.get_type_info().bare_equal_type_info(ti)) {
|
|
||||||
return throw_if_null(ptr);
|
|
||||||
} else {
|
|
||||||
throw chaiscript::detail::exception::bad_any_cast();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
static T *verify_type(const Boxed_Value &ob, const std::type_info &ti, T *ptr) {
|
|
||||||
if (!ob.is_const() && ob.get_type_info().bare_equal_type_info(ti)) {
|
|
||||||
return throw_if_null(ptr);
|
|
||||||
} else {
|
|
||||||
throw chaiscript::detail::exception::bad_any_cast();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Generic Cast_Helper_Inner, for casting to any type
|
/// Generic Cast_Helper_Inner, for casting to any type
|
||||||
template<typename Result>
|
template<typename Result>
|
||||||
struct Cast_Helper_Inner
|
struct Cast_Helper_Inner
|
||||||
{
|
{
|
||||||
static Result cast(const Boxed_Value &ob, const Type_Conversions_State *)
|
typedef typename std::add_const<Result>::type Result_Type;
|
||||||
|
|
||||||
|
static Result_Type cast(const Boxed_Value &ob, const Type_Conversions_State *)
|
||||||
{
|
{
|
||||||
return *static_cast<const Result *>(verify_type(ob, typeid(Result), ob.get_const_ptr()));
|
if (ob.get_type_info().bare_equal_type_info(typeid(Result)))
|
||||||
|
{
|
||||||
|
auto p = throw_if_null(ob.get_const_ptr());
|
||||||
|
return *static_cast<const Result *>(p);
|
||||||
|
} else {
|
||||||
|
throw chaiscript::detail::exception::bad_any_cast();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -86,9 +57,15 @@ namespace chaiscript
|
|||||||
template<typename Result>
|
template<typename Result>
|
||||||
struct Cast_Helper_Inner<const Result *>
|
struct Cast_Helper_Inner<const Result *>
|
||||||
{
|
{
|
||||||
static const Result * cast(const Boxed_Value &ob, const Type_Conversions_State *)
|
typedef const Result * Result_Type;
|
||||||
|
static Result_Type cast(const Boxed_Value &ob, const Type_Conversions_State *)
|
||||||
{
|
{
|
||||||
return static_cast<const Result *>(verify_type_no_throw(ob, typeid(Result), ob.get_const_ptr()));
|
if (ob.get_type_info().bare_equal_type_info(typeid(Result)))
|
||||||
|
{
|
||||||
|
return static_cast<const Result *>(ob.get_const_ptr());
|
||||||
|
} else {
|
||||||
|
throw chaiscript::detail::exception::bad_any_cast();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -96,9 +73,15 @@ namespace chaiscript
|
|||||||
template<typename Result>
|
template<typename Result>
|
||||||
struct Cast_Helper_Inner<Result *>
|
struct Cast_Helper_Inner<Result *>
|
||||||
{
|
{
|
||||||
static Result * cast(const Boxed_Value &ob, const Type_Conversions_State *)
|
typedef Result * Result_Type;
|
||||||
|
static Result_Type cast(const Boxed_Value &ob, const Type_Conversions_State *)
|
||||||
{
|
{
|
||||||
return static_cast<Result *>(verify_type_no_throw(ob, typeid(Result), ob.get_ptr()));
|
if (!ob.get_type_info().is_const() && ob.get_type_info() == typeid(Result))
|
||||||
|
{
|
||||||
|
return static_cast<Result *>(ob.get_ptr());
|
||||||
|
} else {
|
||||||
|
throw chaiscript::detail::exception::bad_any_cast();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -117,9 +100,17 @@ namespace chaiscript
|
|||||||
template<typename Result>
|
template<typename Result>
|
||||||
struct Cast_Helper_Inner<const Result &>
|
struct Cast_Helper_Inner<const Result &>
|
||||||
{
|
{
|
||||||
static const Result & cast(const Boxed_Value &ob, const Type_Conversions_State *)
|
typedef const Result& Result_Type;
|
||||||
|
|
||||||
|
static Result_Type cast(const Boxed_Value &ob, const Type_Conversions_State *)
|
||||||
{
|
{
|
||||||
return *static_cast<const Result *>(verify_type(ob, typeid(Result), ob.get_const_ptr()));
|
if (ob.get_type_info().bare_equal_type_info(typeid(Result)))
|
||||||
|
{
|
||||||
|
auto p = throw_if_null(ob.get_const_ptr());
|
||||||
|
return *static_cast<const Result *>(p);
|
||||||
|
} else {
|
||||||
|
throw chaiscript::detail::exception::bad_any_cast();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -129,9 +120,16 @@ namespace chaiscript
|
|||||||
template<typename Result>
|
template<typename Result>
|
||||||
struct Cast_Helper_Inner<Result &>
|
struct Cast_Helper_Inner<Result &>
|
||||||
{
|
{
|
||||||
static Result& cast(const Boxed_Value &ob, const Type_Conversions_State *)
|
typedef Result& Result_Type;
|
||||||
|
|
||||||
|
static Result_Type cast(const Boxed_Value &ob, const Type_Conversions_State *)
|
||||||
{
|
{
|
||||||
return *static_cast<Result *>(verify_type(ob, typeid(Result), ob.get_ptr()));
|
if (!ob.get_type_info().is_const() && ob.get_type_info().bare_equal_type_info(typeid(Result)))
|
||||||
|
{
|
||||||
|
return *(static_cast<Result *>(throw_if_null(ob.get_ptr())));
|
||||||
|
} else {
|
||||||
|
throw chaiscript::detail::exception::bad_any_cast();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -139,7 +137,9 @@ namespace chaiscript
|
|||||||
template<typename Result>
|
template<typename Result>
|
||||||
struct Cast_Helper_Inner<std::shared_ptr<Result> >
|
struct Cast_Helper_Inner<std::shared_ptr<Result> >
|
||||||
{
|
{
|
||||||
static auto cast(const Boxed_Value &ob, const Type_Conversions_State *)
|
typedef std::shared_ptr<Result> Result_Type;
|
||||||
|
|
||||||
|
static Result_Type cast(const Boxed_Value &ob, const Type_Conversions_State *)
|
||||||
{
|
{
|
||||||
return ob.get().cast<std::shared_ptr<Result> >();
|
return ob.get().cast<std::shared_ptr<Result> >();
|
||||||
}
|
}
|
||||||
@@ -149,7 +149,9 @@ namespace chaiscript
|
|||||||
template<typename Result>
|
template<typename Result>
|
||||||
struct Cast_Helper_Inner<std::shared_ptr<const Result> >
|
struct Cast_Helper_Inner<std::shared_ptr<const Result> >
|
||||||
{
|
{
|
||||||
static auto cast(const Boxed_Value &ob, const Type_Conversions_State *)
|
typedef std::shared_ptr<const Result> Result_Type;
|
||||||
|
|
||||||
|
static Result_Type cast(const Boxed_Value &ob, const Type_Conversions_State *)
|
||||||
{
|
{
|
||||||
if (!ob.get_type_info().is_const())
|
if (!ob.get_type_info().is_const())
|
||||||
{
|
{
|
||||||
@@ -175,7 +177,10 @@ namespace chaiscript
|
|||||||
struct Cast_Helper_Inner<std::shared_ptr<Result> &>
|
struct Cast_Helper_Inner<std::shared_ptr<Result> &>
|
||||||
{
|
{
|
||||||
static_assert(!std::is_const<Result>::value, "Non-const reference to std::shared_ptr<const T> is not supported");
|
static_assert(!std::is_const<Result>::value, "Non-const reference to std::shared_ptr<const T> is not supported");
|
||||||
static auto cast(const Boxed_Value &ob, const Type_Conversions_State *)
|
|
||||||
|
typedef Boxed_Value::Sentinel<Result> Result_Type;
|
||||||
|
|
||||||
|
static Result_Type cast(const Boxed_Value &ob, const Type_Conversions_State *)
|
||||||
{
|
{
|
||||||
std::shared_ptr<Result> &res = ob.get().cast<std::shared_ptr<Result> >();
|
std::shared_ptr<Result> &res = ob.get().cast<std::shared_ptr<Result> >();
|
||||||
return ob.pointer_sentinel(res);
|
return ob.pointer_sentinel(res);
|
||||||
@@ -199,7 +204,9 @@ namespace chaiscript
|
|||||||
template<>
|
template<>
|
||||||
struct Cast_Helper_Inner<Boxed_Value>
|
struct Cast_Helper_Inner<Boxed_Value>
|
||||||
{
|
{
|
||||||
static Boxed_Value cast(const Boxed_Value &ob, const Type_Conversions_State *)
|
typedef Boxed_Value Result_Type;
|
||||||
|
|
||||||
|
static Result_Type cast(const Boxed_Value &ob, const Type_Conversions_State *)
|
||||||
{
|
{
|
||||||
return ob;
|
return ob;
|
||||||
}
|
}
|
||||||
@@ -209,7 +216,9 @@ namespace chaiscript
|
|||||||
template<>
|
template<>
|
||||||
struct Cast_Helper_Inner<Boxed_Value &>
|
struct Cast_Helper_Inner<Boxed_Value &>
|
||||||
{
|
{
|
||||||
static std::reference_wrapper<Boxed_Value> cast(const Boxed_Value &ob, const Type_Conversions_State *)
|
typedef std::reference_wrapper<Boxed_Value> Result_Type;
|
||||||
|
|
||||||
|
static Result_Type cast(const Boxed_Value &ob, const Type_Conversions_State *)
|
||||||
{
|
{
|
||||||
return std::ref(const_cast<Boxed_Value &>(ob));
|
return std::ref(const_cast<Boxed_Value &>(ob));
|
||||||
}
|
}
|
||||||
@@ -263,9 +272,11 @@ namespace chaiscript
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
struct Cast_Helper
|
struct Cast_Helper
|
||||||
{
|
{
|
||||||
static decltype(auto) cast(const Boxed_Value &ob, const Type_Conversions_State *t_conversions)
|
typedef typename Cast_Helper_Inner<T>::Result_Type Result_Type;
|
||||||
|
|
||||||
|
static Result_Type cast(const Boxed_Value &ob, const Type_Conversions_State *t_conversions)
|
||||||
{
|
{
|
||||||
return(Cast_Helper_Inner<T>::cast(ob, t_conversions));
|
return Cast_Helper_Inner<T>::cast(ob, t_conversions);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@@ -30,7 +30,7 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
arithmetic_error(const std::string& reason) : std::runtime_error("Arithmetic error: " + reason) {}
|
arithmetic_error(const std::string& reason) : std::runtime_error("Arithmetic error: " + reason) {}
|
||||||
arithmetic_error(const arithmetic_error &) = default;
|
arithmetic_error(const arithmetic_error &) = default;
|
||||||
virtual ~arithmetic_error() noexcept = default;
|
virtual ~arithmetic_error() CHAISCRIPT_NOEXCEPT {}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -91,7 +91,7 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr Common_Types get_common_type(size_t t_size, bool t_signed)
|
static CHAISCRIPT_CONSTEXPR Common_Types get_common_type(size_t t_size, bool t_signed)
|
||||||
{
|
{
|
||||||
return (t_size == 1 && t_signed)?(Common_Types::t_int8)
|
return (t_size == 1 && t_signed)?(Common_Types::t_int8)
|
||||||
:(t_size == 1)?(Common_Types::t_uint8)
|
:(t_size == 1)?(Common_Types::t_uint8)
|
||||||
@@ -162,17 +162,17 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
switch (t_oper)
|
switch (t_oper)
|
||||||
{
|
{
|
||||||
case Operators::Opers::equals:
|
case Operators::equals:
|
||||||
return const_var(t == u);
|
return const_var(t == u);
|
||||||
case Operators::Opers::less_than:
|
case Operators::less_than:
|
||||||
return const_var(t < u);
|
return const_var(t < u);
|
||||||
case Operators::Opers::greater_than:
|
case Operators::greater_than:
|
||||||
return const_var(t > u);
|
return const_var(t > u);
|
||||||
case Operators::Opers::less_than_equal:
|
case Operators::less_than_equal:
|
||||||
return const_var(t <= u);
|
return const_var(t <= u);
|
||||||
case Operators::Opers::greater_than_equal:
|
case Operators::greater_than_equal:
|
||||||
return const_var(t >= u);
|
return const_var(t >= u);
|
||||||
case Operators::Opers::not_equal:
|
case Operators::not_equal:
|
||||||
return const_var(t != u);
|
return const_var(t != u);
|
||||||
default:
|
default:
|
||||||
throw chaiscript::detail::exception::bad_any_cast();
|
throw chaiscript::detail::exception::bad_any_cast();
|
||||||
@@ -184,10 +184,10 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
switch (t_oper)
|
switch (t_oper)
|
||||||
{
|
{
|
||||||
case Operators::Opers::pre_increment:
|
case Operators::pre_increment:
|
||||||
++t;
|
++t;
|
||||||
break;
|
break;
|
||||||
case Operators::Opers::pre_decrement:
|
case Operators::pre_decrement:
|
||||||
--t;
|
--t;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -202,20 +202,20 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
switch (t_oper)
|
switch (t_oper)
|
||||||
{
|
{
|
||||||
case Operators::Opers::assign:
|
case Operators::assign:
|
||||||
t = u;
|
t = u;
|
||||||
break;
|
break;
|
||||||
case Operators::Opers::assign_product:
|
case Operators::assign_product:
|
||||||
t *= u;
|
t *= u;
|
||||||
break;
|
break;
|
||||||
case Operators::Opers::assign_sum:
|
case Operators::assign_sum:
|
||||||
t += u;
|
t += u;
|
||||||
break;
|
break;
|
||||||
case Operators::Opers::assign_quotient:
|
case Operators::assign_quotient:
|
||||||
check_divide_by_zero(u);
|
check_divide_by_zero(u);
|
||||||
t /= u;
|
t /= u;
|
||||||
break;
|
break;
|
||||||
case Operators::Opers::assign_difference:
|
case Operators::assign_difference:
|
||||||
t -= u;
|
t -= u;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -230,23 +230,23 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
switch (t_oper)
|
switch (t_oper)
|
||||||
{
|
{
|
||||||
case Operators::Opers::assign_bitwise_and:
|
case Operators::assign_bitwise_and:
|
||||||
t &= u;
|
t &= u;
|
||||||
break;
|
break;
|
||||||
case Operators::Opers::assign_bitwise_or:
|
case Operators::assign_bitwise_or:
|
||||||
t |= u;
|
t |= u;
|
||||||
break;
|
break;
|
||||||
case Operators::Opers::assign_shift_left:
|
case Operators::assign_shift_left:
|
||||||
t <<= u;
|
t <<= u;
|
||||||
break;
|
break;
|
||||||
case Operators::Opers::assign_shift_right:
|
case Operators::assign_shift_right:
|
||||||
t >>= u;
|
t >>= u;
|
||||||
break;
|
break;
|
||||||
case Operators::Opers::assign_remainder:
|
case Operators::assign_remainder:
|
||||||
check_divide_by_zero(u);
|
check_divide_by_zero(u);
|
||||||
t %= u;
|
t %= u;
|
||||||
break;
|
break;
|
||||||
case Operators::Opers::assign_bitwise_xor:
|
case Operators::assign_bitwise_xor:
|
||||||
t ^= u;
|
t ^= u;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -260,7 +260,7 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
switch (t_oper)
|
switch (t_oper)
|
||||||
{
|
{
|
||||||
case Operators::Opers::bitwise_complement:
|
case Operators::bitwise_complement:
|
||||||
return const_var(~t);
|
return const_var(~t);
|
||||||
default:
|
default:
|
||||||
throw chaiscript::detail::exception::bad_any_cast();
|
throw chaiscript::detail::exception::bad_any_cast();
|
||||||
@@ -272,18 +272,18 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
switch (t_oper)
|
switch (t_oper)
|
||||||
{
|
{
|
||||||
case Operators::Opers::shift_left:
|
case Operators::shift_left:
|
||||||
return const_var(t << u);
|
return const_var(t << u);
|
||||||
case Operators::Opers::shift_right:
|
case Operators::shift_right:
|
||||||
return const_var(t >> u);
|
return const_var(t >> u);
|
||||||
case Operators::Opers::remainder:
|
case Operators::remainder:
|
||||||
check_divide_by_zero(u);
|
check_divide_by_zero(u);
|
||||||
return const_var(t % u);
|
return const_var(t % u);
|
||||||
case Operators::Opers::bitwise_and:
|
case Operators::bitwise_and:
|
||||||
return const_var(t & u);
|
return const_var(t & u);
|
||||||
case Operators::Opers::bitwise_or:
|
case Operators::bitwise_or:
|
||||||
return const_var(t | u);
|
return const_var(t | u);
|
||||||
case Operators::Opers::bitwise_xor:
|
case Operators::bitwise_xor:
|
||||||
return const_var(t ^ u);
|
return const_var(t ^ u);
|
||||||
default:
|
default:
|
||||||
throw chaiscript::detail::exception::bad_any_cast();
|
throw chaiscript::detail::exception::bad_any_cast();
|
||||||
@@ -295,9 +295,9 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
switch (t_oper)
|
switch (t_oper)
|
||||||
{
|
{
|
||||||
case Operators::Opers::unary_minus:
|
case Operators::unary_minus:
|
||||||
return const_var(-t);
|
return const_var(-t);
|
||||||
case Operators::Opers::unary_plus:
|
case Operators::unary_plus:
|
||||||
return const_var(+t);
|
return const_var(+t);
|
||||||
default:
|
default:
|
||||||
throw chaiscript::detail::exception::bad_any_cast();
|
throw chaiscript::detail::exception::bad_any_cast();
|
||||||
@@ -309,14 +309,14 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
switch (t_oper)
|
switch (t_oper)
|
||||||
{
|
{
|
||||||
case Operators::Opers::sum:
|
case Operators::sum:
|
||||||
return const_var(t + u);
|
return const_var(t + u);
|
||||||
case Operators::Opers::quotient:
|
case Operators::quotient:
|
||||||
check_divide_by_zero(u);
|
check_divide_by_zero(u);
|
||||||
return const_var(t / u);
|
return const_var(t / u);
|
||||||
case Operators::Opers::product:
|
case Operators::product:
|
||||||
return const_var(t * u);
|
return const_var(t * u);
|
||||||
case Operators::Opers::difference:
|
case Operators::difference:
|
||||||
return const_var(t - u);
|
return const_var(t - u);
|
||||||
default:
|
default:
|
||||||
throw chaiscript::detail::exception::bad_any_cast();
|
throw chaiscript::detail::exception::bad_any_cast();
|
||||||
@@ -328,16 +328,16 @@ namespace chaiscript
|
|||||||
-> typename std::enable_if<!std::is_floating_point<LHS>::value && !std::is_floating_point<RHS>::value, Boxed_Value>::type
|
-> typename std::enable_if<!std::is_floating_point<LHS>::value && !std::is_floating_point<RHS>::value, Boxed_Value>::type
|
||||||
{
|
{
|
||||||
typedef typename std::common_type<LHS, RHS>::type common_type;
|
typedef typename std::common_type<LHS, RHS>::type common_type;
|
||||||
if (t_oper > Operators::Opers::boolean_flag && t_oper < Operators::Opers::non_const_flag)
|
if (t_oper > Operators::boolean_flag && t_oper < Operators::non_const_flag)
|
||||||
{
|
{
|
||||||
return boolean_go(t_oper, get_as_aux<common_type, LHS>(t_lhs), get_as_aux<common_type, RHS>(t_rhs));
|
return boolean_go(t_oper, get_as_aux<common_type, LHS>(t_lhs), get_as_aux<common_type, RHS>(t_rhs));
|
||||||
} else if (t_oper > Operators::Opers::non_const_flag && t_oper < Operators::Opers::non_const_int_flag && !t_lhs.is_const() && !t_lhs.is_return_value()) {
|
} else if (t_oper > Operators::non_const_flag && t_oper < Operators::non_const_int_flag && !t_lhs.is_const() && !t_lhs.is_return_value()) {
|
||||||
return binary_go(t_oper, *static_cast<LHS *>(t_lhs.get_ptr()), get_as_aux<common_type, RHS>(t_rhs), t_lhs);
|
return binary_go(t_oper, *static_cast<LHS *>(t_lhs.get_ptr()), get_as_aux<common_type, RHS>(t_rhs), t_lhs);
|
||||||
} else if (t_oper > Operators::Opers::non_const_int_flag && t_oper < Operators::Opers::const_int_flag && !t_lhs.is_const() && !t_lhs.is_return_value()) {
|
} else if (t_oper > Operators::non_const_int_flag && t_oper < Operators::const_int_flag && !t_lhs.is_const() && !t_lhs.is_return_value()) {
|
||||||
return binary_int_go(t_oper, *static_cast<LHS *>(t_lhs.get_ptr()), get_as_aux<common_type, RHS>(t_rhs), t_lhs);
|
return binary_int_go(t_oper, *static_cast<LHS *>(t_lhs.get_ptr()), get_as_aux<common_type, RHS>(t_rhs), t_lhs);
|
||||||
} else if (t_oper > Operators::Opers::const_int_flag && t_oper < Operators::Opers::const_flag) {
|
} else if (t_oper > Operators::const_int_flag && t_oper < Operators::const_flag) {
|
||||||
return const_binary_int_go(t_oper, get_as_aux<common_type, LHS>(t_lhs), get_as_aux<common_type, RHS>(t_rhs));
|
return const_binary_int_go(t_oper, get_as_aux<common_type, LHS>(t_lhs), get_as_aux<common_type, RHS>(t_rhs));
|
||||||
} else if (t_oper > Operators::Opers::const_flag) {
|
} else if (t_oper > Operators::const_flag) {
|
||||||
return const_binary_go(t_oper, get_as_aux<common_type, LHS>(t_lhs), get_as_aux<common_type, RHS>(t_rhs));
|
return const_binary_go(t_oper, get_as_aux<common_type, LHS>(t_lhs), get_as_aux<common_type, RHS>(t_rhs));
|
||||||
} else {
|
} else {
|
||||||
throw chaiscript::detail::exception::bad_any_cast();
|
throw chaiscript::detail::exception::bad_any_cast();
|
||||||
@@ -349,12 +349,12 @@ namespace chaiscript
|
|||||||
-> typename std::enable_if<std::is_floating_point<LHS>::value || std::is_floating_point<RHS>::value, Boxed_Value>::type
|
-> typename std::enable_if<std::is_floating_point<LHS>::value || std::is_floating_point<RHS>::value, Boxed_Value>::type
|
||||||
{
|
{
|
||||||
typedef typename std::common_type<LHS, RHS>::type common_type;
|
typedef typename std::common_type<LHS, RHS>::type common_type;
|
||||||
if (t_oper > Operators::Opers::boolean_flag && t_oper < Operators::Opers::non_const_flag)
|
if (t_oper > Operators::boolean_flag && t_oper < Operators::non_const_flag)
|
||||||
{
|
{
|
||||||
return boolean_go(t_oper, get_as_aux<common_type, LHS>(t_lhs), get_as_aux<common_type, RHS>(t_rhs));
|
return boolean_go(t_oper, get_as_aux<common_type, LHS>(t_lhs), get_as_aux<common_type, RHS>(t_rhs));
|
||||||
} else if (t_oper > Operators::Opers::non_const_flag && t_oper < Operators::Opers::non_const_int_flag && !t_lhs.is_const() && !t_lhs.is_return_value()) {
|
} else if (t_oper > Operators::non_const_flag && t_oper < Operators::non_const_int_flag && !t_lhs.is_const() && !t_lhs.is_return_value()) {
|
||||||
return binary_go(t_oper, *static_cast<LHS *>(t_lhs.get_ptr()), get_as_aux<common_type, RHS>(t_rhs), t_lhs);
|
return binary_go(t_oper, *static_cast<LHS *>(t_lhs.get_ptr()), get_as_aux<common_type, RHS>(t_rhs), t_lhs);
|
||||||
} else if (t_oper > Operators::Opers::const_flag) {
|
} else if (t_oper > Operators::const_flag) {
|
||||||
return const_binary_go(t_oper, get_as_aux<common_type, LHS>(t_lhs), get_as_aux<common_type, RHS>(t_rhs));
|
return const_binary_go(t_oper, get_as_aux<common_type, LHS>(t_lhs), get_as_aux<common_type, RHS>(t_rhs));
|
||||||
} else {
|
} else {
|
||||||
throw chaiscript::detail::exception::bad_any_cast();
|
throw chaiscript::detail::exception::bad_any_cast();
|
||||||
@@ -366,11 +366,11 @@ namespace chaiscript
|
|||||||
static auto go(Operators::Opers t_oper, const Boxed_Value &t_lhs)
|
static auto go(Operators::Opers t_oper, const Boxed_Value &t_lhs)
|
||||||
-> typename std::enable_if<!std::is_floating_point<LHS>::value, Boxed_Value>::type
|
-> typename std::enable_if<!std::is_floating_point<LHS>::value, Boxed_Value>::type
|
||||||
{
|
{
|
||||||
if (t_oper > Operators::Opers::non_const_flag && t_oper < Operators::Opers::non_const_int_flag && !t_lhs.is_const() && !t_lhs.is_return_value()) {
|
if (t_oper > Operators::non_const_flag && t_oper < Operators::non_const_int_flag && !t_lhs.is_const() && !t_lhs.is_return_value()) {
|
||||||
return unary_go(t_oper, *static_cast<LHS *>(t_lhs.get_ptr()), t_lhs);
|
return unary_go(t_oper, *static_cast<LHS *>(t_lhs.get_ptr()), t_lhs);
|
||||||
} else if (t_oper > Operators::Opers::const_int_flag && t_oper < Operators::Opers::const_flag) {
|
} else if (t_oper > Operators::const_int_flag && t_oper < Operators::const_flag) {
|
||||||
return const_unary_int_go(t_oper, *static_cast<const LHS *>(t_lhs.get_const_ptr()));
|
return const_unary_int_go(t_oper, *static_cast<const LHS *>(t_lhs.get_const_ptr()));
|
||||||
} else if (t_oper > Operators::Opers::const_flag) {
|
} else if (t_oper > Operators::const_flag) {
|
||||||
return const_unary_go(t_oper, *static_cast<const LHS *>(t_lhs.get_const_ptr()));
|
return const_unary_go(t_oper, *static_cast<const LHS *>(t_lhs.get_const_ptr()));
|
||||||
} else {
|
} else {
|
||||||
throw chaiscript::detail::exception::bad_any_cast();
|
throw chaiscript::detail::exception::bad_any_cast();
|
||||||
@@ -381,9 +381,9 @@ namespace chaiscript
|
|||||||
static auto go(Operators::Opers t_oper, const Boxed_Value &t_lhs)
|
static auto go(Operators::Opers t_oper, const Boxed_Value &t_lhs)
|
||||||
-> typename std::enable_if<std::is_floating_point<LHS>::value, Boxed_Value>::type
|
-> typename std::enable_if<std::is_floating_point<LHS>::value, Boxed_Value>::type
|
||||||
{
|
{
|
||||||
if (t_oper > Operators::Opers::non_const_flag && t_oper < Operators::Opers::non_const_int_flag && !t_lhs.is_const() && !t_lhs.is_return_value()) {
|
if (t_oper > Operators::non_const_flag && t_oper < Operators::non_const_int_flag && !t_lhs.is_const() && !t_lhs.is_return_value()) {
|
||||||
return unary_go(t_oper, *static_cast<LHS *>(t_lhs.get_ptr()), t_lhs);
|
return unary_go(t_oper, *static_cast<LHS *>(t_lhs.get_ptr()), t_lhs);
|
||||||
} else if (t_oper > Operators::Opers::const_flag) {
|
} else if (t_oper > Operators::const_flag) {
|
||||||
return const_unary_go(t_oper, *static_cast<const LHS *>(t_lhs.get_const_ptr()));
|
return const_unary_go(t_oper, *static_cast<const LHS *>(t_lhs.get_const_ptr()));
|
||||||
} else {
|
} else {
|
||||||
throw chaiscript::detail::exception::bad_any_cast();
|
throw chaiscript::detail::exception::bad_any_cast();
|
||||||
@@ -502,15 +502,18 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
explicit Boxed_Number(Boxed_Value v)
|
Boxed_Number(Boxed_Value v)
|
||||||
: bv(std::move(v))
|
: bv(std::move(v))
|
||||||
{
|
{
|
||||||
validate_boxed_number(bv);
|
validate_boxed_number(bv);
|
||||||
}
|
}
|
||||||
|
|
||||||
Boxed_Number(const Boxed_Number &) = default;
|
Boxed_Number(const Boxed_Number &) = default;
|
||||||
|
|
||||||
|
#if !defined(_MSC_VER) || _MSC_VER != 1800
|
||||||
Boxed_Number(Boxed_Number &&) = default;
|
Boxed_Number(Boxed_Number &&) = default;
|
||||||
Boxed_Number& operator=(Boxed_Number &&) = default;
|
Boxed_Number& operator=(Boxed_Number &&) = default;
|
||||||
|
#endif
|
||||||
|
|
||||||
template<typename T> explicit Boxed_Number(T t)
|
template<typename T> explicit Boxed_Number(T t)
|
||||||
: bv(Boxed_Value(t))
|
: bv(Boxed_Value(t))
|
||||||
@@ -645,6 +648,71 @@ namespace chaiscript
|
|||||||
throw chaiscript::detail::exception::bad_any_cast();
|
throw chaiscript::detail::exception::bad_any_cast();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool operator==(const Boxed_Number &t_rhs) const
|
||||||
|
{
|
||||||
|
return boxed_cast<bool>(oper(Operators::equals, this->bv, t_rhs.bv));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator<(const Boxed_Number &t_rhs) const
|
||||||
|
{
|
||||||
|
return boxed_cast<bool>(oper(Operators::less_than, this->bv, t_rhs.bv));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator>(const Boxed_Number &t_rhs) const
|
||||||
|
{
|
||||||
|
return boxed_cast<bool>(oper(Operators::greater_than, this->bv, t_rhs.bv));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator>=(const Boxed_Number &t_rhs) const
|
||||||
|
{
|
||||||
|
return boxed_cast<bool>(oper(Operators::greater_than_equal, this->bv, t_rhs.bv));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator<=(const Boxed_Number &t_rhs) const
|
||||||
|
{
|
||||||
|
return boxed_cast<bool>(oper(Operators::less_than_equal, this->bv, t_rhs.bv));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator!=(const Boxed_Number &t_rhs) const
|
||||||
|
{
|
||||||
|
return boxed_cast<bool>(oper(Operators::not_equal, this->bv, t_rhs.bv));
|
||||||
|
}
|
||||||
|
|
||||||
|
Boxed_Number operator--()
|
||||||
|
{
|
||||||
|
return oper(Operators::pre_decrement, this->bv);
|
||||||
|
}
|
||||||
|
|
||||||
|
Boxed_Number operator++()
|
||||||
|
{
|
||||||
|
return oper(Operators::pre_increment, this->bv);
|
||||||
|
}
|
||||||
|
|
||||||
|
Boxed_Number operator+(const Boxed_Number &t_rhs) const
|
||||||
|
{
|
||||||
|
return oper(Operators::sum, this->bv, t_rhs.bv);
|
||||||
|
}
|
||||||
|
|
||||||
|
Boxed_Number operator+() const
|
||||||
|
{
|
||||||
|
return oper(Operators::unary_plus, this->bv);
|
||||||
|
}
|
||||||
|
|
||||||
|
Boxed_Number operator-() const
|
||||||
|
{
|
||||||
|
return oper(Operators::unary_minus, this->bv);
|
||||||
|
}
|
||||||
|
|
||||||
|
Boxed_Number operator-(const Boxed_Number &t_rhs) const
|
||||||
|
{
|
||||||
|
return oper(Operators::difference, this->bv, t_rhs.bv);
|
||||||
|
}
|
||||||
|
|
||||||
|
Boxed_Number operator&=(const Boxed_Number &t_rhs)
|
||||||
|
{
|
||||||
|
return oper(Operators::assign_bitwise_and, this->bv, t_rhs.bv);
|
||||||
|
}
|
||||||
|
|
||||||
static void validate_boxed_number(const Boxed_Value &v)
|
static void validate_boxed_number(const Boxed_Value &v)
|
||||||
{
|
{
|
||||||
const Type_Info &inp_ = v.get_type_info();
|
const Type_Info &inp_ = v.get_type_info();
|
||||||
@@ -659,165 +727,266 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// cppcheck-suppress operatorEq
|
||||||
|
Boxed_Number operator=(const Boxed_Value &v)
|
||||||
|
{
|
||||||
|
validate_boxed_number(v);
|
||||||
|
bv = v;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// cppcheck-suppress operatorEq
|
||||||
|
Boxed_Number operator=(const Boxed_Number &t_rhs) const
|
||||||
|
{
|
||||||
|
return oper(Operators::assign, this->bv, t_rhs.bv);
|
||||||
|
}
|
||||||
|
|
||||||
|
Boxed_Number operator|=(const Boxed_Number &t_rhs)
|
||||||
|
{
|
||||||
|
return oper(Operators::assign_bitwise_or, this->bv, t_rhs.bv);
|
||||||
|
}
|
||||||
|
|
||||||
|
Boxed_Number operator^=(const Boxed_Number &t_rhs)
|
||||||
|
{
|
||||||
|
return oper(Operators::assign_bitwise_xor, this->bv, t_rhs.bv);
|
||||||
|
}
|
||||||
|
|
||||||
|
Boxed_Number operator%=(const Boxed_Number &t_rhs)
|
||||||
|
{
|
||||||
|
return oper(Operators::assign_remainder, this->bv, t_rhs.bv);
|
||||||
|
}
|
||||||
|
|
||||||
|
Boxed_Number operator<<=(const Boxed_Number &t_rhs)
|
||||||
|
{
|
||||||
|
return oper(Operators::assign_shift_left, this->bv, t_rhs.bv);
|
||||||
|
}
|
||||||
|
|
||||||
|
Boxed_Number operator>>=(const Boxed_Number &t_rhs)
|
||||||
|
{
|
||||||
|
return oper(Operators::assign_shift_right, this->bv, t_rhs.bv);
|
||||||
|
}
|
||||||
|
|
||||||
|
Boxed_Number operator&(const Boxed_Number &t_rhs) const
|
||||||
|
{
|
||||||
|
return oper(Operators::bitwise_and, this->bv, t_rhs.bv);
|
||||||
|
}
|
||||||
|
|
||||||
|
Boxed_Number operator~() const
|
||||||
|
{
|
||||||
|
return oper(Operators::bitwise_complement, this->bv);
|
||||||
|
}
|
||||||
|
|
||||||
|
Boxed_Number operator^(const Boxed_Number &t_rhs) const
|
||||||
|
{
|
||||||
|
return oper(Operators::bitwise_xor, this->bv, t_rhs.bv);
|
||||||
|
}
|
||||||
|
|
||||||
|
Boxed_Number operator|(const Boxed_Number &t_rhs) const
|
||||||
|
{
|
||||||
|
return oper(Operators::bitwise_or, this->bv, t_rhs.bv);
|
||||||
|
}
|
||||||
|
|
||||||
|
Boxed_Number operator*=(const Boxed_Number &t_rhs)
|
||||||
|
{
|
||||||
|
return oper(Operators::assign_product, this->bv, t_rhs.bv);
|
||||||
|
}
|
||||||
|
Boxed_Number operator/=(const Boxed_Number &t_rhs)
|
||||||
|
{
|
||||||
|
return oper(Operators::assign_quotient, this->bv, t_rhs.bv);
|
||||||
|
}
|
||||||
|
Boxed_Number operator+=(const Boxed_Number &t_rhs)
|
||||||
|
{
|
||||||
|
return oper(Operators::assign_sum, this->bv, t_rhs.bv);
|
||||||
|
}
|
||||||
|
Boxed_Number operator-=(const Boxed_Number &t_rhs)
|
||||||
|
{
|
||||||
|
return oper(Operators::assign_difference, this->bv, t_rhs.bv);
|
||||||
|
}
|
||||||
|
|
||||||
|
Boxed_Number operator/(const Boxed_Number &t_rhs) const
|
||||||
|
{
|
||||||
|
return oper(Operators::quotient, this->bv, t_rhs.bv);
|
||||||
|
}
|
||||||
|
|
||||||
|
Boxed_Number operator<<(const Boxed_Number &t_rhs) const
|
||||||
|
{
|
||||||
|
return oper(Operators::shift_left, this->bv, t_rhs.bv);
|
||||||
|
}
|
||||||
|
|
||||||
|
Boxed_Number operator*(const Boxed_Number &t_rhs) const
|
||||||
|
{
|
||||||
|
return oper(Operators::product, this->bv, t_rhs.bv);
|
||||||
|
}
|
||||||
|
|
||||||
|
Boxed_Number operator%(const Boxed_Number &t_rhs) const
|
||||||
|
{
|
||||||
|
return oper(Operators::remainder, this->bv, t_rhs.bv);
|
||||||
|
}
|
||||||
|
|
||||||
|
Boxed_Number operator>>(const Boxed_Number &t_rhs) const
|
||||||
|
{
|
||||||
|
return oper(Operators::shift_right, this->bv, t_rhs.bv);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static bool equals(const Boxed_Number &t_lhs, const Boxed_Number &t_rhs)
|
static bool equals(const Boxed_Number &t_lhs, const Boxed_Number &t_rhs)
|
||||||
{
|
{
|
||||||
return boxed_cast<bool>(oper(Operators::Opers::equals, t_lhs.bv, t_rhs.bv));
|
return boxed_cast<bool>(oper(Operators::equals, t_lhs.bv, t_rhs.bv));
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool less_than(const Boxed_Number &t_lhs, const Boxed_Number &t_rhs)
|
static bool less_than(const Boxed_Number &t_lhs, const Boxed_Number &t_rhs)
|
||||||
{
|
{
|
||||||
return boxed_cast<bool>(oper(Operators::Opers::less_than, t_lhs.bv, t_rhs.bv));
|
return boxed_cast<bool>(oper(Operators::less_than, t_lhs.bv, t_rhs.bv));
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool greater_than(const Boxed_Number &t_lhs, const Boxed_Number &t_rhs)
|
static bool greater_than(const Boxed_Number &t_lhs, const Boxed_Number &t_rhs)
|
||||||
{
|
{
|
||||||
return boxed_cast<bool>(oper(Operators::Opers::greater_than, t_lhs.bv, t_rhs.bv));
|
return boxed_cast<bool>(oper(Operators::greater_than, t_lhs.bv, t_rhs.bv));
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool greater_than_equal(const Boxed_Number &t_lhs, const Boxed_Number &t_rhs)
|
static bool greater_than_equal(const Boxed_Number &t_lhs, const Boxed_Number &t_rhs)
|
||||||
{
|
{
|
||||||
return boxed_cast<bool>(oper(Operators::Opers::greater_than_equal, t_lhs.bv, t_rhs.bv));
|
return boxed_cast<bool>(oper(Operators::greater_than_equal, t_lhs.bv, t_rhs.bv));
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool less_than_equal(const Boxed_Number &t_lhs, const Boxed_Number &t_rhs)
|
static bool less_than_equal(const Boxed_Number &t_lhs, const Boxed_Number &t_rhs)
|
||||||
{
|
{
|
||||||
return boxed_cast<bool>(oper(Operators::Opers::less_than_equal, t_lhs.bv, t_rhs.bv));
|
return boxed_cast<bool>(oper(Operators::less_than_equal, t_lhs.bv, t_rhs.bv));
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool not_equal(const Boxed_Number &t_lhs, const Boxed_Number &t_rhs)
|
static bool not_equal(const Boxed_Number &t_lhs, const Boxed_Number &t_rhs)
|
||||||
{
|
{
|
||||||
return boxed_cast<bool>(oper(Operators::Opers::not_equal, t_lhs.bv, t_rhs.bv));
|
return boxed_cast<bool>(oper(Operators::not_equal, t_lhs.bv, t_rhs.bv));
|
||||||
}
|
}
|
||||||
|
|
||||||
static Boxed_Number pre_decrement(Boxed_Number t_lhs)
|
static Boxed_Number pre_decrement(Boxed_Number t_lhs)
|
||||||
{
|
{
|
||||||
return Boxed_Number(oper(Operators::Opers::pre_decrement, t_lhs.bv));
|
return oper(Operators::pre_decrement, t_lhs.bv);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Boxed_Number pre_increment(Boxed_Number t_lhs)
|
static Boxed_Number pre_increment(Boxed_Number t_lhs)
|
||||||
{
|
{
|
||||||
return Boxed_Number(oper(Operators::Opers::pre_increment, t_lhs.bv));
|
return oper(Operators::pre_increment, t_lhs.bv);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const Boxed_Number sum(const Boxed_Number &t_lhs, const Boxed_Number &t_rhs)
|
static const Boxed_Number sum(const Boxed_Number &t_lhs, const Boxed_Number &t_rhs)
|
||||||
{
|
{
|
||||||
return Boxed_Number(oper(Operators::Opers::sum, t_lhs.bv, t_rhs.bv));
|
return oper(Operators::sum, t_lhs.bv, t_rhs.bv);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const Boxed_Number unary_plus(const Boxed_Number &t_lhs)
|
static const Boxed_Number unary_plus(const Boxed_Number &t_lhs)
|
||||||
{
|
{
|
||||||
return Boxed_Number(oper(Operators::Opers::unary_plus, t_lhs.bv));
|
return oper(Operators::unary_plus, t_lhs.bv);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const Boxed_Number unary_minus(const Boxed_Number &t_lhs)
|
static const Boxed_Number unary_minus(const Boxed_Number &t_lhs)
|
||||||
{
|
{
|
||||||
return Boxed_Number(oper(Operators::Opers::unary_minus, t_lhs.bv));
|
return oper(Operators::unary_minus, t_lhs.bv);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const Boxed_Number difference(const Boxed_Number &t_lhs, const Boxed_Number &t_rhs)
|
static const Boxed_Number difference(const Boxed_Number &t_lhs, const Boxed_Number &t_rhs)
|
||||||
{
|
{
|
||||||
return Boxed_Number(oper(Operators::Opers::difference, t_lhs.bv, t_rhs.bv));
|
return oper(Operators::difference, t_lhs.bv, t_rhs.bv);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Boxed_Number assign_bitwise_and(Boxed_Number t_lhs, const Boxed_Number &t_rhs)
|
static Boxed_Number assign_bitwise_and(Boxed_Number t_lhs, const Boxed_Number &t_rhs)
|
||||||
{
|
{
|
||||||
return Boxed_Number(oper(Operators::Opers::assign_bitwise_and, t_lhs.bv, t_rhs.bv));
|
return oper(Operators::assign_bitwise_and, t_lhs.bv, t_rhs.bv);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Boxed_Number assign(Boxed_Number t_lhs, const Boxed_Number &t_rhs)
|
static Boxed_Number assign(Boxed_Number t_lhs, const Boxed_Number &t_rhs)
|
||||||
{
|
{
|
||||||
return Boxed_Number(oper(Operators::Opers::assign, t_lhs.bv, t_rhs.bv));
|
return oper(Operators::assign, t_lhs.bv, t_rhs.bv);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Boxed_Number assign_bitwise_or(Boxed_Number t_lhs, const Boxed_Number &t_rhs)
|
static Boxed_Number assign_bitwise_or(Boxed_Number t_lhs, const Boxed_Number &t_rhs)
|
||||||
{
|
{
|
||||||
return Boxed_Number(oper(Operators::Opers::assign_bitwise_or, t_lhs.bv, t_rhs.bv));
|
return oper(Operators::assign_bitwise_or, t_lhs.bv, t_rhs.bv);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Boxed_Number assign_bitwise_xor(Boxed_Number t_lhs, const Boxed_Number &t_rhs)
|
static Boxed_Number assign_bitwise_xor(Boxed_Number t_lhs, const Boxed_Number &t_rhs)
|
||||||
{
|
{
|
||||||
return Boxed_Number(oper(Operators::Opers::assign_bitwise_xor, t_lhs.bv, t_rhs.bv));
|
return oper(Operators::assign_bitwise_xor, t_lhs.bv, t_rhs.bv);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Boxed_Number assign_remainder(Boxed_Number t_lhs, const Boxed_Number &t_rhs)
|
static Boxed_Number assign_remainder(Boxed_Number t_lhs, const Boxed_Number &t_rhs)
|
||||||
{
|
{
|
||||||
return Boxed_Number(oper(Operators::Opers::assign_remainder, t_lhs.bv, t_rhs.bv));
|
return oper(Operators::assign_remainder, t_lhs.bv, t_rhs.bv);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Boxed_Number assign_shift_left(Boxed_Number t_lhs, const Boxed_Number &t_rhs)
|
static Boxed_Number assign_shift_left(Boxed_Number t_lhs, const Boxed_Number &t_rhs)
|
||||||
{
|
{
|
||||||
return Boxed_Number(oper(Operators::Opers::assign_shift_left, t_lhs.bv, t_rhs.bv));
|
return oper(Operators::assign_shift_left, t_lhs.bv, t_rhs.bv);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Boxed_Number assign_shift_right(Boxed_Number t_lhs, const Boxed_Number &t_rhs)
|
static Boxed_Number assign_shift_right(Boxed_Number t_lhs, const Boxed_Number &t_rhs)
|
||||||
{
|
{
|
||||||
return Boxed_Number(oper(Operators::Opers::assign_shift_right, t_lhs.bv, t_rhs.bv));
|
return oper(Operators::assign_shift_right, t_lhs.bv, t_rhs.bv);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const Boxed_Number bitwise_and(const Boxed_Number &t_lhs, const Boxed_Number &t_rhs)
|
static const Boxed_Number bitwise_and(const Boxed_Number &t_lhs, const Boxed_Number &t_rhs)
|
||||||
{
|
{
|
||||||
return Boxed_Number(oper(Operators::Opers::bitwise_and, t_lhs.bv, t_rhs.bv));
|
return oper(Operators::bitwise_and, t_lhs.bv, t_rhs.bv);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const Boxed_Number bitwise_complement(const Boxed_Number &t_lhs)
|
static const Boxed_Number bitwise_complement(const Boxed_Number &t_lhs)
|
||||||
{
|
{
|
||||||
return Boxed_Number(oper(Operators::Opers::bitwise_complement, t_lhs.bv, Boxed_Value(0)));
|
return oper(Operators::bitwise_complement, t_lhs.bv, Boxed_Value(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
static const Boxed_Number bitwise_xor(const Boxed_Number &t_lhs, const Boxed_Number &t_rhs)
|
static const Boxed_Number bitwise_xor(const Boxed_Number &t_lhs, const Boxed_Number &t_rhs)
|
||||||
{
|
{
|
||||||
return Boxed_Number(oper(Operators::Opers::bitwise_xor, t_lhs.bv, t_rhs.bv));
|
return oper(Operators::bitwise_xor, t_lhs.bv, t_rhs.bv);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const Boxed_Number bitwise_or(const Boxed_Number &t_lhs, const Boxed_Number &t_rhs)
|
static const Boxed_Number bitwise_or(const Boxed_Number &t_lhs, const Boxed_Number &t_rhs)
|
||||||
{
|
{
|
||||||
return Boxed_Number(oper(Operators::Opers::bitwise_or, t_lhs.bv, t_rhs.bv));
|
return oper(Operators::bitwise_or, t_lhs.bv, t_rhs.bv);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Boxed_Number assign_product(Boxed_Number t_lhs, const Boxed_Number &t_rhs)
|
static Boxed_Number assign_product(Boxed_Number t_lhs, const Boxed_Number &t_rhs)
|
||||||
{
|
{
|
||||||
return Boxed_Number(oper(Operators::Opers::assign_product, t_lhs.bv, t_rhs.bv));
|
return oper(Operators::assign_product, t_lhs.bv, t_rhs.bv);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Boxed_Number assign_quotient(Boxed_Number t_lhs, const Boxed_Number &t_rhs)
|
static Boxed_Number assign_quotient(Boxed_Number t_lhs, const Boxed_Number &t_rhs)
|
||||||
{
|
{
|
||||||
return Boxed_Number(oper(Operators::Opers::assign_quotient, t_lhs.bv, t_rhs.bv));
|
return oper(Operators::assign_quotient, t_lhs.bv, t_rhs.bv);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Boxed_Number assign_sum(Boxed_Number t_lhs, const Boxed_Number &t_rhs)
|
static Boxed_Number assign_sum(Boxed_Number t_lhs, const Boxed_Number &t_rhs)
|
||||||
{
|
{
|
||||||
return Boxed_Number(oper(Operators::Opers::assign_sum, t_lhs.bv, t_rhs.bv));
|
return oper(Operators::assign_sum, t_lhs.bv, t_rhs.bv);
|
||||||
}
|
}
|
||||||
static Boxed_Number assign_difference(Boxed_Number t_lhs, const Boxed_Number &t_rhs)
|
static Boxed_Number assign_difference(Boxed_Number t_lhs, const Boxed_Number &t_rhs)
|
||||||
{
|
{
|
||||||
return Boxed_Number(oper(Operators::Opers::assign_difference, t_lhs.bv, t_rhs.bv));
|
return oper(Operators::assign_difference, t_lhs.bv, t_rhs.bv);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const Boxed_Number quotient(const Boxed_Number &t_lhs, const Boxed_Number &t_rhs)
|
static const Boxed_Number quotient(const Boxed_Number &t_lhs, const Boxed_Number &t_rhs)
|
||||||
{
|
{
|
||||||
return Boxed_Number(oper(Operators::Opers::quotient, t_lhs.bv, t_rhs.bv));
|
return oper(Operators::quotient, t_lhs.bv, t_rhs.bv);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const Boxed_Number shift_left(const Boxed_Number &t_lhs, const Boxed_Number &t_rhs)
|
static const Boxed_Number shift_left(const Boxed_Number &t_lhs, const Boxed_Number &t_rhs)
|
||||||
{
|
{
|
||||||
return Boxed_Number(oper(Operators::Opers::shift_left, t_lhs.bv, t_rhs.bv));
|
return oper(Operators::shift_left, t_lhs.bv, t_rhs.bv);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const Boxed_Number product(const Boxed_Number &t_lhs, const Boxed_Number &t_rhs)
|
static const Boxed_Number product(const Boxed_Number &t_lhs, const Boxed_Number &t_rhs)
|
||||||
{
|
{
|
||||||
return Boxed_Number(oper(Operators::Opers::product, t_lhs.bv, t_rhs.bv));
|
return oper(Operators::product, t_lhs.bv, t_rhs.bv);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const Boxed_Number remainder(const Boxed_Number &t_lhs, const Boxed_Number &t_rhs)
|
static const Boxed_Number remainder(const Boxed_Number &t_lhs, const Boxed_Number &t_rhs)
|
||||||
{
|
{
|
||||||
return Boxed_Number(oper(Operators::Opers::remainder, t_lhs.bv, t_rhs.bv));
|
return oper(Operators::remainder, t_lhs.bv, t_rhs.bv);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const Boxed_Number shift_right(const Boxed_Number &t_lhs, const Boxed_Number &t_rhs)
|
static const Boxed_Number shift_right(const Boxed_Number &t_lhs, const Boxed_Number &t_rhs)
|
||||||
{
|
{
|
||||||
return Boxed_Number(oper(Operators::Opers::shift_right, t_lhs.bv, t_rhs.bv));
|
return oper(Operators::shift_right, t_lhs.bv, t_rhs.bv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -843,7 +1012,9 @@ namespace chaiscript
|
|||||||
template<>
|
template<>
|
||||||
struct Cast_Helper<Boxed_Number>
|
struct Cast_Helper<Boxed_Number>
|
||||||
{
|
{
|
||||||
static Boxed_Number cast(const Boxed_Value &ob, const Type_Conversions_State *)
|
typedef Boxed_Number Result_Type;
|
||||||
|
|
||||||
|
static Result_Type cast(const Boxed_Value &ob, const Type_Conversions_State *)
|
||||||
{
|
{
|
||||||
return Boxed_Number(ob);
|
return Boxed_Number(ob);
|
||||||
}
|
}
|
||||||
|
@@ -62,8 +62,10 @@ namespace chaiscript
|
|||||||
|
|
||||||
Data(const Data &) = delete;
|
Data(const Data &) = delete;
|
||||||
|
|
||||||
|
#if !defined(__APPLE__) && (!defined(_MSC_VER) || _MSC_VER != 1800)
|
||||||
Data(Data &&) = default;
|
Data(Data &&) = default;
|
||||||
Data &operator=(Data &&rhs) = default;
|
Data &operator=(Data &&rhs) = default;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
Type_Info m_type_info;
|
Type_Info m_type_info;
|
||||||
@@ -187,8 +189,11 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !defined(_MSC_VER) || _MSC_VER != 1800
|
||||||
Boxed_Value(Boxed_Value&&) = default;
|
Boxed_Value(Boxed_Value&&) = default;
|
||||||
Boxed_Value& operator=(Boxed_Value&&) = default;
|
Boxed_Value& operator=(Boxed_Value&&) = default;
|
||||||
|
#endif
|
||||||
|
|
||||||
Boxed_Value(const Boxed_Value&) = default;
|
Boxed_Value(const Boxed_Value&) = default;
|
||||||
Boxed_Value& operator=(const Boxed_Value&) = default;
|
Boxed_Value& operator=(const Boxed_Value&) = default;
|
||||||
|
|
||||||
@@ -205,98 +210,107 @@ namespace chaiscript
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Type_Info &get_type_info() const noexcept
|
const Type_Info &get_type_info() const CHAISCRIPT_NOEXCEPT
|
||||||
{
|
{
|
||||||
return m_data->m_type_info;
|
return m_data->m_type_info;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// return true if the object is uninitialized
|
/// return true if the object is uninitialized
|
||||||
bool is_undef() const noexcept
|
bool is_undef() const CHAISCRIPT_NOEXCEPT
|
||||||
{
|
{
|
||||||
return m_data->m_type_info.is_undef();
|
return m_data->m_type_info.is_undef();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_const() const noexcept
|
bool is_const() const CHAISCRIPT_NOEXCEPT
|
||||||
{
|
{
|
||||||
return m_data->m_type_info.is_const();
|
return m_data->m_type_info.is_const();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_type(const Type_Info &ti) const noexcept
|
bool is_type(const Type_Info &ti) const CHAISCRIPT_NOEXCEPT
|
||||||
{
|
{
|
||||||
return m_data->m_type_info.bare_equal(ti);
|
return m_data->m_type_info.bare_equal(ti);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct Sentinel {
|
||||||
|
Sentinel(std::shared_ptr<T> &ptr, Data &data)
|
||||||
|
: m_ptr(ptr), m_data(data)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
~Sentinel()
|
||||||
|
{
|
||||||
|
// save new pointer data
|
||||||
|
m_data.get().m_data_ptr = m_ptr.get().get();
|
||||||
|
m_data.get().m_const_data_ptr = m_ptr.get().get();
|
||||||
|
}
|
||||||
|
|
||||||
|
Sentinel& operator=(Sentinel&&s) {
|
||||||
|
m_ptr = std::move(s.m_ptr);
|
||||||
|
m_data = std::move(s.m_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
Sentinel(Sentinel &&s)
|
||||||
|
: m_ptr(std::move(s.m_ptr)),
|
||||||
|
m_data(std::move(s.m_data))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
operator std::shared_ptr<T>&() const
|
||||||
|
{
|
||||||
|
return m_ptr.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
Sentinel &operator=(const Sentinel &) = delete;
|
||||||
|
Sentinel(Sentinel&) = delete;
|
||||||
|
|
||||||
|
std::reference_wrapper<std::shared_ptr<T>> m_ptr;
|
||||||
|
std::reference_wrapper<Data> m_data;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
auto pointer_sentinel(std::shared_ptr<T> &ptr) const
|
Sentinel<T> pointer_sentinel(std::shared_ptr<T> &ptr) const
|
||||||
{
|
{
|
||||||
struct Sentinel {
|
return Sentinel<T>(ptr, *(m_data.get()));
|
||||||
Sentinel(std::shared_ptr<T> &t_ptr, Data &data)
|
|
||||||
: m_ptr(t_ptr), m_data(data)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
~Sentinel()
|
|
||||||
{
|
|
||||||
// save new pointer data
|
|
||||||
m_data.get().m_data_ptr = m_ptr.get().get();
|
|
||||||
m_data.get().m_const_data_ptr = m_ptr.get().get();
|
|
||||||
}
|
|
||||||
|
|
||||||
Sentinel& operator=(Sentinel&&s) = default;
|
|
||||||
Sentinel(Sentinel &&s) = default;
|
|
||||||
|
|
||||||
operator std::shared_ptr<T>&() const
|
|
||||||
{
|
|
||||||
return m_ptr.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
Sentinel &operator=(const Sentinel &) = delete;
|
|
||||||
Sentinel(Sentinel&) = delete;
|
|
||||||
|
|
||||||
std::reference_wrapper<std::shared_ptr<T>> m_ptr;
|
|
||||||
std::reference_wrapper<Data> m_data;
|
|
||||||
};
|
|
||||||
|
|
||||||
return Sentinel(ptr, *(m_data.get()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_null() const noexcept
|
bool is_null() const CHAISCRIPT_NOEXCEPT
|
||||||
{
|
{
|
||||||
return (m_data->m_data_ptr == nullptr && m_data->m_const_data_ptr == nullptr);
|
return (m_data->m_data_ptr == nullptr && m_data->m_const_data_ptr == nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
const chaiscript::detail::Any & get() const noexcept
|
const chaiscript::detail::Any & get() const CHAISCRIPT_NOEXCEPT
|
||||||
{
|
{
|
||||||
return m_data->m_obj;
|
return m_data->m_obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_ref() const noexcept
|
bool is_ref() const CHAISCRIPT_NOEXCEPT
|
||||||
{
|
{
|
||||||
return m_data->m_is_ref;
|
return m_data->m_is_ref;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_return_value() const noexcept
|
bool is_return_value() const CHAISCRIPT_NOEXCEPT
|
||||||
{
|
{
|
||||||
return m_data->m_return_value;
|
return m_data->m_return_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void reset_return_value() const noexcept
|
void reset_return_value() const CHAISCRIPT_NOEXCEPT
|
||||||
{
|
{
|
||||||
m_data->m_return_value = false;
|
m_data->m_return_value = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_pointer() const noexcept
|
bool is_pointer() const CHAISCRIPT_NOEXCEPT
|
||||||
{
|
{
|
||||||
return !is_ref();
|
return !is_ref();
|
||||||
}
|
}
|
||||||
|
|
||||||
void *get_ptr() const noexcept
|
void *get_ptr() const CHAISCRIPT_NOEXCEPT
|
||||||
{
|
{
|
||||||
return m_data->m_data_ptr;
|
return m_data->m_data_ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
const void *get_const_ptr() const noexcept
|
const void *get_const_ptr() const CHAISCRIPT_NOEXCEPT
|
||||||
{
|
{
|
||||||
return m_data->m_const_data_ptr;
|
return m_data->m_const_data_ptr;
|
||||||
}
|
}
|
||||||
@@ -336,7 +350,7 @@ namespace chaiscript
|
|||||||
|
|
||||||
|
|
||||||
/// \returns true if the two Boxed_Values share the same internal type
|
/// \returns true if the two Boxed_Values share the same internal type
|
||||||
static bool type_match(const Boxed_Value &l, const Boxed_Value &r) noexcept
|
static bool type_match(const Boxed_Value &l, const Boxed_Value &r) CHAISCRIPT_NOEXCEPT
|
||||||
{
|
{
|
||||||
return l.get_type_info() == r.get_type_info();
|
return l.get_type_info() == r.get_type_info();
|
||||||
}
|
}
|
||||||
@@ -446,14 +460,10 @@ namespace chaiscript
|
|||||||
return detail::const_var_impl(t);
|
return detail::const_var_impl(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Boxed_Value void_var() {
|
#ifdef CHAISCRIPT_HAS_MAGIC_STATICS
|
||||||
static const auto v = Boxed_Value(Boxed_Value::Void_Type());
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Boxed_Value const_var(bool b) {
|
inline Boxed_Value const_var(bool b) {
|
||||||
static const auto t = detail::const_var_impl(true);
|
static auto t = detail::const_var_impl(true);
|
||||||
static const auto f = detail::const_var_impl(false);
|
static auto f = detail::const_var_impl(false);
|
||||||
|
|
||||||
if (b) {
|
if (b) {
|
||||||
return t;
|
return t;
|
||||||
@@ -461,6 +471,7 @@ namespace chaiscript
|
|||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -37,9 +37,6 @@ class Boxed_Number;
|
|||||||
} // namespace chaiscript
|
} // namespace chaiscript
|
||||||
|
|
||||||
namespace chaiscript {
|
namespace chaiscript {
|
||||||
namespace parser {
|
|
||||||
class ChaiScript_Parser_Base;
|
|
||||||
}
|
|
||||||
namespace dispatch {
|
namespace dispatch {
|
||||||
class Dynamic_Proxy_Function;
|
class Dynamic_Proxy_Function;
|
||||||
class Proxy_Function_Base;
|
class Proxy_Function_Base;
|
||||||
@@ -48,7 +45,6 @@ struct Placeholder_Object;
|
|||||||
} // namespace chaiscript
|
} // namespace chaiscript
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// \namespace chaiscript::dispatch
|
/// \namespace chaiscript::dispatch
|
||||||
/// \brief Classes and functions specific to the runtime dispatch side of ChaiScript. Some items may be of use to the end user.
|
/// \brief Classes and functions specific to the runtime dispatch side of ChaiScript. Some items may be of use to the end user.
|
||||||
|
|
||||||
@@ -60,14 +56,14 @@ namespace chaiscript
|
|||||||
class reserved_word_error : public std::runtime_error
|
class reserved_word_error : public std::runtime_error
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit reserved_word_error(const std::string &t_word) noexcept
|
reserved_word_error(const std::string &t_word) CHAISCRIPT_NOEXCEPT
|
||||||
: std::runtime_error("Reserved word not allowed in object name: " + t_word), m_word(t_word)
|
: std::runtime_error("Reserved word not allowed in object name: " + t_word), m_word(t_word)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
reserved_word_error(const reserved_word_error &) = default;
|
reserved_word_error(const reserved_word_error &) = default;
|
||||||
|
|
||||||
virtual ~reserved_word_error() noexcept = default;
|
virtual ~reserved_word_error() CHAISCRIPT_NOEXCEPT {}
|
||||||
|
|
||||||
std::string word() const
|
std::string word() const
|
||||||
{
|
{
|
||||||
@@ -82,14 +78,14 @@ namespace chaiscript
|
|||||||
class illegal_name_error : public std::runtime_error
|
class illegal_name_error : public std::runtime_error
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit illegal_name_error(const std::string &t_name) noexcept
|
illegal_name_error(const std::string &t_name) CHAISCRIPT_NOEXCEPT
|
||||||
: std::runtime_error("Reserved name not allowed in object name: " + t_name), m_name(t_name)
|
: std::runtime_error("Reserved name not allowed in object name: " + t_name), m_name(t_name)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
illegal_name_error(const illegal_name_error &) = default;
|
illegal_name_error(const illegal_name_error &) = default;
|
||||||
|
|
||||||
virtual ~illegal_name_error() noexcept = default;
|
virtual ~illegal_name_error() CHAISCRIPT_NOEXCEPT {}
|
||||||
|
|
||||||
std::string name() const
|
std::string name() const
|
||||||
{
|
{
|
||||||
@@ -105,14 +101,14 @@ namespace chaiscript
|
|||||||
class name_conflict_error : public std::runtime_error
|
class name_conflict_error : public std::runtime_error
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit name_conflict_error(const std::string &t_name) noexcept
|
name_conflict_error(const std::string &t_name) CHAISCRIPT_NOEXCEPT
|
||||||
: std::runtime_error("Name already exists in current context " + t_name), m_name(t_name)
|
: std::runtime_error("Name already exists in current context " + t_name), m_name(t_name)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
name_conflict_error(const name_conflict_error &) = default;
|
name_conflict_error(const name_conflict_error &) = default;
|
||||||
|
|
||||||
virtual ~name_conflict_error() noexcept = default;
|
virtual ~name_conflict_error() CHAISCRIPT_NOEXCEPT {}
|
||||||
|
|
||||||
std::string name() const
|
std::string name() const
|
||||||
{
|
{
|
||||||
@@ -129,13 +125,13 @@ namespace chaiscript
|
|||||||
class global_non_const : public std::runtime_error
|
class global_non_const : public std::runtime_error
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
global_non_const() noexcept
|
global_non_const() CHAISCRIPT_NOEXCEPT
|
||||||
: std::runtime_error("a global object must be const")
|
: std::runtime_error("a global object must be const")
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
global_non_const(const global_non_const &) = default;
|
global_non_const(const global_non_const &) = default;
|
||||||
virtual ~global_non_const() noexcept = default;
|
virtual ~global_non_const() CHAISCRIPT_NOEXCEPT {}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,6 +178,12 @@ namespace chaiscript
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Module &add(const std::shared_ptr<Module> &m)
|
||||||
|
{
|
||||||
|
m->apply(*this, *this);
|
||||||
|
return *m;
|
||||||
|
}
|
||||||
|
|
||||||
template<typename Eval, typename Engine>
|
template<typename Eval, typename Engine>
|
||||||
void apply(Eval &t_eval, Engine &t_engine) const
|
void apply(Eval &t_eval, Engine &t_engine) const
|
||||||
{
|
{
|
||||||
@@ -192,28 +194,30 @@ namespace chaiscript
|
|||||||
apply_globals(m_globals.begin(), m_globals.end(), t_engine);
|
apply_globals(m_globals.begin(), m_globals.end(), t_engine);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
~Module()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
bool has_function(const Proxy_Function &new_f, const std::string &name)
|
bool has_function(const Proxy_Function &new_f, const std::string &name)
|
||||||
{
|
{
|
||||||
return std::any_of(m_funcs.begin(), m_funcs.end(),
|
return std::any_of(m_funcs.begin(), m_funcs.end(), [&](const std::pair<Proxy_Function, std::string> &existing_f) {
|
||||||
[&](const std::pair<Proxy_Function, std::string> &existing_f) {
|
return existing_f.second == name && *(existing_f.first) == *(new_f);
|
||||||
return existing_f.second == name && *(existing_f.first) == *(new_f);
|
});
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<std::pair<Type_Info, std::string>> m_typeinfos;
|
std::vector<std::pair<Type_Info, std::string> > m_typeinfos;
|
||||||
std::vector<std::pair<Proxy_Function, std::string>> m_funcs;
|
std::vector<std::pair<Proxy_Function, std::string> > m_funcs;
|
||||||
std::vector<std::pair<Boxed_Value, std::string>> m_globals;
|
std::vector<std::pair<Boxed_Value, std::string> > m_globals;
|
||||||
std::vector<std::string> m_evals;
|
std::vector<std::string> m_evals;
|
||||||
std::vector<Type_Conversion> m_conversions;
|
std::vector<Type_Conversion> m_conversions;
|
||||||
|
|
||||||
template<typename T, typename InItr>
|
template<typename T, typename InItr>
|
||||||
static void apply(InItr begin, const InItr end, T &t)
|
static void apply(InItr begin, const InItr end, T &t)
|
||||||
{
|
{
|
||||||
for_each(begin, end,
|
for_each(begin, end, [&t](typename std::iterator_traits<InItr>::reference obj)
|
||||||
[&t](const auto &obj) {
|
{
|
||||||
try {
|
try {
|
||||||
t.add(obj.first, obj.second);
|
t.add(obj.first, obj.second);
|
||||||
} catch (const chaiscript::exception::name_conflict_error &) {
|
} catch (const chaiscript::exception::name_conflict_error &) {
|
||||||
@@ -263,7 +267,7 @@ namespace chaiscript
|
|||||||
/// A Proxy_Function implementation that is able to take
|
/// A Proxy_Function implementation that is able to take
|
||||||
/// a vector of Proxy_Functions and perform a dispatch on them. It is
|
/// a vector of Proxy_Functions and perform a dispatch on them. It is
|
||||||
/// used specifically in the case of dealing with Function object variables
|
/// used specifically in the case of dealing with Function object variables
|
||||||
class Dispatch_Function final : public dispatch::Proxy_Function_Base
|
class Dispatch_Function : public dispatch::Proxy_Function_Base
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Dispatch_Function(std::vector<Proxy_Function> t_funcs)
|
Dispatch_Function(std::vector<Proxy_Function> t_funcs)
|
||||||
@@ -272,7 +276,7 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator==(const dispatch::Proxy_Function_Base &rhs) const override
|
virtual bool operator==(const dispatch::Proxy_Function_Base &rhs) const CHAISCRIPT_OVERRIDE
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
const auto &dispatch_fun = dynamic_cast<const Dispatch_Function &>(rhs);
|
const auto &dispatch_fun = dynamic_cast<const Dispatch_Function &>(rhs);
|
||||||
@@ -282,7 +286,9 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Const_Proxy_Function> get_contained_functions() const override
|
virtual ~Dispatch_Function() {}
|
||||||
|
|
||||||
|
virtual std::vector<Const_Proxy_Function> get_contained_functions() const CHAISCRIPT_OVERRIDE
|
||||||
{
|
{
|
||||||
return std::vector<Const_Proxy_Function>(m_funcs.begin(), m_funcs.end());
|
return std::vector<Const_Proxy_Function>(m_funcs.begin(), m_funcs.end());
|
||||||
}
|
}
|
||||||
@@ -308,14 +314,19 @@ namespace chaiscript
|
|||||||
return arity;
|
return arity;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool call_match(const std::vector<Boxed_Value> &vals, const Type_Conversions_State &t_conversions) const override
|
virtual bool call_match(const std::vector<Boxed_Value> &vals, const Type_Conversions_State &t_conversions) const CHAISCRIPT_OVERRIDE
|
||||||
{
|
{
|
||||||
return std::any_of(std::begin(m_funcs), std::end(m_funcs),
|
return std::any_of(m_funcs.cbegin(), m_funcs.cend(),
|
||||||
[&vals, &t_conversions](const Proxy_Function &f){ return f->call_match(vals, t_conversions); });
|
[&vals, &t_conversions](const Proxy_Function &f){ return f->call_match(vals, t_conversions); });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual std::string annotation() const CHAISCRIPT_OVERRIDE
|
||||||
|
{
|
||||||
|
return "Multiple method dispatch function wrapper.";
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Boxed_Value do_call(const std::vector<Boxed_Value> ¶ms, const Type_Conversions_State &t_conversions) const override
|
virtual Boxed_Value do_call(const std::vector<Boxed_Value> ¶ms, const Type_Conversions_State &t_conversions) const CHAISCRIPT_OVERRIDE
|
||||||
{
|
{
|
||||||
return dispatch::dispatch(m_funcs, params, t_conversions);
|
return dispatch::dispatch(m_funcs, params, t_conversions);
|
||||||
}
|
}
|
||||||
@@ -380,6 +391,7 @@ namespace chaiscript
|
|||||||
typedef std::vector<Scope> StackData;
|
typedef std::vector<Scope> StackData;
|
||||||
|
|
||||||
Stack_Holder()
|
Stack_Holder()
|
||||||
|
: call_depth(0)
|
||||||
{
|
{
|
||||||
stacks.reserve(2);
|
stacks.reserve(2);
|
||||||
stacks.emplace_back(1);
|
stacks.emplace_back(1);
|
||||||
@@ -390,7 +402,7 @@ namespace chaiscript
|
|||||||
std::vector<StackData> stacks;
|
std::vector<StackData> stacks;
|
||||||
|
|
||||||
std::vector<std::vector<Boxed_Value>> call_params;
|
std::vector<std::vector<Boxed_Value>> call_params;
|
||||||
int call_depth = 0;
|
int call_depth;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Main class for the dispatchkit. Handles management
|
/// Main class for the dispatchkit. Handles management
|
||||||
@@ -410,24 +422,29 @@ namespace chaiscript
|
|||||||
std::vector<std::pair<std::string, Boxed_Value>> m_boxed_functions;
|
std::vector<std::pair<std::string, Boxed_Value>> m_boxed_functions;
|
||||||
std::map<std::string, Boxed_Value> m_global_objects;
|
std::map<std::string, Boxed_Value> m_global_objects;
|
||||||
Type_Name_Map m_types;
|
Type_Name_Map m_types;
|
||||||
std::set<std::string> m_reserved_words
|
std::set<std::string> m_reserved_words;
|
||||||
= {"def", "fun", "while", "for", "if", "else", "&&", "||", ",", "auto",
|
|
||||||
"return", "break", "true", "false", "class", "attr", "var", "global", "GLOBAL", "_"};
|
State &operator=(const State &) = default;
|
||||||
|
State() = default;
|
||||||
|
State(const State &) = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
Dispatch_Engine(chaiscript::parser::ChaiScript_Parser_Base &parser)
|
Dispatch_Engine()
|
||||||
: m_stack_holder(this),
|
: m_stack_holder(this),
|
||||||
m_parser(parser)
|
m_method_missing_loc(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
~Dispatch_Engine()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \brief casts an object while applying any Dynamic_Conversion available
|
/// \brief casts an object while applying any Dynamic_Conversion available
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
decltype(auto) boxed_cast(const Boxed_Value &bv) const
|
typename detail::Cast_Helper<Type>::Result_Type boxed_cast(const Boxed_Value &bv) const
|
||||||
{
|
{
|
||||||
Type_Conversions_State state(m_conversions, m_conversions.conversion_saves());
|
Type_Conversions_State state(m_conversions, m_conversions.conversion_saves());
|
||||||
return(chaiscript::boxed_cast<Type>(bv, &state));
|
return chaiscript::boxed_cast<Type>(bv, &state);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add a new conversion for upcasting to a base class
|
/// Add a new conversion for upcasting to a base class
|
||||||
@@ -586,10 +603,12 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
t_holder.call_params.pop_back();
|
t_holder.call_params.pop_back();
|
||||||
StackData &stack = get_stack_data(t_holder);
|
StackData &stack = get_stack_data(t_holder);
|
||||||
|
if (stack.size() > 1)
|
||||||
assert(!stack.empty());
|
{
|
||||||
|
stack.pop_back();
|
||||||
stack.pop_back();
|
} else {
|
||||||
|
throw std::range_error("Unable to pop global stack");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -608,7 +627,7 @@ namespace chaiscript
|
|||||||
/// Searches the current stack for an object of the given name
|
/// Searches the current stack for an object of the given name
|
||||||
/// includes a special overload for the _ place holder object to
|
/// includes a special overload for the _ place holder object to
|
||||||
/// ensure that it is always in scope.
|
/// ensure that it is always in scope.
|
||||||
Boxed_Value get_object(const std::string &name, std::atomic_uint_fast32_t &t_loc, Stack_Holder &t_holder) const
|
Boxed_Value get_object(const std::string &name, std::atomic_uint_fast32_t &t_loc) const
|
||||||
{
|
{
|
||||||
enum class Loc : uint_fast32_t {
|
enum class Loc : uint_fast32_t {
|
||||||
located = 0x80000000,
|
located = 0x80000000,
|
||||||
@@ -621,7 +640,7 @@ namespace chaiscript
|
|||||||
|
|
||||||
if (loc == 0)
|
if (loc == 0)
|
||||||
{
|
{
|
||||||
auto &stack = get_stack_data(t_holder);
|
auto &stack = get_stack_data();
|
||||||
|
|
||||||
// Is it in the stack?
|
// Is it in the stack?
|
||||||
for (auto stack_elem = stack.rbegin(); stack_elem != stack.rend(); ++stack_elem)
|
for (auto stack_elem = stack.rbegin(); stack_elem != stack.rend(); ++stack_elem)
|
||||||
@@ -640,7 +659,7 @@ namespace chaiscript
|
|||||||
|
|
||||||
t_loc = static_cast<uint_fast32_t>(Loc::located);
|
t_loc = static_cast<uint_fast32_t>(Loc::located);
|
||||||
} else if (loc & static_cast<uint_fast32_t>(Loc::is_local)) {
|
} else if (loc & static_cast<uint_fast32_t>(Loc::is_local)) {
|
||||||
auto &stack = get_stack_data(t_holder);
|
auto &stack = get_stack_data();
|
||||||
|
|
||||||
return stack[stack.size() - 1 - ((loc & static_cast<uint_fast32_t>(Loc::stack_mask)) >> 16)][loc & static_cast<uint_fast32_t>(Loc::loc_mask)].second;
|
return stack[stack.size() - 1 - ((loc & static_cast<uint_fast32_t>(Loc::stack_mask)) >> 16)][loc & static_cast<uint_fast32_t>(Loc::loc_mask)].second;
|
||||||
}
|
}
|
||||||
@@ -880,6 +899,12 @@ namespace chaiscript
|
|||||||
return rets;
|
return rets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void add_reserved_word(const std::string &name)
|
||||||
|
{
|
||||||
|
chaiscript::detail::threading::unique_lock<chaiscript::detail::threading::shared_mutex> l(m_mutex);
|
||||||
|
|
||||||
|
m_state.m_reserved_words.insert(name);
|
||||||
|
}
|
||||||
|
|
||||||
const Type_Conversions &conversions() const
|
const Type_Conversions &conversions() const
|
||||||
{
|
{
|
||||||
@@ -893,12 +918,15 @@ namespace chaiscript
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return std::any_of(std::begin(t_funs), std::end(t_funs),
|
for (const auto &fun : t_funs) {
|
||||||
[&](const auto &fun) {
|
if (fun->is_attribute_function()) {
|
||||||
return fun->is_attribute_function() && fun->compare_first_type(t_params[0], t_conversions);
|
if (fun->compare_first_type(t_params[0], t_conversions)) {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CHAISCRIPT_MSVC
|
#ifdef CHAISCRIPT_MSVC
|
||||||
@@ -935,14 +963,20 @@ namespace chaiscript
|
|||||||
|
|
||||||
This_Foist fi(*this, l_params.front());
|
This_Foist fi(*this, l_params.front());
|
||||||
|
|
||||||
auto func = boxed_cast<std::shared_ptr<const dispatch::Proxy_Function_Base>>(bv);
|
|
||||||
try {
|
try {
|
||||||
return (*func)({l_params.begin() + l_num_params, l_params.end()}, l_conversions);
|
auto func = boxed_cast<std::shared_ptr<const dispatch::Proxy_Function_Base>>(bv);
|
||||||
|
try {
|
||||||
|
return (*func)({l_params.begin() + l_num_params, l_params.end()}, l_conversions);
|
||||||
|
} catch (const chaiscript::exception::bad_boxed_cast &) {
|
||||||
|
} catch (const chaiscript::exception::arity_error &) {
|
||||||
|
} catch (const chaiscript::exception::guard_error &) {
|
||||||
|
}
|
||||||
|
throw chaiscript::exception::dispatch_error({l_params.begin() + l_num_params, l_params.end()}, std::vector<Const_Proxy_Function>{func});
|
||||||
} catch (const chaiscript::exception::bad_boxed_cast &) {
|
} catch (const chaiscript::exception::bad_boxed_cast &) {
|
||||||
} catch (const chaiscript::exception::arity_error &) {
|
// unable to convert bv into a Proxy_Function_Base
|
||||||
} catch (const chaiscript::exception::guard_error &) {
|
throw chaiscript::exception::dispatch_error({l_params.begin() + l_num_params, l_params.end()},
|
||||||
|
std::vector<Const_Proxy_Function>(l_funs.begin(), l_funs.end()));
|
||||||
}
|
}
|
||||||
throw chaiscript::exception::dispatch_error({l_params.begin() + l_num_params, l_params.end()}, std::vector<Const_Proxy_Function>{func});
|
|
||||||
} else {
|
} else {
|
||||||
return bv;
|
return bv;
|
||||||
}
|
}
|
||||||
@@ -1046,7 +1080,11 @@ namespace chaiscript
|
|||||||
void dump_function(const std::pair<const std::string, Proxy_Function > &f) const
|
void dump_function(const std::pair<const std::string, Proxy_Function > &f) const
|
||||||
{
|
{
|
||||||
std::vector<Type_Info> params = f.second->get_param_types();
|
std::vector<Type_Info> params = f.second->get_param_types();
|
||||||
|
std::string annotation = f.second->annotation();
|
||||||
|
|
||||||
|
if (annotation.size() > 0) {
|
||||||
|
std::cout << annotation;
|
||||||
|
}
|
||||||
dump_type(params.front());
|
dump_type(params.front());
|
||||||
std::cout << " " << f.first << "(";
|
std::cout << " " << f.first << "(";
|
||||||
|
|
||||||
@@ -1078,7 +1116,7 @@ namespace chaiscript
|
|||||||
const Const_Proxy_Function &f = this->boxed_cast<Const_Proxy_Function>(params[0]);
|
const Const_Proxy_Function &f = this->boxed_cast<Const_Proxy_Function>(params[0]);
|
||||||
const Type_Conversions_State convs(m_conversions, m_conversions.conversion_saves());
|
const Type_Conversions_State convs(m_conversions, m_conversions.conversion_saves());
|
||||||
|
|
||||||
return const_var(f->call_match(std::vector<Boxed_Value>(params.begin() + 1, params.end()), convs));
|
return Boxed_Value(f->call_match(std::vector<Boxed_Value>(params.begin() + 1, params.end()), convs));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Dump all system info to stdout
|
/// Dump all system info to stdout
|
||||||
@@ -1237,11 +1275,6 @@ namespace chaiscript
|
|||||||
return m_stack_holder->stacks.back();
|
return m_stack_holder->stacks.back();
|
||||||
}
|
}
|
||||||
|
|
||||||
parser::ChaiScript_Parser_Base &get_parser()
|
|
||||||
{
|
|
||||||
return m_parser.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
const std::vector<std::pair<std::string, Boxed_Value>> &get_boxed_functions_int() const
|
const std::vector<std::pair<std::string, Boxed_Value>> &get_boxed_functions_int() const
|
||||||
@@ -1306,8 +1339,13 @@ namespace chaiscript
|
|||||||
const auto lhssize = lhsparamtypes.size();
|
const auto lhssize = lhsparamtypes.size();
|
||||||
const auto rhssize = rhsparamtypes.size();
|
const auto rhssize = rhsparamtypes.size();
|
||||||
|
|
||||||
static const auto boxed_type = user_type<Boxed_Value>();
|
#ifdef CHAISCRIPT_HAS_MAGIC_STATICS
|
||||||
static const auto boxed_pod_type = user_type<Boxed_Number>();
|
static auto boxed_type = user_type<Boxed_Value>();
|
||||||
|
static auto boxed_pod_type = user_type<Boxed_Number>();
|
||||||
|
#else
|
||||||
|
auto boxed_type = user_type<Boxed_Value>();
|
||||||
|
auto boxed_pod_type = user_type<Boxed_Number>();
|
||||||
|
#endif
|
||||||
|
|
||||||
for (size_t i = 1; i < lhssize && i < rhssize; ++i)
|
for (size_t i = 1; i < lhssize && i < rhssize; ++i)
|
||||||
{
|
{
|
||||||
@@ -1338,6 +1376,10 @@ namespace chaiscript
|
|||||||
|
|
||||||
if (rt.bare_equal(boxed_type))
|
if (rt.bare_equal(boxed_type))
|
||||||
{
|
{
|
||||||
|
if (lt.bare_equal(boxed_pod_type))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1467,7 +1509,6 @@ namespace chaiscript
|
|||||||
|
|
||||||
Type_Conversions m_conversions;
|
Type_Conversions m_conversions;
|
||||||
chaiscript::detail::threading::Thread_Storage<Stack_Holder> m_stack_holder;
|
chaiscript::detail::threading::Thread_Storage<Stack_Holder> m_stack_holder;
|
||||||
std::reference_wrapper<parser::ChaiScript_Parser_Base> m_parser;
|
|
||||||
|
|
||||||
mutable std::atomic_uint_fast32_t m_method_missing_loc;
|
mutable std::atomic_uint_fast32_t m_method_missing_loc;
|
||||||
|
|
||||||
@@ -1508,10 +1549,6 @@ namespace chaiscript
|
|||||||
m_engine.get().add_object(t_name, std::move(obj), m_stack_holder.get());
|
m_engine.get().add_object(t_name, std::move(obj), m_stack_holder.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
Boxed_Value get_object(const std::string &t_name, std::atomic_uint_fast32_t &t_loc) const {
|
|
||||||
return m_engine.get().get_object(t_name, t_loc, m_stack_holder.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::reference_wrapper<Dispatch_Engine> m_engine;
|
std::reference_wrapper<Dispatch_Engine> m_engine;
|
||||||
std::reference_wrapper<Stack_Holder> m_stack_holder;
|
std::reference_wrapper<Stack_Holder> m_stack_holder;
|
||||||
@@ -1522,4 +1559,3 @@ namespace chaiscript
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@@ -33,7 +33,7 @@ namespace chaiscript
|
|||||||
|
|
||||||
option_explicit_set(const option_explicit_set &) = default;
|
option_explicit_set(const option_explicit_set &) = default;
|
||||||
|
|
||||||
virtual ~option_explicit_set() noexcept = default;
|
virtual ~option_explicit_set() CHAISCRIPT_NOEXCEPT {}
|
||||||
};
|
};
|
||||||
|
|
||||||
class Dynamic_Object
|
class Dynamic_Object
|
||||||
@@ -44,7 +44,9 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Dynamic_Object() = default;
|
Dynamic_Object() : m_type_name(""), m_option_explicit(false)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
bool is_explicit() const
|
bool is_explicit() const
|
||||||
{
|
{
|
||||||
@@ -82,10 +84,6 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool has_attr(const std::string &t_attr_name) const {
|
|
||||||
return m_attrs.find(t_attr_name) != m_attrs.end();
|
|
||||||
}
|
|
||||||
|
|
||||||
Boxed_Value &get_attr(const std::string &t_attr_name)
|
Boxed_Value &get_attr(const std::string &t_attr_name)
|
||||||
{
|
{
|
||||||
return m_attrs[t_attr_name];
|
return m_attrs[t_attr_name];
|
||||||
@@ -109,14 +107,15 @@ namespace chaiscript
|
|||||||
return get_attr(t_method_name);
|
return get_attr(t_method_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::map<std::string, Boxed_Value> get_attrs() const
|
std::map<std::string, Boxed_Value> get_attrs() const
|
||||||
{
|
{
|
||||||
return m_attrs;
|
return m_attrs;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const std::string m_type_name = "";
|
std::string m_type_name;
|
||||||
bool m_option_explicit = false;
|
bool m_option_explicit;
|
||||||
|
|
||||||
std::map<std::string, Boxed_Value> m_attrs;
|
std::map<std::string, Boxed_Value> m_attrs;
|
||||||
};
|
};
|
||||||
|
@@ -39,7 +39,7 @@ namespace chaiscript
|
|||||||
/// A Proxy_Function implementation designed for calling a function
|
/// A Proxy_Function implementation designed for calling a function
|
||||||
/// that is automatically guarded based on the first param based on the
|
/// that is automatically guarded based on the first param based on the
|
||||||
/// param's type name
|
/// param's type name
|
||||||
class Dynamic_Object_Function final : public Proxy_Function_Base
|
class Dynamic_Object_Function : public Proxy_Function_Base
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Dynamic_Object_Function(
|
Dynamic_Object_Function(
|
||||||
@@ -67,11 +67,12 @@ namespace chaiscript
|
|||||||
&& "Programming error, Dynamic_Object_Function must have at least one parameter (this)");
|
&& "Programming error, Dynamic_Object_Function must have at least one parameter (this)");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual ~Dynamic_Object_Function() {}
|
||||||
|
|
||||||
Dynamic_Object_Function &operator=(const Dynamic_Object_Function) = delete;
|
Dynamic_Object_Function &operator=(const Dynamic_Object_Function) = delete;
|
||||||
Dynamic_Object_Function(Dynamic_Object_Function &) = delete;
|
Dynamic_Object_Function(Dynamic_Object_Function &) = delete;
|
||||||
|
|
||||||
bool operator==(const Proxy_Function_Base &f) const override
|
virtual bool operator==(const Proxy_Function_Base &f) const CHAISCRIPT_OVERRIDE
|
||||||
{
|
{
|
||||||
if (const auto *df = dynamic_cast<const Dynamic_Object_Function *>(&f))
|
if (const auto *df = dynamic_cast<const Dynamic_Object_Function *>(&f))
|
||||||
{
|
{
|
||||||
@@ -81,9 +82,9 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_attribute_function() const override { return m_is_attribute; }
|
virtual bool is_attribute_function() const CHAISCRIPT_OVERRIDE { return m_is_attribute; }
|
||||||
|
|
||||||
bool call_match(const std::vector<Boxed_Value> &vals, const Type_Conversions_State &t_conversions) const override
|
virtual bool call_match(const std::vector<Boxed_Value> &vals, const Type_Conversions_State &t_conversions) const CHAISCRIPT_OVERRIDE
|
||||||
{
|
{
|
||||||
if (dynamic_object_typename_match(vals, m_type_name, m_ti, t_conversions))
|
if (dynamic_object_typename_match(vals, m_type_name, m_ti, t_conversions))
|
||||||
{
|
{
|
||||||
@@ -93,13 +94,19 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Const_Proxy_Function> get_contained_functions() const override
|
virtual std::vector<Const_Proxy_Function> get_contained_functions() const CHAISCRIPT_OVERRIDE
|
||||||
{
|
{
|
||||||
return {m_func};
|
return {m_func};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual std::string annotation() const CHAISCRIPT_OVERRIDE
|
||||||
|
{
|
||||||
|
return m_func->annotation();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual Boxed_Value do_call(const std::vector<Boxed_Value> ¶ms, const Type_Conversions_State &t_conversions) const override
|
virtual Boxed_Value do_call(const std::vector<Boxed_Value> ¶ms, const Type_Conversions_State &t_conversions) const CHAISCRIPT_OVERRIDE
|
||||||
{
|
{
|
||||||
if (dynamic_object_typename_match(params, m_type_name, m_ti, t_conversions))
|
if (dynamic_object_typename_match(params, m_type_name, m_ti, t_conversions))
|
||||||
{
|
{
|
||||||
@@ -109,7 +116,7 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool compare_first_type(const Boxed_Value &bv, const Type_Conversions_State &t_conversions) const override
|
virtual bool compare_first_type(const Boxed_Value &bv, const Type_Conversions_State &t_conversions) const CHAISCRIPT_OVERRIDE
|
||||||
{
|
{
|
||||||
return dynamic_object_typename_match(bv, m_type_name, m_ti, t_conversions);
|
return dynamic_object_typename_match(bv, m_type_name, m_ti, t_conversions);
|
||||||
}
|
}
|
||||||
@@ -163,7 +170,9 @@ namespace chaiscript
|
|||||||
Proxy_Function m_func;
|
Proxy_Function m_func;
|
||||||
std::unique_ptr<Type_Info> m_ti;
|
std::unique_ptr<Type_Info> m_ti;
|
||||||
const Type_Info m_doti;
|
const Type_Info m_doti;
|
||||||
const bool m_is_attribute;
|
bool m_is_attribute;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -173,7 +182,7 @@ namespace chaiscript
|
|||||||
* that is automatically guarded based on the first param based on the
|
* that is automatically guarded based on the first param based on the
|
||||||
* param's type name
|
* param's type name
|
||||||
*/
|
*/
|
||||||
class Dynamic_Object_Constructor final : public Proxy_Function_Base
|
class Dynamic_Object_Constructor : public Proxy_Function_Base
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Dynamic_Object_Constructor(
|
Dynamic_Object_Constructor(
|
||||||
@@ -199,22 +208,29 @@ namespace chaiscript
|
|||||||
return std::vector<Type_Info>(begin, end);
|
return std::vector<Type_Info>(begin, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator==(const Proxy_Function_Base &f) const override
|
virtual ~Dynamic_Object_Constructor() {}
|
||||||
|
|
||||||
|
virtual bool operator==(const Proxy_Function_Base &f) const CHAISCRIPT_OVERRIDE
|
||||||
{
|
{
|
||||||
const Dynamic_Object_Constructor *dc = dynamic_cast<const Dynamic_Object_Constructor*>(&f);
|
const Dynamic_Object_Constructor *dc = dynamic_cast<const Dynamic_Object_Constructor*>(&f);
|
||||||
return dc && dc->m_type_name == m_type_name && (*dc->m_func) == (*m_func);
|
return dc && dc->m_type_name == m_type_name && (*dc->m_func) == (*m_func);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool call_match(const std::vector<Boxed_Value> &vals, const Type_Conversions_State &t_conversions) const override
|
virtual bool call_match(const std::vector<Boxed_Value> &vals, const Type_Conversions_State &t_conversions) const CHAISCRIPT_OVERRIDE
|
||||||
{
|
{
|
||||||
std::vector<Boxed_Value> new_vals{Boxed_Value(Dynamic_Object(m_type_name))};
|
std::vector<Boxed_Value> new_vals{Boxed_Value(Dynamic_Object(m_type_name))};
|
||||||
new_vals.insert(new_vals.end(), vals.begin(), vals.end());
|
new_vals.insert(new_vals.end(), vals.begin(), vals.end());
|
||||||
|
|
||||||
return m_func->call_match(new_vals, t_conversions);
|
return m_func->call_match(new_vals, t_conversions);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual std::string annotation() const CHAISCRIPT_OVERRIDE
|
||||||
|
{
|
||||||
|
return m_func->annotation();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Boxed_Value do_call(const std::vector<Boxed_Value> ¶ms, const Type_Conversions_State &t_conversions) const override
|
virtual Boxed_Value do_call(const std::vector<Boxed_Value> ¶ms, const Type_Conversions_State &t_conversions) const CHAISCRIPT_OVERRIDE
|
||||||
{
|
{
|
||||||
auto bv = Boxed_Value(Dynamic_Object(m_type_name), true);
|
auto bv = Boxed_Value(Dynamic_Object(m_type_name), true);
|
||||||
std::vector<Boxed_Value> new_params{bv};
|
std::vector<Boxed_Value> new_params{bv};
|
||||||
@@ -226,8 +242,8 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const std::string m_type_name;
|
std::string m_type_name;
|
||||||
const Proxy_Function m_func;
|
Proxy_Function m_func;
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@@ -23,11 +23,12 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
namespace detail
|
namespace detail
|
||||||
{
|
{
|
||||||
|
/// \todo make this a variadic template
|
||||||
struct Exception_Handler_Base
|
struct Exception_Handler_Base
|
||||||
{
|
{
|
||||||
virtual void handle(const Boxed_Value &bv, const Dispatch_Engine &t_engine) = 0;
|
virtual void handle(const Boxed_Value &bv, const Dispatch_Engine &t_engine) = 0;
|
||||||
|
|
||||||
virtual ~Exception_Handler_Base() = default;
|
virtual ~Exception_Handler_Base() {}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
template<typename T>
|
template<typename T>
|
||||||
@@ -37,12 +38,65 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename ... T>
|
template<typename T1>
|
||||||
struct Exception_Handler_Impl : Exception_Handler_Base
|
struct Exception_Handler_Impl1 : Exception_Handler_Base
|
||||||
{
|
{
|
||||||
void handle(const Boxed_Value &bv, const Dispatch_Engine &t_engine) override
|
virtual ~Exception_Handler_Impl1() {}
|
||||||
|
|
||||||
|
virtual void handle(const Boxed_Value &bv, const Dispatch_Engine &t_engine) CHAISCRIPT_OVERRIDE
|
||||||
{
|
{
|
||||||
(void)std::initializer_list<int>{(throw_type<T>(bv, t_engine), 0)...};
|
throw_type<T1>(bv, t_engine);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
template<typename T1, typename T2>
|
||||||
|
struct Exception_Handler_Impl2 : Exception_Handler_Base
|
||||||
|
{
|
||||||
|
virtual ~Exception_Handler_Impl2() {}
|
||||||
|
|
||||||
|
virtual void handle(const Boxed_Value &bv, const Dispatch_Engine &t_engine) CHAISCRIPT_OVERRIDE
|
||||||
|
{
|
||||||
|
throw_type<T1>(bv, t_engine);
|
||||||
|
throw_type<T2>(bv, t_engine);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T1, typename T2, typename T3>
|
||||||
|
struct Exception_Handler_Impl3 : Exception_Handler_Base
|
||||||
|
{
|
||||||
|
virtual ~Exception_Handler_Impl3() {}
|
||||||
|
|
||||||
|
virtual void handle(const Boxed_Value &bv, const Dispatch_Engine &t_engine) CHAISCRIPT_OVERRIDE
|
||||||
|
{
|
||||||
|
throw_type<T1>(bv, t_engine);
|
||||||
|
throw_type<T2>(bv, t_engine);
|
||||||
|
throw_type<T3>(bv, t_engine);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
template<typename T1, typename T2, typename T3, typename T4>
|
||||||
|
struct Exception_Handler_Impl4 : Exception_Handler_Base
|
||||||
|
{
|
||||||
|
virtual ~Exception_Handler_Impl4() {}
|
||||||
|
|
||||||
|
virtual void handle(const Boxed_Value &bv, const Dispatch_Engine &t_engine) CHAISCRIPT_OVERRIDE
|
||||||
|
{
|
||||||
|
throw_type<T1>(bv, t_engine);
|
||||||
|
throw_type<T2>(bv, t_engine);
|
||||||
|
throw_type<T3>(bv, t_engine);
|
||||||
|
throw_type<T4>(bv, t_engine);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
template<typename T1, typename T2, typename T3, typename T4, typename T5>
|
||||||
|
struct Exception_Handler_Impl5 : Exception_Handler_Base
|
||||||
|
{
|
||||||
|
virtual ~Exception_Handler_Impl5() {}
|
||||||
|
|
||||||
|
virtual void handle(const Boxed_Value &bv, const Dispatch_Engine &t_engine) CHAISCRIPT_OVERRIDE
|
||||||
|
{
|
||||||
|
throw_type<T1>(bv, t_engine);
|
||||||
|
throw_type<T2>(bv, t_engine);
|
||||||
|
throw_type<T3>(bv, t_engine);
|
||||||
|
throw_type<T4>(bv, t_engine);
|
||||||
|
throw_type<T5>(bv, t_engine);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -101,10 +155,42 @@ namespace chaiscript
|
|||||||
|
|
||||||
/// \brief creates a chaiscript::Exception_Handler which handles one type of exception unboxing
|
/// \brief creates a chaiscript::Exception_Handler which handles one type of exception unboxing
|
||||||
/// \sa \ref exceptions
|
/// \sa \ref exceptions
|
||||||
template<typename ... T>
|
template<typename T1>
|
||||||
Exception_Handler exception_specification()
|
Exception_Handler exception_specification()
|
||||||
{
|
{
|
||||||
return std::make_shared<detail::Exception_Handler_Impl<T...>>();
|
return Exception_Handler(new detail::Exception_Handler_Impl1<T1>());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// \brief creates a chaiscript::Exception_Handler which handles two types of exception unboxing
|
||||||
|
/// \sa \ref exceptions
|
||||||
|
template<typename T1, typename T2>
|
||||||
|
Exception_Handler exception_specification()
|
||||||
|
{
|
||||||
|
return Exception_Handler(new detail::Exception_Handler_Impl2<T1, T2>());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// \brief creates a chaiscript::Exception_Handler which handles three types of exception unboxing
|
||||||
|
/// \sa \ref exceptions
|
||||||
|
template<typename T1, typename T2, typename T3>
|
||||||
|
Exception_Handler exception_specification()
|
||||||
|
{
|
||||||
|
return Exception_Handler(new detail::Exception_Handler_Impl3<T1, T2, T3>());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// \brief creates a chaiscript::Exception_Handler which handles four types of exception unboxing
|
||||||
|
/// \sa \ref exceptions
|
||||||
|
template<typename T1, typename T2, typename T3, typename T4>
|
||||||
|
Exception_Handler exception_specification()
|
||||||
|
{
|
||||||
|
return Exception_Handler(new detail::Exception_Handler_Impl4<T1, T2, T3, T4>());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// \brief creates a chaiscript::Exception_Handler which handles five types of exception unboxing
|
||||||
|
/// \sa \ref exceptions
|
||||||
|
template<typename T1, typename T2, typename T3, typename T4, typename T5>
|
||||||
|
Exception_Handler exception_specification()
|
||||||
|
{
|
||||||
|
return Exception_Handler(new detail::Exception_Handler_Impl5<T1, T2, T3, T4, T5>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -35,7 +35,8 @@ namespace chaiscript
|
|||||||
/// \returns A std::function object for dispatching
|
/// \returns A std::function object for dispatching
|
||||||
/// \param[in] funcs the set of functions to dispatch on.
|
/// \param[in] funcs the set of functions to dispatch on.
|
||||||
template<typename FunctionType>
|
template<typename FunctionType>
|
||||||
std::function<FunctionType> functor(const std::vector<Const_Proxy_Function> &funcs, const Type_Conversions_State *t_conversions)
|
std::function<FunctionType>
|
||||||
|
functor(const std::vector<Const_Proxy_Function> &funcs, const Type_Conversions_State *t_conversions)
|
||||||
{
|
{
|
||||||
const bool has_arity_match = std::any_of(funcs.begin(), funcs.end(),
|
const bool has_arity_match = std::any_of(funcs.begin(), funcs.end(),
|
||||||
[](const Const_Proxy_Function &f) {
|
[](const Const_Proxy_Function &f) {
|
||||||
@@ -62,7 +63,8 @@ namespace chaiscript
|
|||||||
/// \returns A std::function object for dispatching
|
/// \returns A std::function object for dispatching
|
||||||
/// \param[in] func A function to execute.
|
/// \param[in] func A function to execute.
|
||||||
template<typename FunctionType>
|
template<typename FunctionType>
|
||||||
std::function<FunctionType> functor(Const_Proxy_Function func, const Type_Conversions_State *t_conversions)
|
std::function<FunctionType>
|
||||||
|
functor(Const_Proxy_Function func, const Type_Conversions_State *t_conversions)
|
||||||
{
|
{
|
||||||
return functor<FunctionType>(std::vector<Const_Proxy_Function>({std::move(func)}), t_conversions);
|
return functor<FunctionType>(std::vector<Const_Proxy_Function>({std::move(func)}), t_conversions);
|
||||||
}
|
}
|
||||||
@@ -70,7 +72,8 @@ namespace chaiscript
|
|||||||
/// Helper for automatically unboxing a Boxed_Value that contains a function object
|
/// Helper for automatically unboxing a Boxed_Value that contains a function object
|
||||||
/// and creating a typesafe C++ function caller from it.
|
/// and creating a typesafe C++ function caller from it.
|
||||||
template<typename FunctionType>
|
template<typename FunctionType>
|
||||||
std::function<FunctionType> functor(const Boxed_Value &bv, const Type_Conversions_State *t_conversions)
|
std::function<FunctionType>
|
||||||
|
functor(const Boxed_Value &bv, const Type_Conversions_State *t_conversions)
|
||||||
{
|
{
|
||||||
return functor<FunctionType>(boxed_cast<Const_Proxy_Function >(bv, t_conversions), t_conversions);
|
return functor<FunctionType>(boxed_cast<Const_Proxy_Function >(bv, t_conversions), t_conversions);
|
||||||
}
|
}
|
||||||
@@ -81,7 +84,9 @@ namespace chaiscript
|
|||||||
template<typename Signature>
|
template<typename Signature>
|
||||||
struct Cast_Helper<const std::function<Signature> &>
|
struct Cast_Helper<const std::function<Signature> &>
|
||||||
{
|
{
|
||||||
static std::function<Signature> cast(const Boxed_Value &ob, const Type_Conversions_State *t_conversions)
|
typedef std::function<Signature> Result_Type;
|
||||||
|
|
||||||
|
static Result_Type cast(const Boxed_Value &ob, const Type_Conversions_State *t_conversions)
|
||||||
{
|
{
|
||||||
if (ob.get_type_info().bare_equal(user_type<Const_Proxy_Function>()))
|
if (ob.get_type_info().bare_equal(user_type<Const_Proxy_Function>()))
|
||||||
{
|
{
|
||||||
@@ -96,7 +101,9 @@ namespace chaiscript
|
|||||||
template<typename Signature>
|
template<typename Signature>
|
||||||
struct Cast_Helper<std::function<Signature> >
|
struct Cast_Helper<std::function<Signature> >
|
||||||
{
|
{
|
||||||
static std::function<Signature> cast(const Boxed_Value &ob, const Type_Conversions_State *t_conversions)
|
typedef std::function<Signature> Result_Type;
|
||||||
|
|
||||||
|
static Result_Type cast(const Boxed_Value &ob, const Type_Conversions_State *t_conversions)
|
||||||
{
|
{
|
||||||
if (ob.get_type_info().bare_equal(user_type<Const_Proxy_Function>()))
|
if (ob.get_type_info().bare_equal(user_type<Const_Proxy_Function>()))
|
||||||
{
|
{
|
||||||
@@ -111,7 +118,9 @@ namespace chaiscript
|
|||||||
template<typename Signature>
|
template<typename Signature>
|
||||||
struct Cast_Helper<const std::function<Signature> >
|
struct Cast_Helper<const std::function<Signature> >
|
||||||
{
|
{
|
||||||
static std::function<Signature> cast(const Boxed_Value &ob, const Type_Conversions_State *t_conversions)
|
typedef std::function<Signature> Result_Type;
|
||||||
|
|
||||||
|
static Result_Type cast(const Boxed_Value &ob, const Type_Conversions_State *t_conversions)
|
||||||
{
|
{
|
||||||
if (ob.get_type_info().bare_equal(user_type<Const_Proxy_Function>()))
|
if (ob.get_type_info().bare_equal(user_type<Const_Proxy_Function>()))
|
||||||
{
|
{
|
||||||
|
@@ -59,8 +59,13 @@ namespace chaiscript
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<typename Ret>
|
template<typename Ret>
|
||||||
struct Handle_Return<std::function<Ret>> : Handle_Return<const std::function<Ret> &>
|
struct Handle_Return<std::function<Ret>>
|
||||||
{
|
{
|
||||||
|
static Boxed_Value handle(const std::function<Ret> &f) {
|
||||||
|
return Boxed_Value(
|
||||||
|
chaiscript::make_shared<dispatch::Proxy_Function_Base, dispatch::Proxy_Function_Callable_Impl<Ret, std::function<Ret>>>(f)
|
||||||
|
);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename Ret>
|
template<typename Ret>
|
||||||
@@ -74,13 +79,23 @@ namespace chaiscript
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<typename Ret>
|
template<typename Ret>
|
||||||
struct Handle_Return<const std::shared_ptr<std::function<Ret>> &> : Handle_Return<const std::shared_ptr<std::function<Ret>>>
|
struct Handle_Return<const std::shared_ptr<std::function<Ret>> &>
|
||||||
{
|
{
|
||||||
|
static Boxed_Value handle(const std::shared_ptr<std::function<Ret>> &f) {
|
||||||
|
return Boxed_Value(
|
||||||
|
chaiscript::make_shared<dispatch::Proxy_Function_Base, dispatch::Assignable_Proxy_Function_Impl<Ret>>(std::ref(*f),f)
|
||||||
|
);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename Ret>
|
template<typename Ret>
|
||||||
struct Handle_Return<std::shared_ptr<std::function<Ret>>> : Handle_Return<const std::shared_ptr<std::function<Ret>>>
|
struct Handle_Return<std::shared_ptr<std::function<Ret>>>
|
||||||
{
|
{
|
||||||
|
static Boxed_Value handle(const std::shared_ptr<std::function<Ret>> &f) {
|
||||||
|
return Boxed_Value(
|
||||||
|
chaiscript::make_shared<dispatch::Proxy_Function_Base, dispatch::Assignable_Proxy_Function_Impl<Ret>>(std::ref(*f),f)
|
||||||
|
);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename Ret>
|
template<typename Ret>
|
||||||
@@ -146,13 +161,21 @@ namespace chaiscript
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<typename Ret>
|
template<typename Ret>
|
||||||
struct Handle_Return<std::shared_ptr<Ret>> : Handle_Return<std::shared_ptr<Ret> &>
|
struct Handle_Return<std::shared_ptr<Ret> >
|
||||||
{
|
{
|
||||||
|
static Boxed_Value handle(const std::shared_ptr<Ret> &r)
|
||||||
|
{
|
||||||
|
return Boxed_Value(r, true);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename Ret>
|
template<typename Ret>
|
||||||
struct Handle_Return<const std::shared_ptr<Ret> &> : Handle_Return<std::shared_ptr<Ret> &>
|
struct Handle_Return<const std::shared_ptr<Ret> &>
|
||||||
{
|
{
|
||||||
|
static Boxed_Value handle(const std::shared_ptr<Ret> &r)
|
||||||
|
{
|
||||||
|
return Boxed_Value(r, true);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename Ret>
|
template<typename Ret>
|
||||||
@@ -164,15 +187,10 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename Ret>
|
|
||||||
struct Handle_Return<const Ret>
|
|
||||||
{
|
|
||||||
static Boxed_Value handle(const Ret &r)
|
|
||||||
{
|
|
||||||
return Boxed_Value(std::cref(r));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used internally for handling a return value from a Proxy_Function call
|
||||||
|
*/
|
||||||
template<typename Ret>
|
template<typename Ret>
|
||||||
struct Handle_Return<Ret &>
|
struct Handle_Return<Ret &>
|
||||||
{
|
{
|
||||||
@@ -180,8 +198,16 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
return Boxed_Value(std::ref(r));
|
return Boxed_Value(std::ref(r));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Boxed_Value handle(const Ret &r)
|
||||||
|
{
|
||||||
|
return Boxed_Value(std::cref(r));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used internally for handling a return value from a Proxy_Function call
|
||||||
|
*/
|
||||||
template<>
|
template<>
|
||||||
struct Handle_Return<Boxed_Value>
|
struct Handle_Return<Boxed_Value>
|
||||||
{
|
{
|
||||||
@@ -191,19 +217,40 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used internally for handling a return value from a Proxy_Function call
|
||||||
|
*/
|
||||||
template<>
|
template<>
|
||||||
struct Handle_Return<const Boxed_Value> : Handle_Return<Boxed_Value>
|
struct Handle_Return<const Boxed_Value>
|
||||||
{
|
{
|
||||||
|
static Boxed_Value handle(const Boxed_Value &r)
|
||||||
|
{
|
||||||
|
return r;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used internally for handling a return value from a Proxy_Function call
|
||||||
|
*/
|
||||||
template<>
|
template<>
|
||||||
struct Handle_Return<Boxed_Value &> : Handle_Return<Boxed_Value>
|
struct Handle_Return<Boxed_Value &>
|
||||||
{
|
{
|
||||||
|
static Boxed_Value handle(const Boxed_Value &r)
|
||||||
|
{
|
||||||
|
return r;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used internally for handling a return value from a Proxy_Function call
|
||||||
|
*/
|
||||||
template<>
|
template<>
|
||||||
struct Handle_Return<const Boxed_Value &> : Handle_Return<Boxed_Value>
|
struct Handle_Return<const Boxed_Value &>
|
||||||
{
|
{
|
||||||
|
static Boxed_Value handle(const Boxed_Value &r)
|
||||||
|
{
|
||||||
|
return r;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -218,9 +265,16 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used internally for handling a return value from a Proxy_Function call
|
||||||
|
*/
|
||||||
template<>
|
template<>
|
||||||
struct Handle_Return<const Boxed_Number> : Handle_Return<Boxed_Number>
|
struct Handle_Return<const Boxed_Number>
|
||||||
{
|
{
|
||||||
|
static Boxed_Value handle(const Boxed_Number &r)
|
||||||
|
{
|
||||||
|
return r.bv;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -232,7 +286,7 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
static Boxed_Value handle()
|
static Boxed_Value handle()
|
||||||
{
|
{
|
||||||
return void_var();
|
return Boxed_Value(Boxed_Value::Void_Type());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@@ -16,202 +16,447 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
namespace operators
|
namespace operators
|
||||||
{
|
{
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
/// \todo make this return a decltype once we drop gcc 4.6
|
||||||
|
template<typename L, typename R>
|
||||||
|
auto assign(L l, R r) -> L&
|
||||||
|
{
|
||||||
|
return (l = r);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename L, typename R>
|
||||||
|
auto assign_bitwise_and(L l, R r) -> decltype((l &= r))
|
||||||
|
{
|
||||||
|
return (l &= r);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename L, typename R>
|
||||||
|
auto assign_xor(L l, R r) -> decltype((l^=r))
|
||||||
|
{
|
||||||
|
return (l ^= r);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename L, typename R>
|
||||||
|
auto assign_bitwise_or(L l, R r) -> decltype((l |= r))
|
||||||
|
{
|
||||||
|
return (l |= r);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename L, typename R>
|
||||||
|
auto assign_difference(L l, R r) -> decltype(( l -= r))
|
||||||
|
{
|
||||||
|
return (l -= r);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename L, typename R>
|
||||||
|
auto assign_left_shift(L l, R r) -> decltype(( l <<= r))
|
||||||
|
{
|
||||||
|
return (l <<= r);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename L, typename R>
|
||||||
|
auto assign_product(L l, R r) -> decltype(( l *= r ))
|
||||||
|
{
|
||||||
|
return (l *= r);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename L, typename R>
|
||||||
|
auto assign_quotient(L l, R r) -> decltype(( l /= r ))
|
||||||
|
{
|
||||||
|
return (l /= r);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename L, typename R>
|
||||||
|
auto assign_remainder(L l, R r) -> decltype(( l %= r ))
|
||||||
|
{
|
||||||
|
return (l %= r);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename L, typename R>
|
||||||
|
auto assign_right_shift(L l, R r) -> decltype(( l >>= r))
|
||||||
|
{
|
||||||
|
return (l >>= r);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// \todo make this return a decltype once we drop gcc 4.6
|
||||||
|
template<typename L, typename R>
|
||||||
|
auto assign_sum(L l, R r) -> L&
|
||||||
|
{
|
||||||
|
return (l += r);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename L>
|
||||||
|
auto prefix_decrement(L l) -> decltype(( --l ))
|
||||||
|
{
|
||||||
|
return (--l);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename L>
|
||||||
|
auto prefix_increment(L l) -> decltype(( ++l ))
|
||||||
|
{
|
||||||
|
return (++l);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename L, typename R>
|
||||||
|
auto equal(L l, R r) -> decltype(( l == r ))
|
||||||
|
{
|
||||||
|
return (l == r);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename L, typename R>
|
||||||
|
auto greater_than(L l, R r) -> decltype(( l > r ))
|
||||||
|
{
|
||||||
|
return (l > r);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename L, typename R>
|
||||||
|
auto greater_than_equal(L l, R r) -> decltype(( l >= r ))
|
||||||
|
{
|
||||||
|
return (l >= r);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename L, typename R>
|
||||||
|
auto less_than(L l, R r) -> decltype(( l < r ))
|
||||||
|
{
|
||||||
|
return (l < r);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename L, typename R>
|
||||||
|
auto less_than_equal(L l, R r) -> decltype(( l <= r ))
|
||||||
|
{
|
||||||
|
return (l <= r);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename L>
|
||||||
|
auto logical_compliment(L l) -> decltype(( !l ))
|
||||||
|
{
|
||||||
|
return (!l);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename L, typename R>
|
||||||
|
auto not_equal(L l, R r) -> decltype(( l != r ))
|
||||||
|
{
|
||||||
|
return (l != r);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename L, typename R>
|
||||||
|
auto addition(L l, R r) -> decltype(( l + r ))
|
||||||
|
{
|
||||||
|
return (l + r);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename L>
|
||||||
|
auto unary_plus(L l) -> decltype(( +l ))
|
||||||
|
{
|
||||||
|
return (+l);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename L, typename R>
|
||||||
|
auto subtraction(L l, R r) -> decltype(( l - r ))
|
||||||
|
{
|
||||||
|
return (l - r);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename L>
|
||||||
|
auto unary_minus(L l) -> decltype(( -l ))
|
||||||
|
{
|
||||||
|
#ifdef CHAISCRIPT_MSVC
|
||||||
|
#pragma warning(push)
|
||||||
|
#pragma warning(disable : 4146)
|
||||||
|
return (-l);
|
||||||
|
#pragma warning(pop)
|
||||||
|
#else
|
||||||
|
return (-l);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename L, typename R>
|
||||||
|
auto bitwise_and(L l, R r) -> decltype(( l & r ))
|
||||||
|
{
|
||||||
|
return (l & r);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename L>
|
||||||
|
auto bitwise_compliment(L l) -> decltype(( ~l ))
|
||||||
|
{
|
||||||
|
return (~l);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename L, typename R>
|
||||||
|
auto bitwise_xor(L l, R r) -> decltype(( l ^ r ))
|
||||||
|
{
|
||||||
|
return (l ^ r);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename L, typename R>
|
||||||
|
auto bitwise_or(L l, R r) -> decltype(( l | r ))
|
||||||
|
{
|
||||||
|
return (l | r);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename L, typename R>
|
||||||
|
auto division(L l, R r) -> decltype(( l / r ))
|
||||||
|
{
|
||||||
|
return (l / r);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename L, typename R>
|
||||||
|
auto left_shift(L l, R r) -> decltype(( l << r ))
|
||||||
|
{
|
||||||
|
return l << r;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename L, typename R>
|
||||||
|
auto multiplication(L l, R r) -> decltype(( l * r ))
|
||||||
|
{
|
||||||
|
return l * r;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename L, typename R>
|
||||||
|
auto remainder(L l, R r) -> decltype(( l % r ))
|
||||||
|
{
|
||||||
|
return (l % r);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename L, typename R>
|
||||||
|
auto right_shift(L l, R r) -> decltype(( l >> r ))
|
||||||
|
{
|
||||||
|
return (l >> r);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void assign(Module& m)
|
ModulePtr assign(ModulePtr m = std::make_shared<Module>())
|
||||||
{
|
{
|
||||||
m.add(chaiscript::fun([](T &lhs, const T&rhs)->T&{return lhs = rhs;}), "=");
|
m->add(chaiscript::fun(&detail::assign<T &, const T&>), "=");
|
||||||
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void assign_bitwise_and(Module& m)
|
ModulePtr assign_bitwise_and(ModulePtr m = std::make_shared<Module>())
|
||||||
{
|
{
|
||||||
m.add(chaiscript::fun([](T &lhs, const T&rhs)->T&{return lhs &= rhs;}), "&=");
|
m->add(chaiscript::fun(&detail::assign_bitwise_and<T &, const T&>), "&=");
|
||||||
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void assign_xor(Module& m)
|
ModulePtr assign_xor(ModulePtr m = std::make_shared<Module>())
|
||||||
{
|
{
|
||||||
m.add(chaiscript::fun([](T &lhs, const T&rhs)->T&{return lhs ^= rhs;}), "^=");
|
m->add(chaiscript::fun(&detail::assign_xor<T &, const T&>), "^=");
|
||||||
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void assign_bitwise_or(Module& m)
|
ModulePtr assign_bitwise_or(ModulePtr m = std::make_shared<Module>())
|
||||||
{
|
{
|
||||||
m.add(chaiscript::fun([](T &lhs, const T&rhs)->T&{return lhs |= rhs;}), "|=");
|
m->add(chaiscript::fun(&detail::assign_bitwise_or<T &, const T&>), "|=");
|
||||||
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void assign_difference(Module& m)
|
ModulePtr assign_difference(ModulePtr m = std::make_shared<Module>())
|
||||||
{
|
{
|
||||||
m.add(chaiscript::fun([](T &lhs, const T&rhs)->T&{return lhs -= rhs;}), "-=");
|
m->add(chaiscript::fun(&detail::assign_difference<T &, const T&>), "-=");
|
||||||
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void assign_left_shift(Module& m)
|
ModulePtr assign_left_shift(ModulePtr m = std::make_shared<Module>())
|
||||||
{
|
{
|
||||||
m.add(chaiscript::fun([](T &lhs, const T&rhs)->T&{return lhs <<= rhs;}), "<<=");
|
m->add(chaiscript::fun(&detail::assign_left_shift<T &, const T&>), "<<=");
|
||||||
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void assign_product(Module& m)
|
ModulePtr assign_product(ModulePtr m = std::make_shared<Module>())
|
||||||
{
|
{
|
||||||
m.add(chaiscript::fun([](T &lhs, const T&rhs)->T&{return lhs <<= rhs;}), "*=");
|
m->add(chaiscript::fun(&detail::assign_product<T &, const T&>), "*=");
|
||||||
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void assign_quotient(Module& m)
|
ModulePtr assign_quotient(ModulePtr m = std::make_shared<Module>())
|
||||||
{
|
{
|
||||||
m.add(chaiscript::fun([](T &lhs, const T&rhs)->T&{return lhs /= rhs;}), "/=");
|
m->add(chaiscript::fun(&detail::assign_quotient<T &, const T&>), "/=");
|
||||||
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void assign_remainder(Module& m)
|
ModulePtr assign_remainder(ModulePtr m = std::make_shared<Module>())
|
||||||
{
|
{
|
||||||
m.add(chaiscript::fun([](T &lhs, const T&rhs)->T&{return lhs %= rhs;}), "%=");
|
m->add(chaiscript::fun(&detail::assign_remainder<T &, const T&>), "%=");
|
||||||
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void assign_right_shift(Module& m)
|
ModulePtr assign_right_shift(ModulePtr m = std::make_shared<Module>())
|
||||||
{
|
{
|
||||||
m.add(chaiscript::fun([](T &lhs, const T&rhs)->T&{return lhs >>= rhs;}), ">>=");
|
m->add(chaiscript::fun(&detail::assign_right_shift<T &, const T&>), ">>=");
|
||||||
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void assign_sum(Module& m)
|
ModulePtr assign_sum(ModulePtr m = std::make_shared<Module>())
|
||||||
{
|
{
|
||||||
m.add(chaiscript::fun([](T &lhs, const T&rhs)->T&{return lhs += rhs;}), "+=");
|
m->add(chaiscript::fun(&detail::assign_sum<T &, const T&>), "+=");
|
||||||
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void prefix_decrement(Module& m)
|
ModulePtr prefix_decrement(ModulePtr m = std::make_shared<Module>())
|
||||||
{
|
{
|
||||||
m.add(chaiscript::fun([](T &lhs)->T&{return --lhs;}), "--");
|
m->add(chaiscript::fun(&detail::prefix_decrement<T &>), "--");
|
||||||
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void prefix_increment(Module& m)
|
ModulePtr prefix_increment(ModulePtr m = std::make_shared<Module>())
|
||||||
{
|
{
|
||||||
m.add(chaiscript::fun([](T &lhs)->T&{return ++lhs;}), "++");
|
m->add(chaiscript::fun(&detail::prefix_increment<T &>), "++");
|
||||||
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void equal(Module& m)
|
ModulePtr equal(ModulePtr m = std::make_shared<Module>())
|
||||||
{
|
{
|
||||||
m.add(chaiscript::fun([](const T &lhs, const T &rhs){return lhs==rhs;}), "==");
|
m->add(chaiscript::fun(&detail::equal<const T&, const T&>), "==");
|
||||||
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void greater_than(Module& m)
|
ModulePtr greater_than(ModulePtr m = std::make_shared<Module>())
|
||||||
{
|
{
|
||||||
m.add(chaiscript::fun([](const T &lhs, const T &rhs){return lhs>rhs;}), ">");
|
m->add(chaiscript::fun(&detail::greater_than<const T&, const T&>), ">");
|
||||||
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void greater_than_equal(Module& m)
|
ModulePtr greater_than_equal(ModulePtr m = std::make_shared<Module>())
|
||||||
{
|
{
|
||||||
m.add(chaiscript::fun([](const T &lhs, const T &rhs){return lhs>=rhs;}), ">=");
|
m->add(chaiscript::fun(&detail::greater_than_equal<const T&, const T&>), ">=");
|
||||||
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void less_than(Module& m)
|
ModulePtr less_than(ModulePtr m = std::make_shared<Module>())
|
||||||
{
|
{
|
||||||
m.add(chaiscript::fun([](const T &lhs, const T &rhs){return lhs<rhs;}), "<");
|
m->add(chaiscript::fun(&detail::less_than<const T&, const T&>), "<");
|
||||||
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void less_than_equal(Module& m)
|
ModulePtr less_than_equal(ModulePtr m = std::make_shared<Module>())
|
||||||
{
|
{
|
||||||
m.add(chaiscript::fun([](const T &lhs, const T &rhs){return lhs<=rhs;}), "<=");
|
m->add(chaiscript::fun(&detail::less_than_equal<const T&, const T&>), "<=");
|
||||||
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void logical_compliment(Module& m)
|
ModulePtr logical_compliment(ModulePtr m = std::make_shared<Module>())
|
||||||
{
|
{
|
||||||
m.add(chaiscript::fun([](const T &lhs){return !lhs;}), "!");
|
m->add(chaiscript::fun(&detail::logical_compliment<const T &>), "!");
|
||||||
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void not_equal(Module& m)
|
ModulePtr not_equal(ModulePtr m = std::make_shared<Module>())
|
||||||
{
|
{
|
||||||
m.add(chaiscript::fun([](const T &lhs, const T &rhs){return lhs!=rhs;}), "!=");
|
m->add(chaiscript::fun(&detail::not_equal<const T &, const T &>), "!=");
|
||||||
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void addition(Module& m)
|
ModulePtr addition(ModulePtr m = std::make_shared<Module>())
|
||||||
{
|
{
|
||||||
m.add(chaiscript::fun([](const T &lhs, const T &rhs){return lhs+rhs;}), "+");
|
m->add(chaiscript::fun(&detail::addition<const T &, const T &>), "+");
|
||||||
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void unary_plus(Module& m)
|
ModulePtr unary_plus(ModulePtr m = std::make_shared<Module>())
|
||||||
{
|
{
|
||||||
m.add(chaiscript::fun([](const T &lhs){return +lhs;}), "+");
|
m->add(chaiscript::fun(&detail::unary_plus<const T &>), "+");
|
||||||
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void subtraction(Module& m)
|
ModulePtr subtraction(ModulePtr m = std::make_shared<Module>())
|
||||||
{
|
{
|
||||||
m.add(chaiscript::fun([](const T &lhs, const T &rhs){return lhs-rhs;}), "-");
|
m->add(chaiscript::fun(&detail::subtraction<const T &, const T &>), "-");
|
||||||
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void unary_minus(Module& m)
|
ModulePtr unary_minus(ModulePtr m = std::make_shared<Module>())
|
||||||
{
|
{
|
||||||
m.add(chaiscript::fun([](const T &lhs){return -lhs;}), "-");
|
m->add(chaiscript::fun(&detail::unary_minus<const T &>), "-");
|
||||||
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void bitwise_and(Module& m)
|
ModulePtr bitwise_and(ModulePtr m = std::make_shared<Module>())
|
||||||
{
|
{
|
||||||
m.add(chaiscript::fun([](const T &lhs, const T &rhs){return lhs&rhs;}), "&");
|
m->add(chaiscript::fun(&detail::bitwise_and<const T &, const T &>), "&");
|
||||||
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void bitwise_compliment(Module& m)
|
ModulePtr bitwise_compliment(ModulePtr m = std::make_shared<Module>())
|
||||||
{
|
{
|
||||||
m.add(chaiscript::fun([](const T &lhs){return ~lhs;}), "~");
|
m->add(chaiscript::fun(&detail::bitwise_compliment<const T &>), "~");
|
||||||
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void bitwise_xor(Module& m)
|
ModulePtr bitwise_xor(ModulePtr m = std::make_shared<Module>())
|
||||||
{
|
{
|
||||||
m.add(chaiscript::fun([](const T &lhs, const T &rhs){return lhs^rhs;}), "^");
|
m->add(chaiscript::fun(&detail::bitwise_xor<const T &, const T &>), "^");
|
||||||
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void bitwise_or(Module& m)
|
ModulePtr bitwise_or(ModulePtr m = std::make_shared<Module>())
|
||||||
{
|
{
|
||||||
m.add(chaiscript::fun([](const T &lhs, const T &rhs){return lhs|rhs;}), "|");
|
m->add(chaiscript::fun(&detail::bitwise_or<const T &, const T &>), "|");
|
||||||
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void division(Module& m)
|
ModulePtr division(ModulePtr m = std::make_shared<Module>())
|
||||||
{
|
{
|
||||||
m.add(chaiscript::fun([](const T &lhs, const T &rhs){return lhs/rhs;}), "/");
|
m->add(chaiscript::fun(&detail::division<const T &, const T &>), "/");
|
||||||
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void left_shift(Module& m)
|
ModulePtr left_shift(ModulePtr m = std::make_shared<Module>())
|
||||||
{
|
{
|
||||||
m.add(chaiscript::fun([](const T &lhs, const T &rhs){return lhs<<rhs;}), "<<");
|
m->add(chaiscript::fun(&detail::left_shift<const T &, const T &>), "<<");
|
||||||
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void multiplication(Module& m)
|
ModulePtr multiplication(ModulePtr m = std::make_shared<Module>())
|
||||||
{
|
{
|
||||||
m.add(chaiscript::fun([](const T &lhs, const T &rhs){return lhs*rhs;}), "*");
|
m->add(chaiscript::fun(&detail::multiplication<const T &, const T &>), "*");
|
||||||
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void remainder(Module& m)
|
ModulePtr remainder(ModulePtr m = std::make_shared<Module>())
|
||||||
{
|
{
|
||||||
m.add(chaiscript::fun([](const T &lhs, const T &rhs){return lhs%rhs;}), "%");
|
m->add(chaiscript::fun(&detail::remainder<const T &, const T &>), "%");
|
||||||
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void right_shift(Module& m)
|
ModulePtr right_shift(ModulePtr m = std::make_shared<Module>())
|
||||||
{
|
{
|
||||||
m.add(chaiscript::fun([](const T &lhs, const T &rhs){return lhs>>rhs;}), ">>");
|
m->add(chaiscript::fun(&detail::right_shift<const T &, const T &>), ">>");
|
||||||
|
return m;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -145,7 +145,7 @@ namespace chaiscript
|
|||||||
class Proxy_Function_Base
|
class Proxy_Function_Base
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~Proxy_Function_Base() = default;
|
virtual ~Proxy_Function_Base() {}
|
||||||
|
|
||||||
Boxed_Value operator()(const std::vector<Boxed_Value> ¶ms, const chaiscript::Type_Conversions_State &t_conversions) const
|
Boxed_Value operator()(const std::vector<Boxed_Value> ¶ms, const chaiscript::Type_Conversions_State &t_conversions) const
|
||||||
{
|
{
|
||||||
@@ -181,15 +181,20 @@ namespace chaiscript
|
|||||||
//! to the passed in values
|
//! to the passed in values
|
||||||
bool filter(const std::vector<Boxed_Value> &vals, const Type_Conversions_State &t_conversions) const
|
bool filter(const std::vector<Boxed_Value> &vals, const Type_Conversions_State &t_conversions) const
|
||||||
{
|
{
|
||||||
assert(m_arity == -1 || (m_arity > 0 && static_cast<int>(vals.size()) == m_arity));
|
|
||||||
|
|
||||||
if (m_arity < 0)
|
if (m_arity < 0)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
} else if (m_arity > 1) {
|
} else if (static_cast<size_t>(m_arity) == vals.size()) {
|
||||||
return compare_type_to_param(m_types[1], vals[0], t_conversions) && compare_type_to_param(m_types[2], vals[1], t_conversions);
|
if (m_arity == 0)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
} else if (m_arity > 1) {
|
||||||
|
return compare_type_to_param(m_types[1], vals[0], t_conversions) && compare_type_to_param(m_types[2], vals[1], t_conversions);
|
||||||
|
} else {
|
||||||
|
return compare_type_to_param(m_types[1], vals[0], t_conversions);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return compare_type_to_param(m_types[1], vals[0], t_conversions);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,6 +204,8 @@ namespace chaiscript
|
|||||||
return m_arity;
|
return m_arity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual std::string annotation() const = 0;
|
||||||
|
|
||||||
static bool compare_type_to_param(const Type_Info &ti, const Boxed_Value &bv, const Type_Conversions_State &t_conversions)
|
static bool compare_type_to_param(const Type_Info &ti, const Boxed_Value &bv, const Type_Conversions_State &t_conversions)
|
||||||
{
|
{
|
||||||
if (ti.is_undef()
|
if (ti.is_undef()
|
||||||
@@ -241,8 +248,7 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool compare_types(const std::vector<Type_Info> &tis, const std::vector<Boxed_Value> &bvs,
|
static bool compare_types(const std::vector<Type_Info> &tis, const std::vector<Boxed_Value> &bvs, const Type_Conversions_State &t_conversions)
|
||||||
const Type_Conversions_State &t_conversions)
|
|
||||||
{
|
{
|
||||||
if (tis.size() - 1 != bvs.size())
|
if (tis.size() - 1 != bvs.size())
|
||||||
{
|
{
|
||||||
@@ -276,13 +282,14 @@ namespace chaiscript
|
|||||||
class guard_error : public std::runtime_error
|
class guard_error : public std::runtime_error
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
guard_error() noexcept
|
guard_error() CHAISCRIPT_NOEXCEPT
|
||||||
: std::runtime_error("Guard evaluation failed")
|
: std::runtime_error("Guard evaluation failed")
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
guard_error(const guard_error &) = default;
|
guard_error(const guard_error &) = default;
|
||||||
|
|
||||||
virtual ~guard_error() noexcept = default;
|
virtual ~guard_error() CHAISCRIPT_NOEXCEPT
|
||||||
|
{ }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -299,15 +306,17 @@ namespace chaiscript
|
|||||||
int t_arity=-1,
|
int t_arity=-1,
|
||||||
AST_NodePtr t_parsenode = AST_NodePtr(),
|
AST_NodePtr t_parsenode = AST_NodePtr(),
|
||||||
Param_Types t_param_types = Param_Types(),
|
Param_Types t_param_types = Param_Types(),
|
||||||
|
std::string t_description = "",
|
||||||
Proxy_Function t_guard = Proxy_Function())
|
Proxy_Function t_guard = Proxy_Function())
|
||||||
: Proxy_Function_Base(build_param_type_list(t_param_types), t_arity),
|
: Proxy_Function_Base(build_param_type_list(t_param_types), t_arity),
|
||||||
m_param_types(std::move(t_param_types)),
|
m_param_types(std::move(t_param_types)),
|
||||||
m_guard(std::move(t_guard)), m_parsenode(std::move(t_parsenode))
|
m_guard(std::move(t_guard)), m_parsenode(std::move(t_parsenode)), m_description(std::move(t_description))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual ~Dynamic_Proxy_Function() {}
|
||||||
|
|
||||||
virtual bool operator==(const Proxy_Function_Base &rhs) const override
|
virtual bool operator==(const Proxy_Function_Base &rhs) const CHAISCRIPT_OVERRIDE
|
||||||
{
|
{
|
||||||
const Dynamic_Proxy_Function *prhs = dynamic_cast<const Dynamic_Proxy_Function *>(&rhs);
|
const Dynamic_Proxy_Function *prhs = dynamic_cast<const Dynamic_Proxy_Function *>(&rhs);
|
||||||
|
|
||||||
@@ -318,7 +327,7 @@ namespace chaiscript
|
|||||||
&& this->m_param_types == prhs->m_param_types);
|
&& this->m_param_types == prhs->m_param_types);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool call_match(const std::vector<Boxed_Value> &vals, const Type_Conversions_State &t_conversions) const override
|
virtual bool call_match(const std::vector<Boxed_Value> &vals, const Type_Conversions_State &t_conversions) const CHAISCRIPT_OVERRIDE
|
||||||
{
|
{
|
||||||
return (m_arity < 0 || (vals.size() == size_t(m_arity) && m_param_types.match(vals, t_conversions)))
|
return (m_arity < 0 || (vals.size() == size_t(m_arity) && m_param_types.match(vals, t_conversions)))
|
||||||
&& test_guard(vals, t_conversions);
|
&& test_guard(vals, t_conversions);
|
||||||
@@ -335,6 +344,11 @@ namespace chaiscript
|
|||||||
return m_parsenode;
|
return m_parsenode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual std::string annotation() const CHAISCRIPT_OVERRIDE
|
||||||
|
{
|
||||||
|
return m_description;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool test_guard(const std::vector<Boxed_Value> ¶ms, const Type_Conversions_State &t_conversions) const
|
bool test_guard(const std::vector<Boxed_Value> ¶ms, const Type_Conversions_State &t_conversions) const
|
||||||
@@ -374,12 +388,13 @@ namespace chaiscript
|
|||||||
Param_Types m_param_types;
|
Param_Types m_param_types;
|
||||||
Proxy_Function m_guard;
|
Proxy_Function m_guard;
|
||||||
AST_NodePtr m_parsenode;
|
AST_NodePtr m_parsenode;
|
||||||
|
std::string m_description;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template<typename Callable>
|
template<typename Callable>
|
||||||
class Dynamic_Proxy_Function_Impl final : public Dynamic_Proxy_Function
|
class Dynamic_Proxy_Function_Impl : public Dynamic_Proxy_Function
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Dynamic_Proxy_Function_Impl(
|
Dynamic_Proxy_Function_Impl(
|
||||||
@@ -387,20 +402,24 @@ namespace chaiscript
|
|||||||
int t_arity=-1,
|
int t_arity=-1,
|
||||||
AST_NodePtr t_parsenode = AST_NodePtr(),
|
AST_NodePtr t_parsenode = AST_NodePtr(),
|
||||||
Param_Types t_param_types = Param_Types(),
|
Param_Types t_param_types = Param_Types(),
|
||||||
|
std::string t_description = "",
|
||||||
Proxy_Function t_guard = Proxy_Function())
|
Proxy_Function t_guard = Proxy_Function())
|
||||||
: Dynamic_Proxy_Function(
|
: Dynamic_Proxy_Function(
|
||||||
t_arity,
|
t_arity,
|
||||||
std::move(t_parsenode),
|
std::move(t_parsenode),
|
||||||
std::move(t_param_types),
|
std::move(t_param_types),
|
||||||
|
std::move(t_description),
|
||||||
std::move(t_guard)
|
std::move(t_guard)
|
||||||
),
|
),
|
||||||
m_f(std::move(t_f))
|
m_f(std::move(t_f))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual ~Dynamic_Proxy_Function_Impl() {}
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Boxed_Value do_call(const std::vector<Boxed_Value> ¶ms, const Type_Conversions_State &t_conversions) const override
|
virtual Boxed_Value do_call(const std::vector<Boxed_Value> ¶ms, const Type_Conversions_State &t_conversions) const CHAISCRIPT_OVERRIDE
|
||||||
{
|
{
|
||||||
if (call_match(params, t_conversions) && test_guard(params, t_conversions))
|
if (call_match(params, t_conversions) && test_guard(params, t_conversions))
|
||||||
{
|
{
|
||||||
@@ -411,6 +430,7 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
Callable m_f;
|
Callable m_f;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -431,7 +451,7 @@ namespace chaiscript
|
|||||||
/// and substitutes bound parameters into the parameter list
|
/// and substitutes bound parameters into the parameter list
|
||||||
/// at runtime, when call() is executed.
|
/// at runtime, when call() is executed.
|
||||||
/// it is used for bind(function, param1, _, param2) style calls
|
/// it is used for bind(function, param1, _, param2) style calls
|
||||||
class Bound_Function final : public Proxy_Function_Base
|
class Bound_Function : public Proxy_Function_Base
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Bound_Function(const Const_Proxy_Function &t_f,
|
Bound_Function(const Const_Proxy_Function &t_f,
|
||||||
@@ -442,18 +462,19 @@ namespace chaiscript
|
|||||||
assert(m_f->get_arity() < 0 || m_f->get_arity() == static_cast<int>(m_args.size()));
|
assert(m_f->get_arity() < 0 || m_f->get_arity() == static_cast<int>(m_args.size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator==(const Proxy_Function_Base &t_f) const override
|
virtual bool operator==(const Proxy_Function_Base &t_f) const CHAISCRIPT_OVERRIDE
|
||||||
{
|
{
|
||||||
return &t_f == this;
|
return &t_f == this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual ~Bound_Function() {}
|
||||||
|
|
||||||
bool call_match(const std::vector<Boxed_Value> &vals, const Type_Conversions_State &t_conversions) const override
|
virtual bool call_match(const std::vector<Boxed_Value> &vals, const Type_Conversions_State &t_conversions) const CHAISCRIPT_OVERRIDE
|
||||||
{
|
{
|
||||||
return m_f->call_match(build_param_list(vals), t_conversions);
|
return m_f->call_match(build_param_list(vals), t_conversions);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Const_Proxy_Function> get_contained_functions() const override
|
virtual std::vector<Const_Proxy_Function> get_contained_functions() const CHAISCRIPT_OVERRIDE
|
||||||
{
|
{
|
||||||
return std::vector<Const_Proxy_Function>{m_f};
|
return std::vector<Const_Proxy_Function>{m_f};
|
||||||
}
|
}
|
||||||
@@ -490,6 +511,10 @@ namespace chaiscript
|
|||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual std::string annotation() const CHAISCRIPT_OVERRIDE
|
||||||
|
{
|
||||||
|
return "Bound: " + m_f->annotation();
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static std::vector<Type_Info> build_param_type_info(const Const_Proxy_Function &t_f,
|
static std::vector<Type_Info> build_param_type_info(const Const_Proxy_Function &t_f,
|
||||||
@@ -499,11 +524,18 @@ namespace chaiscript
|
|||||||
|
|
||||||
if (t_f->get_arity() < 0) { return std::vector<Type_Info>(); }
|
if (t_f->get_arity() < 0) { return std::vector<Type_Info>(); }
|
||||||
|
|
||||||
const auto types = t_f->get_param_types();
|
std::vector<Type_Info> types = t_f->get_param_types();
|
||||||
assert(types.size() == t_args.size() + 1);
|
assert(types.size() == t_args.size() + 1);
|
||||||
|
|
||||||
|
#ifdef CHAISCRIPT_MSVC_12
|
||||||
|
#pragma warning(push)
|
||||||
|
#pragma warning(disable : 6011)
|
||||||
|
#endif
|
||||||
// this analysis warning is invalid in MSVC12 and doesn't exist in MSVC14
|
// this analysis warning is invalid in MSVC12 and doesn't exist in MSVC14
|
||||||
std::vector<Type_Info> retval{types[0]};
|
std::vector<Type_Info> retval{types[0]};
|
||||||
|
#ifdef CHAISCRIPT_MSVC_12
|
||||||
|
#pragma warning(pop)
|
||||||
|
#endif
|
||||||
|
|
||||||
for (size_t i = 0; i < types.size() - 1; ++i)
|
for (size_t i = 0; i < types.size() - 1; ++i)
|
||||||
{
|
{
|
||||||
@@ -516,7 +548,7 @@ namespace chaiscript
|
|||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual Boxed_Value do_call(const std::vector<Boxed_Value> ¶ms, const Type_Conversions_State &t_conversions) const override
|
virtual Boxed_Value do_call(const std::vector<Boxed_Value> ¶ms, const Type_Conversions_State &t_conversions) const CHAISCRIPT_OVERRIDE
|
||||||
{
|
{
|
||||||
return (*m_f)(build_param_list(params), t_conversions);
|
return (*m_f)(build_param_list(params), t_conversions);
|
||||||
}
|
}
|
||||||
@@ -534,10 +566,16 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool call_match(const std::vector<Boxed_Value> &vals, const Type_Conversions_State &t_conversions) const override
|
virtual ~Proxy_Function_Impl_Base() {}
|
||||||
|
|
||||||
|
virtual std::string annotation() const CHAISCRIPT_OVERRIDE
|
||||||
{
|
{
|
||||||
return static_cast<int>(vals.size()) == get_arity()
|
return "";
|
||||||
&& (compare_types(m_types, vals, t_conversions) && compare_types_with_cast(vals, t_conversions));
|
}
|
||||||
|
|
||||||
|
virtual bool call_match(const std::vector<Boxed_Value> &vals, const Type_Conversions_State &t_conversions) const CHAISCRIPT_OVERRIDE
|
||||||
|
{
|
||||||
|
return static_cast<int>(vals.size()) == get_arity() && (compare_types(m_types, vals, t_conversions) && compare_types_with_cast(vals, t_conversions));
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool compare_types_with_cast(const std::vector<Boxed_Value> &vals, const Type_Conversions_State &t_conversions) const = 0;
|
virtual bool compare_types_with_cast(const std::vector<Boxed_Value> &vals, const Type_Conversions_State &t_conversions) const = 0;
|
||||||
@@ -547,7 +585,7 @@ namespace chaiscript
|
|||||||
|
|
||||||
/// For any callable object
|
/// For any callable object
|
||||||
template<typename Func, typename Callable>
|
template<typename Func, typename Callable>
|
||||||
class Proxy_Function_Callable_Impl final : public Proxy_Function_Impl_Base
|
class Proxy_Function_Callable_Impl : public Proxy_Function_Impl_Base
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Proxy_Function_Callable_Impl(Callable f)
|
Proxy_Function_Callable_Impl(Callable f)
|
||||||
@@ -556,21 +594,24 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool compare_types_with_cast(const std::vector<Boxed_Value> &vals, const Type_Conversions_State &t_conversions) const override
|
virtual ~Proxy_Function_Callable_Impl() {}
|
||||||
|
|
||||||
|
virtual bool compare_types_with_cast(const std::vector<Boxed_Value> &vals, const Type_Conversions_State &t_conversions) const CHAISCRIPT_OVERRIDE
|
||||||
{
|
{
|
||||||
return detail::compare_types_cast(static_cast<Func *>(nullptr), vals, t_conversions);
|
return detail::compare_types_cast(static_cast<Func *>(nullptr), vals, t_conversions);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator==(const Proxy_Function_Base &t_func) const override
|
virtual bool operator==(const Proxy_Function_Base &t_func) const CHAISCRIPT_OVERRIDE
|
||||||
{
|
{
|
||||||
return dynamic_cast<const Proxy_Function_Callable_Impl<Func, Callable> *>(&t_func) != nullptr;
|
return dynamic_cast<const Proxy_Function_Callable_Impl<Func, Callable> *>(&t_func) != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Boxed_Value do_call(const std::vector<Boxed_Value> ¶ms, const Type_Conversions_State &t_conversions) const override
|
virtual Boxed_Value do_call(const std::vector<Boxed_Value> ¶ms, const Type_Conversions_State &t_conversions) const CHAISCRIPT_OVERRIDE
|
||||||
{
|
{
|
||||||
return detail::call_func(detail::Function_Signature<Func>(), m_f, params, t_conversions);
|
typedef typename detail::Function_Signature<Func>::Return_Type Return_Type;
|
||||||
|
return detail::Do_Call<Return_Type>::template go<Func>(m_f, params, t_conversions);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -586,11 +627,16 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void assign(const std::shared_ptr<const Proxy_Function_Base> &t_rhs) = 0;
|
virtual ~Assignable_Proxy_Function() {}
|
||||||
|
|
||||||
|
|
||||||
|
virtual void assign(const std::shared_ptr<const Proxy_Function_Base> &t_rhs) = 0;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename Func>
|
template<typename Func>
|
||||||
class Assignable_Proxy_Function_Impl final : public Assignable_Proxy_Function
|
class Assignable_Proxy_Function_Impl : public Assignable_Proxy_Function
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Assignable_Proxy_Function_Impl(std::reference_wrapper<std::function<Func>> t_f, std::shared_ptr<std::function<Func>> t_ptr)
|
Assignable_Proxy_Function_Impl(std::reference_wrapper<std::function<Func>> t_f, std::shared_ptr<std::function<Func>> t_ptr)
|
||||||
@@ -600,12 +646,14 @@ namespace chaiscript
|
|||||||
assert(!m_shared_ptr_holder || m_shared_ptr_holder.get() == &m_f.get());
|
assert(!m_shared_ptr_holder || m_shared_ptr_holder.get() == &m_f.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool compare_types_with_cast(const std::vector<Boxed_Value> &vals, const Type_Conversions_State &t_conversions) const override
|
virtual ~Assignable_Proxy_Function_Impl() {}
|
||||||
|
|
||||||
|
virtual bool compare_types_with_cast(const std::vector<Boxed_Value> &vals, const Type_Conversions_State &t_conversions) const CHAISCRIPT_OVERRIDE
|
||||||
{
|
{
|
||||||
return detail::compare_types_cast(static_cast<Func *>(nullptr), vals, t_conversions);
|
return detail::compare_types_cast(static_cast<Func *>(nullptr), vals, t_conversions);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator==(const Proxy_Function_Base &t_func) const override
|
virtual bool operator==(const Proxy_Function_Base &t_func) const CHAISCRIPT_OVERRIDE
|
||||||
{
|
{
|
||||||
return dynamic_cast<const Assignable_Proxy_Function_Impl<Func> *>(&t_func) != nullptr;
|
return dynamic_cast<const Assignable_Proxy_Function_Impl<Func> *>(&t_func) != nullptr;
|
||||||
}
|
}
|
||||||
@@ -615,14 +663,14 @@ namespace chaiscript
|
|||||||
return m_f.get();
|
return m_f.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
void assign(const std::shared_ptr<const Proxy_Function_Base> &t_rhs) override {
|
virtual void assign(const std::shared_ptr<const Proxy_Function_Base> &t_rhs) CHAISCRIPT_OVERRIDE {
|
||||||
m_f.get() = dispatch::functor<Func>(t_rhs, nullptr);
|
m_f.get() = dispatch::functor<Func>(t_rhs, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Boxed_Value do_call(const std::vector<Boxed_Value> ¶ms, const Type_Conversions_State &t_conversions) const override
|
virtual Boxed_Value do_call(const std::vector<Boxed_Value> ¶ms, const Type_Conversions_State &t_conversions) const CHAISCRIPT_OVERRIDE
|
||||||
{
|
{
|
||||||
return detail::call_func(detail::Function_Signature<Func>(), m_f.get(), params, t_conversions);
|
return detail::Do_Call<typename std::function<Func>::result_type>::template go<Func>(m_f.get(), params, t_conversions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -630,11 +678,9 @@ namespace chaiscript
|
|||||||
std::reference_wrapper<std::function<Func>> m_f;
|
std::reference_wrapper<std::function<Func>> m_f;
|
||||||
std::shared_ptr<std::function<Func>> m_shared_ptr_holder;
|
std::shared_ptr<std::function<Func>> m_shared_ptr_holder;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/// Attribute getter Proxy_Function implementation
|
/// Attribute getter Proxy_Function implementation
|
||||||
template<typename T, typename Class>
|
template<typename T, typename Class>
|
||||||
class Attribute_Access final : public Proxy_Function_Base
|
class Attribute_Access : public Proxy_Function_Base
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Attribute_Access(T Class::* t_attr)
|
Attribute_Access(T Class::* t_attr)
|
||||||
@@ -643,9 +689,11 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_attribute_function() const override { return true; }
|
virtual ~Attribute_Access() {}
|
||||||
|
|
||||||
bool operator==(const Proxy_Function_Base &t_func) const override
|
virtual bool is_attribute_function() const CHAISCRIPT_OVERRIDE { return true; }
|
||||||
|
|
||||||
|
virtual bool operator==(const Proxy_Function_Base &t_func) const CHAISCRIPT_OVERRIDE
|
||||||
{
|
{
|
||||||
const Attribute_Access<T, Class> * aa
|
const Attribute_Access<T, Class> * aa
|
||||||
= dynamic_cast<const Attribute_Access<T, Class> *>(&t_func);
|
= dynamic_cast<const Attribute_Access<T, Class> *>(&t_func);
|
||||||
@@ -657,7 +705,7 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool call_match(const std::vector<Boxed_Value> &vals, const Type_Conversions_State &) const override
|
virtual bool call_match(const std::vector<Boxed_Value> &vals, const Type_Conversions_State &) const CHAISCRIPT_OVERRIDE
|
||||||
{
|
{
|
||||||
if (vals.size() != 1)
|
if (vals.size() != 1)
|
||||||
{
|
{
|
||||||
@@ -667,47 +715,26 @@ namespace chaiscript
|
|||||||
return vals[0].get_type_info().bare_equal(user_type<Class>());
|
return vals[0].get_type_info().bare_equal(user_type<Class>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual std::string annotation() const CHAISCRIPT_OVERRIDE
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Boxed_Value do_call(const std::vector<Boxed_Value> ¶ms, const Type_Conversions_State &t_conversions) const override
|
virtual Boxed_Value do_call(const std::vector<Boxed_Value> ¶ms, const Type_Conversions_State &t_conversions) const CHAISCRIPT_OVERRIDE
|
||||||
{
|
{
|
||||||
const Boxed_Value &bv = params[0];
|
const Boxed_Value &bv = params[0];
|
||||||
if (bv.is_const())
|
if (bv.is_const())
|
||||||
{
|
{
|
||||||
const Class *o = boxed_cast<const Class *>(bv, &t_conversions);
|
const Class *o = boxed_cast<const Class *>(bv, &t_conversions);
|
||||||
return do_call_impl<T>(o);
|
return detail::Handle_Return<const typename std::add_lvalue_reference<T>::type>::handle(o->*m_attr);
|
||||||
} else {
|
} else {
|
||||||
Class *o = boxed_cast<Class *>(bv, &t_conversions);
|
Class *o = boxed_cast<Class *>(bv, &t_conversions);
|
||||||
return do_call_impl<T>(o);
|
return detail::Handle_Return<typename std::add_lvalue_reference<T>::type>::handle(o->*m_attr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
template<typename Type>
|
|
||||||
auto do_call_impl(Class *o) const -> std::enable_if_t<std::is_pointer<Type>::value, Boxed_Value>
|
|
||||||
{
|
|
||||||
return detail::Handle_Return<Type>::handle(o->*m_attr);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Type>
|
|
||||||
auto do_call_impl(const Class *o) const -> std::enable_if_t<std::is_pointer<Type>::value, Boxed_Value>
|
|
||||||
{
|
|
||||||
return detail::Handle_Return<const Type>::handle(o->*m_attr);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Type>
|
|
||||||
auto do_call_impl(Class *o) const -> std::enable_if_t<!std::is_pointer<Type>::value, Boxed_Value>
|
|
||||||
{
|
|
||||||
return detail::Handle_Return<typename std::add_lvalue_reference<Type>::type>::handle(o->*m_attr);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Type>
|
|
||||||
auto do_call_impl(const Class *o) const -> std::enable_if_t<!std::is_pointer<Type>::value, Boxed_Value>
|
|
||||||
{
|
|
||||||
return detail::Handle_Return<typename std::add_lvalue_reference<typename std::add_const<Type>::type>::type>::handle(o->*m_attr);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static std::vector<Type_Info> param_types()
|
static std::vector<Type_Info> param_types()
|
||||||
{
|
{
|
||||||
return {user_type<T>(), user_type<Class>()};
|
return {user_type<T>(), user_type<Class>()};
|
||||||
@@ -742,7 +769,7 @@ namespace chaiscript
|
|||||||
|
|
||||||
|
|
||||||
dispatch_error(const dispatch_error &) = default;
|
dispatch_error(const dispatch_error &) = default;
|
||||||
virtual ~dispatch_error() noexcept = default;
|
virtual ~dispatch_error() CHAISCRIPT_NOEXCEPT {}
|
||||||
|
|
||||||
std::vector<Boxed_Value> parameters;
|
std::vector<Boxed_Value> parameters;
|
||||||
std::vector<Const_Proxy_Function> functions;
|
std::vector<Const_Proxy_Function> functions;
|
||||||
@@ -819,7 +846,8 @@ namespace chaiscript
|
|||||||
plist.begin(),
|
plist.begin(),
|
||||||
std::back_inserter(newplist),
|
std::back_inserter(newplist),
|
||||||
[](const Type_Info &ti, const Boxed_Value ¶m) -> Boxed_Value {
|
[](const Type_Info &ti, const Boxed_Value ¶m) -> Boxed_Value {
|
||||||
if (ti.is_arithmetic() && param.get_type_info().is_arithmetic()) {
|
if (ti.is_arithmetic() && param.get_type_info().is_arithmetic()
|
||||||
|
&& param.get_type_info() != ti) {
|
||||||
return Boxed_Number(param).get_as(ti).bv;
|
return Boxed_Number(param).get_as(ti).bv;
|
||||||
} else {
|
} else {
|
||||||
return param;
|
return param;
|
||||||
@@ -827,8 +855,6 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return (*(matching_func->second))(newplist, t_conversions);
|
return (*(matching_func->second))(newplist, t_conversions);
|
||||||
} catch (const exception::bad_boxed_cast &) {
|
} catch (const exception::bad_boxed_cast &) {
|
||||||
@@ -882,7 +908,7 @@ namespace chaiscript
|
|||||||
for (const auto &func : ordered_funcs )
|
for (const auto &func : ordered_funcs )
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
if (func.first == i && (i == 0 || func.second->filter(plist, t_conversions)))
|
if (func.first == i && func.second->filter(plist, t_conversions))
|
||||||
{
|
{
|
||||||
return (*(func.second))(plist, t_conversions);
|
return (*(func.second))(plist, t_conversions);
|
||||||
}
|
}
|
||||||
|
@@ -10,7 +10,6 @@
|
|||||||
#include <functional>
|
#include <functional>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <array>
|
|
||||||
|
|
||||||
#include "../chaiscript_defines.hpp"
|
#include "../chaiscript_defines.hpp"
|
||||||
#include "boxed_cast.hpp"
|
#include "boxed_cast.hpp"
|
||||||
@@ -44,7 +43,7 @@ namespace chaiscript
|
|||||||
|
|
||||||
arity_error(const arity_error &) = default;
|
arity_error(const arity_error &) = default;
|
||||||
|
|
||||||
virtual ~arity_error() noexcept {}
|
virtual ~arity_error() CHAISCRIPT_NOEXCEPT {}
|
||||||
|
|
||||||
int got;
|
int got;
|
||||||
int expected;
|
int expected;
|
||||||
@@ -67,6 +66,34 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef CHAISCRIPT_GCC_4_6
|
||||||
|
/// \todo REMOVE THIS WHEN WE DROP G++4.6
|
||||||
|
|
||||||
|
|
||||||
|
// Forward declaration
|
||||||
|
template<typename ... Rest>
|
||||||
|
struct Try_Cast;
|
||||||
|
|
||||||
|
template<typename Param, typename ... Rest>
|
||||||
|
struct Try_Cast<Param, Rest...>
|
||||||
|
{
|
||||||
|
static void do_try(const std::vector<Boxed_Value> ¶ms, size_t generation, const Type_Conversions_State &t_conversions)
|
||||||
|
{
|
||||||
|
boxed_cast<Param>(params[generation], &t_conversions);
|
||||||
|
Try_Cast<Rest...>::do_try(params, generation+1, t_conversions);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 0th case
|
||||||
|
template<>
|
||||||
|
struct Try_Cast<>
|
||||||
|
{
|
||||||
|
static void do_try(const std::vector<Boxed_Value> &, size_t, const Type_Conversions_State &)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used by Proxy_Function_Impl to determine if it is equivalent to another
|
* Used by Proxy_Function_Impl to determine if it is equivalent to another
|
||||||
* Proxy_Function_Impl object. This function is primarily used to prevent
|
* Proxy_Function_Impl object. This function is primarily used to prevent
|
||||||
@@ -77,46 +104,137 @@ namespace chaiscript
|
|||||||
const std::vector<Boxed_Value> ¶ms, const Type_Conversions_State &t_conversions)
|
const std::vector<Boxed_Value> ¶ms, const Type_Conversions_State &t_conversions)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
std::vector<Boxed_Value>::size_type i = 0;
|
Try_Cast<Params...>::do_try(params, 0, t_conversions);
|
||||||
(void)i;
|
} catch (const exception::bad_boxed_cast &) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Ret, int count, typename ... Params>
|
||||||
|
struct Call_Func
|
||||||
|
{
|
||||||
|
|
||||||
|
template<typename Callable, typename ... InnerParams>
|
||||||
|
static Ret do_call(const Callable &f,
|
||||||
|
const std::vector<Boxed_Value> ¶ms, const Type_Conversions_State &t_conversions, InnerParams &&... innerparams)
|
||||||
|
{
|
||||||
|
return Call_Func<Ret, count - 1, Params...>::do_call(f, params, t_conversions, std::forward<InnerParams>(innerparams)..., params[sizeof...(Params) - count]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename Ret, typename ... Params>
|
||||||
|
struct Call_Func<Ret, 0, Params...>
|
||||||
|
{
|
||||||
|
#ifdef CHAISCRIPT_MSVC
|
||||||
|
#pragma warning(push)
|
||||||
|
#pragma warning(disable : 4100) /// Disable unreferenced formal parameter warning, which only shows up in MSVC I don't think there's any way around it \todo evaluate this
|
||||||
|
#endif
|
||||||
|
template<typename Callable, typename ... InnerParams>
|
||||||
|
static Ret do_call(const Callable &f,
|
||||||
|
const std::vector<Boxed_Value> &, const Type_Conversions_State &t_conversions, InnerParams &&... innerparams)
|
||||||
|
{
|
||||||
|
return f(boxed_cast<Params>(std::forward<InnerParams>(innerparams), &t_conversions)...);
|
||||||
|
}
|
||||||
|
#ifdef CHAISCRIPT_MSVC
|
||||||
|
#pragma warning(pop)
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used by Proxy_Function_Impl to perform typesafe execution of a function.
|
||||||
|
* The function attempts to unbox each parameter to the expected type.
|
||||||
|
* if any unboxing fails the execution of the function fails and
|
||||||
|
* the bad_boxed_cast is passed up to the caller.
|
||||||
|
*/
|
||||||
|
template<typename Callable, typename Ret, typename ... Params>
|
||||||
|
Ret call_func(const chaiscript::dispatch::detail::Function_Signature<Ret (Params...)> &, const Callable &f,
|
||||||
|
const std::vector<Boxed_Value> ¶ms, const Type_Conversions_State &t_conversions)
|
||||||
|
{
|
||||||
|
if (params.size() == sizeof...(Params))
|
||||||
|
{
|
||||||
|
return Call_Func<Ret, sizeof...(Params), Params...>::do_call(f, params, t_conversions);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw exception::arity_error(static_cast<int>(params.size()), sizeof...(Params));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
template<size_t ... I>
|
||||||
|
struct Indexes
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
template<size_t S, size_t ... I>
|
||||||
|
struct Make_Indexes
|
||||||
|
{
|
||||||
|
typedef typename Make_Indexes<S-1, I..., sizeof...(I)>::indexes indexes;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<size_t ... I>
|
||||||
|
struct Make_Indexes<0, I...>
|
||||||
|
{
|
||||||
|
typedef Indexes<I...> indexes;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used by Proxy_Function_Impl to determine if it is equivalent to another
|
||||||
|
* Proxy_Function_Impl object. This function is primarily used to prevent
|
||||||
|
* registration of two functions with the exact same signatures
|
||||||
|
*/
|
||||||
|
template<typename Ret, typename ... Params, size_t ... I>
|
||||||
|
bool compare_types_cast(Indexes<I...>, Ret (*)(Params...),
|
||||||
|
const std::vector<Boxed_Value> ¶ms, const Type_Conversions_State &t_conversions)
|
||||||
|
{
|
||||||
|
try {
|
||||||
(void)params; (void)t_conversions;
|
(void)params; (void)t_conversions;
|
||||||
// this is ok because the order of evaluation of initializer lists is well defined
|
(void)std::initializer_list<int>{(boxed_cast<Params>(params[I], &t_conversions), 0)...};
|
||||||
(void)std::initializer_list<int>{(boxed_cast<Params>(params[i++], &t_conversions), 0)...};
|
|
||||||
return true;
|
return true;
|
||||||
} catch (const exception::bad_boxed_cast &) {
|
} catch (const exception::bad_boxed_cast &) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Ret, typename ... Params>
|
||||||
|
bool compare_types_cast(Ret (*f)(Params...),
|
||||||
|
const std::vector<Boxed_Value> ¶ms, const Type_Conversions_State &t_conversions)
|
||||||
|
{
|
||||||
|
typedef typename Make_Indexes<sizeof...(Params)>::indexes indexes;
|
||||||
|
return compare_types_cast(indexes(), f, params, t_conversions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<typename Callable, typename Ret, typename ... Params, size_t ... I>
|
template<typename Callable, typename Ret, typename ... Params, size_t ... I>
|
||||||
Ret call_func(const chaiscript::dispatch::detail::Function_Signature<Ret (Params...)> &,
|
Ret call_func(const chaiscript::dispatch::detail::Function_Signature<Ret (Params...)> &, Indexes<I...>, const Callable &f,
|
||||||
std::index_sequence<I...>, const Callable &f,
|
const std::vector<Boxed_Value> ¶ms, const Type_Conversions_State &t_conversions)
|
||||||
const std::vector<Boxed_Value> ¶ms, const Type_Conversions_State &t_conversions)
|
|
||||||
{
|
{
|
||||||
(void)params; (void)t_conversions;
|
(void)params; (void)t_conversions;
|
||||||
return f(boxed_cast<Params>(params[I], &t_conversions)...);
|
return f(boxed_cast<Params>(params[I], &t_conversions)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Used by Proxy_Function_Impl to perform typesafe execution of a function.
|
/**
|
||||||
/// The function attempts to unbox each parameter to the expected type.
|
* Used by Proxy_Function_Impl to perform typesafe execution of a function.
|
||||||
/// if any unboxing fails the execution of the function fails and
|
* The function attempts to unbox each parameter to the expected type.
|
||||||
/// the bad_boxed_cast is passed up to the caller.
|
* if any unboxing fails the execution of the function fails and
|
||||||
|
* the bad_boxed_cast is passed up to the caller.
|
||||||
|
*/
|
||||||
template<typename Callable, typename Ret, typename ... Params>
|
template<typename Callable, typename Ret, typename ... Params>
|
||||||
Boxed_Value call_func(const chaiscript::dispatch::detail::Function_Signature<Ret (Params...)> &sig, const Callable &f,
|
Ret call_func(const chaiscript::dispatch::detail::Function_Signature<Ret (Params...)> &sig, const Callable &f,
|
||||||
const std::vector<Boxed_Value> ¶ms, const Type_Conversions_State &t_conversions)
|
const std::vector<Boxed_Value> ¶ms, const Type_Conversions_State &t_conversions)
|
||||||
{
|
{
|
||||||
return Handle_Return<Ret>::handle(call_func(sig, std::index_sequence_for<Params...>{}, f, params, t_conversions));
|
typedef typename Make_Indexes<sizeof...(Params)>::indexes indexes;
|
||||||
|
return call_func(sig, indexes(), f, params, t_conversions);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Callable, typename ... Params>
|
#endif
|
||||||
Boxed_Value call_func(const chaiscript::dispatch::detail::Function_Signature<void (Params...)> &sig, const Callable &f,
|
|
||||||
const std::vector<Boxed_Value> ¶ms, const Type_Conversions_State &t_conversions)
|
|
||||||
{
|
|
||||||
call_func(sig, std::index_sequence_for<Params...>{}, f, params, t_conversions);
|
|
||||||
return Handle_Return<void>::handle();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -124,4 +242,34 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
namespace chaiscript
|
||||||
|
{
|
||||||
|
namespace dispatch
|
||||||
|
{
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
template<typename Ret>
|
||||||
|
struct Do_Call
|
||||||
|
{
|
||||||
|
template<typename Signature, typename Callable>
|
||||||
|
static Boxed_Value go(const Callable &fun, const std::vector<Boxed_Value> ¶ms, const Type_Conversions_State &t_conversions)
|
||||||
|
{
|
||||||
|
return Handle_Return<Ret>::handle(call_func(Function_Signature<Signature>(), fun, params, t_conversions));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct Do_Call<void>
|
||||||
|
{
|
||||||
|
template<typename Signature, typename Callable>
|
||||||
|
static Boxed_Value go(const Callable &fun, const std::vector<Boxed_Value> ¶ms, const Type_Conversions_State &t_conversions)
|
||||||
|
{
|
||||||
|
call_func(Function_Signature<Signature>(), fun, params, t_conversions);
|
||||||
|
return Handle_Return<void>::handle();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -29,48 +29,48 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
bad_boxed_dynamic_cast(const Type_Info &t_from, const std::type_info &t_to,
|
bad_boxed_dynamic_cast(const Type_Info &t_from, const std::type_info &t_to,
|
||||||
const std::string &t_what) noexcept
|
const std::string &t_what) CHAISCRIPT_NOEXCEPT
|
||||||
: bad_boxed_cast(t_from, t_to, t_what)
|
: bad_boxed_cast(t_from, t_to, t_what)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bad_boxed_dynamic_cast(const Type_Info &t_from, const std::type_info &t_to) noexcept
|
bad_boxed_dynamic_cast(const Type_Info &t_from, const std::type_info &t_to) CHAISCRIPT_NOEXCEPT
|
||||||
: bad_boxed_cast(t_from, t_to)
|
: bad_boxed_cast(t_from, t_to)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bad_boxed_dynamic_cast(const std::string &w) noexcept
|
bad_boxed_dynamic_cast(const std::string &w) CHAISCRIPT_NOEXCEPT
|
||||||
: bad_boxed_cast(w)
|
: bad_boxed_cast(w)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bad_boxed_dynamic_cast(const bad_boxed_dynamic_cast &) = default;
|
bad_boxed_dynamic_cast(const bad_boxed_dynamic_cast &) = default;
|
||||||
|
|
||||||
virtual ~bad_boxed_dynamic_cast() noexcept = default;
|
virtual ~bad_boxed_dynamic_cast() CHAISCRIPT_NOEXCEPT {}
|
||||||
};
|
};
|
||||||
|
|
||||||
class bad_boxed_type_cast : public bad_boxed_cast
|
class bad_boxed_type_cast : public bad_boxed_cast
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
bad_boxed_type_cast(const Type_Info &t_from, const std::type_info &t_to,
|
bad_boxed_type_cast(const Type_Info &t_from, const std::type_info &t_to,
|
||||||
const std::string &t_what) noexcept
|
const std::string &t_what) CHAISCRIPT_NOEXCEPT
|
||||||
: bad_boxed_cast(t_from, t_to, t_what)
|
: bad_boxed_cast(t_from, t_to, t_what)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bad_boxed_type_cast(const Type_Info &t_from, const std::type_info &t_to) noexcept
|
bad_boxed_type_cast(const Type_Info &t_from, const std::type_info &t_to) CHAISCRIPT_NOEXCEPT
|
||||||
: bad_boxed_cast(t_from, t_to)
|
: bad_boxed_cast(t_from, t_to)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bad_boxed_type_cast(const std::string &w) noexcept
|
bad_boxed_type_cast(const std::string &w) CHAISCRIPT_NOEXCEPT
|
||||||
: bad_boxed_cast(w)
|
: bad_boxed_cast(w)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bad_boxed_type_cast(const bad_boxed_type_cast &) = default;
|
bad_boxed_type_cast(const bad_boxed_type_cast &) = default;
|
||||||
|
|
||||||
virtual ~bad_boxed_type_cast() noexcept = default;
|
virtual ~bad_boxed_type_cast() CHAISCRIPT_NOEXCEPT {}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,7 +97,7 @@ namespace chaiscript
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~Type_Conversion_Base() = default;
|
virtual ~Type_Conversion_Base() {}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Type_Conversion_Base(const Type_Info &t_to, const Type_Info &t_from)
|
Type_Conversion_Base(const Type_Info &t_to, const Type_Info &t_from)
|
||||||
@@ -107,8 +107,8 @@ namespace chaiscript
|
|||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const Type_Info m_to;
|
Type_Info m_to;
|
||||||
const Type_Info m_from;
|
Type_Info m_from;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -126,7 +126,7 @@ namespace chaiscript
|
|||||||
if (t_from.is_const())
|
if (t_from.is_const())
|
||||||
{
|
{
|
||||||
return Boxed_Value(
|
return Boxed_Value(
|
||||||
[&](){
|
[&]()->std::shared_ptr<const To>{
|
||||||
if (auto data = std::static_pointer_cast<const To>(detail::Cast_Helper<std::shared_ptr<const From> >::cast(t_from, nullptr)))
|
if (auto data = std::static_pointer_cast<const To>(detail::Cast_Helper<std::shared_ptr<const From> >::cast(t_from, nullptr)))
|
||||||
{
|
{
|
||||||
return data;
|
return data;
|
||||||
@@ -137,7 +137,7 @@ namespace chaiscript
|
|||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return Boxed_Value(
|
return Boxed_Value(
|
||||||
[&](){
|
[&]()->std::shared_ptr<To>{
|
||||||
if (auto data = std::static_pointer_cast<To>(detail::Cast_Helper<std::shared_ptr<From> >::cast(t_from, nullptr)))
|
if (auto data = std::static_pointer_cast<To>(detail::Cast_Helper<std::shared_ptr<From> >::cast(t_from, nullptr)))
|
||||||
{
|
{
|
||||||
return data;
|
return data;
|
||||||
@@ -182,7 +182,7 @@ namespace chaiscript
|
|||||||
if (t_from.is_const())
|
if (t_from.is_const())
|
||||||
{
|
{
|
||||||
return Boxed_Value(
|
return Boxed_Value(
|
||||||
[&](){
|
[&]()->std::shared_ptr<const To>{
|
||||||
if (auto data = std::dynamic_pointer_cast<const To>(detail::Cast_Helper<std::shared_ptr<const From> >::cast(t_from, nullptr)))
|
if (auto data = std::dynamic_pointer_cast<const To>(detail::Cast_Helper<std::shared_ptr<const From> >::cast(t_from, nullptr)))
|
||||||
{
|
{
|
||||||
return data;
|
return data;
|
||||||
@@ -193,7 +193,7 @@ namespace chaiscript
|
|||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return Boxed_Value(
|
return Boxed_Value(
|
||||||
[&](){
|
[&]()->std::shared_ptr<To>{
|
||||||
if (auto data = std::dynamic_pointer_cast<To>(detail::Cast_Helper<std::shared_ptr<From> >::cast(t_from, nullptr)))
|
if (auto data = std::dynamic_pointer_cast<To>(detail::Cast_Helper<std::shared_ptr<From> >::cast(t_from, nullptr)))
|
||||||
{
|
{
|
||||||
return data;
|
return data;
|
||||||
@@ -242,12 +242,12 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Boxed_Value convert_down(const Boxed_Value &t_base) const override
|
virtual Boxed_Value convert_down(const Boxed_Value &t_base) const CHAISCRIPT_OVERRIDE
|
||||||
{
|
{
|
||||||
return Dynamic_Caster<Base, Derived>::cast(t_base);
|
return Dynamic_Caster<Base, Derived>::cast(t_base);
|
||||||
}
|
}
|
||||||
|
|
||||||
Boxed_Value convert(const Boxed_Value &t_derived) const override
|
virtual Boxed_Value convert(const Boxed_Value &t_derived) const CHAISCRIPT_OVERRIDE
|
||||||
{
|
{
|
||||||
return Static_Caster<Derived, Base>::cast(t_derived);
|
return Static_Caster<Derived, Base>::cast(t_derived);
|
||||||
}
|
}
|
||||||
@@ -262,18 +262,17 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Boxed_Value convert_down(const Boxed_Value &t_base) const override
|
virtual Boxed_Value convert_down(const Boxed_Value &t_base) const CHAISCRIPT_OVERRIDE
|
||||||
{
|
{
|
||||||
throw chaiscript::exception::bad_boxed_dynamic_cast(t_base.get_type_info(), typeid(Derived),
|
throw chaiscript::exception::bad_boxed_dynamic_cast(t_base.get_type_info(), typeid(Derived), "Unable to cast down inheritance hierarchy with non-polymorphic types");
|
||||||
"Unable to cast down inheritance hierarchy with non-polymorphic types");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool bidir() const override
|
virtual bool bidir() const CHAISCRIPT_OVERRIDE
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Boxed_Value convert(const Boxed_Value &t_derived) const override
|
virtual Boxed_Value convert(const Boxed_Value &t_derived) const CHAISCRIPT_OVERRIDE
|
||||||
{
|
{
|
||||||
return Static_Caster<Derived, Base>::cast(t_derived);
|
return Static_Caster<Derived, Base>::cast(t_derived);
|
||||||
}
|
}
|
||||||
@@ -291,18 +290,18 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Boxed_Value convert_down(const Boxed_Value &) const override
|
virtual Boxed_Value convert_down(const Boxed_Value &) const CHAISCRIPT_OVERRIDE
|
||||||
{
|
{
|
||||||
throw chaiscript::exception::bad_boxed_type_cast("No conversion exists");
|
throw chaiscript::exception::bad_boxed_type_cast("No conversion exists");
|
||||||
}
|
}
|
||||||
|
|
||||||
Boxed_Value convert(const Boxed_Value &t_from) const override
|
virtual Boxed_Value convert(const Boxed_Value &t_from) const CHAISCRIPT_OVERRIDE
|
||||||
{
|
{
|
||||||
/// \todo better handling of errors from the conversion function
|
/// \todo better handling of errors from the conversion function
|
||||||
return m_func(t_from);
|
return m_func(t_from);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool bidir() const override
|
virtual bool bidir() const CHAISCRIPT_OVERRIDE
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -318,7 +317,11 @@ namespace chaiscript
|
|||||||
public:
|
public:
|
||||||
struct Conversion_Saves
|
struct Conversion_Saves
|
||||||
{
|
{
|
||||||
bool enabled = false;
|
Conversion_Saves()
|
||||||
|
: enabled(false)
|
||||||
|
{}
|
||||||
|
|
||||||
|
bool enabled;
|
||||||
std::vector<Boxed_Value> saves;
|
std::vector<Boxed_Value> saves;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -347,6 +350,7 @@ namespace chaiscript
|
|||||||
m_num_types(m_conversions.size()),
|
m_num_types(m_conversions.size()),
|
||||||
m_thread_cache(this),
|
m_thread_cache(this),
|
||||||
m_conversion_saves(this)
|
m_conversion_saves(this)
|
||||||
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -444,7 +448,7 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
chaiscript::detail::threading::shared_lock<chaiscript::detail::threading::shared_mutex> l(m_mutex);
|
chaiscript::detail::threading::shared_lock<chaiscript::detail::threading::shared_mutex> l(m_mutex);
|
||||||
|
|
||||||
const auto itr = find(to, from);
|
auto itr = find(to, from);
|
||||||
|
|
||||||
if (itr != m_conversions.end())
|
if (itr != m_conversions.end())
|
||||||
{
|
{
|
||||||
|
@@ -29,8 +29,8 @@ namespace chaiscript
|
|||||||
class Type_Info
|
class Type_Info
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
constexpr Type_Info(const bool t_is_const, const bool t_is_reference, const bool t_is_pointer, const bool t_is_void,
|
CHAISCRIPT_CONSTEXPR Type_Info(bool t_is_const, bool t_is_reference, bool t_is_pointer, bool t_is_void,
|
||||||
const bool t_is_arithmetic, const std::type_info *t_ti, const std::type_info *t_bare_ti)
|
bool t_is_arithmetic, const std::type_info *t_ti, const std::type_info *t_bare_ti)
|
||||||
: m_type_info(t_ti), m_bare_type_info(t_bare_ti),
|
: m_type_info(t_ti), m_bare_type_info(t_bare_ti),
|
||||||
m_flags((static_cast<unsigned int>(t_is_const) << is_const_flag)
|
m_flags((static_cast<unsigned int>(t_is_const) << is_const_flag)
|
||||||
+ (static_cast<unsigned int>(t_is_reference) << is_reference_flag)
|
+ (static_cast<unsigned int>(t_is_reference) << is_reference_flag)
|
||||||
@@ -40,45 +40,69 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr Type_Info() = default;
|
CHAISCRIPT_CONSTEXPR Type_Info()
|
||||||
|
: m_type_info(nullptr), m_bare_type_info(nullptr),
|
||||||
|
m_flags(1 << is_undef_flag)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
constexpr bool operator<(const Type_Info &ti) const noexcept
|
#if !defined(_MSC_VER) || _MSC_VER != 1800
|
||||||
|
Type_Info(Type_Info&&) = default;
|
||||||
|
Type_Info& operator=(Type_Info&&) = default;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
Type_Info(const Type_Info&) = default;
|
||||||
|
Type_Info& operator=(const Type_Info&) = default;
|
||||||
|
|
||||||
|
|
||||||
|
CHAISCRIPT_CONSTEXPR bool operator<(const Type_Info &ti) const CHAISCRIPT_NOEXCEPT
|
||||||
{
|
{
|
||||||
return m_type_info < ti.m_type_info;
|
return m_type_info < ti.m_type_info;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr bool operator==(const Type_Info &ti) const noexcept
|
CHAISCRIPT_CONSTEXPR bool operator!=(const Type_Info &ti) const CHAISCRIPT_NOEXCEPT
|
||||||
|
{
|
||||||
|
return !(operator==(ti));
|
||||||
|
}
|
||||||
|
|
||||||
|
CHAISCRIPT_CONSTEXPR bool operator!=(const std::type_info &ti) const CHAISCRIPT_NOEXCEPT
|
||||||
|
{
|
||||||
|
return !(operator==(ti));
|
||||||
|
}
|
||||||
|
|
||||||
|
CHAISCRIPT_CONSTEXPR bool operator==(const Type_Info &ti) const CHAISCRIPT_NOEXCEPT
|
||||||
{
|
{
|
||||||
return ti.m_type_info == m_type_info
|
return ti.m_type_info == m_type_info
|
||||||
|| *ti.m_type_info == *m_type_info;
|
|| (ti.m_type_info && m_type_info && *ti.m_type_info == *m_type_info);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr bool operator==(const std::type_info &ti) const noexcept
|
CHAISCRIPT_CONSTEXPR bool operator==(const std::type_info &ti) const CHAISCRIPT_NOEXCEPT
|
||||||
{
|
{
|
||||||
return !is_undef() && (*m_type_info) == ti;
|
return m_type_info != nullptr && (*m_type_info) == ti;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr bool bare_equal(const Type_Info &ti) const noexcept
|
CHAISCRIPT_CONSTEXPR bool bare_equal(const Type_Info &ti) const CHAISCRIPT_NOEXCEPT
|
||||||
{
|
{
|
||||||
return ti.m_bare_type_info == m_bare_type_info
|
return ti.m_bare_type_info == m_bare_type_info
|
||||||
|| *ti.m_bare_type_info == *m_bare_type_info;
|
|| (ti.m_bare_type_info && m_bare_type_info && *ti.m_bare_type_info == *m_bare_type_info);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr bool bare_equal_type_info(const std::type_info &ti) const noexcept
|
CHAISCRIPT_CONSTEXPR bool bare_equal_type_info(const std::type_info &ti) const CHAISCRIPT_NOEXCEPT
|
||||||
{
|
{
|
||||||
return !is_undef() && (*m_bare_type_info) == ti;
|
return m_bare_type_info != nullptr
|
||||||
|
&& (*m_bare_type_info) == ti;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr bool is_const() const noexcept { return (m_flags & (1 << is_const_flag)) != 0; }
|
CHAISCRIPT_CONSTEXPR bool is_const() const CHAISCRIPT_NOEXCEPT { return (m_flags & (1 << is_const_flag)) != 0; }
|
||||||
constexpr bool is_reference() const noexcept { return (m_flags & (1 << is_reference_flag)) != 0; }
|
CHAISCRIPT_CONSTEXPR bool is_reference() const CHAISCRIPT_NOEXCEPT { return (m_flags & (1 << is_reference_flag)) != 0; }
|
||||||
constexpr bool is_void() const noexcept { return (m_flags & (1 << is_void_flag)) != 0; }
|
CHAISCRIPT_CONSTEXPR bool is_void() const CHAISCRIPT_NOEXCEPT { return (m_flags & (1 << is_void_flag)) != 0; }
|
||||||
constexpr bool is_arithmetic() const noexcept { return (m_flags & (1 << is_arithmetic_flag)) != 0; }
|
CHAISCRIPT_CONSTEXPR bool is_arithmetic() const CHAISCRIPT_NOEXCEPT { return (m_flags & (1 << is_arithmetic_flag)) != 0; }
|
||||||
constexpr bool is_undef() const noexcept { return (m_flags & (1 << is_undef_flag)) != 0; }
|
CHAISCRIPT_CONSTEXPR bool is_undef() const CHAISCRIPT_NOEXCEPT { return (m_flags & (1 << is_undef_flag)) != 0; }
|
||||||
constexpr bool is_pointer() const noexcept { return (m_flags & (1 << is_pointer_flag)) != 0; }
|
CHAISCRIPT_CONSTEXPR bool is_pointer() const CHAISCRIPT_NOEXCEPT { return (m_flags & (1 << is_pointer_flag)) != 0; }
|
||||||
|
|
||||||
std::string name() const
|
std::string name() const
|
||||||
{
|
{
|
||||||
if (!is_undef())
|
if (m_type_info)
|
||||||
{
|
{
|
||||||
return m_type_info->name();
|
return m_type_info->name();
|
||||||
} else {
|
} else {
|
||||||
@@ -88,7 +112,7 @@ namespace chaiscript
|
|||||||
|
|
||||||
std::string bare_name() const
|
std::string bare_name() const
|
||||||
{
|
{
|
||||||
if (!is_undef())
|
if (m_bare_type_info)
|
||||||
{
|
{
|
||||||
return m_bare_type_info->name();
|
return m_bare_type_info->name();
|
||||||
} else {
|
} else {
|
||||||
@@ -96,23 +120,21 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr const std::type_info *bare_type_info() const
|
CHAISCRIPT_CONSTEXPR const std::type_info *bare_type_info() const
|
||||||
{
|
{
|
||||||
return m_bare_type_info;
|
return m_bare_type_info;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct Unknown_Type {};
|
const std::type_info *m_type_info;
|
||||||
|
const std::type_info *m_bare_type_info;
|
||||||
const std::type_info *m_type_info = &typeid(Unknown_Type);
|
unsigned int m_flags;
|
||||||
const std::type_info *m_bare_type_info = &typeid(Unknown_Type);
|
|
||||||
static const int is_const_flag = 0;
|
static const int is_const_flag = 0;
|
||||||
static const int is_reference_flag = 1;
|
static const int is_reference_flag = 1;
|
||||||
static const int is_pointer_flag = 2;
|
static const int is_pointer_flag = 2;
|
||||||
static const int is_void_flag = 3;
|
static const int is_void_flag = 3;
|
||||||
static const int is_arithmetic_flag = 4;
|
static const int is_arithmetic_flag = 4;
|
||||||
static const int is_undef_flag = 5;
|
static const int is_undef_flag = 5;
|
||||||
unsigned int m_flags = (1 << is_undef_flag);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace detail
|
namespace detail
|
||||||
@@ -121,7 +143,9 @@ namespace chaiscript
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
struct Get_Type_Info
|
struct Get_Type_Info
|
||||||
{
|
{
|
||||||
static constexpr Type_Info get()
|
typedef T type;
|
||||||
|
|
||||||
|
static Type_Info get()
|
||||||
{
|
{
|
||||||
return Type_Info(std::is_const<typename std::remove_pointer<typename std::remove_reference<T>::type>::type>::value,
|
return Type_Info(std::is_const<typename std::remove_pointer<typename std::remove_reference<T>::type>::type>::value,
|
||||||
std::is_reference<T>::value, std::is_pointer<T>::value,
|
std::is_reference<T>::value, std::is_pointer<T>::value,
|
||||||
@@ -136,9 +160,9 @@ namespace chaiscript
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
struct Get_Type_Info<std::shared_ptr<T> >
|
struct Get_Type_Info<std::shared_ptr<T> >
|
||||||
{
|
{
|
||||||
// typedef T type;
|
typedef T type;
|
||||||
|
|
||||||
static constexpr Type_Info get()
|
static Type_Info get()
|
||||||
{
|
{
|
||||||
return Type_Info(std::is_const<T>::value, std::is_reference<T>::value, std::is_pointer<T>::value,
|
return Type_Info(std::is_const<T>::value, std::is_reference<T>::value, std::is_pointer<T>::value,
|
||||||
std::is_void<T>::value,
|
std::is_void<T>::value,
|
||||||
@@ -156,7 +180,9 @@ namespace chaiscript
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
struct Get_Type_Info<const std::shared_ptr<T> &>
|
struct Get_Type_Info<const std::shared_ptr<T> &>
|
||||||
{
|
{
|
||||||
static constexpr Type_Info get()
|
typedef T type;
|
||||||
|
|
||||||
|
static Type_Info get()
|
||||||
{
|
{
|
||||||
return Type_Info(std::is_const<T>::value, std::is_reference<T>::value, std::is_pointer<T>::value,
|
return Type_Info(std::is_const<T>::value, std::is_reference<T>::value, std::is_pointer<T>::value,
|
||||||
std::is_void<T>::value,
|
std::is_void<T>::value,
|
||||||
@@ -169,7 +195,9 @@ namespace chaiscript
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
struct Get_Type_Info<std::reference_wrapper<T> >
|
struct Get_Type_Info<std::reference_wrapper<T> >
|
||||||
{
|
{
|
||||||
static constexpr Type_Info get()
|
typedef T type;
|
||||||
|
|
||||||
|
static Type_Info get()
|
||||||
{
|
{
|
||||||
return Type_Info(std::is_const<T>::value, std::is_reference<T>::value, std::is_pointer<T>::value,
|
return Type_Info(std::is_const<T>::value, std::is_reference<T>::value, std::is_pointer<T>::value,
|
||||||
std::is_void<T>::value,
|
std::is_void<T>::value,
|
||||||
@@ -182,7 +210,9 @@ namespace chaiscript
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
struct Get_Type_Info<const std::reference_wrapper<T> &>
|
struct Get_Type_Info<const std::reference_wrapper<T> &>
|
||||||
{
|
{
|
||||||
static constexpr Type_Info get()
|
typedef T type;
|
||||||
|
|
||||||
|
static Type_Info get()
|
||||||
{
|
{
|
||||||
return Type_Info(std::is_const<T>::value, std::is_reference<T>::value, std::is_pointer<T>::value,
|
return Type_Info(std::is_const<T>::value, std::is_reference<T>::value, std::is_pointer<T>::value,
|
||||||
std::is_void<T>::value,
|
std::is_void<T>::value,
|
||||||
@@ -204,7 +234,7 @@ namespace chaiscript
|
|||||||
/// chaiscript::Type_Info ti = chaiscript::user_type(i);
|
/// chaiscript::Type_Info ti = chaiscript::user_type(i);
|
||||||
/// \endcode
|
/// \endcode
|
||||||
template<typename T>
|
template<typename T>
|
||||||
constexpr Type_Info user_type(const T &/*t*/)
|
Type_Info user_type(const T &/*t*/)
|
||||||
{
|
{
|
||||||
return detail::Get_Type_Info<T>::get();
|
return detail::Get_Type_Info<T>::get();
|
||||||
}
|
}
|
||||||
@@ -219,7 +249,7 @@ namespace chaiscript
|
|||||||
/// chaiscript::Type_Info ti = chaiscript::user_type<int>();
|
/// chaiscript::Type_Info ti = chaiscript::user_type<int>();
|
||||||
/// \endcode
|
/// \endcode
|
||||||
template<typename T>
|
template<typename T>
|
||||||
constexpr Type_Info user_type()
|
Type_Info user_type()
|
||||||
{
|
{
|
||||||
return detail::Get_Type_Info<T>::get();
|
return detail::Get_Type_Info<T>::get();
|
||||||
}
|
}
|
||||||
|
@@ -13,7 +13,7 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
|
|
||||||
struct Operators {
|
struct Operators {
|
||||||
enum class Opers
|
enum Opers
|
||||||
{
|
{
|
||||||
boolean_flag,
|
boolean_flag,
|
||||||
equals, less_than, greater_than, less_than_equal, greater_than_equal, not_equal,
|
equals, less_than, greater_than, less_than_equal, greater_than_equal, not_equal,
|
||||||
@@ -31,7 +31,7 @@ namespace chaiscript
|
|||||||
};
|
};
|
||||||
|
|
||||||
static const char *to_string(Opers t_oper) {
|
static const char *to_string(Opers t_oper) {
|
||||||
static const char *opers[] = {
|
const char *opers[] = {
|
||||||
"",
|
"",
|
||||||
"==", "<", ">", "<=", ">=", "!=",
|
"==", "<", ">", "<=", ">=", "!=",
|
||||||
"",
|
"",
|
||||||
@@ -46,80 +46,80 @@ namespace chaiscript
|
|||||||
"+", "/", "*", "-", "+", "-",
|
"+", "/", "*", "-", "+", "-",
|
||||||
""
|
""
|
||||||
};
|
};
|
||||||
return opers[static_cast<int>(t_oper)];
|
return opers[t_oper];
|
||||||
}
|
}
|
||||||
|
|
||||||
static Opers to_operator(const std::string &t_str, bool t_is_unary = false)
|
static Opers to_operator(const std::string &t_str, bool t_is_unary = false)
|
||||||
{
|
{
|
||||||
if (t_str == "==")
|
if (t_str == "==")
|
||||||
{
|
{
|
||||||
return Opers::equals;
|
return equals;
|
||||||
} else if (t_str == "<") {
|
} else if (t_str == "<") {
|
||||||
return Opers::less_than;
|
return less_than;
|
||||||
} else if (t_str == ">") {
|
} else if (t_str == ">") {
|
||||||
return Opers::greater_than;
|
return greater_than;
|
||||||
} else if (t_str == "<=") {
|
} else if (t_str == "<=") {
|
||||||
return Opers::less_than_equal;
|
return less_than_equal;
|
||||||
} else if (t_str == ">=") {
|
} else if (t_str == ">=") {
|
||||||
return Opers::greater_than_equal;
|
return greater_than_equal;
|
||||||
} else if (t_str == "!=") {
|
} else if (t_str == "!=") {
|
||||||
return Opers::not_equal;
|
return not_equal;
|
||||||
} else if (t_str == "=") {
|
} else if (t_str == "=") {
|
||||||
return Opers::assign;
|
return assign;
|
||||||
} else if (t_str == "++") {
|
} else if (t_str == "++") {
|
||||||
return Opers::pre_increment;
|
return pre_increment;
|
||||||
} else if (t_str == "--") {
|
} else if (t_str == "--") {
|
||||||
return Opers::pre_decrement;
|
return pre_decrement;
|
||||||
} else if (t_str == "*=") {
|
} else if (t_str == "*=") {
|
||||||
return Opers::assign_product;
|
return assign_product;
|
||||||
} else if (t_str == "+=") {
|
} else if (t_str == "+=") {
|
||||||
return Opers::assign_sum;
|
return assign_sum;
|
||||||
} else if (t_str == "-=") {
|
} else if (t_str == "-=") {
|
||||||
return Opers::assign_difference;
|
return assign_difference;
|
||||||
} else if (t_str == "&=") {
|
} else if (t_str == "&=") {
|
||||||
return Opers::assign_bitwise_and;
|
return assign_bitwise_and;
|
||||||
} else if (t_str == "|=") {
|
} else if (t_str == "|=") {
|
||||||
return Opers::assign_bitwise_or;
|
return assign_bitwise_or;
|
||||||
} else if (t_str == "<<=") {
|
} else if (t_str == "<<=") {
|
||||||
return Opers::assign_shift_left;
|
return assign_shift_left;
|
||||||
} else if (t_str == ">>=") {
|
} else if (t_str == ">>=") {
|
||||||
return Opers::assign_shift_right;
|
return assign_shift_right;
|
||||||
} else if (t_str == "%=") {
|
} else if (t_str == "%=") {
|
||||||
return Opers::assign_remainder;
|
return assign_remainder;
|
||||||
} else if (t_str == "^=") {
|
} else if (t_str == "^=") {
|
||||||
return Opers::assign_bitwise_xor;
|
return assign_bitwise_xor;
|
||||||
} else if (t_str == "<<") {
|
} else if (t_str == "<<") {
|
||||||
return Opers::shift_left;
|
return shift_left;
|
||||||
} else if (t_str == ">>") {
|
} else if (t_str == ">>") {
|
||||||
return Opers::shift_right;
|
return shift_right;
|
||||||
} else if (t_str == "%") {
|
} else if (t_str == "%") {
|
||||||
return Opers::remainder;
|
return remainder;
|
||||||
} else if (t_str == "&") {
|
} else if (t_str == "&") {
|
||||||
return Opers::bitwise_and;
|
return bitwise_and;
|
||||||
} else if (t_str == "|") {
|
} else if (t_str == "|") {
|
||||||
return Opers::bitwise_or;
|
return bitwise_or;
|
||||||
} else if (t_str == "^") {
|
} else if (t_str == "^") {
|
||||||
return Opers::bitwise_xor;
|
return bitwise_xor;
|
||||||
} else if (t_str == "~") {
|
} else if (t_str == "~") {
|
||||||
return Opers::bitwise_complement;
|
return bitwise_complement;
|
||||||
} else if (t_str == "+") {
|
} else if (t_str == "+") {
|
||||||
if (t_is_unary) {
|
if (t_is_unary) {
|
||||||
return Opers::unary_plus;
|
return unary_plus;
|
||||||
} else {
|
} else {
|
||||||
return Opers::sum;
|
return sum;
|
||||||
}
|
}
|
||||||
} else if (t_str == "-") {
|
} else if (t_str == "-") {
|
||||||
if (t_is_unary) {
|
if (t_is_unary) {
|
||||||
return Opers::unary_minus;
|
return unary_minus;
|
||||||
} else {
|
} else {
|
||||||
return Opers::difference;
|
return difference;
|
||||||
}
|
}
|
||||||
} else if (t_str == "/") {
|
} else if (t_str == "/") {
|
||||||
return Opers::quotient;
|
return quotient;
|
||||||
} else if (t_str == "*") {
|
} else if (t_str == "*") {
|
||||||
return Opers::product;
|
return product;
|
||||||
} else {
|
} else {
|
||||||
return Opers::invalid;
|
return invalid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -32,26 +32,28 @@ namespace chaiscript
|
|||||||
|
|
||||||
|
|
||||||
/// Types of AST nodes available to the parser and eval
|
/// Types of AST nodes available to the parser and eval
|
||||||
enum class AST_Node_Type { Id, Caching_Id, Fun_Call, Arg_List, Equation, Var_Decl,
|
class AST_Node_Type {
|
||||||
Array_Call, Dot_Access,
|
public:
|
||||||
Lambda, Block, Def, While, If, For, Inline_Array, Inline_Map, Return, File, Prefix, Break, Continue, Map_Pair, Value_Range,
|
enum Type { Error, Int, Float, Id, Char, Str, Eol, Fun_Call, Arg_List, Variable, Equation, Var_Decl,
|
||||||
Inline_Range, Try, Catch, Finally, Method, Attr_Decl,
|
Comparison, Addition, Subtraction, Multiplication, Division, Modulus, Array_Call, Dot_Access, Quoted_String, Single_Quoted_String,
|
||||||
Logical_And, Logical_Or, Reference, Switch, Case, Default, Ternary_Cond, Noop, Class, Binary, Arg, Global_Decl, Constant, Compiled
|
Lambda, Block, Def, While, If, For, Inline_Array, Inline_Map, Return, File, Prefix, Break, Continue, Map_Pair, Value_Range,
|
||||||
|
Inline_Range, Annotation, Try, Catch, Finally, Method, Attr_Decl, Shift, Equality, Bitwise_And, Bitwise_Xor, Bitwise_Or,
|
||||||
|
Logical_And, Logical_Or, Reference, Switch, Case, Default, Ternary_Cond, Noop, Class, Binary, Arg, Global_Decl
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class Operator_Precidence { Ternary_Cond, Logical_Or, Logical_And, Bitwise_Or, Bitwise_Xor, Bitwise_And, Equality, Comparison, Shift, Addition, Multiplication };
|
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
/// Helper lookup to get the name of each node type
|
|
||||||
const char *ast_node_type_to_string(AST_Node_Type ast_node_type) {
|
|
||||||
static const char * const ast_node_types[] = { "Id", "Caching_Id", "Fun_Call", "Arg_List", "Equation", "Var_Decl",
|
|
||||||
"Array_Call", "Dot_Access",
|
|
||||||
"Lambda", "Block", "Def", "While", "If", "For", "Inline_Array", "Inline_Map", "Return", "File", "Prefix", "Break", "Continue", "Map_Pair", "Value_Range",
|
|
||||||
"Inline_Range", "Try", "Catch", "Finally", "Method", "Attr_Decl",
|
|
||||||
"Logical_And", "Logical_Or", "Reference", "Switch", "Case", "Default", "Ternary Condition", "Noop", "Class", "Binary", "Arg", "Global_Decl", "Constant", "Compiled"};
|
|
||||||
|
|
||||||
return ast_node_types[static_cast<int>(ast_node_type)];
|
/// Helper lookup to get the name of each node type
|
||||||
|
const char *ast_node_type_to_string(int ast_node_type) {
|
||||||
|
const char *ast_node_types[] = { "Internal Parser Error", "Int", "Float", "Id", "Char", "Str", "Eol", "Fun_Call", "Arg_List", "Variable", "Equation", "Var_Decl",
|
||||||
|
"Comparison", "Addition", "Subtraction", "Multiplication", "Division", "Modulus", "Array_Call", "Dot_Access", "Quoted_String", "Single_Quoted_String",
|
||||||
|
"Lambda", "Block", "Def", "While", "If", "For", "Inline_Array", "Inline_Map", "Return", "File", "Prefix", "Break", "Continue", "Map_Pair", "Value_Range",
|
||||||
|
"Inline_Range", "Annotation", "Try", "Catch", "Finally", "Method", "Attr_Decl", "Shift", "Equality", "Bitwise_And", "Bitwise_Xor", "Bitwise_Or",
|
||||||
|
"Logical_And", "Logical_Or", "Reference", "Switch", "Case", "Default", "Ternary Condition", "Noop", "Class", "Binary", "Arg"};
|
||||||
|
|
||||||
|
return ast_node_types[ast_node_type];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,36 +101,6 @@ namespace chaiscript
|
|||||||
/// \brief Classes which may be thrown during error cases when ChaiScript is executing.
|
/// \brief Classes which may be thrown during error cases when ChaiScript is executing.
|
||||||
namespace exception
|
namespace exception
|
||||||
{
|
{
|
||||||
/// \brief Thrown if an error occurs while attempting to load a binary module
|
|
||||||
struct load_module_error : std::runtime_error
|
|
||||||
{
|
|
||||||
load_module_error(const std::string &t_reason) noexcept
|
|
||||||
: std::runtime_error(t_reason)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
load_module_error(const std::string &t_name, const std::vector<load_module_error> &t_errors)
|
|
||||||
: std::runtime_error(format_error(t_name, t_errors))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
load_module_error(const load_module_error &) = default;
|
|
||||||
virtual ~load_module_error() noexcept = default;
|
|
||||||
|
|
||||||
static std::string format_error(const std::string &t_name, const std::vector<load_module_error> &t_errors)
|
|
||||||
{
|
|
||||||
std::stringstream ss;
|
|
||||||
ss << "Error loading module '" << t_name << "'\n"
|
|
||||||
<< " The following locations were searched:\n";
|
|
||||||
|
|
||||||
for (const auto &err : t_errors) {
|
|
||||||
ss << " " << err.what() << "\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
return ss.str();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/// Errors generated during parsing or evaluation
|
/// Errors generated during parsing or evaluation
|
||||||
struct eval_error : std::runtime_error {
|
struct eval_error : std::runtime_error {
|
||||||
@@ -141,7 +113,7 @@ namespace chaiscript
|
|||||||
eval_error(const std::string &t_why, const File_Position &t_where, const std::string &t_fname,
|
eval_error(const std::string &t_why, const File_Position &t_where, const std::string &t_fname,
|
||||||
const std::vector<Boxed_Value> &t_parameters, const std::vector<chaiscript::Const_Proxy_Function> &t_functions,
|
const std::vector<Boxed_Value> &t_parameters, const std::vector<chaiscript::Const_Proxy_Function> &t_functions,
|
||||||
bool t_dot_notation,
|
bool t_dot_notation,
|
||||||
const chaiscript::detail::Dispatch_Engine &t_ss) noexcept :
|
const chaiscript::detail::Dispatch_Engine &t_ss) CHAISCRIPT_NOEXCEPT :
|
||||||
std::runtime_error(format(t_why, t_where, t_fname, t_parameters, t_dot_notation, t_ss)),
|
std::runtime_error(format(t_why, t_where, t_fname, t_parameters, t_dot_notation, t_ss)),
|
||||||
reason(t_why), start_position(t_where), filename(t_fname), detail(format_detail(t_functions, t_dot_notation, t_ss))
|
reason(t_why), start_position(t_where), filename(t_fname), detail(format_detail(t_functions, t_dot_notation, t_ss))
|
||||||
{}
|
{}
|
||||||
@@ -149,18 +121,18 @@ namespace chaiscript
|
|||||||
eval_error(const std::string &t_why,
|
eval_error(const std::string &t_why,
|
||||||
const std::vector<Boxed_Value> &t_parameters, const std::vector<chaiscript::Const_Proxy_Function> &t_functions,
|
const std::vector<Boxed_Value> &t_parameters, const std::vector<chaiscript::Const_Proxy_Function> &t_functions,
|
||||||
bool t_dot_notation,
|
bool t_dot_notation,
|
||||||
const chaiscript::detail::Dispatch_Engine &t_ss) noexcept :
|
const chaiscript::detail::Dispatch_Engine &t_ss) CHAISCRIPT_NOEXCEPT :
|
||||||
std::runtime_error(format(t_why, t_parameters, t_dot_notation, t_ss)),
|
std::runtime_error(format(t_why, t_parameters, t_dot_notation, t_ss)),
|
||||||
reason(t_why), detail(format_detail(t_functions, t_dot_notation, t_ss))
|
reason(t_why), detail(format_detail(t_functions, t_dot_notation, t_ss))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
eval_error(const std::string &t_why, const File_Position &t_where, const std::string &t_fname) noexcept :
|
eval_error(const std::string &t_why, const File_Position &t_where, const std::string &t_fname) CHAISCRIPT_NOEXCEPT :
|
||||||
std::runtime_error(format(t_why, t_where, t_fname)),
|
std::runtime_error(format(t_why, t_where, t_fname)),
|
||||||
reason(t_why), start_position(t_where), filename(t_fname)
|
reason(t_why), start_position(t_where), filename(t_fname)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
eval_error(const std::string &t_why) noexcept
|
eval_error(const std::string &t_why) CHAISCRIPT_NOEXCEPT
|
||||||
: std::runtime_error("Error: \"" + t_why + "\" "),
|
: std::runtime_error("Error: \"" + t_why + "\" "),
|
||||||
reason(t_why)
|
reason(t_why)
|
||||||
{}
|
{}
|
||||||
@@ -189,12 +161,12 @@ namespace chaiscript
|
|||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~eval_error() noexcept = default;
|
virtual ~eval_error() CHAISCRIPT_NOEXCEPT {}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static AST_Node_Type id(const T& t)
|
static int id(const T& t)
|
||||||
{
|
{
|
||||||
return t->identifier;
|
return t->identifier;
|
||||||
}
|
}
|
||||||
@@ -448,12 +420,12 @@ namespace chaiscript
|
|||||||
|
|
||||||
/// Errors generated when loading a file
|
/// Errors generated when loading a file
|
||||||
struct file_not_found_error : std::runtime_error {
|
struct file_not_found_error : std::runtime_error {
|
||||||
file_not_found_error(const std::string &t_filename) noexcept
|
file_not_found_error(const std::string &t_filename) CHAISCRIPT_NOEXCEPT
|
||||||
: std::runtime_error("File Not Found: " + t_filename)
|
: std::runtime_error("File Not Found: " + t_filename)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
file_not_found_error(const file_not_found_error &) = default;
|
file_not_found_error(const file_not_found_error &) = default;
|
||||||
virtual ~file_not_found_error() noexcept {}
|
virtual ~file_not_found_error() CHAISCRIPT_NOEXCEPT {}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -462,9 +434,11 @@ namespace chaiscript
|
|||||||
/// \brief Struct that doubles as both a parser ast_node and an AST node.
|
/// \brief Struct that doubles as both a parser ast_node and an AST node.
|
||||||
struct AST_Node : std::enable_shared_from_this<AST_Node> {
|
struct AST_Node : std::enable_shared_from_this<AST_Node> {
|
||||||
public:
|
public:
|
||||||
const AST_Node_Type identifier;
|
const int identifier; //< \todo shouldn't this be a strongly typed enum value?
|
||||||
const std::string text;
|
const std::string text;
|
||||||
Parse_Location location;
|
Parse_Location location;
|
||||||
|
std::vector<AST_NodePtr> children;
|
||||||
|
AST_NodePtr annotation;
|
||||||
|
|
||||||
const std::string &filename() const {
|
const std::string &filename() const {
|
||||||
return *location.filename;
|
return *location.filename;
|
||||||
@@ -478,22 +452,19 @@ namespace chaiscript
|
|||||||
return location.end;
|
return location.end;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string pretty_print() const
|
virtual std::string pretty_print() const
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
|
|
||||||
oss << text;
|
oss << text;
|
||||||
|
|
||||||
for (auto & elem : this->get_children()) {
|
for (auto & elem : this->children) {
|
||||||
oss << elem->pretty_print() << ' ';
|
oss << elem->pretty_print();
|
||||||
}
|
}
|
||||||
|
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual std::vector<AST_NodePtr> get_children() const = 0;
|
|
||||||
virtual Boxed_Value eval(const chaiscript::detail::Dispatch_State &t_e) const = 0;
|
|
||||||
|
|
||||||
|
|
||||||
/// Prints the contents of an AST node, including its children, recursively
|
/// Prints the contents of an AST node, including its children, recursively
|
||||||
std::string to_string(const std::string &t_prepend = "") const {
|
std::string to_string(const std::string &t_prepend = "") const {
|
||||||
@@ -502,16 +473,25 @@ namespace chaiscript
|
|||||||
oss << t_prepend << "(" << ast_node_type_to_string(this->identifier) << ") "
|
oss << t_prepend << "(" << ast_node_type_to_string(this->identifier) << ") "
|
||||||
<< this->text << " : " << this->location.start.line << ", " << this->location.start.column << '\n';
|
<< this->text << " : " << this->location.start.line << ", " << this->location.start.column << '\n';
|
||||||
|
|
||||||
for (auto & elem : this->get_children()) {
|
for (auto & elem : this->children) {
|
||||||
oss << elem->to_string(t_prepend + " ");
|
oss << elem->to_string(t_prepend + " ");
|
||||||
}
|
}
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Boxed_Value eval(const chaiscript::detail::Dispatch_State &t_e) const
|
||||||
static bool get_bool_condition(const Boxed_Value &t_bv) {
|
{
|
||||||
try {
|
try {
|
||||||
return boxed_cast<bool>(t_bv);
|
return eval_internal(t_e);
|
||||||
|
} catch (exception::eval_error &ee) {
|
||||||
|
ee.call_stack.push_back(shared_from_this());
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool get_bool_condition(const Boxed_Value &t_bv, const chaiscript::detail::Dispatch_State &t_ss) {
|
||||||
|
try {
|
||||||
|
return t_ss->boxed_cast<bool>(t_bv);
|
||||||
}
|
}
|
||||||
catch (const exception::bad_boxed_cast &) {
|
catch (const exception::bad_boxed_cast &) {
|
||||||
throw exception::eval_error("Condition not boolean");
|
throw exception::eval_error("Condition not boolean");
|
||||||
@@ -519,47 +499,33 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
virtual ~AST_Node() = default;
|
void replace_child(const AST_NodePtr &t_child, const AST_NodePtr &t_new_child)
|
||||||
AST_Node(AST_Node &&) = default;
|
{
|
||||||
AST_Node &operator=(AST_Node &&) = default;
|
std::replace(children.begin(), children.end(), t_child, t_new_child);
|
||||||
AST_Node(const AST_Node &) = delete;
|
}
|
||||||
AST_Node& operator=(const AST_Node &) = delete;
|
|
||||||
|
|
||||||
|
virtual ~AST_Node() {}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
AST_Node(std::string t_ast_node_text, AST_Node_Type t_id, Parse_Location t_loc)
|
AST_Node(std::string t_ast_node_text, int t_id, Parse_Location t_loc,
|
||||||
: identifier(t_id), text(std::move(t_ast_node_text)),
|
std::vector<AST_NodePtr> t_children = std::vector<AST_NodePtr>()) :
|
||||||
location(std::move(t_loc))
|
identifier(t_id), text(std::move(t_ast_node_text)),
|
||||||
|
location(std::move(t_loc)),
|
||||||
|
children(std::move(t_children))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &) const
|
||||||
|
{
|
||||||
|
throw std::runtime_error("Undispatched ast_node (internal error)");
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
// Copy and assignment explicitly unimplemented
|
||||||
|
AST_Node(const AST_Node &) = delete;
|
||||||
|
AST_Node& operator=(const AST_Node &) = delete;
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace parser {
|
|
||||||
class ChaiScript_Parser_Base
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual AST_NodePtr parse(const std::string &t_input, const std::string &t_fname) = 0;
|
|
||||||
virtual void debug_print(AST_NodePtr t, std::string prepend = "") const = 0;
|
|
||||||
virtual void *get_tracer_ptr() = 0;
|
|
||||||
virtual ~ChaiScript_Parser_Base() = default;
|
|
||||||
ChaiScript_Parser_Base() = default;
|
|
||||||
ChaiScript_Parser_Base(ChaiScript_Parser_Base &&) = default;
|
|
||||||
ChaiScript_Parser_Base &operator=(ChaiScript_Parser_Base &&) = delete;
|
|
||||||
ChaiScript_Parser_Base &operator=(const ChaiScript_Parser_Base &&) = delete;
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
T &get_tracer()
|
|
||||||
{
|
|
||||||
// to do type check this somehow?
|
|
||||||
return *static_cast<T*>(get_tracer_ptr());
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
ChaiScript_Parser_Base(const ChaiScript_Parser_Base &) = default;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace eval
|
namespace eval
|
||||||
{
|
{
|
||||||
@@ -588,83 +554,77 @@ namespace chaiscript
|
|||||||
/// Creates a new scope then pops it on destruction
|
/// Creates a new scope then pops it on destruction
|
||||||
struct Scope_Push_Pop
|
struct Scope_Push_Pop
|
||||||
{
|
{
|
||||||
Scope_Push_Pop(Scope_Push_Pop &&) = default;
|
|
||||||
Scope_Push_Pop& operator=(Scope_Push_Pop &&) = default;
|
|
||||||
Scope_Push_Pop(const Scope_Push_Pop &) = delete;
|
Scope_Push_Pop(const Scope_Push_Pop &) = delete;
|
||||||
Scope_Push_Pop& operator=(const Scope_Push_Pop &) = delete;
|
Scope_Push_Pop& operator=(const Scope_Push_Pop &) = delete;
|
||||||
|
|
||||||
Scope_Push_Pop(const chaiscript::detail::Dispatch_State &t_ds)
|
Scope_Push_Pop(const chaiscript::detail::Dispatch_State &t_ds)
|
||||||
: m_ds(t_ds)
|
: m_ds(t_ds)
|
||||||
{
|
{
|
||||||
m_ds->new_scope(m_ds.stack_holder());
|
m_ds.get()->new_scope(m_ds.get().stack_holder());
|
||||||
}
|
}
|
||||||
|
|
||||||
~Scope_Push_Pop()
|
~Scope_Push_Pop()
|
||||||
{
|
{
|
||||||
m_ds->pop_scope(m_ds.stack_holder());
|
m_ds.get()->pop_scope(m_ds.get().stack_holder());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const chaiscript::detail::Dispatch_State &m_ds;
|
std::reference_wrapper<const chaiscript::detail::Dispatch_State> m_ds;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Creates a new function call and pops it on destruction
|
/// Creates a new function call and pops it on destruction
|
||||||
struct Function_Push_Pop
|
struct Function_Push_Pop
|
||||||
{
|
{
|
||||||
Function_Push_Pop(Function_Push_Pop &&) = default;
|
|
||||||
Function_Push_Pop& operator=(Function_Push_Pop &&) = default;
|
|
||||||
Function_Push_Pop(const Function_Push_Pop &) = delete;
|
Function_Push_Pop(const Function_Push_Pop &) = delete;
|
||||||
Function_Push_Pop& operator=(const Function_Push_Pop &) = delete;
|
Function_Push_Pop& operator=(const Function_Push_Pop &) = delete;
|
||||||
|
|
||||||
Function_Push_Pop(const chaiscript::detail::Dispatch_State &t_ds)
|
Function_Push_Pop(const chaiscript::detail::Dispatch_State &t_ds)
|
||||||
: m_ds(t_ds)
|
: m_ds(t_ds)
|
||||||
{
|
{
|
||||||
m_ds->new_function_call(m_ds.stack_holder(), m_ds.conversion_saves());
|
m_ds.get()->new_function_call(m_ds.get().stack_holder(), m_ds.get().conversion_saves());
|
||||||
}
|
}
|
||||||
|
|
||||||
~Function_Push_Pop()
|
~Function_Push_Pop()
|
||||||
{
|
{
|
||||||
m_ds->pop_function_call(m_ds.stack_holder(), m_ds.conversion_saves());
|
m_ds.get()->pop_function_call(m_ds.get().stack_holder(), m_ds.get().conversion_saves());
|
||||||
}
|
}
|
||||||
|
|
||||||
void save_params(const std::vector<Boxed_Value> &t_params)
|
void save_params(const std::vector<Boxed_Value> &t_params)
|
||||||
{
|
{
|
||||||
m_ds->save_function_params(t_params);
|
m_ds.get()->save_function_params(t_params);
|
||||||
}
|
}
|
||||||
|
|
||||||
void save_params(std::initializer_list<Boxed_Value> t_params)
|
void save_params(std::initializer_list<Boxed_Value> t_params)
|
||||||
{
|
{
|
||||||
m_ds->save_function_params(std::move(t_params));
|
m_ds.get()->save_function_params(std::move(t_params));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const chaiscript::detail::Dispatch_State &m_ds;
|
std::reference_wrapper<const chaiscript::detail::Dispatch_State> m_ds;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Creates a new scope then pops it on destruction
|
/// Creates a new scope then pops it on destruction
|
||||||
struct Stack_Push_Pop
|
struct Stack_Push_Pop
|
||||||
{
|
{
|
||||||
Stack_Push_Pop(Stack_Push_Pop &&) = default;
|
|
||||||
Stack_Push_Pop& operator=(Stack_Push_Pop &&) = default;
|
|
||||||
Stack_Push_Pop(const Stack_Push_Pop &) = delete;
|
Stack_Push_Pop(const Stack_Push_Pop &) = delete;
|
||||||
Stack_Push_Pop& operator=(const Stack_Push_Pop &) = delete;
|
Stack_Push_Pop& operator=(const Stack_Push_Pop &) = delete;
|
||||||
|
|
||||||
Stack_Push_Pop(const chaiscript::detail::Dispatch_State &t_ds)
|
Stack_Push_Pop(const chaiscript::detail::Dispatch_State &t_ds)
|
||||||
: m_ds(t_ds)
|
: m_ds(t_ds)
|
||||||
{
|
{
|
||||||
m_ds->new_stack(m_ds.stack_holder());
|
m_ds.get()->new_stack(m_ds.get().stack_holder());
|
||||||
}
|
}
|
||||||
|
|
||||||
~Stack_Push_Pop()
|
~Stack_Push_Pop()
|
||||||
{
|
{
|
||||||
m_ds->pop_stack(m_ds.stack_holder());
|
m_ds.get()->pop_stack(m_ds.get().stack_holder());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const chaiscript::detail::Dispatch_State &m_ds;
|
std::reference_wrapper<const chaiscript::detail::Dispatch_State> m_ds;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -33,15 +33,14 @@
|
|||||||
|
|
||||||
#if defined(_POSIX_VERSION) && !defined(__CYGWIN__)
|
#if defined(_POSIX_VERSION) && !defined(__CYGWIN__)
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef CHAISCRIPT_WINDOWS
|
|
||||||
#include "chaiscript_windows.hpp"
|
|
||||||
#elif _POSIX_VERSION
|
|
||||||
#include "chaiscript_posix.hpp"
|
|
||||||
#else
|
#else
|
||||||
#include "chaiscript_unknown.hpp"
|
#ifdef CHAISCRIPT_WINDOWS
|
||||||
|
#define VC_EXTRA_LEAN
|
||||||
|
#if !defined(WIN32_LEAN_AND_MEAN)
|
||||||
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
#endif
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@@ -50,9 +49,205 @@
|
|||||||
|
|
||||||
namespace chaiscript
|
namespace chaiscript
|
||||||
{
|
{
|
||||||
|
namespace exception
|
||||||
|
{
|
||||||
|
/// \brief Thrown if an error occurs while attempting to load a binary module
|
||||||
|
struct load_module_error : std::runtime_error
|
||||||
|
{
|
||||||
|
load_module_error(const std::string &t_reason) CHAISCRIPT_NOEXCEPT
|
||||||
|
: std::runtime_error(t_reason)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
load_module_error(const load_module_error &) = default;
|
||||||
|
virtual ~load_module_error() CHAISCRIPT_NOEXCEPT {}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
namespace detail
|
namespace detail
|
||||||
{
|
{
|
||||||
|
#if defined(_POSIX_VERSION) && !defined(__CYGWIN__)
|
||||||
|
struct Loadable_Module
|
||||||
|
{
|
||||||
|
struct DLModule
|
||||||
|
{
|
||||||
|
DLModule(const std::string &t_filename)
|
||||||
|
: m_data(dlopen(t_filename.c_str(), RTLD_NOW))
|
||||||
|
{
|
||||||
|
if (!m_data)
|
||||||
|
{
|
||||||
|
throw chaiscript::exception::load_module_error(dlerror());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DLModule(const DLModule &); // Explicitly unimplemented copy constructor
|
||||||
|
DLModule &operator=(const DLModule &); // Explicitly unimplemented assignment operator
|
||||||
|
|
||||||
|
~DLModule()
|
||||||
|
{
|
||||||
|
dlclose(m_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
void *m_data;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct DLSym
|
||||||
|
{
|
||||||
|
DLSym(DLModule &t_mod, const std::string &t_symbol)
|
||||||
|
: m_symbol(cast_symbol(dlsym(t_mod.m_data, t_symbol.c_str())))
|
||||||
|
{
|
||||||
|
if (!m_symbol)
|
||||||
|
{
|
||||||
|
throw chaiscript::exception::load_module_error(dlerror());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static T cast_symbol(void *p)
|
||||||
|
{
|
||||||
|
union cast_union
|
||||||
|
{
|
||||||
|
T func_ptr;
|
||||||
|
void *in_ptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
cast_union c;
|
||||||
|
c.in_ptr = p;
|
||||||
|
return c.func_ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
T m_symbol;
|
||||||
|
};
|
||||||
|
|
||||||
|
Loadable_Module(const std::string &t_module_name, const std::string &t_filename)
|
||||||
|
: m_dlmodule(t_filename), m_func(m_dlmodule, "create_chaiscript_module_" + t_module_name),
|
||||||
|
m_moduleptr(m_func.m_symbol())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
DLModule m_dlmodule;
|
||||||
|
DLSym<Create_Module_Func> m_func;
|
||||||
|
ModulePtr m_moduleptr;
|
||||||
|
};
|
||||||
|
#else
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
|
||||||
|
|
||||||
|
struct Loadable_Module
|
||||||
|
{
|
||||||
|
template<typename T>
|
||||||
|
static std::wstring to_wstring(const T &t_str)
|
||||||
|
{
|
||||||
|
return std::wstring(t_str.begin(), t_str.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
static std::string to_string(const T &t_str)
|
||||||
|
{
|
||||||
|
return std::string(t_str.begin(), t_str.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(_UNICODE) || defined(UNICODE)
|
||||||
|
template<typename T>
|
||||||
|
static std::wstring to_proper_string(const T &t_str)
|
||||||
|
{
|
||||||
|
return to_wstring(t_str);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
template<typename T>
|
||||||
|
static std::string to_proper_string(const T &t_str)
|
||||||
|
{
|
||||||
|
return to_string(t_str);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static std::string get_error_message(DWORD t_err)
|
||||||
|
{
|
||||||
|
typedef LPTSTR StringType;
|
||||||
|
|
||||||
|
#if defined(_UNICODE) || defined(UNICODE)
|
||||||
|
std::wstring retval = L"Unknown Error";
|
||||||
|
#else
|
||||||
|
std::string retval = "Unknown Error";
|
||||||
|
#endif
|
||||||
|
StringType lpMsgBuf = nullptr;
|
||||||
|
|
||||||
|
if (FormatMessage(
|
||||||
|
FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
||||||
|
FORMAT_MESSAGE_FROM_SYSTEM |
|
||||||
|
FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||||
|
nullptr,
|
||||||
|
t_err,
|
||||||
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||||
|
reinterpret_cast<StringType>(&lpMsgBuf),
|
||||||
|
0, nullptr ) != 0 && lpMsgBuf)
|
||||||
|
{
|
||||||
|
retval = lpMsgBuf;
|
||||||
|
LocalFree(lpMsgBuf);
|
||||||
|
}
|
||||||
|
|
||||||
|
return to_string(retval);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct DLModule
|
||||||
|
{
|
||||||
|
DLModule(const std::string &t_filename)
|
||||||
|
: m_data(LoadLibrary(to_proper_string(t_filename).c_str()))
|
||||||
|
{
|
||||||
|
if (!m_data)
|
||||||
|
{
|
||||||
|
throw chaiscript::exception::load_module_error(get_error_message(GetLastError()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
~DLModule()
|
||||||
|
{
|
||||||
|
FreeLibrary(m_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
HMODULE m_data;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct DLSym
|
||||||
|
{
|
||||||
|
DLSym(DLModule &t_mod, const std::string &t_symbol)
|
||||||
|
: m_symbol(reinterpret_cast<T>(GetProcAddress(t_mod.m_data, t_symbol.c_str())))
|
||||||
|
{
|
||||||
|
if (!m_symbol)
|
||||||
|
{
|
||||||
|
throw chaiscript::exception::load_module_error(get_error_message(GetLastError()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
T m_symbol;
|
||||||
|
};
|
||||||
|
|
||||||
|
Loadable_Module(const std::string &t_module_name, const std::string &t_filename)
|
||||||
|
: m_dlmodule(t_filename), m_func(m_dlmodule, "create_chaiscript_module_" + t_module_name),
|
||||||
|
m_moduleptr(m_func.m_symbol())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
DLModule m_dlmodule;
|
||||||
|
DLSym<Create_Module_Func> m_func;
|
||||||
|
ModulePtr m_moduleptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
#else
|
||||||
|
struct Loadable_Module
|
||||||
|
{
|
||||||
|
Loadable_Module(const std::string &, const std::string &)
|
||||||
|
{
|
||||||
|
throw chaiscript::exception::load_module_error("Loadable module support not available for your platform");
|
||||||
|
}
|
||||||
|
|
||||||
|
ModulePtr m_moduleptr;
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef std::shared_ptr<Loadable_Module> Loadable_Module_Ptr;
|
typedef std::shared_ptr<Loadable_Module> Loadable_Module_Ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,16 +265,19 @@ namespace chaiscript
|
|||||||
std::vector<std::string> m_module_paths;
|
std::vector<std::string> m_module_paths;
|
||||||
std::vector<std::string> m_use_paths;
|
std::vector<std::string> m_use_paths;
|
||||||
|
|
||||||
std::unique_ptr<parser::ChaiScript_Parser_Base> m_parser;
|
|
||||||
|
|
||||||
chaiscript::detail::Dispatch_Engine m_engine;
|
chaiscript::detail::Dispatch_Engine m_engine;
|
||||||
|
|
||||||
/// Evaluates the given string in by parsing it and running the results through the evaluator
|
/// Evaluates the given string in by parsing it and running the results through the evaluator
|
||||||
Boxed_Value do_eval(const std::string &t_input, const std::string &t_filename = "__EVAL__", bool /* t_internal*/ = false)
|
Boxed_Value do_eval(const std::string &t_input, const std::string &t_filename = "__EVAL__", bool /* t_internal*/ = false)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
const auto p = m_parser->parse(t_input, t_filename);
|
parser::ChaiScript_Parser parser;
|
||||||
return p->eval(m_engine);
|
if (parser.parse(t_input, t_filename)) {
|
||||||
|
//parser.show_match_stack();
|
||||||
|
return parser.optimized_ast()->eval(m_engine);
|
||||||
|
} else {
|
||||||
|
return Boxed_Value();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (chaiscript::eval::detail::Return_Value &rv) {
|
catch (chaiscript::eval::detail::Return_Value &rv) {
|
||||||
return rv.retval;
|
return rv.retval;
|
||||||
@@ -88,6 +286,8 @@ namespace chaiscript
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// Evaluates the given file and looks in the 'use' paths
|
/// Evaluates the given file and looks in the 'use' paths
|
||||||
const Boxed_Value internal_eval_file(const std::string &t_filename) {
|
const Boxed_Value internal_eval_file(const std::string &t_filename) {
|
||||||
for (const auto &path : m_use_paths)
|
for (const auto &path : m_use_paths)
|
||||||
@@ -125,6 +325,27 @@ namespace chaiscript
|
|||||||
|
|
||||||
/// Builds all the requirements for ChaiScript, including its evaluator and a run of its prelude.
|
/// Builds all the requirements for ChaiScript, including its evaluator and a run of its prelude.
|
||||||
void build_eval_system(const ModulePtr &t_lib) {
|
void build_eval_system(const ModulePtr &t_lib) {
|
||||||
|
m_engine.add_reserved_word("def");
|
||||||
|
m_engine.add_reserved_word("fun");
|
||||||
|
m_engine.add_reserved_word("while");
|
||||||
|
m_engine.add_reserved_word("for");
|
||||||
|
m_engine.add_reserved_word("if");
|
||||||
|
m_engine.add_reserved_word("else");
|
||||||
|
m_engine.add_reserved_word("&&");
|
||||||
|
m_engine.add_reserved_word("||");
|
||||||
|
m_engine.add_reserved_word(",");
|
||||||
|
m_engine.add_reserved_word("auto");
|
||||||
|
m_engine.add_reserved_word("return");
|
||||||
|
m_engine.add_reserved_word("break");
|
||||||
|
m_engine.add_reserved_word("true");
|
||||||
|
m_engine.add_reserved_word("false");
|
||||||
|
m_engine.add_reserved_word("class");
|
||||||
|
m_engine.add_reserved_word("attr");
|
||||||
|
m_engine.add_reserved_word("var");
|
||||||
|
m_engine.add_reserved_word("global");
|
||||||
|
m_engine.add_reserved_word("GLOBAL");
|
||||||
|
m_engine.add_reserved_word("_");
|
||||||
|
|
||||||
if (t_lib)
|
if (t_lib)
|
||||||
{
|
{
|
||||||
add(t_lib);
|
add(t_lib);
|
||||||
@@ -176,10 +397,16 @@ namespace chaiscript
|
|||||||
m_engine.add(fun([this](const std::string &t_file){ return internal_eval_file(t_file); }), "eval_file");
|
m_engine.add(fun([this](const std::string &t_file){ return internal_eval_file(t_file); }), "eval_file");
|
||||||
m_engine.add(fun([this](const std::string &t_str){ return internal_eval(t_str); }), "eval");
|
m_engine.add(fun([this](const std::string &t_str){ return internal_eval(t_str); }), "eval");
|
||||||
m_engine.add(fun([this](const AST_NodePtr &t_ast){ return eval(t_ast); }), "eval");
|
m_engine.add(fun([this](const AST_NodePtr &t_ast){ return eval(t_ast); }), "eval");
|
||||||
|
m_engine.add(fun(&parse), "parse");
|
||||||
|
|
||||||
m_engine.add(fun([this](const std::string &t_str, const bool t_dump){ return parse(t_str, t_dump); }), "parse");
|
m_engine.add(fun(&ChaiScript::version_major), "version_major");
|
||||||
m_engine.add(fun([this](const std::string &t_str){ return parse(t_str); }), "parse");
|
m_engine.add(fun(&ChaiScript::version_minor), "version_minor");
|
||||||
|
m_engine.add(fun(&ChaiScript::version_patch), "version_patch");
|
||||||
|
m_engine.add(fun(&ChaiScript::version), "version");
|
||||||
|
m_engine.add(fun(&ChaiScript::compiler_version), "compiler_version");
|
||||||
|
m_engine.add(fun(&ChaiScript::compiler_name), "compiler_name");
|
||||||
|
m_engine.add(fun(&ChaiScript::compiler_id), "compiler_id");
|
||||||
|
m_engine.add(fun(&ChaiScript::debug_build), "debug_build");
|
||||||
|
|
||||||
m_engine.add(fun([this](const Boxed_Value &t_bv, const std::string &t_name){ add_global_const(t_bv, t_name); }), "add_global_const");
|
m_engine.add(fun([this](const Boxed_Value &t_bv, const std::string &t_name){ add_global_const(t_bv, t_name); }), "add_global_const");
|
||||||
m_engine.add(fun([this](const Boxed_Value &t_bv, const std::string &t_name){ add_global(t_bv, t_name); }), "add_global");
|
m_engine.add(fun([this](const Boxed_Value &t_bv, const std::string &t_name){ add_global(t_bv, t_name); }), "add_global");
|
||||||
@@ -218,10 +445,7 @@ namespace chaiscript
|
|||||||
ChaiScript(const ModulePtr &t_lib,
|
ChaiScript(const ModulePtr &t_lib,
|
||||||
std::vector<std::string> t_modulepaths = std::vector<std::string>(),
|
std::vector<std::string> t_modulepaths = std::vector<std::string>(),
|
||||||
std::vector<std::string> t_usepaths = std::vector<std::string>())
|
std::vector<std::string> t_usepaths = std::vector<std::string>())
|
||||||
: m_module_paths(std::move(t_modulepaths)), m_use_paths(std::move(t_usepaths)),
|
: m_module_paths(std::move(t_modulepaths)), m_use_paths(std::move(t_usepaths))
|
||||||
m_parser(std::make_unique<parser::ChaiScript_Parser<eval::Noop_Tracer, optimizer::Optimizer<optimizer::Block, optimizer::Caching_Id, optimizer::Constant_Fold, optimizer::If, optimizer::Return, optimizer::For_Loop>>>()),
|
|
||||||
m_engine(*m_parser)
|
|
||||||
|
|
||||||
{
|
{
|
||||||
if (m_module_paths.empty())
|
if (m_module_paths.empty())
|
||||||
{
|
{
|
||||||
@@ -245,9 +469,7 @@ namespace chaiscript
|
|||||||
/// \param[in] t_usepaths Vector of paths to search when attempting to "use" an included ChaiScript file
|
/// \param[in] t_usepaths Vector of paths to search when attempting to "use" an included ChaiScript file
|
||||||
ChaiScript( std::vector<std::string> t_modulepaths = std::vector<std::string>(),
|
ChaiScript( std::vector<std::string> t_modulepaths = std::vector<std::string>(),
|
||||||
std::vector<std::string> t_usepaths = std::vector<std::string>())
|
std::vector<std::string> t_usepaths = std::vector<std::string>())
|
||||||
: m_module_paths(std::move(t_modulepaths)), m_use_paths(std::move(t_usepaths)),
|
: m_module_paths(std::move(t_modulepaths)), m_use_paths(std::move(t_usepaths))
|
||||||
m_parser(std::make_unique<parser::ChaiScript_Parser<eval::Noop_Tracer, optimizer::Optimizer<optimizer::Block, optimizer::Caching_Id, optimizer::Constant_Fold, optimizer::If, optimizer::Return, optimizer::For_Loop>>>()),
|
|
||||||
m_engine(*m_parser)
|
|
||||||
{
|
{
|
||||||
if (m_module_paths.empty())
|
if (m_module_paths.empty())
|
||||||
{
|
{
|
||||||
@@ -294,21 +516,8 @@ namespace chaiscript
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
try {
|
// attempt to load the stdlib
|
||||||
// attempt to load the stdlib
|
load_module("chaiscript_stdlib-" + version());
|
||||||
load_module("chaiscript_stdlib-" + Build_Info::version());
|
|
||||||
} catch (const exception::load_module_error &t_err) {
|
|
||||||
std::cout << "An error occured while trying to load the chaiscript standard library.\n"
|
|
||||||
<< "\n"
|
|
||||||
<< "You must either provide a standard library, or compile it in.\n"
|
|
||||||
<< "For an example of compiling the standard library in,\n"
|
|
||||||
<< "see: https://gist.github.com/lefticus/9456197\n"
|
|
||||||
<< "Compiling the stdlib in is the recommended and MOST SUPPORTED method.\n"
|
|
||||||
<< "\n"
|
|
||||||
<< "\n"
|
|
||||||
<< t_err.what();
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
|
|
||||||
build_eval_system(ModulePtr());
|
build_eval_system(ModulePtr());
|
||||||
}
|
}
|
||||||
@@ -323,16 +532,65 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AST_NodePtr parse(const std::string &t_input, const bool t_debug_print = false)
|
static AST_NodePtr parse(const std::string &t_input)
|
||||||
{
|
{
|
||||||
const auto ast = m_parser->parse(t_input, "PARSE");
|
parser::ChaiScript_Parser parser;
|
||||||
if (t_debug_print) {
|
if (parser.parse(t_input, "PARSE")) {
|
||||||
m_parser->debug_print(ast);
|
//parser.show_match_stack();
|
||||||
|
return parser.optimized_ast();
|
||||||
|
} else {
|
||||||
|
throw chaiscript::exception::eval_error("Unknown error while parsing");
|
||||||
}
|
}
|
||||||
return ast;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int version_major()
|
||||||
|
{
|
||||||
|
return chaiscript::version_major;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int version_minor()
|
||||||
|
{
|
||||||
|
return chaiscript::version_minor;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int version_patch()
|
||||||
|
{
|
||||||
|
return chaiscript::version_patch;
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::string version()
|
||||||
|
{
|
||||||
|
return std::to_string(version_major()) + '.' + std::to_string(version_minor()) + '.' + std::to_string(version_patch());
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::string compiler_id()
|
||||||
|
{
|
||||||
|
return compiler_name() + '-' + compiler_version();
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::string build_id()
|
||||||
|
{
|
||||||
|
return compiler_id() + (debug_build()?"-Debug":"-Release");
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::string compiler_version()
|
||||||
|
{
|
||||||
|
return chaiscript::compiler_version;
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::string compiler_name()
|
||||||
|
{
|
||||||
|
return chaiscript::compiler_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool debug_build()
|
||||||
|
{
|
||||||
|
return chaiscript::debug_build;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
std::string get_type_name(const Type_Info &ti) const
|
std::string get_type_name(const Type_Info &ti) const
|
||||||
{
|
{
|
||||||
return m_engine.get_type_name(ti);
|
return m_engine.get_type_name(ti);
|
||||||
@@ -547,7 +805,7 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
std::vector<exception::load_module_error> errors;
|
std::vector<exception::load_module_error> errors;
|
||||||
std::string version_stripped_name = t_module_name;
|
std::string version_stripped_name = t_module_name;
|
||||||
size_t version_pos = version_stripped_name.find("-" + Build_Info::version());
|
size_t version_pos = version_stripped_name.find("-"+version());
|
||||||
if (version_pos != std::string::npos)
|
if (version_pos != std::string::npos)
|
||||||
{
|
{
|
||||||
version_stripped_name.erase(version_pos);
|
version_stripped_name.erase(version_pos);
|
||||||
@@ -577,7 +835,21 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
throw chaiscript::exception::load_module_error(t_module_name, errors);
|
std::string errstring;
|
||||||
|
|
||||||
|
for (std::vector<exception::load_module_error>::const_iterator itr = errors.begin();
|
||||||
|
itr != errors.end();
|
||||||
|
++itr)
|
||||||
|
{
|
||||||
|
if (!errstring.empty())
|
||||||
|
{
|
||||||
|
errstring += "; ";
|
||||||
|
}
|
||||||
|
|
||||||
|
errstring += itr->what();
|
||||||
|
}
|
||||||
|
|
||||||
|
throw chaiscript::exception::load_module_error("Unable to find module: " + t_module_name + " Errors: " + errstring);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \brief Load a binary module from a dynamic library. Works on platforms that support
|
/// \brief Load a binary module from a dynamic library. Works on platforms that support
|
||||||
@@ -614,7 +886,14 @@ namespace chaiscript
|
|||||||
/// \throw chaiscript::exception::eval_error In the case that evaluation fails.
|
/// \throw chaiscript::exception::eval_error In the case that evaluation fails.
|
||||||
Boxed_Value operator()(const std::string &t_script, const Exception_Handler &t_handler = Exception_Handler())
|
Boxed_Value operator()(const std::string &t_script, const Exception_Handler &t_handler = Exception_Handler())
|
||||||
{
|
{
|
||||||
return eval(t_script, t_handler);
|
try {
|
||||||
|
return do_eval(t_script);
|
||||||
|
} catch (Boxed_Value &bv) {
|
||||||
|
if (t_handler) {
|
||||||
|
t_handler->handle(bv, m_engine);
|
||||||
|
}
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \brief Evaluates a string and returns a typesafe result.
|
/// \brief Evaluates a string and returns a typesafe result.
|
||||||
@@ -633,14 +912,21 @@ namespace chaiscript
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
T eval(const std::string &t_input, const Exception_Handler &t_handler = Exception_Handler(), const std::string &t_filename="__EVAL__")
|
T eval(const std::string &t_input, const Exception_Handler &t_handler = Exception_Handler(), const std::string &t_filename="__EVAL__")
|
||||||
{
|
{
|
||||||
return m_engine.boxed_cast<T>(eval(t_input, t_handler, t_filename));
|
try {
|
||||||
|
return m_engine.boxed_cast<T>(do_eval(t_input, t_filename));
|
||||||
|
} catch (Boxed_Value &bv) {
|
||||||
|
if (t_handler) {
|
||||||
|
t_handler->handle(bv, m_engine);
|
||||||
|
}
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \brief casts an object while applying any Dynamic_Conversion available
|
/// \brief casts an object while applying any Dynamic_Conversion available
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
decltype(auto) boxed_cast(const Boxed_Value &bv) const
|
typename detail::Cast_Helper<Type>::Result_Type boxed_cast(const Boxed_Value &bv) const
|
||||||
{
|
{
|
||||||
return(m_engine.boxed_cast<Type>(bv));
|
return m_engine.boxed_cast<Type>(bv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -672,7 +958,14 @@ namespace chaiscript
|
|||||||
/// \return result of the script execution
|
/// \return result of the script execution
|
||||||
/// \throw chaiscript::exception::eval_error In the case that evaluation fails.
|
/// \throw chaiscript::exception::eval_error In the case that evaluation fails.
|
||||||
Boxed_Value eval_file(const std::string &t_filename, const Exception_Handler &t_handler = Exception_Handler()) {
|
Boxed_Value eval_file(const std::string &t_filename, const Exception_Handler &t_handler = Exception_Handler()) {
|
||||||
return eval(load_file(t_filename), t_handler, t_filename);
|
try {
|
||||||
|
return do_eval(load_file(t_filename), t_filename);
|
||||||
|
} catch (Boxed_Value &bv) {
|
||||||
|
if (t_handler) {
|
||||||
|
t_handler->handle(bv, m_engine);
|
||||||
|
}
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \brief Loads the file specified by filename, evaluates it, and returns the type safe result.
|
/// \brief Loads the file specified by filename, evaluates it, and returns the type safe result.
|
||||||
@@ -685,7 +978,14 @@ namespace chaiscript
|
|||||||
/// to the requested type.
|
/// to the requested type.
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T eval_file(const std::string &t_filename, const Exception_Handler &t_handler = Exception_Handler()) {
|
T eval_file(const std::string &t_filename, const Exception_Handler &t_handler = Exception_Handler()) {
|
||||||
return m_engine.boxed_cast<T>(eval_file(t_filename, t_handler));
|
try {
|
||||||
|
return m_engine.boxed_cast<T>(do_eval(load_file(t_filename), t_filename));
|
||||||
|
} catch (Boxed_Value &bv) {
|
||||||
|
if (t_handler) {
|
||||||
|
t_handler->handle(bv, m_engine);
|
||||||
|
}
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
@@ -1,284 +0,0 @@
|
|||||||
// This file is distributed under the BSD License.
|
|
||||||
// See "license.txt" for details.
|
|
||||||
// Copyright 2009-2012, Jonathan Turner (jonathan@emptycrate.com)
|
|
||||||
// Copyright 2009-2016, Jason Turner (jason@emptycrate.com)
|
|
||||||
// http://www.chaiscript.com
|
|
||||||
|
|
||||||
#ifndef CHAISCRIPT_OPTIMIZER_HPP_
|
|
||||||
#define CHAISCRIPT_OPTIMIZER_HPP_
|
|
||||||
|
|
||||||
#include "chaiscript_eval.hpp"
|
|
||||||
|
|
||||||
|
|
||||||
namespace chaiscript {
|
|
||||||
namespace optimizer {
|
|
||||||
|
|
||||||
template<typename ... T>
|
|
||||||
struct Optimizer : T...
|
|
||||||
{
|
|
||||||
Optimizer() = default;
|
|
||||||
Optimizer(T ... t)
|
|
||||||
: T(std::move(t))...
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Tracer>
|
|
||||||
auto optimize(eval::AST_Node_Impl_Ptr<Tracer> p) {
|
|
||||||
(void)std::initializer_list<int>{ (p = T::optimize(p), 0)... };
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
auto child_at(const eval::AST_Node_Impl_Ptr<T> &node, const size_t offset) {
|
|
||||||
if (node->identifier == AST_Node_Type::Compiled) {
|
|
||||||
return dynamic_cast<const eval::Compiled_AST_Node<T>&>(*node).m_original_node->children[offset];
|
|
||||||
} else {
|
|
||||||
return node->children[offset];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
auto child_count(const eval::AST_Node_Impl_Ptr<T> &node) {
|
|
||||||
if (node->identifier == AST_Node_Type::Compiled) {
|
|
||||||
return dynamic_cast<const eval::Compiled_AST_Node<T>&>(*node).m_original_node->children.size();
|
|
||||||
} else {
|
|
||||||
return node->children.size();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T, typename Callable>
|
|
||||||
auto make_compiled_node(const eval::AST_Node_Impl_Ptr<T> &original_node, std::vector<eval::AST_Node_Impl_Ptr<T>> children, Callable callable)
|
|
||||||
{
|
|
||||||
return chaiscript::make_shared<eval::AST_Node_Impl<T>, eval::Compiled_AST_Node<T>>(original_node, std::move(children), std::move(callable));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
struct Return {
|
|
||||||
template<typename T>
|
|
||||||
auto optimize(const eval::AST_Node_Impl_Ptr<T> &p)
|
|
||||||
{
|
|
||||||
if (p->identifier == AST_Node_Type::Def
|
|
||||||
&& !p->children.empty())
|
|
||||||
{
|
|
||||||
auto &last_child = p->children.back();
|
|
||||||
if (last_child->identifier == AST_Node_Type::Block) {
|
|
||||||
auto &block_last_child = last_child->children.back();
|
|
||||||
if (block_last_child->identifier == AST_Node_Type::Return) {
|
|
||||||
if (block_last_child->children.size() == 1) {
|
|
||||||
last_child->children.back() = block_last_child->children[0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
bool contains_var_decl_in_scope(const T &node)
|
|
||||||
{
|
|
||||||
if (node->identifier == AST_Node_Type::Var_Decl) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto num = child_count(node);
|
|
||||||
|
|
||||||
for (size_t i = 0; i < num; ++i) {
|
|
||||||
const auto &child = child_at(node, i);
|
|
||||||
if (child->identifier != AST_Node_Type::Block
|
|
||||||
&& contains_var_decl_in_scope(child)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Block {
|
|
||||||
template<typename T>
|
|
||||||
auto optimize(const eval::AST_Node_Impl_Ptr<T> &node) {
|
|
||||||
if (node->identifier == AST_Node_Type::Block
|
|
||||||
&& node->children.size() == 1
|
|
||||||
&& !contains_var_decl_in_scope(node))
|
|
||||||
{
|
|
||||||
return node->children[0];
|
|
||||||
} else {
|
|
||||||
return node;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct If {
|
|
||||||
template<typename T>
|
|
||||||
auto optimize(const eval::AST_Node_Impl_Ptr<T> &node) {
|
|
||||||
if (node->identifier == AST_Node_Type::If
|
|
||||||
&& node->children.size() >= 2
|
|
||||||
&& node->children[0]->identifier == AST_Node_Type::Constant)
|
|
||||||
{
|
|
||||||
const auto condition = std::dynamic_pointer_cast<eval::Constant_AST_Node<T>>(node->children[0])->m_value;
|
|
||||||
if (condition.get_type_info().bare_equal_type_info(typeid(bool))) {
|
|
||||||
if (boxed_cast<bool>(condition)) {
|
|
||||||
return node->children[1];
|
|
||||||
} else if (node->children.size() == 3) {
|
|
||||||
return node->children[2];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return node;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Caching_Id {
|
|
||||||
template<typename T>
|
|
||||||
auto optimize(const eval::AST_Node_Impl_Ptr<T> &node) {
|
|
||||||
if (node->identifier == AST_Node_Type::Id)
|
|
||||||
{
|
|
||||||
return chaiscript::make_shared<eval::AST_Node_Impl<T>, eval::Caching_Id_AST_Node<T>>(node->text, node->location);
|
|
||||||
} else {
|
|
||||||
return node;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Constant_Fold {
|
|
||||||
template<typename T>
|
|
||||||
auto optimize(const eval::AST_Node_Impl_Ptr<T> &node) {
|
|
||||||
|
|
||||||
if (node->identifier == AST_Node_Type::Binary
|
|
||||||
&& node->children.size() == 2
|
|
||||||
&& node->children[0]->identifier == AST_Node_Type::Constant
|
|
||||||
&& node->children[1]->identifier == AST_Node_Type::Constant)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
const auto &oper = node->text;
|
|
||||||
const auto parsed = Operators::to_operator(oper);
|
|
||||||
if (parsed != Operators::Opers::invalid) {
|
|
||||||
const auto lhs = std::dynamic_pointer_cast<eval::Constant_AST_Node<T>>(node->children[0])->m_value;
|
|
||||||
const auto rhs = std::dynamic_pointer_cast<eval::Constant_AST_Node<T>>(node->children[1])->m_value;
|
|
||||||
if (lhs.get_type_info().is_arithmetic() && rhs.get_type_info().is_arithmetic()) {
|
|
||||||
const auto val = Boxed_Number::do_oper(parsed, lhs, rhs);
|
|
||||||
const auto match = node->children[0]->text + " " + oper + " " + node->children[1]->text;
|
|
||||||
return chaiscript::make_shared<eval::AST_Node_Impl<T>, eval::Constant_AST_Node<T>>(std::move(match), node->location, std::move(val));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (const std::exception &) {
|
|
||||||
//failure to fold, that's OK
|
|
||||||
}
|
|
||||||
} else if (node->identifier == AST_Node_Type::Fun_Call
|
|
||||||
&& node->children.size() == 2
|
|
||||||
&& node->children[0]->identifier == AST_Node_Type::Id
|
|
||||||
&& node->children[1]->identifier == AST_Node_Type::Arg_List
|
|
||||||
&& node->children[1]->children.size() == 1
|
|
||||||
&& node->children[1]->children[0]->identifier == AST_Node_Type::Constant) {
|
|
||||||
|
|
||||||
const auto arg = std::dynamic_pointer_cast<eval::Constant_AST_Node<T>>(node->children[1]->children[0])->m_value;
|
|
||||||
if (arg.get_type_info().is_arithmetic()) {
|
|
||||||
const auto &fun_name = node->children[0]->text;
|
|
||||||
|
|
||||||
const auto make_constant = [&node, &fun_name](auto val){
|
|
||||||
const auto match = fun_name + "(" + node->children[1]->children[0]->text + ")";
|
|
||||||
return chaiscript::make_shared<eval::AST_Node_Impl<T>, eval::Constant_AST_Node<T>>(std::move(match), node->location, Boxed_Value(val));
|
|
||||||
};
|
|
||||||
|
|
||||||
if (fun_name == "double") {
|
|
||||||
return make_constant(Boxed_Number(arg).get_as<double>());
|
|
||||||
} else if (fun_name == "int") {
|
|
||||||
return make_constant(Boxed_Number(arg).get_as<int>());
|
|
||||||
} else if (fun_name == "float") {
|
|
||||||
return make_constant(Boxed_Number(arg).get_as<float>());
|
|
||||||
} else if (fun_name == "long") {
|
|
||||||
return make_constant(Boxed_Number(arg).get_as<long>());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return node;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct For_Loop {
|
|
||||||
template<typename T>
|
|
||||||
auto optimize(const eval::AST_Node_Impl_Ptr<T> &for_node) {
|
|
||||||
|
|
||||||
if (for_node->identifier != AST_Node_Type::For) {
|
|
||||||
return for_node;
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto eq_node = child_at(for_node, 0);
|
|
||||||
const auto binary_node = child_at(for_node, 1);
|
|
||||||
const auto prefix_node = child_at(for_node, 2);
|
|
||||||
|
|
||||||
if (eq_node->identifier == AST_Node_Type::Equation
|
|
||||||
&& child_count(eq_node) == 2
|
|
||||||
&& child_at(eq_node, 0)->identifier == AST_Node_Type::Var_Decl
|
|
||||||
&& child_at(eq_node, 1)->identifier == AST_Node_Type::Constant
|
|
||||||
&& binary_node->identifier == AST_Node_Type::Binary
|
|
||||||
&& binary_node->text == "<"
|
|
||||||
&& child_count(binary_node) == 2
|
|
||||||
&& child_at(binary_node, 0)->identifier == AST_Node_Type::Id
|
|
||||||
&& child_at(binary_node, 0)->text == child_at(child_at(eq_node,0), 0)->text
|
|
||||||
&& child_at(binary_node, 1)->identifier == AST_Node_Type::Constant
|
|
||||||
&& prefix_node->identifier == AST_Node_Type::Prefix
|
|
||||||
&& prefix_node->text == "++"
|
|
||||||
&& child_count(prefix_node) == 1
|
|
||||||
&& child_at(prefix_node, 0)->identifier == AST_Node_Type::Id
|
|
||||||
&& child_at(prefix_node, 0)->text == child_at(child_at(eq_node,0), 0)->text)
|
|
||||||
{
|
|
||||||
const Boxed_Value &begin = std::dynamic_pointer_cast<const eval::Constant_AST_Node<T>>(child_at(eq_node, 1))->m_value;
|
|
||||||
const Boxed_Value &end = std::dynamic_pointer_cast<const eval::Constant_AST_Node<T>>(child_at(binary_node, 1))->m_value;
|
|
||||||
const std::string &id = child_at(prefix_node, 0)->text;
|
|
||||||
|
|
||||||
if (begin.get_type_info().bare_equal(user_type<int>())
|
|
||||||
&& end.get_type_info().bare_equal(user_type<int>())) {
|
|
||||||
|
|
||||||
const auto start_int = boxed_cast<int>(begin);
|
|
||||||
const auto end_int = boxed_cast<int>(end);
|
|
||||||
|
|
||||||
const auto body = child_at(for_node, 3);
|
|
||||||
|
|
||||||
return make_compiled_node(for_node, {body},
|
|
||||||
[id, start_int, end_int](const std::vector<eval::AST_Node_Impl_Ptr<T>> &children, const chaiscript::detail::Dispatch_State &t_ss) {
|
|
||||||
assert(children.size() == 1);
|
|
||||||
chaiscript::eval::detail::Scope_Push_Pop spp(t_ss);
|
|
||||||
|
|
||||||
int i = start_int;
|
|
||||||
t_ss.add_object(id, var(&i));
|
|
||||||
|
|
||||||
try {
|
|
||||||
for (; i < end_int; ++i) {
|
|
||||||
try {
|
|
||||||
// Body of Loop
|
|
||||||
children[0]->eval(t_ss);
|
|
||||||
} catch (eval::detail::Continue_Loop &) {
|
|
||||||
// we got a continue exception, which means all of the remaining
|
|
||||||
// loop implementation is skipped and we just need to continue to
|
|
||||||
// the next iteration step
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (eval::detail::Break_Loop &) {
|
|
||||||
// loop broken
|
|
||||||
}
|
|
||||||
|
|
||||||
return void_var();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
return for_node;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return for_node;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
File diff suppressed because it is too large
Load Diff
@@ -1,81 +0,0 @@
|
|||||||
// This file is distributed under the BSD License.
|
|
||||||
// See "license.txt" for details.
|
|
||||||
// Copyright 2009-2012, Jonathan Turner (jonathan@emptycrate.com)
|
|
||||||
// Copyright 2009-2016, Jason Turner (jason@emptycrate.com)
|
|
||||||
// http://www.chaiscript.com
|
|
||||||
|
|
||||||
#ifndef CHAISCRIPT_POSIX_HPP_
|
|
||||||
#define CHAISCRIPT_POSIX_HPP_
|
|
||||||
|
|
||||||
namespace chaiscript
|
|
||||||
{
|
|
||||||
namespace detail
|
|
||||||
{
|
|
||||||
struct Loadable_Module
|
|
||||||
{
|
|
||||||
struct DLModule
|
|
||||||
{
|
|
||||||
DLModule(const std::string &t_filename)
|
|
||||||
: m_data(dlopen(t_filename.c_str(), RTLD_NOW))
|
|
||||||
{
|
|
||||||
if (!m_data)
|
|
||||||
{
|
|
||||||
throw chaiscript::exception::load_module_error(dlerror());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DLModule(DLModule &&) = default;
|
|
||||||
DLModule &operator=(DLModule &&) = default;
|
|
||||||
DLModule(const DLModule &) = delete;
|
|
||||||
DLModule &operator=(const DLModule &) = delete;
|
|
||||||
|
|
||||||
~DLModule()
|
|
||||||
{
|
|
||||||
dlclose(m_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
void *m_data;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
struct DLSym
|
|
||||||
{
|
|
||||||
DLSym(DLModule &t_mod, const std::string &t_symbol)
|
|
||||||
: m_symbol(cast_symbol(dlsym(t_mod.m_data, t_symbol.c_str())))
|
|
||||||
{
|
|
||||||
if (!m_symbol)
|
|
||||||
{
|
|
||||||
throw chaiscript::exception::load_module_error(dlerror());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static T cast_symbol(void *p)
|
|
||||||
{
|
|
||||||
union cast_union
|
|
||||||
{
|
|
||||||
T func_ptr;
|
|
||||||
void *in_ptr;
|
|
||||||
};
|
|
||||||
|
|
||||||
cast_union c;
|
|
||||||
c.in_ptr = p;
|
|
||||||
return c.func_ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
T m_symbol;
|
|
||||||
};
|
|
||||||
|
|
||||||
Loadable_Module(const std::string &t_module_name, const std::string &t_filename)
|
|
||||||
: m_dlmodule(t_filename), m_func(m_dlmodule, "create_chaiscript_module_" + t_module_name),
|
|
||||||
m_moduleptr(m_func.m_symbol())
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
DLModule m_dlmodule;
|
|
||||||
DLSym<Create_Module_Func> m_func;
|
|
||||||
ModulePtr m_moduleptr;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
@@ -1,7 +1,7 @@
|
|||||||
// This file is distributed under the BSD License.
|
// This file is distributed under the BSD License.
|
||||||
// See "license.txt" for details.
|
// See "license.txt" for details.
|
||||||
// Copyright 2009-2012, Jonathan Turner (jonathan@emptycrate.com)
|
// Copyright 2009-2012, Jonathan Turner (jonathan@emptycrate.com)
|
||||||
// and 2009-2016, Jason Turner (jason@emptycrate.com)
|
// and Jason Turner (jason@emptycrate.com)
|
||||||
// http://www.chaiscript.com
|
// http://www.chaiscript.com
|
||||||
|
|
||||||
#ifndef CHAISCRIPT_PRELUDE_HPP_
|
#ifndef CHAISCRIPT_PRELUDE_HPP_
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
namespace chaiscript {
|
namespace chaiscript {
|
||||||
struct ChaiScript_Prelude {
|
struct ChaiScript_Prelude {
|
||||||
static std::string chaiscript_prelude() { return R"chaiscript(
|
static std::string chaiscript_prelude() { return R""(
|
||||||
|
|
||||||
def lt(l, r) {
|
def lt(l, r) {
|
||||||
if (call_exists(`<`, l, r)) {
|
if (call_exists(`<`, l, r)) {
|
||||||
@@ -215,29 +215,6 @@ def for_each(container, func) : call_exists(range, container) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def any_of(container, func) : call_exists(range, container) {
|
|
||||||
var t_range := range(container);
|
|
||||||
while (!t_range.empty()) {
|
|
||||||
if (func(t_range.front())) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
t_range.pop_front();
|
|
||||||
}
|
|
||||||
false;
|
|
||||||
}
|
|
||||||
|
|
||||||
def all_of(container, func) : call_exists(range, container) {
|
|
||||||
var t_range := range(container);
|
|
||||||
while (!t_range.empty()) {
|
|
||||||
if (!func(t_range.front())) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
t_range.pop_front();
|
|
||||||
}
|
|
||||||
|
|
||||||
true;
|
|
||||||
}
|
|
||||||
|
|
||||||
def back_inserter(container) {
|
def back_inserter(container) {
|
||||||
bind(push_back, container, _);
|
bind(push_back, container, _);
|
||||||
}
|
}
|
||||||
@@ -553,7 +530,7 @@ def find(container, value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
)chaiscript";
|
)"";
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
@@ -505,7 +505,7 @@ class Function
|
|||||||
/// \endcode
|
/// \endcode
|
||||||
Vector get_contained_functions() const;
|
Vector get_contained_functions() const;
|
||||||
|
|
||||||
/// \brief Returns a function guard as function
|
/// \brief Returns a vector of the contained functions
|
||||||
///
|
///
|
||||||
/// Example:
|
/// Example:
|
||||||
/// \code
|
/// \code
|
||||||
|
@@ -1,43 +0,0 @@
|
|||||||
// This file is distributed under the BSD License.
|
|
||||||
// See "license.txt" for details.
|
|
||||||
// Copyright 2009-2012, Jonathan Turner (jonathan@emptycrate.com)
|
|
||||||
// Copyright 2009-2016, Jason Turner (jason@emptycrate.com)
|
|
||||||
// http://www.chaiscript.com
|
|
||||||
|
|
||||||
#ifndef CHAISCRIPT_TRACER_HPP_
|
|
||||||
#define CHAISCRIPT_TRACER_HPP_
|
|
||||||
|
|
||||||
namespace chaiscript {
|
|
||||||
namespace eval {
|
|
||||||
|
|
||||||
struct Noop_Tracer
|
|
||||||
{
|
|
||||||
template<typename T>
|
|
||||||
static void trace(const chaiscript::detail::Dispatch_State &, const AST_Node_Impl<T> *)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename ... T>
|
|
||||||
struct Tracer : T...
|
|
||||||
{
|
|
||||||
Tracer() = default;
|
|
||||||
Tracer(T ... t)
|
|
||||||
: T(std::move(t))...
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void do_trace(const chaiscript::detail::Dispatch_State &ds, const AST_Node_Impl<Tracer<T...>> *node) {
|
|
||||||
(void)std::initializer_list<int>{ (T::trace(ds, node), 0)... };
|
|
||||||
}
|
|
||||||
|
|
||||||
static void trace(const chaiscript::detail::Dispatch_State &ds, const AST_Node_Impl<Tracer<T...>> *node) {
|
|
||||||
ds->get_parser().get_tracer<Tracer<T...>>().do_trace(ds, node);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
@@ -1,27 +0,0 @@
|
|||||||
// This file is distributed under the BSD License.
|
|
||||||
// See "license.txt" for details.
|
|
||||||
// Copyright 2009-2012, Jonathan Turner (jonathan@emptycrate.com)
|
|
||||||
// Copyright 2009-2016, Jason Turner (jason@emptycrate.com)
|
|
||||||
// http://www.chaiscript.com
|
|
||||||
|
|
||||||
#ifndef CHAISCRIPT_UNKNOWN_HPP_
|
|
||||||
#define CHAISCRIPT_UNKNOWN_HPP_
|
|
||||||
|
|
||||||
|
|
||||||
namespace chaiscript
|
|
||||||
{
|
|
||||||
namespace detail
|
|
||||||
{
|
|
||||||
struct Loadable_Module
|
|
||||||
{
|
|
||||||
Loadable_Module(const std::string &, const std::string &)
|
|
||||||
{
|
|
||||||
throw chaiscript::exception::load_module_error("Loadable module support not available for your platform");
|
|
||||||
}
|
|
||||||
|
|
||||||
ModulePtr m_moduleptr;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
@@ -1,133 +0,0 @@
|
|||||||
// This file is distributed under the BSD License.
|
|
||||||
// See "license.txt" for details.
|
|
||||||
// Copyright 2009-2012, Jonathan Turner (jonathan@emptycrate.com)
|
|
||||||
// Copyright 2009-2016, Jason Turner (jason@emptycrate.com)
|
|
||||||
// http://www.chaiscript.com
|
|
||||||
|
|
||||||
#ifndef CHAISCRIPT_WINDOWS_HPP_
|
|
||||||
#define CHAISCRIPT_WINDOWS_HPP_
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#ifdef CHAISCRIPT_WINDOWS
|
|
||||||
#define VC_EXTRA_LEAN
|
|
||||||
#if !defined(WIN32_LEAN_AND_MEAN)
|
|
||||||
#define WIN32_LEAN_AND_MEAN
|
|
||||||
#endif
|
|
||||||
#include <windows.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
namespace chaiscript
|
|
||||||
{
|
|
||||||
namespace detail
|
|
||||||
{
|
|
||||||
struct Loadable_Module
|
|
||||||
{
|
|
||||||
template<typename T>
|
|
||||||
static std::wstring to_wstring(const T &t_str)
|
|
||||||
{
|
|
||||||
return std::wstring(t_str.begin(), t_str.end());
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
static std::string to_string(const T &t_str)
|
|
||||||
{
|
|
||||||
return std::string(t_str.begin(), t_str.end());
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(_UNICODE) || defined(UNICODE)
|
|
||||||
template<typename T>
|
|
||||||
static std::wstring to_proper_string(const T &t_str)
|
|
||||||
{
|
|
||||||
return to_wstring(t_str);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
template<typename T>
|
|
||||||
static std::string to_proper_string(const T &t_str)
|
|
||||||
{
|
|
||||||
return to_string(t_str);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static std::string get_error_message(DWORD t_err)
|
|
||||||
{
|
|
||||||
typedef LPTSTR StringType;
|
|
||||||
|
|
||||||
#if defined(_UNICODE) || defined(UNICODE)
|
|
||||||
std::wstring retval = L"Unknown Error";
|
|
||||||
#else
|
|
||||||
std::string retval = "Unknown Error";
|
|
||||||
#endif
|
|
||||||
StringType lpMsgBuf = nullptr;
|
|
||||||
|
|
||||||
if (FormatMessage(
|
|
||||||
FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
|
||||||
FORMAT_MESSAGE_FROM_SYSTEM |
|
|
||||||
FORMAT_MESSAGE_IGNORE_INSERTS,
|
|
||||||
nullptr,
|
|
||||||
t_err,
|
|
||||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
|
||||||
reinterpret_cast<StringType>(&lpMsgBuf),
|
|
||||||
0, nullptr ) != 0 && lpMsgBuf)
|
|
||||||
{
|
|
||||||
retval = lpMsgBuf;
|
|
||||||
LocalFree(lpMsgBuf);
|
|
||||||
}
|
|
||||||
|
|
||||||
return to_string(retval);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct DLModule
|
|
||||||
{
|
|
||||||
DLModule(const std::string &t_filename)
|
|
||||||
: m_data(LoadLibrary(to_proper_string(t_filename).c_str()))
|
|
||||||
{
|
|
||||||
if (!m_data)
|
|
||||||
{
|
|
||||||
throw chaiscript::exception::load_module_error(get_error_message(GetLastError()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DLModule(DLModule &&) = default;
|
|
||||||
DLModule &operator=(DLModule &&) = default;
|
|
||||||
DLModule(const DLModule &) = delete;
|
|
||||||
DLModule &operator=(const DLModule &) = delete;
|
|
||||||
|
|
||||||
~DLModule()
|
|
||||||
{
|
|
||||||
FreeLibrary(m_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
HMODULE m_data;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
struct DLSym
|
|
||||||
{
|
|
||||||
DLSym(DLModule &t_mod, const std::string &t_symbol)
|
|
||||||
: m_symbol(reinterpret_cast<T>(GetProcAddress(t_mod.m_data, t_symbol.c_str())))
|
|
||||||
{
|
|
||||||
if (!m_symbol)
|
|
||||||
{
|
|
||||||
throw chaiscript::exception::load_module_error(get_error_message(GetLastError()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
T m_symbol;
|
|
||||||
};
|
|
||||||
|
|
||||||
Loadable_Module(const std::string &t_module_name, const std::string &t_filename)
|
|
||||||
: m_dlmodule(t_filename), m_func(m_dlmodule, "create_chaiscript_module_" + t_module_name),
|
|
||||||
m_moduleptr(m_func.m_symbol())
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
DLModule m_dlmodule;
|
|
||||||
DLSym<Create_Module_Func> m_func;
|
|
||||||
ModulePtr m_moduleptr;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
@@ -9,11 +9,11 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
static Module& library(Module& m)
|
static ModulePtr library(ModulePtr m = std::make_shared<Module>())
|
||||||
{
|
{
|
||||||
|
|
||||||
m.add(chaiscript::fun([](const std::string &t_str) { return from_json(t_str); }), "from_json");
|
m->add(chaiscript::fun([](const std::string &t_str) { return from_json(t_str); }), "from_json");
|
||||||
m.add(chaiscript::fun(&json_wrap::to_json), "to_json");
|
m->add(chaiscript::fun(&json_wrap::to_json), "to_json");
|
||||||
|
|
||||||
return m;
|
return m;
|
||||||
|
|
||||||
@@ -30,7 +30,7 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
std::map<std::string, Boxed_Value> m;
|
std::map<std::string, Boxed_Value> m;
|
||||||
|
|
||||||
for (const auto &p : t_json.object_range())
|
for (const auto &p : t_json.ObjectRange())
|
||||||
{
|
{
|
||||||
m.insert(std::make_pair(p.first, from_json(p.second)));
|
m.insert(std::make_pair(p.first, from_json(p.second)));
|
||||||
}
|
}
|
||||||
@@ -41,7 +41,7 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
std::vector<Boxed_Value> vec;
|
std::vector<Boxed_Value> vec;
|
||||||
|
|
||||||
for (const auto &p : t_json.array_range())
|
for (const auto &p : t_json.ArrayRange())
|
||||||
{
|
{
|
||||||
vec.emplace_back(from_json(p));
|
vec.emplace_back(from_json(p));
|
||||||
}
|
}
|
||||||
@@ -49,13 +49,13 @@ namespace chaiscript
|
|||||||
return Boxed_Value(vec);
|
return Boxed_Value(vec);
|
||||||
}
|
}
|
||||||
case json::JSON::Class::String:
|
case json::JSON::Class::String:
|
||||||
return Boxed_Value(t_json.to_string());
|
return Boxed_Value(t_json.ToString());
|
||||||
case json::JSON::Class::Floating:
|
case json::JSON::Class::Floating:
|
||||||
return Boxed_Value(t_json.to_float());
|
return Boxed_Value(t_json.ToFloat());
|
||||||
case json::JSON::Class::Integral:
|
case json::JSON::Class::Integral:
|
||||||
return Boxed_Value(t_json.to_int());
|
return Boxed_Value(t_json.ToInt());
|
||||||
case json::JSON::Class::Boolean:
|
case json::JSON::Class::Boolean:
|
||||||
return Boxed_Value(t_json.to_bool());
|
return Boxed_Value(t_json.ToBool());
|
||||||
}
|
}
|
||||||
|
|
||||||
throw std::runtime_error("Unknown JSON type");
|
throw std::runtime_error("Unknown JSON type");
|
||||||
@@ -102,24 +102,32 @@ namespace chaiscript
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
Boxed_Number bn(t_bv);
|
Boxed_Number bn(t_bv);
|
||||||
|
json::JSON obj;
|
||||||
if (Boxed_Number::is_floating_point(t_bv))
|
if (Boxed_Number::is_floating_point(t_bv))
|
||||||
{
|
{
|
||||||
return json::JSON(bn.get_as<double>());
|
obj = bn.get_as<double>();
|
||||||
} else {
|
} else {
|
||||||
return json::JSON(bn.get_as<long>());
|
obj = bn.get_as<long>();
|
||||||
}
|
}
|
||||||
|
return obj;
|
||||||
} catch (const chaiscript::detail::exception::bad_any_cast &) {
|
} catch (const chaiscript::detail::exception::bad_any_cast &) {
|
||||||
// not a number
|
// not a number
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return json::JSON(boxed_cast<bool>(t_bv));
|
bool b = boxed_cast<bool>(t_bv);
|
||||||
|
json::JSON obj;
|
||||||
|
obj = b;
|
||||||
|
return obj;
|
||||||
} catch (const chaiscript::exception::bad_boxed_cast &) {
|
} catch (const chaiscript::exception::bad_boxed_cast &) {
|
||||||
// not a bool
|
// not a bool
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return json::JSON(boxed_cast<std::string>(t_bv));
|
std::string s = boxed_cast<std::string>(t_bv);
|
||||||
|
json::JSON obj;
|
||||||
|
obj = s;
|
||||||
|
return obj;
|
||||||
} catch (const chaiscript::exception::bad_boxed_cast &) {
|
} catch (const chaiscript::exception::bad_boxed_cast &) {
|
||||||
// not a string
|
// not a string
|
||||||
}
|
}
|
||||||
|
@@ -12,8 +12,9 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "../language/chaiscript_common.hpp"
|
#include "../chaiscript.hpp"
|
||||||
#include "../dispatchkit/register_function.hpp"
|
#include "../dispatchkit/proxy_functions.hpp"
|
||||||
|
#include "../dispatchkit/type_info.hpp"
|
||||||
#include "../dispatchkit/operators.hpp"
|
#include "../dispatchkit/operators.hpp"
|
||||||
|
|
||||||
|
|
||||||
@@ -68,7 +69,11 @@ namespace chaiscript
|
|||||||
typename std::enable_if<std::is_enum<Enum>::value, void>::type
|
typename std::enable_if<std::is_enum<Enum>::value, void>::type
|
||||||
add_class(ModuleType &t_module,
|
add_class(ModuleType &t_module,
|
||||||
const std::string &t_class_name,
|
const std::string &t_class_name,
|
||||||
|
#ifdef CHAISCRIPT_GCC_4_6
|
||||||
|
const std::vector<std::pair<int, std::string>> &t_constants
|
||||||
|
#else
|
||||||
const std::vector<std::pair<typename std::underlying_type<Enum>::type, std::string>> &t_constants
|
const std::vector<std::pair<typename std::underlying_type<Enum>::type, std::string>> &t_constants
|
||||||
|
#endif
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
t_module.add(chaiscript::user_type<Enum>(), t_class_name);
|
t_module.add(chaiscript::user_type<Enum>(), t_class_name);
|
||||||
@@ -77,12 +82,18 @@ namespace chaiscript
|
|||||||
t_module.add(chaiscript::constructor<Enum (const Enum &)>(), t_class_name);
|
t_module.add(chaiscript::constructor<Enum (const Enum &)>(), t_class_name);
|
||||||
|
|
||||||
using namespace chaiscript::bootstrap::operators;
|
using namespace chaiscript::bootstrap::operators;
|
||||||
equal<Enum>(t_module);
|
t_module.add([](){
|
||||||
not_equal<Enum>(t_module);
|
// add some comparison and assignment operators
|
||||||
assign<Enum>(t_module);
|
return assign<Enum>(not_equal<Enum>(equal<Enum>()));
|
||||||
|
}());
|
||||||
|
|
||||||
|
#ifdef CHAISCRIPT_GCC_4_6
|
||||||
t_module.add(chaiscript::fun([](const Enum &e, const int &i) { return e == i; }), "==");
|
t_module.add(chaiscript::fun([](const Enum &e, const int &i) { return e == i; }), "==");
|
||||||
t_module.add(chaiscript::fun([](const int &i, const Enum &e) { return i == e; }), "==");
|
t_module.add(chaiscript::fun([](const int &i, const Enum &e) { return i == e; }), "==");
|
||||||
|
#else
|
||||||
|
t_module.add(chaiscript::fun([](const Enum &e, const typename std::underlying_type<Enum>::type &i) { return e == i; }), "==");
|
||||||
|
t_module.add(chaiscript::fun([](const typename std::underlying_type<Enum>::type &i, const Enum &e) { return i == e; }), "==");
|
||||||
|
#endif
|
||||||
|
|
||||||
for (const auto &constant : t_constants)
|
for (const auto &constant : t_constants)
|
||||||
{
|
{
|
||||||
|
@@ -1,8 +1,3 @@
|
|||||||
<a href="https://www.patreon.com/bePatron?u=2977989&redirect_uri=https%3A%2F%2Fwww.patreon.com%2Flefticus">
|
|
||||||
<img height="40" width="204" src="https://s3-us-west-1.amazonaws.com/widget-images/become-patron-widget-medium%402x.png">
|
|
||||||
</a>
|
|
||||||
|
|
||||||
|
|
||||||
Master Status: [](https://travis-ci.org/ChaiScript/ChaiScript) [](https://ci.appveyor.com/project/lefticus/chaiscript) [](http://codecov.io/github/ChaiScript/ChaiScript?branch=master)
|
Master Status: [](https://travis-ci.org/ChaiScript/ChaiScript) [](https://ci.appveyor.com/project/lefticus/chaiscript) [](http://codecov.io/github/ChaiScript/ChaiScript?branch=master)
|
||||||
|
|
||||||
Develop Status: [](https://travis-ci.org/ChaiScript/ChaiScript) [](https://ci.appveyor.com/project/lefticus/chaiscript/branch/develop) [](http://codecov.io/github/ChaiScript/ChaiScript?branch=develop)
|
Develop Status: [](https://travis-ci.org/ChaiScript/ChaiScript) [](https://ci.appveyor.com/project/lefticus/chaiscript/branch/develop) [](http://codecov.io/github/ChaiScript/ChaiScript?branch=develop)
|
||||||
|
@@ -1,6 +1,24 @@
|
|||||||
Notes:
|
Notes:
|
||||||
=======
|
=======
|
||||||
Current Version: 5.8.2
|
|
||||||
|
Current Version: 5.8.6
|
||||||
|
|
||||||
|
### Changes since 5.8.5
|
||||||
|
* Optimize away `return` statements in lambdas also
|
||||||
|
* Allow conversions to bool in conditionals
|
||||||
|
* Don't allow `class` statements inside of scopes
|
||||||
|
* Properly error when a dynamic object non-function member is called
|
||||||
|
|
||||||
|
### Changes since 5.8.4
|
||||||
|
* Fix order of operations for prefix operators
|
||||||
|
* Make sure atomics are initialized properly
|
||||||
|
* Remove parsing of unused prefix `&` operator
|
||||||
|
|
||||||
|
### Changes since 5.8.3
|
||||||
|
* Fix case with some numeric conversions mixed with numerics that do not need conversion
|
||||||
|
|
||||||
|
### Changes since 5.8.2
|
||||||
|
* Add support for reference of pointer return types
|
||||||
|
|
||||||
### Changes since 5.8.1
|
### Changes since 5.8.1
|
||||||
* Allow casting to non-const & std::shared_ptr<T>
|
* Allow casting to non-const & std::shared_ptr<T>
|
||||||
|
@@ -44,14 +44,14 @@ class ChaiScriptDerived : public BaseClass
|
|||||||
tie(t_funcs.at(1), m_validateValueImpl);
|
tie(t_funcs.at(1), m_validateValueImpl);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string doSomething(float f, double d) const override
|
std::string doSomething(float f, double d) const CHAISCRIPT_OVERRIDE
|
||||||
{
|
{
|
||||||
assert(m_doSomethingImpl);
|
assert(m_doSomethingImpl);
|
||||||
return m_doSomethingImpl(*this, f, d);
|
return m_doSomethingImpl(*this, f, d);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool validateValue(const std::string &t_val) override
|
bool validateValue(const std::string &t_val) CHAISCRIPT_OVERRIDE
|
||||||
{
|
{
|
||||||
assert(m_validateValueImpl);
|
assert(m_validateValueImpl);
|
||||||
return m_validateValueImpl(*this, t_val);
|
return m_validateValueImpl(*this, t_val);
|
||||||
|
@@ -371,9 +371,6 @@ int main(int argc, char *argv[])
|
|||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (const chaiscript::exception::load_module_error &e) {
|
|
||||||
std::cout << "Unhandled module load error\n" << e.what() << '\n';
|
|
||||||
}
|
|
||||||
|
|
||||||
// catch (std::exception &e) {
|
// catch (std::exception &e) {
|
||||||
// std::cout << e.what() << '\n';
|
// std::cout << e.what() << '\n';
|
||||||
|
@@ -23,9 +23,9 @@
|
|||||||
|
|
||||||
CHAISCRIPT_MODULE_EXPORT chaiscript::ModulePtr create_chaiscript_module_stl_extra()
|
CHAISCRIPT_MODULE_EXPORT chaiscript::ModulePtr create_chaiscript_module_stl_extra()
|
||||||
{
|
{
|
||||||
auto module = std::make_shared<chaiscript::Module>();
|
|
||||||
chaiscript::bootstrap::standard_library::list_type<std::list<chaiscript::Boxed_Value> >("List", *module);
|
auto module = chaiscript::bootstrap::standard_library::list_type<std::list<chaiscript::Boxed_Value> >("List");
|
||||||
chaiscript::bootstrap::standard_library::vector_type<std::vector<uint16_t> >("u16vector", *module);
|
module->add(chaiscript::bootstrap::standard_library::vector_type<std::vector<uint16_t> >("u16vector"));
|
||||||
module->add(chaiscript::vector_conversion<std::vector<uint16_t>>());
|
module->add(chaiscript::vector_conversion<std::vector<uint16_t>>());
|
||||||
return module;
|
return module;
|
||||||
}
|
}
|
||||||
|
@@ -8,10 +8,18 @@
|
|||||||
class TestBaseType
|
class TestBaseType
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
#ifdef CHAISCRIPT_MSVC_12
|
||||||
|
#pragma warning(push)
|
||||||
|
#pragma warning(disable : 4351)
|
||||||
|
#endif
|
||||||
|
// MSVC 12 warns that we are using new (correct) behavior
|
||||||
TestBaseType() : val(10), const_val(15), mdarray{} { }
|
TestBaseType() : val(10), const_val(15), mdarray{} { }
|
||||||
TestBaseType(int) : val(10), const_val(15), mdarray{} { }
|
TestBaseType(int) : val(10), const_val(15), mdarray{} { }
|
||||||
TestBaseType(int *) : val(10), const_val(15), mdarray{} { }
|
TestBaseType(int *) : val(10), const_val(15), mdarray{} { }
|
||||||
|
#ifdef CHAISCRIPT_MSVC_12
|
||||||
|
#pragma warning(pop)
|
||||||
|
#endif
|
||||||
|
|
||||||
TestBaseType(const TestBaseType &) = default;
|
TestBaseType(const TestBaseType &) = default;
|
||||||
virtual ~TestBaseType() {}
|
virtual ~TestBaseType() {}
|
||||||
virtual int func() { return 0; }
|
virtual int func() { return 0; }
|
||||||
@@ -22,11 +30,6 @@ class TestBaseType
|
|||||||
|
|
||||||
int val;
|
int val;
|
||||||
const int const_val;
|
const int const_val;
|
||||||
const int *const_val_ptr = &const_val;
|
|
||||||
|
|
||||||
const int *get_const_val_ptr() {
|
|
||||||
return const_val_ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
int mdarray[2][3][5];
|
int mdarray[2][3][5];
|
||||||
std::function<int (int)> func_member;
|
std::function<int (int)> func_member;
|
||||||
@@ -81,7 +84,7 @@ class TestDerivedType : public TestBaseType
|
|||||||
virtual ~TestDerivedType() {}
|
virtual ~TestDerivedType() {}
|
||||||
TestDerivedType(const TestDerivedType &) = default;
|
TestDerivedType(const TestDerivedType &) = default;
|
||||||
TestDerivedType() = default;
|
TestDerivedType() = default;
|
||||||
virtual int func() override { return 1; }
|
virtual int func() CHAISCRIPT_OVERRIDE { return 1; }
|
||||||
int derived_only_func() { return 19; }
|
int derived_only_func() { return 19; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -183,15 +186,19 @@ CHAISCRIPT_MODULE_EXPORT chaiscript::ModulePtr create_chaiscript_module_test_mo
|
|||||||
m->add(chaiscript::fun(&TestBaseType::func), "func");
|
m->add(chaiscript::fun(&TestBaseType::func), "func");
|
||||||
m->add(chaiscript::fun(&TestBaseType::val), "val");
|
m->add(chaiscript::fun(&TestBaseType::val), "val");
|
||||||
m->add(chaiscript::fun(&TestBaseType::const_val), "const_val");
|
m->add(chaiscript::fun(&TestBaseType::const_val), "const_val");
|
||||||
m->add(chaiscript::fun(&TestBaseType::const_val_ptr), "const_val_ptr");
|
|
||||||
m->add(chaiscript::fun(&TestBaseType::get_const_val_ptr), "get_const_val_ptr");
|
|
||||||
m->add(chaiscript::fun(&TestBaseType::base_only_func), "base_only_func");
|
m->add(chaiscript::fun(&TestBaseType::base_only_func), "base_only_func");
|
||||||
m->add(chaiscript::fun(&TestBaseType::set_string_val), "set_string_val");
|
m->add(chaiscript::fun(&TestBaseType::set_string_val), "set_string_val");
|
||||||
|
|
||||||
|
#ifndef CHAISCRIPT_MSVC_12
|
||||||
|
// we cannot support these in MSVC_12 because of a bug in the implementation of
|
||||||
|
// std::reference_wrapper
|
||||||
|
// Array types
|
||||||
m->add(chaiscript::fun(&TestBaseType::mdarray), "mdarray");
|
m->add(chaiscript::fun(&TestBaseType::mdarray), "mdarray");
|
||||||
chaiscript::bootstrap::array<int[2][3][5]>("IntArray_2_3_5", *m);
|
m->add(chaiscript::bootstrap::array<int[2][3][5]>("IntArray_2_3_5"));
|
||||||
chaiscript::bootstrap::array<int[3][5]>("IntArray_3_5", *m);
|
m->add(chaiscript::bootstrap::array<int[3][5]>("IntArray_3_5"));
|
||||||
chaiscript::bootstrap::array<int[5]>("IntArray_5", *m);
|
m->add(chaiscript::bootstrap::array<int[5]>("IntArray_5"));
|
||||||
|
// end array types
|
||||||
|
#endif
|
||||||
|
|
||||||
// member that is a function
|
// member that is a function
|
||||||
m->add(chaiscript::fun(&TestBaseType::func_member), "func_member");
|
m->add(chaiscript::fun(&TestBaseType::func_member), "func_member");
|
||||||
|
@@ -1 +0,0 @@
|
|||||||
|
|
@@ -1,6 +1,7 @@
|
|||||||
assert_equal(`==`, `==`);
|
assert_equal(`==`, `==`);
|
||||||
assert_not_equal(`==`, `<`);
|
assert_not_equal(`==`, `<`);
|
||||||
assert_equal(`<`.get_arity(), 2);
|
assert_equal(`<`.get_arity(), 2);
|
||||||
|
assert_equal(`+`.get_annotation(), "Multiple method dispatch function wrapper.");
|
||||||
assert_equal(get_arity.get_contained_functions().size(), 0);
|
assert_equal(get_arity.get_contained_functions().size(), 0);
|
||||||
assert_equal(get_arity.get_arity(), 1);
|
assert_equal(get_arity.get_arity(), 1);
|
||||||
assert_equal(get_arity.get_param_types().size(), 2);
|
assert_equal(get_arity.get_param_types().size(), 2);
|
||||||
|
@@ -10,6 +10,7 @@ def test_function(a)
|
|||||||
|
|
||||||
// test_function tests
|
// test_function tests
|
||||||
assert_equal(test_function.get_arity(), 1);
|
assert_equal(test_function.get_arity(), 1);
|
||||||
|
assert_equal(trim(test_function.get_annotation()), "#Test Function Description");
|
||||||
assert_equal(test_function.get_contained_functions().size(), 0);
|
assert_equal(test_function.get_contained_functions().size(), 0);
|
||||||
assert_equal(test_function.get_param_types().size(), 2);
|
assert_equal(test_function.get_param_types().size(), 2);
|
||||||
|
|
||||||
|
36
unittests/3.x/reflection_test.chai
Normal file
36
unittests/3.x/reflection_test.chai
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
var parser := ChaiScript_Parser()
|
||||||
|
var parse_success = parser.parse("3 + 4", "INPUT")
|
||||||
|
var a := parser.ast()
|
||||||
|
|
||||||
|
assert_equal(eval(a), 7)
|
||||||
|
|
||||||
|
var childs := a.children.front().children
|
||||||
|
var node := childs[0]
|
||||||
|
|
||||||
|
var parser2 := ChaiScript_Parser()
|
||||||
|
parser2.parse("9", "INPUT")
|
||||||
|
|
||||||
|
|
||||||
|
a.children.front().replace_child(childs[0], parser2.ast())
|
||||||
|
|
||||||
|
assert_equal(eval(a), 13)
|
||||||
|
assert_equal(node.filename, "INPUT")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def my_fun()
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
assert_equal(true, my_fun.has_parse_tree());
|
||||||
|
assert_equal(false, `+`.has_parse_tree());
|
||||||
|
|
||||||
|
assert_throws("Function does not have a parse tree", fun() { `+`.get_parse_tree(); } );
|
||||||
|
|
||||||
|
var parsetree := my_fun.get_parse_tree();
|
||||||
|
|
||||||
|
assert_equal(1, eval(parsetree));
|
||||||
|
|
||||||
|
print(parsetree.text());
|
@@ -206,7 +206,7 @@ bool built_in_type_test(const T &initial, bool ispod)
|
|||||||
|
|
||||||
/** shared_ptr tests **/
|
/** shared_ptr tests **/
|
||||||
|
|
||||||
auto ip = std::make_shared<T>(initial);
|
std::shared_ptr<T> ip(new T(initial));
|
||||||
|
|
||||||
passed &= do_test<T>(var(ip), true, true, true, true, true,
|
passed &= do_test<T>(var(ip), true, true, true, true, true,
|
||||||
true, true, true, true, true,
|
true, true, true, true, true,
|
||||||
@@ -221,7 +221,7 @@ bool built_in_type_test(const T &initial, bool ispod)
|
|||||||
ispod, ispod, ispod, false, true);
|
ispod, ispod, ispod, false, true);
|
||||||
|
|
||||||
/** const shared_ptr tests **/
|
/** const shared_ptr tests **/
|
||||||
auto ipc = std::make_shared<const T>(T(initial));
|
std::shared_ptr<const T> ipc(new T(initial));
|
||||||
|
|
||||||
passed &= do_test<T>(var(ipc), true, true, false, true, false,
|
passed &= do_test<T>(var(ipc), true, true, false, true, false,
|
||||||
true, false, true, false, true,
|
true, false, true, false, true,
|
||||||
|
8
unittests/class_inside_scope.chai
Normal file
8
unittests/class_inside_scope.chai
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
parse("{ class C { var data; def C() {} } }")
|
||||||
|
assert_false(true)
|
||||||
|
} catch (e) {
|
||||||
|
assert_true(true)
|
||||||
|
}
|
@@ -950,4 +950,34 @@ TEST_CASE("Parse floats with non-posix locale")
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool FindBitmap(int &ox, int &oy, long) {
|
||||||
|
ox = 1;
|
||||||
|
oy = 2;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Mismatched numeric types only convert necessary params")
|
||||||
|
{
|
||||||
|
chaiscript::ChaiScript chai;
|
||||||
|
|
||||||
|
chai.add(chaiscript::fun(&FindBitmap), "FindBitmap");
|
||||||
|
int x = 0;
|
||||||
|
int y = 0;
|
||||||
|
chai.add(chaiscript::var(&x), "x");
|
||||||
|
chai.add(chaiscript::var(&y), "y");
|
||||||
|
chai.eval( "if ( FindBitmap ( x, y, 0) ) { print(\"found at \" + to_string(x) + \", \" + to_string(y))}" );
|
||||||
|
CHECK(x == 1);
|
||||||
|
CHECK(y == 2);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("type_conversion to bool")
|
||||||
|
{
|
||||||
|
auto module = std::make_shared<chaiscript::Module>();
|
||||||
|
struct T {
|
||||||
|
operator bool() const { return true; }
|
||||||
|
};
|
||||||
|
module->add(chaiscript::type_conversion<T, bool>());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
17
unittests/conversion_to_bool.chai
Normal file
17
unittests/conversion_to_bool.chai
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
|
||||||
|
// all we care is that this executes, really
|
||||||
|
|
||||||
|
add_type_conversion(type("int"), type("bool"), fun(int i) { return i != 0; });
|
||||||
|
|
||||||
|
if (0) {
|
||||||
|
assert_true(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
while (0) {
|
||||||
|
assert_true(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (; 0; ) {
|
||||||
|
assert_true(false);
|
||||||
|
}
|
||||||
|
|
@@ -1,6 +1,7 @@
|
|||||||
assert_equal(`==`, `==`);
|
assert_equal(`==`, `==`);
|
||||||
assert_not_equal(`==`, `<`);
|
assert_not_equal(`==`, `<`);
|
||||||
assert_equal(`<`.get_arity(), 2);
|
assert_equal(`<`.get_arity(), 2);
|
||||||
|
assert_equal(`+`.get_annotation(), "Multiple method dispatch function wrapper.");
|
||||||
assert_equal(get_arity.get_contained_functions().size(), 0);
|
assert_equal(get_arity.get_contained_functions().size(), 0);
|
||||||
assert_equal(get_arity.get_arity(), 1);
|
assert_equal(get_arity.get_arity(), 1);
|
||||||
assert_equal(get_arity.get_param_types().size(), 2);
|
assert_equal(get_arity.get_param_types().size(), 2);
|
||||||
|
@@ -1,26 +0,0 @@
|
|||||||
class MyClass
|
|
||||||
{
|
|
||||||
def MyClass()
|
|
||||||
{
|
|
||||||
this.x = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
var x;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
var o = MyClass();
|
|
||||||
var o2 = MyClass();
|
|
||||||
|
|
||||||
o2.x = 5;
|
|
||||||
o = o2;
|
|
||||||
|
|
||||||
assert_true(o.x == 5)
|
|
||||||
assert_true(o == o2)
|
|
||||||
|
|
||||||
o2.x = 3;
|
|
||||||
|
|
||||||
print(o2.x);
|
|
||||||
print(o.x);
|
|
||||||
|
|
||||||
assert_true(o != o2)
|
|
@@ -10,6 +10,7 @@ def test_function(a)
|
|||||||
|
|
||||||
// test_function tests
|
// test_function tests
|
||||||
assert_equal(test_function.get_arity(), 1);
|
assert_equal(test_function.get_arity(), 1);
|
||||||
|
assert_equal(trim(test_function.get_annotation()), "#Test Function Description");
|
||||||
assert_equal(test_function.get_contained_functions().size(), 0);
|
assert_equal(test_function.get_contained_functions().size(), 0);
|
||||||
assert_equal(test_function.get_param_types().size(), 2);
|
assert_equal(test_function.get_param_types().size(), 2);
|
||||||
|
|
||||||
|
Binary file not shown.
@@ -16,8 +16,3 @@ def f() {
|
|||||||
|
|
||||||
f();
|
f();
|
||||||
|
|
||||||
|
|
||||||
global &h = v;
|
|
||||||
assert_true(h == v)
|
|
||||||
v = 3;
|
|
||||||
assert_true(h == 3)
|
|
||||||
|
@@ -1,13 +0,0 @@
|
|||||||
load_module("stl_extra");
|
|
||||||
|
|
||||||
auto list = List();
|
|
||||||
|
|
||||||
list.resize(2);
|
|
||||||
assert_equal(list.size(), 2);
|
|
||||||
|
|
||||||
list.resize(6, "AAA");
|
|
||||||
assert_equal(list.back(), "AAA");
|
|
||||||
|
|
||||||
list.resize(0);
|
|
||||||
assert_equal(list.size(), 0);
|
|
||||||
|
|
@@ -8,6 +8,4 @@ assert_equal(13, t0.val)
|
|||||||
assert_equal(15, t0.constMe().const_val)
|
assert_equal(15, t0.constMe().const_val)
|
||||||
assert_equal(13, t0.constMe().val)
|
assert_equal(13, t0.constMe().val)
|
||||||
|
|
||||||
assert_equal(15, t0.get_const_val_ptr())
|
|
||||||
assert_equal(15, t0.const_val_ptr)
|
|
||||||
|
|
||||||
|
4
unittests/precedence_4.chai
Normal file
4
unittests/precedence_4.chai
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
var i = 2;
|
||||||
|
|
||||||
|
assert_equal(++i * i, 9)
|
@@ -1,9 +1,22 @@
|
|||||||
auto a = parse("3 + 4")
|
auto& parser = ChaiScript_Parser()
|
||||||
|
auto parse_success = parser.parse("3 + 4", "INPUT")
|
||||||
|
auto& a = parser.ast()
|
||||||
|
|
||||||
assert_equal(eval(a), 7)
|
assert_equal(eval(a), 7)
|
||||||
|
|
||||||
assert_equal(1, a.children.size());
|
auto& childs = a.children.front().children
|
||||||
assert_equal("3 + 4", a.children[0].text());
|
auto& node = childs[0]
|
||||||
|
|
||||||
|
auto& parser2 = ChaiScript_Parser()
|
||||||
|
parser2.parse("9", "INPUT")
|
||||||
|
|
||||||
|
|
||||||
|
a.children.front().replace_child(childs[0], parser2.ast())
|
||||||
|
|
||||||
|
assert_equal(eval(a), 13)
|
||||||
|
assert_equal(node.filename, "INPUT")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def my_fun()
|
def my_fun()
|
||||||
{
|
{
|
||||||
|
@@ -1,7 +0,0 @@
|
|||||||
load_module("stl_extra");
|
|
||||||
|
|
||||||
auto uint16v = u16vector();
|
|
||||||
|
|
||||||
uint16v.reserve(5);
|
|
||||||
assert_true(uint16v.capacity() >= 5);
|
|
||||||
|
|
@@ -1,13 +0,0 @@
|
|||||||
load_module("stl_extra");
|
|
||||||
|
|
||||||
auto uint16v = u16vector();
|
|
||||||
|
|
||||||
uint16v.resize(2);
|
|
||||||
assert_equal(uint16v.size(), 2);
|
|
||||||
|
|
||||||
uint16v.resize(6, 3);
|
|
||||||
assert_equal(uint16v[5], 3);
|
|
||||||
|
|
||||||
uint16v.resize(0);
|
|
||||||
assert_equal(uint16v.size(), 0);
|
|
||||||
|
|
Reference in New Issue
Block a user