4
Copyright (c) 2021 МГТУ им. Н.Э. Баумана, кафедра ИУ-6, Михаил Фетисов,
6
https://bmstu.codes/lsx/simodo
9
#include "simodo/interpret/Interpret.h"
10
#include "simodo/interpret/AnalyzeException.h"
12
#include "simodo/loom/Loom_interface.h"
13
#include "simodo/bormental/DrBormental.h"
14
#include "simodo/inout/convert/functions.h"
19
#define SemanticFiber_DEBUG_no
21
namespace simodo::interpret
23
bool Interpret::wait(const variable::Variable & var)
25
const ChildFlowInfo * info = findChildFlowInfo(var);
29
if (var.origin().type() != variable::ValueType::Object)
32
_waiting_for = info->child->fiber();
37
bool Interpret::push(const variable::Variable & var)
39
const ChildFlowInfo * info = findChildFlowInfo(var);
43
if (var.origin().type() != variable::ValueType::Object)
46
std::shared_ptr<variable::Object> source_object = var.origin().value().getObject();
47
auto [begin,end] = info->child->stack().boundaryLowAndTop(info->child_bound);
49
for(name_index_t i=begin; i < end; ++i) {
50
variable::Variable & target_variable = info->child->stack().variable(i);
51
if (!target_variable.value().isFunction()) {
52
const variable::Variable & source_element = source_object->getVariableByName(target_variable.name());
53
assert(!source_element.name().empty());
54
target_variable.value() = source_element.value().copy();
61
bool Interpret::pull(variable::Variable & var)
63
const ChildFlowInfo * info = findChildFlowInfo(var);
67
if (var.origin().type() != variable::ValueType::Object)
70
// _loom.wait(info->child->fiber());
72
std::shared_ptr<variable::Object> target_object = var.origin().value().getObject();
73
auto [begin,end] = info->child->stack().boundaryLowAndTop(info->child_bound);
75
for(name_index_t i=begin; i < end; ++i) {
76
const variable::Variable & source_element = info->child->stack().variable(i);
77
if (!source_element.value().isFunction()) {
78
variable::Variable & target_variable = const_cast<variable::Variable &>(target_object->getVariableByName(source_element.name()));
79
assert(!target_variable.name().empty());
80
target_variable.value() = source_element.value().copy();
87
// bool Interpret::cut()
93
bool Interpret::addChildFiber(const variable::Variable & var)
95
const ChildFlowInfo * info = findChildFlowInfo(var);
99
if (var.origin().type() != variable::ValueType::Object)
102
std::shared_ptr<variable::Object> obj = var.origin().value().getObject();
104
Interpret * child = new Interpret(_type, _m, _loom, _semantic_factories);
106
boundary_index_t child_bound = child->copyBaseBounds(stack());
108
child->stack().fillFromObject(obj);
109
child->stack().startBoundary();
111
/// \todo Это одноразовое копирование не годится для общего случая, особенно для итеративной отладки!
113
child->_files = _files;
114
child->_breakpoints = _breakpoints;
117
const variable::Value & name_value = obj->find(u"name");
119
if (name_value.isString())
120
name = inout::toU8(name_value.getString());
122
name = inout::toU8(var.origin().name());
124
if (!_loom.dock(child,true,this,loom::FiberStatus::Delayed,name)) {
129
_childs.push_back({obj,child,child_bound});
133
const ChildFlowInfo * Interpret::findChildFlowInfo(const variable::Variable & var) const
135
if (var.origin().type() != variable::ValueType::Object)
138
std::shared_ptr<variable::Object> obj = var.origin().value().getObject();
140
auto it = std::find_if( _childs.begin(), _childs.end(),
141
[obj](const ChildFlowInfo & info)
143
return info.our_object.get() == obj.get();
146
if (it == _childs.end())