From 257513e72a3535f6570b1a9b957e99d116ee3616 Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Sat, 25 Apr 2020 01:49:46 +0200 Subject: [PATCH] Sample code that prints a message from wren --- .gitmodules | 3 + meson.build | 13 +++ src/main.cpp | 32 ++++++++ subprojects/wren/meson.build | 125 +++++++++++++++++++++++++++++ subprojects/wren/meson_options.txt | 3 + subprojects/wren/wren | 1 + 6 files changed, 177 insertions(+) create mode 100644 .gitmodules create mode 100644 meson.build create mode 100644 src/main.cpp create mode 100644 subprojects/wren/meson.build create mode 100644 subprojects/wren/meson_options.txt create mode 160000 subprojects/wren/wren diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..ce67337 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "subprojects/wren/wren"] + path = subprojects/wren/wren + url = https://github.com/wren-lang/wren.git diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..8397c1b --- /dev/null +++ b/meson.build @@ -0,0 +1,13 @@ +project('wrentest', 'cpp', + version: '1.0.0', + meson_version: '>=0.49.2', + default_options: ['debug=true', 'cpp_std=c++17', 'b_ndebug=if-release'], +) + +wren_dep = dependency('wren', version: '>=0.2.0', fallback: ['wren', 'wren_dep']) + +executable(meson.project_name(), + 'src/main.cpp', + dependencies: [wren_dep], + install: true, +) diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..a41eda5 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,32 @@ +#include +#include +#include +#include + +namespace { + void wren_print (WrenVM*, const char* text) { + std::cout << text; + } + + void wren_error (WrenVM*, WrenErrorType type, const char* module, int line, const char* message) { + std::cerr << "Wren error: " << message << " in " << module << ':' << line << '\n'; + } +} //unnamed namespace + +int main() { + std::cout << "hello world\n"; + WrenConfiguration config; + wrenInitConfiguration(&config); + config.writeFn = &wren_print; + config.errorFn = &wren_error; + WrenVM* vm = wrenNewVM(&config); + WrenInterpretResult result = wrenInterpret( + vm, + "my_module", + "System.print(\"I am running in a VM!\")" + ); + std::this_thread::sleep_for(std::chrono::milliseconds(2000)); + wrenFreeVM(vm); + + return 0; +} diff --git a/subprojects/wren/meson.build b/subprojects/wren/meson.build new file mode 100644 index 0000000..943409b --- /dev/null +++ b/subprojects/wren/meson.build @@ -0,0 +1,125 @@ +project('wren', 'c', + version: '0.2.0', + meson_version: '>=0.49.2', + default_options: ['debug=false', 'c_std=c99', 'build_testing=true'], +) + +c_compiler = meson.get_compiler('c') + +wren_incl = include_directories('wren/src/include', is_system: true) +wren_pvt_incl = include_directories('wren/src/vm', 'wren/src/optional') +module_incl = include_directories('wren/src/module') +cli_incl = include_directories('wren/src/cli') + +threads_dep = dependency('threads') +libuv_dep = c_compiler.find_library('libuv', required: true) +m_dep = c_compiler.find_library('m', required: true) + +opt_src = [ + 'wren/src/optional/wren_opt_random.c', + 'wren/src/optional/wren_opt_meta.c', +] + +vm_src = [ + 'wren/src/vm/wren_debug.c', + 'wren/src/vm/wren_core.c', + 'wren/src/vm/wren_utils.c', + 'wren/src/vm/wren_vm.c', + 'wren/src/vm/wren_value.c', + 'wren/src/vm/wren_primitive.c', + 'wren/src/vm/wren_compiler.c', +] + +module_src = [ + 'wren/src/module/io.c', + 'wren/src/module/timer.c', + 'wren/src/module/repl.c', + 'wren/src/module/os.c', + 'wren/src/module/scheduler.c', +] + +wren = library(meson.project_name(), + opt_src, + vm_src, + include_directories: [wren_incl, wren_pvt_incl], + dependencies: [threads_dep, m_dep], + install: get_option('wren_installable'), +) +wren_dep = declare_dependency( + include_directories: [wren_incl], + link_with: wren, +) + +if get_option('wren_with_cli') + cli = executable(meson.project_name(), + 'wren/src/cli/main.c', + 'wren/src/cli/path.c', + 'wren/src/cli/modules.c', + 'wren/src/cli/vm.c', + module_src, + install: get_option('wren_installable'), + include_directories: [cli_incl, module_incl], + dependencies: [wren_dep, libuv_dep], + c_args: ['-D_XOPEN_SOURCE=600'], + ) +endif + +if get_option('build_testing') + test_api_src = [ + 'wren/test/api/main.c', + 'wren/test/api/reset_stack_after_foreign_construct.c', + 'wren/test/api/new_vm.c', + 'wren/test/api/get_variable.c', + 'wren/test/api/slots.c', + 'wren/test/api/lists.c', + 'wren/test/api/user_data.c', + 'wren/test/api/call.c', + 'wren/test/api/foreign_class.c', + 'wren/test/api/call_wren_call_root.c', + 'wren/test/api/handle.c', + 'wren/test/api/resolution.c', + 'wren/test/api/error.c', + 'wren/test/api/call_calls_foreign.c', + 'wren/test/api/reset_stack_after_call_abort.c', + 'wren/test/api/benchmark.c', + ] + + test_unit_src = [ + 'wren/test/unit/main.c', + 'wren/test/unit/test.c', + 'wren/test/unit/path_test.c', + ] + + test_api = executable('api_' + meson.project_name(), + test_api_src, + module_src, + 'wren/src/cli/path.c', + 'wren/src/cli/modules.c', + 'wren/src/cli/vm.c', + install: false, + dependencies: [wren_dep, libuv_dep], + include_directories: [cli_incl, module_incl], + c_args: ['-D_XOPEN_SOURCE=600'], + ) + test(meson.project_name() + ' api test', test_api) + + test_unit = executable('unit_' + meson.project_name(), + test_unit_src, + module_src, + 'wren/src/cli/path.c', + 'wren/src/cli/modules.c', + 'wren/src/cli/vm.c', + install: false, + include_directories: [cli_incl, module_incl], + dependencies: [wren_dep, libuv_dep], + c_args: ['-D_XOPEN_SOURCE=600'], + ) + test(meson.project_name() + ' unit test', test_unit) +endif + +if get_option('wren_installable') + install_headers( + 'wren/src/include/wren.h', + 'wren/src/include/wren.hpp', + ) +endif diff --git a/subprojects/wren/meson_options.txt b/subprojects/wren/meson_options.txt new file mode 100644 index 0000000..143e01a --- /dev/null +++ b/subprojects/wren/meson_options.txt @@ -0,0 +1,3 @@ +option('build_testing', type: 'boolean', value: false) +option('wren_with_cli', type: 'boolean', value: true) +option('wren_installable', type: 'boolean', value: true) diff --git a/subprojects/wren/wren b/subprojects/wren/wren new file mode 160000 index 0000000..6ab4abe --- /dev/null +++ b/subprojects/wren/wren @@ -0,0 +1 @@ +Subproject commit 6ab4abe9e3a2767ced01589e9a3d583c840f54c3