|
@@ -1,35 +1,31 @@
|
|
|
-#include "core-activation.h"
|
|
|
-#include "inter.h"
|
|
|
-#include "core-logger.h"
|
|
|
-#include "msg.h"
|
|
|
-#include "aFuncode.h"
|
|
|
-#include "core-exception.h"
|
|
|
-
|
|
|
-namespace aFuncore {
|
|
|
+#include "rt-activation.h"
|
|
|
+#include "rt-exception.h"
|
|
|
+#include "rt-message.h"
|
|
|
+#include "rt-logger.h"
|
|
|
+
|
|
|
+namespace aFunrt {
|
|
|
/**
|
|
|
* 创建基本Activation
|
|
|
* 自动继承上层VarList和UpMessage
|
|
|
* 自动压入inter
|
|
|
* @param inter_
|
|
|
*/
|
|
|
- Activation::Activation(Inter &inter_)
|
|
|
- : inter{inter_}, up{inter_.activation == nullptr ? nullptr : &inter_.activation->up}, down{}, line{0} {
|
|
|
- if (inter_.activation != nullptr) {
|
|
|
- varlist.connect(inter_.activation->varlist);
|
|
|
- line = inter_.activation->line;
|
|
|
- path = inter_.activation->path;
|
|
|
+ NormalActivation::NormalActivation(aFuncore::Inter &inter_)
|
|
|
+ : Activation(), inter{inter_}, up{inter_.getActivation() == nullptr ? nullptr : &inter_.getActivation()->getUpStream()}, down{}, line{0} {
|
|
|
+ auto activation = dynamic_cast<NormalActivation *>(inter_.getActivation());
|
|
|
+ if (activation != nullptr) {
|
|
|
+ varlist.connect(activation->getVarlist());
|
|
|
+ line = inter_.getActivation()->getFileLine();
|
|
|
+ path = inter_.getActivation()->getFilePath();
|
|
|
} else {
|
|
|
auto global = new VarSpace(inter);
|
|
|
- varlist.push(inter_.getProtectVarSpace());
|
|
|
varlist.push(global);
|
|
|
global->delReference();
|
|
|
path = "";
|
|
|
}
|
|
|
-
|
|
|
- inter.pushActivation(this);
|
|
|
}
|
|
|
|
|
|
- static void ActivationTopProgress(Message *msg, Inter &inter, Activation &activation){
|
|
|
+ static void ActivationTopProgress(aFuncore::Message *msg, aFuncore::Inter &inter, NormalActivation &activation){
|
|
|
auto *t = dynamic_cast<TopMessage *>(msg);
|
|
|
if (t)
|
|
|
t->topProgress(inter, activation);
|
|
@@ -40,14 +36,14 @@ namespace aFuncore {
|
|
|
* 注意: 不会自动从inter中弹出
|
|
|
* 释放Varlist并且将DownMessage压入上层
|
|
|
*/
|
|
|
- Activation::~Activation(){
|
|
|
- if (inter.activation != nullptr)
|
|
|
- down.joinMsg(inter.activation->down);
|
|
|
+ NormalActivation::~NormalActivation(){
|
|
|
+ if (inter.getActivation() != nullptr)
|
|
|
+ down.joinMsg(inter.getActivation()->getDownStream());
|
|
|
else
|
|
|
down.forEach(ActivationTopProgress, std::ref(inter), std::ref(*this));
|
|
|
}
|
|
|
|
|
|
- void Activation::endRun() {
|
|
|
+ void NormalActivation::endRun() {
|
|
|
|
|
|
}
|
|
|
|
|
@@ -55,10 +51,10 @@ namespace aFuncore {
|
|
|
* 运行代码
|
|
|
* @param code
|
|
|
*/
|
|
|
- void Activation::runCode(const aFuncode::Code::ByteCode *code){
|
|
|
+ void NormalActivation::runCode(const aFuncode::Code::ByteCode *code){
|
|
|
auto code_type = code->getType();
|
|
|
if (code_type == aFuncode::Code::ByteCode::code_start) { // start 不处理 msg
|
|
|
- auto *none = new Object("None", inter);
|
|
|
+ auto *none = new aFuncore::Object("None", inter);
|
|
|
down.pushMessage("NORMAL", new NormalMessage(none));
|
|
|
none->delReference();
|
|
|
} else {
|
|
@@ -76,28 +72,34 @@ namespace aFuncore {
|
|
|
runCodeBlockC(code);
|
|
|
break;
|
|
|
default:
|
|
|
- errorLog(aFunCoreLogger, "Error block type.");
|
|
|
+ errorLog(aFunRuntimeLogger, "Error block type.");
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- void Activation::runCodeElement(const aFuncode::Code::ByteCode *code){
|
|
|
+ void NormalActivation::runCodeElement(const aFuncode::Code::ByteCode *code){
|
|
|
std::string literaler_name;
|
|
|
bool in_protect = false;
|
|
|
- Object *obj = nullptr;
|
|
|
+ aFuncore::Object *obj = nullptr;
|
|
|
if (inter.checkLiteral(code->getElement(), literaler_name, in_protect)) {
|
|
|
if (in_protect)
|
|
|
- obj = inter.getProtectVarSpace()->findObject(literaler_name);
|
|
|
- else
|
|
|
+ inter.getEnvVarSpace().findObject(literaler_name, obj);
|
|
|
+ else {
|
|
|
obj = varlist.findObject(literaler_name);
|
|
|
+ if (obj == nullptr)
|
|
|
+ inter.getEnvVarSpace().findObject(literaler_name, obj);
|
|
|
+ }
|
|
|
auto literaler = dynamic_cast<Literaler *>(obj);
|
|
|
if (literaler != nullptr)
|
|
|
literaler->getObject(code->getElement(), code->getPrefix(), inter, *this);
|
|
|
else
|
|
|
- down.pushMessage("ERROR", new ErrorMessage("TypeError", "Error type of literal.", this));
|
|
|
+ down.pushMessage("ERROR", new ErrorMessage("TypeError", "Error type of literal.", inter));
|
|
|
} else {
|
|
|
obj = varlist.findObject(code->getElement());
|
|
|
+ if (obj == nullptr)
|
|
|
+ inter.getEnvVarSpace().findObject(code->getElement(), obj);
|
|
|
+
|
|
|
if (obj != nullptr) {
|
|
|
auto cbv = dynamic_cast<CallBackVar *>(obj);
|
|
|
if (cbv != nullptr && cbv->isCallBack(inter, *this))
|
|
@@ -106,45 +108,40 @@ namespace aFuncore {
|
|
|
down.pushMessage("NORMAL", new NormalMessage(obj));
|
|
|
} else
|
|
|
down.pushMessage("ERROR",
|
|
|
- new ErrorMessage("NameError", std::string("Variable ") + code->getElement() + " not fount.",
|
|
|
- this));
|
|
|
+ new ErrorMessage("NameError",
|
|
|
+ std::string("Variable ") + code->getElement() + " not fount.", inter));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- void Activation::runCodeBlockP(const aFuncode::Code::ByteCode *code){
|
|
|
- new ExeActivation(code->getSon(), inter);
|
|
|
+ void NormalActivation::runCodeBlockP(const aFuncode::Code::ByteCode *code){
|
|
|
+ inter.pushActivation(new ExeActivation(code->getSon(), inter));
|
|
|
}
|
|
|
|
|
|
- void Activation::runCodeBlockC(const aFuncode::Code::ByteCode *code){
|
|
|
- new FuncActivation(code, inter);
|
|
|
+ void NormalActivation::runCodeBlockC(const aFuncode::Code::ByteCode *code){
|
|
|
+ inter.pushActivation(new FuncActivation(code, inter));
|
|
|
}
|
|
|
|
|
|
- void Activation::runCodeBlockB(const aFuncode::Code::ByteCode *code){
|
|
|
- new FuncActivation(code, inter);
|
|
|
+ void NormalActivation::runCodeBlockB(const aFuncode::Code::ByteCode *code){
|
|
|
+ inter.pushActivation(new FuncActivation(code, inter));
|
|
|
}
|
|
|
|
|
|
- Activation::ActivationStatus ExeActivation::getCode(const aFuncode::Code::ByteCode *&code){
|
|
|
- code = next;
|
|
|
- if (code == nullptr)
|
|
|
- return as_end;
|
|
|
+ aFuncore::UpMessageStream &NormalActivation::getUpStream() {
|
|
|
+ return up;
|
|
|
+ }
|
|
|
|
|
|
- if (!first) {
|
|
|
- auto msg = down.getMessage<NormalMessage>("NORMAL");
|
|
|
- if (msg == nullptr)
|
|
|
- return as_end;
|
|
|
- else
|
|
|
- down.popMessage("NORMAL");
|
|
|
- delete msg;
|
|
|
- }
|
|
|
+ aFuncore::DownMessageStream &NormalActivation::getDownStream() {
|
|
|
+ return down;
|
|
|
+ }
|
|
|
|
|
|
- first = false;
|
|
|
- line = code->getFileLine();
|
|
|
- path = code->getFilePath();
|
|
|
- next = code->toNext();
|
|
|
- return as_run;
|
|
|
+ aFuntool::FileLine NormalActivation::getFileLine() {
|
|
|
+ return line;
|
|
|
}
|
|
|
|
|
|
- Activation::VarList::~VarList() {
|
|
|
+ const aFuntool::FilePath &NormalActivation::getFilePath() {
|
|
|
+ return path;
|
|
|
+ }
|
|
|
+
|
|
|
+ NormalActivation::VarList::~VarList() {
|
|
|
for (auto &t : varspace)
|
|
|
t->delReference();
|
|
|
}
|
|
@@ -154,7 +151,7 @@ namespace aFuncore {
|
|
|
* @param name 变量名
|
|
|
* @return
|
|
|
*/
|
|
|
- Var *Activation::VarList::findVar(const std::string &name){
|
|
|
+ Var *NormalActivation::VarList::findVar(const std::string &name){
|
|
|
Var *ret = nullptr;
|
|
|
for (auto tmp = varspace.begin(), end = varspace.end(); tmp != end && ret == nullptr; tmp++)
|
|
|
ret = (*tmp)->findVar(name);
|
|
@@ -169,7 +166,7 @@ namespace aFuncore {
|
|
|
* @param data 变量(Object)
|
|
|
* @return
|
|
|
*/
|
|
|
- bool Activation::VarList::defineVar(const std::string &name, Object *data){
|
|
|
+ bool NormalActivation::VarList::defineVar(const std::string &name, aFuncore::Object *data){
|
|
|
VarSpace::VarOperationFlat ret = VarSpace::vof_fail;
|
|
|
for (auto tmp = varspace.begin(), end = varspace.end(); tmp != end && ret == VarSpace::vof_fail; tmp++)
|
|
|
ret = (*tmp)->defineVar(name, data);
|
|
@@ -184,7 +181,7 @@ namespace aFuncore {
|
|
|
* @param data 变量(Var)
|
|
|
* @return
|
|
|
*/
|
|
|
- bool Activation::VarList::defineVar(const std::string &name, Var *data){
|
|
|
+ bool NormalActivation::VarList::defineVar(const std::string &name, Var *data){
|
|
|
VarSpace::VarOperationFlat ret = VarSpace::vof_fail;
|
|
|
for (auto tmp = varspace.begin(), end = varspace.end(); tmp != end && ret == VarSpace::vof_fail; tmp++)
|
|
|
ret = (*tmp)->defineVar(name, data);
|
|
@@ -199,7 +196,7 @@ namespace aFuncore {
|
|
|
* @param data 数据
|
|
|
* @return
|
|
|
*/
|
|
|
- bool Activation::VarList::setVar(const std::string &name, Object *data){
|
|
|
+ bool NormalActivation::VarList::setVar(const std::string &name, aFuncore::Object *data){
|
|
|
VarSpace::VarOperationFlat ret = VarSpace::vof_not_var;
|
|
|
for (auto tmp = varspace.begin(), end = varspace.end(); tmp != end && ret == VarSpace::vof_not_var; tmp++)
|
|
|
ret = (*tmp)->setVar(name, data);
|
|
@@ -213,32 +210,53 @@ namespace aFuncore {
|
|
|
* @param name
|
|
|
* @return
|
|
|
*/
|
|
|
- bool Activation::VarList::delVar(const std::string &name){
|
|
|
+ bool NormalActivation::VarList::delVar(const std::string &name){
|
|
|
VarSpace::VarOperationFlat ret = VarSpace::vof_not_var;
|
|
|
for (auto tmp = varspace.begin(), end = varspace.end(); tmp != end && ret == VarSpace::vof_not_var; tmp++)
|
|
|
ret = (*tmp)->delVar(name);
|
|
|
return ret == VarSpace::vof_success;
|
|
|
}
|
|
|
|
|
|
- void Activation::VarList::clear(){
|
|
|
+ void NormalActivation::VarList::clear(){
|
|
|
for (auto &t: varspace)
|
|
|
t->delReference();
|
|
|
varspace.clear();
|
|
|
}
|
|
|
|
|
|
- void Activation::VarList::connect(VarList &new_varlist){
|
|
|
+ void NormalActivation::VarList::connect(VarList &new_varlist){
|
|
|
for (auto &t: new_varlist.varspace) {
|
|
|
t->addReference();
|
|
|
this->varspace.push_back(t);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- TopActivation::TopActivation(const aFuncode::Code &code, Inter &inter_) : ExeActivation(code, inter_), base{code} {
|
|
|
+ NormalActivation::ActivationStatus ExeActivation::getCode(const aFuncode::Code::ByteCode *&code){
|
|
|
+ code = next;
|
|
|
+ if (code == nullptr)
|
|
|
+ return as_end;
|
|
|
+
|
|
|
+ if (!first) {
|
|
|
+ auto msg = down.getMessage<NormalMessage>("NORMAL");
|
|
|
+ if (msg == nullptr)
|
|
|
+ return as_end;
|
|
|
+ else
|
|
|
+ down.popMessage("NORMAL");
|
|
|
+ delete msg;
|
|
|
+ }
|
|
|
+
|
|
|
+ first = false;
|
|
|
+ line = code->getFileLine();
|
|
|
+ path = code->getFilePath();
|
|
|
+ next = code->toNext();
|
|
|
+ return as_run;
|
|
|
+ }
|
|
|
+
|
|
|
+ TopActivation::TopActivation(const aFuncode::Code &code, aFuncore::Inter &inter_) : ExeActivation(code, inter_), base{code} {
|
|
|
|
|
|
}
|
|
|
|
|
|
- FuncActivation::FuncActivation(Function *func_, Inter &inter_)
|
|
|
- : Activation(inter_), status{func_get_func}, on_tail{false}, call{nullptr}, func{func_}, acl_begin{}, acl_end{} {
|
|
|
+ FuncActivation::FuncActivation(Function *func_, aFuncore::Inter &inter_)
|
|
|
+ : NormalActivation(inter_), status{func_get_func}, on_tail{false}, call{nullptr}, func{func_}, acl_begin{}, acl_end{} {
|
|
|
func->addReference();
|
|
|
}
|
|
|
|
|
@@ -248,7 +266,7 @@ namespace aFuncore {
|
|
|
delete call_func;
|
|
|
}
|
|
|
|
|
|
- Activation::ActivationStatus FuncActivation::getCode(const aFuncode::Code::ByteCode *&code) {
|
|
|
+ NormalActivation::ActivationStatus FuncActivation::getCode(const aFuncode::Code::ByteCode *&code) {
|
|
|
if (on_tail)
|
|
|
return as_end;
|
|
|
|
|
@@ -259,7 +277,8 @@ namespace aFuncore {
|
|
|
code = call->getSon();
|
|
|
if (code == nullptr) {
|
|
|
line = 0;
|
|
|
- down.pushMessage("ERROR", new ErrorMessage("SyntaxError", "Callback without code.", this));
|
|
|
+ down.pushMessage("ERROR", new ErrorMessage("SyntaxError", "Callback without code.",
|
|
|
+ inter));
|
|
|
return as_end;
|
|
|
}
|
|
|
line = code->getFileLine();
|
|
@@ -275,7 +294,9 @@ namespace aFuncore {
|
|
|
if (var->getType() != aFuncode::Code::ByteCode::code_element || var->getPrefix() == quote ||
|
|
|
inter.checkLiteral(var->getElement()))
|
|
|
continue;
|
|
|
- Object *obj = varlist.findObject(var->getElement());
|
|
|
+ aFuncore::Object *obj = varlist.findObject(var->getElement());
|
|
|
+ if (obj == nullptr)
|
|
|
+ inter.getEnvVarSpace().findObject(var->getElement(), obj);
|
|
|
if (obj == nullptr || !dynamic_cast<Function *>(obj) ||
|
|
|
!dynamic_cast<Function *>(obj)->isInfix())
|
|
|
continue;
|
|
@@ -288,15 +309,17 @@ namespace aFuncore {
|
|
|
}
|
|
|
if (status != func_get_func) {
|
|
|
line = 0;
|
|
|
- down.pushMessage("ERROR", new ErrorMessage("SyntaxError", "Callback without code.", this));
|
|
|
+ down.pushMessage("ERROR", new ErrorMessage("SyntaxError", "Callback without code.",
|
|
|
+ inter));
|
|
|
return as_end;
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
default:
|
|
|
- errorLog(aFunCoreLogger, "Error FuncActivation block type");
|
|
|
+ errorLog(aFunRuntimeLogger, "Error FuncActivation block type");
|
|
|
line = 0;
|
|
|
- down.pushMessage("ERROR", new ErrorMessage("RuntimeError", "Error FuncActivation block type.", this));
|
|
|
+ down.pushMessage("ERROR", new ErrorMessage("RuntimeError", "Error FuncActivation block type.",
|
|
|
+ inter));
|
|
|
return as_end;
|
|
|
}
|
|
|
}
|
|
@@ -311,7 +334,7 @@ namespace aFuncore {
|
|
|
func = dynamic_cast<Function *>(msg->getObject());
|
|
|
delete msg;
|
|
|
if (func == nullptr) {
|
|
|
- down.pushMessage("ERROR", new ErrorMessage("TypeError", "Callback without function.", this));
|
|
|
+ down.pushMessage("ERROR", new ErrorMessage("TypeError", "Callback without function.", inter));
|
|
|
return as_end;
|
|
|
}
|
|
|
func->addReference();
|
|
@@ -323,7 +346,7 @@ namespace aFuncore {
|
|
|
call_func = func->getCallFunction(call, inter);
|
|
|
acl = call_func->getArgCodeList(inter, *this, call);
|
|
|
} catch (RuntimeError &e) {
|
|
|
- down.pushMessage("ERROR", new ErrorMessage(e.getType(), e.getMessage(), this));
|
|
|
+ down.pushMessage("ERROR", new ErrorMessage(e.getType(), e.getMessage(), inter));
|
|
|
return as_end;
|
|
|
}
|
|
|
acl_begin = acl->begin();
|