4
Copyright (c) 2021 МГТУ им. Н.Э. Баумана, кафедра ИУ-6, Михаил Фетисов,
6
https://bmstu.codes/lsx/simodo/loom
9
#include "simodo/variable/Module_interface.h"
10
#include "simodo/variable/VariableSetWrapper.h"
12
#include "simodo/interpret/Interpret_interface.h"
13
#include "simodo/loom/Loom_interface.h"
14
#include "simodo/loom/FiberStatus.h"
16
#include "simodo/inout/convert/functions.h"
23
// MinGW related workaround
24
#define BOOST_DLL_FORCE_ALIAS_INSTANTIATION
27
#include <boost/dll/alias.hpp>
29
using namespace simodo;
30
using namespace simodo::variable;
34
Value get_test_string(Module_interface * host, const VariableSetWrapper & );
35
Value set_test_string(Module_interface * host, const VariableSetWrapper & args);
36
Value get_fibers(Module_interface * host, const VariableSetWrapper & );
39
class ModuleHost_test : public Module_interface
41
std::u16string _test_string; // = u"initial test string";
42
interpret::Interpret_interface * _interpret = nullptr;
45
ModuleHost_test(interpret::Interpret_interface * interpret)
47
_test_string = u"initial test string";
48
_interpret = interpret;
51
const std::u16string & test_string() const { return _test_string; }
52
void setTestString(const std::u16string & str) { _test_string = str; }
54
interpret::Interpret_interface * interpret() { return _interpret; }
56
virtual version_t version() const override { return lib_version(); }
58
virtual Object instantiate(std::shared_ptr<variable::Module_interface> module_object) override
60
// cout << "getNamespace(0x" << hex << module_host << ")"<< endl;
61
// cout << "." << convertToU8(_test_string) << endl;
64
{u"doc", u"Нужно будет предусмотреть поддержку трансляции"},
65
// {u"doc", u"\\href http://.../README.md", {}, {}},
66
// {u"pi", 3.14, {}, {{u"doc", u"Число pi", {}, {}}}},
67
{u"get_test_string", {ValueType::Function, Object {{
68
{u"@", ExternalFunction {module_object, get_test_string}},
69
{{}, ValueType::String},
71
{u"set_test_string", {ValueType::Function, Object {{
72
{u"@", ExternalFunction {module_object, set_test_string}},
73
{{}, ValueType::Null},
74
{u"test_string", ValueType::String},
76
{u"get_fibers", {ValueType::Function, Object {{
77
{u"@", ExternalFunction {module_object, get_fibers}},
78
{{}, ValueType::Object},
84
static std::shared_ptr<Module_interface> create(interpret::Interpret_interface * interpret) {
85
return std::make_shared<ModuleHost_test>(interpret);
90
ModuleHost_test::create, // <-- this function is exported with...
91
create_simodo_module // <-- ...this alias name
96
Value get_test_string(Module_interface * host, const VariableSetWrapper & )
98
// cout << "get_test_string(0x" << hex << host << ",)"<< endl;
99
assert(host != nullptr);
100
ModuleHost_test * test = static_cast<ModuleHost_test *>(host);
101
// cout << "." << convertToU8(test->test_string()) << endl;
103
return test->test_string();
106
Value set_test_string(Module_interface * host, const VariableSetWrapper & args)
108
// cout << "set_test_string(0x" << hex << host << ",)"<< endl;
109
assert(host != nullptr);
110
ModuleHost_test * test = static_cast<ModuleHost_test *>(host);
111
// cout << "." << convertToU8(test->test_string()) << endl;
113
assert(args.size() == 1);
115
test->setTestString(args[0].origin().value().getString());
116
// test->setTestString(u"set_test_string called");
121
Value get_fibers(Module_interface * host, const VariableSetWrapper & )
123
assert(host != nullptr);
124
ModuleHost_test * test = static_cast<ModuleHost_test *>(host);
126
if (test->interpret() == nullptr)
127
return {u"Have to use script module for fibers request"};
129
const loom::Loom_interface * loom = test->interpret()->loom();
132
variable::VariableSet_t fibers_info;
134
std::vector<loom::FiberStructure> fibers = loom->fibers();
136
for(const loom::FiberStructure & f : fibers)
137
fibers_info.push_back({inout::toU16(std::to_string(int64_t(f.no))), inout::toU16(loom::getFiberStatusName(f.status))});