Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
steve02081504 committed May 15, 2022
1 parent 50380a9 commit 49d1adf
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 49 deletions.
42 changes: 12 additions & 30 deletions function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#endif
////////////////////////////////////////

CFunction::CFunction(CAyaVM& vmr, const yaya::string_t& n, choicetype_t ct, const yaya::string_t& df, int lc) : pvm(&vmr), name(n), dupl_func(ct), dicfilename(df), linecount(lc), dicfilename_fullpath(vmr.basis().ToFullPath(df))
CFunction::CFunction(CAyaVM& vmr, const yaya::string_t& n, const yaya::string_t& df, int lc) : pvm(&vmr), name(n), dicfilename(df), linecount(lc), dicfilename_fullpath(vmr.basis().ToFullPath(df))
{
statelenm1 = 0;
namelen = name.size();
Expand Down Expand Up @@ -126,7 +126,7 @@ CFunction::ExecutionResult CFunction::Execute(const CValue &arg, CLocalVariable

void CFunction::Execute_SEHhelper(CFunction::ExecutionResult& aret, CLocalVariable& lvar, int& exitcode)
{
aret = ExecuteInBrace(0, lvar, BRACE_DEFAULT, exitcode, NULL, 0);
aret = ExecuteInBrace(1, lvar, BRACE_DEFAULT, exitcode, NULL, 0);
}

void CFunction::Execute_SEHbody(ExecutionResult& retas, CLocalVariable& lvar, int& exitcode)
Expand Down Expand Up @@ -156,16 +156,13 @@ CFunction::ExecutionInBraceResult CFunction::ExecuteInBrace(size_t line, CLocalV
{
// 開始時の処理
lvar.AddDepth();
CDuplEvInfo* pdupl = &dupl_func;
if (lvar.GetDepth() != 1) {
pdupl = statement[line-1].dupl_block.get();
}
CDuplEvInfo* pdupl = statement[line-1].dupl_block.get();
const bool inmutiarea = statement[line-1].ismutiarea; // pool用

// 実行
CSelecter output(pvm, pdupl, (ptrdiff_t)type);
bool exec_end = 0; // この{}の実行を終了するためのフラグ 1で終了
bool ifflg = 0; // if-elseif-else制御用。1でそのブロックを処理したことを示す
bool inmutiarea = 0; // pool用
bool notpoolblock = 0; // pool用
const bool ispoolbegin = !inpool; // pool用
bool meltblock = 0;
Expand All @@ -188,22 +185,7 @@ CFunction::ExecutionInBraceResult CFunction::ExecuteInBrace(size_t line, CLocalV
meltblock = 0;
}

{//init inmutiarea
size_t i = 0;
size_t st_num = 0;
for(i = line; i < statelenm1; i++) {
if(statement[i].type == ST_OPEN)
st_num++;
if(statement[i].type == ST_CLOSE)
st_num--;
if(statement[i].type == ST_COMBINE && st_num==0) {
inmutiarea = 1;
break;
}
}
}

#define INPOOL_TO_NEXT (!inmutiarea ? inpool : false)
const bool inpool_to_next = (!inmutiarea ? !notpoolblock : false);

size_t t_statelenm1 = statelenm1;

Expand All @@ -213,7 +195,7 @@ CFunction::ExecutionInBraceResult CFunction::ExecuteInBrace(size_t line, CLocalV

switch(st.type) {
case ST_OPEN: { // "{"
ExecutionInBraceResult info = ExecuteInBrace(i + 1, lvar, BRACE_DEFAULT, exitcode, UpperLvCandidatePool, INPOOL_TO_NEXT);
ExecutionInBraceResult info = ExecuteInBrace(i + 1, lvar, BRACE_DEFAULT, exitcode, UpperLvCandidatePool, inpool_to_next);
i = info.linenum;
output.Append(info.Output());
break;
Expand All @@ -233,7 +215,7 @@ CFunction::ExecutionInBraceResult CFunction::ExecuteInBrace(size_t line, CLocalV
case ST_IF: // if
ifflg = 0;
if (GetFormulaAnswer(lvar, st).GetTruth()) {
ExecutionInBraceResult info = ExecuteInBrace(i + 2, lvar, BRACE_DEFAULT, exitcode, UpperLvCandidatePool, INPOOL_TO_NEXT);
ExecutionInBraceResult info = ExecuteInBrace(i + 2, lvar, BRACE_DEFAULT, exitcode, UpperLvCandidatePool, inpool_to_next);
i = info.linenum;
output.Append(info.Output());
ifflg = 1;
Expand All @@ -245,7 +227,7 @@ CFunction::ExecutionInBraceResult CFunction::ExecuteInBrace(size_t line, CLocalV
if (ifflg)
i = st.jumpto;
else if (GetFormulaAnswer(lvar, st).GetTruth()) {
ExecutionInBraceResult info = ExecuteInBrace(i + 2, lvar, BRACE_DEFAULT, exitcode, UpperLvCandidatePool, INPOOL_TO_NEXT);
ExecutionInBraceResult info = ExecuteInBrace(i + 2, lvar, BRACE_DEFAULT, exitcode, UpperLvCandidatePool, inpool_to_next);
i = info.linenum;
output.Append(info.Output());
ifflg = 1;
Expand All @@ -257,7 +239,7 @@ CFunction::ExecutionInBraceResult CFunction::ExecuteInBrace(size_t line, CLocalV
if (ifflg)
i = st.jumpto;
else {
ExecutionInBraceResult info = ExecuteInBrace(i + 2, lvar, BRACE_DEFAULT, exitcode, UpperLvCandidatePool, INPOOL_TO_NEXT);
ExecutionInBraceResult info = ExecuteInBrace(i + 2, lvar, BRACE_DEFAULT, exitcode, UpperLvCandidatePool, inpool_to_next);
i = info.linenum;
output.Append(info.Output());
}
Expand Down Expand Up @@ -287,7 +269,7 @@ CFunction::ExecutionInBraceResult CFunction::ExecuteInBrace(size_t line, CLocalV
while ( (loop_max == 0) || (loop_max > loop_cur++) ) {
if (!GetFormulaAnswer(lvar, st).GetTruth())
break;
CValue t_value = ExecuteInBrace(i + 2, lvar, BRACE_LOOP, exitcode, UpperLvCandidatePool, INPOOL_TO_NEXT);
CValue t_value = ExecuteInBrace(i + 2, lvar, BRACE_LOOP, exitcode, UpperLvCandidatePool, inpool_to_next);
output.Append(t_value);

if (exitcode == ST_BREAK) {
Expand Down Expand Up @@ -330,7 +312,7 @@ CFunction::ExecutionInBraceResult CFunction::ExecuteInBrace(size_t line, CLocalV
while ( (loop_max == 0) || (loop_max > loop_cur++) ) {
if (!GetFormulaAnswer(lvar, statement[i + 1]).GetTruth()) //for第二パラメータ
break;
CValue t_value = ExecuteInBrace(i + 4, lvar, BRACE_LOOP, exitcode, UpperLvCandidatePool, INPOOL_TO_NEXT);
CValue t_value = ExecuteInBrace(i + 4, lvar, BRACE_LOOP, exitcode, UpperLvCandidatePool, inpool_to_next);
output.Append(t_value);

if (exitcode == ST_BREAK) {
Expand Down Expand Up @@ -375,7 +357,7 @@ CFunction::ExecutionInBraceResult CFunction::ExecuteInBrace(size_t line, CLocalV
}
break;
case ST_FOREACH: // foreach
Foreach(lvar, output, i, exitcode, UpperLvCandidatePool, INPOOL_TO_NEXT);
Foreach(lvar, output, i, exitcode, UpperLvCandidatePool, inpool_to_next);
i = st.jumpto;
break;
case ST_BREAK: // break
Expand Down
8 changes: 5 additions & 3 deletions function.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class CStatement
ptrdiff_t linecount; // 辞書ファイル中の行番号

mutable std_shared_ptr < CDuplEvInfo > dupl_block; // pool:{ //...
mutable bool ismutiarea;

private:
mutable std_shared_ptr<std::vector<CCell> > m_cell; // 数式の項の群 
Expand All @@ -52,12 +53,14 @@ class CStatement
linecount = l;
jumpto = 0;
dupl_block=dupl;
ismutiarea = false;
}
CStatement(void) {
type = ST_NOP;
linecount = 0;
jumpto = 0;
dupl_block.reset();
ismutiarea = false;
}
~CStatement(void) {}

Expand Down Expand Up @@ -129,7 +132,6 @@ class CFunction
yaya::string_t name; // 名前
yaya::string_t::size_type namelen; // 名前の長さ
std::vector<CStatement> statement; // 命令郡
CDuplEvInfo dupl_func; // 重複回避制御
yaya::string_t dicfilename; // 対応する辞書ファイル名
yaya::string_t dicfilename_fullpath;

Expand All @@ -141,7 +143,7 @@ class CFunction
CFunction(void);

public:
CFunction(CAyaVM& vmr, const yaya::string_t& n, choicetype_t ct, const yaya::string_t& df, int lc);
CFunction(CAyaVM& vmr, const yaya::string_t& n, const yaya::string_t& df, int lc);

~CFunction(void) {}

Expand Down Expand Up @@ -176,7 +178,7 @@ class CFunction

const yaya::string_t& GetFileName() const {return dicfilename;}
size_t GetLineNumBegin() const { return linecount;}
size_t GetLineNumEnd() const { return statement.empty() ? 0 : statement[statement.size()-1].linecount;}
size_t GetLineNumEnd() const { return statement.empty() ? 0 : statement.back().linecount;}

protected:

Expand Down
2 changes: 1 addition & 1 deletion logexcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void CLogExCode::OutExecutionCodeForCheck(void)
vm.logger().Write(L" ------------------------------------------------------------------------\n");
// 関数の重複回避モード
vm.logger().Write(L"Duplication evasion mode : ");
vm.logger().Write(CSelecter::ChoiceTypeToString(it->dupl_func.GetType()));
vm.logger().Write(CSelecter::ChoiceTypeToString(it->statement[0].dupl_block.get()->GetType()));
vm.logger().Write(L"\n");
// 関数が記述されている辞書ファイル名
vm.logger().Write(L"dic filename : ");
Expand Down
24 changes: 17 additions & 7 deletions parser0.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -882,12 +882,19 @@ ptrdiff_t CParser0::MakeFunction(const yaya::string_t& name, choicetype_t chtype
return -1;
*/

vm.function_parse().func.emplace_back(CFunction(vm, name, chtype, dicfilename, linecount));
vm.function_parse().AddFunctionIndex(name,vm.function_parse().func.size()-1);
vm.function_parse().func.emplace_back(vm, name, dicfilename, linecount);
size_t index = vm.function_parse().func.size()-1;
vm.function_parse().AddFunctionIndex(name, index);

CFunction& targetfunction = vm.function_parse().func[index];
targetfunction.statement.emplace_back(ST_OPEN, linecount, std::make_shared<CDuplEvInfo>(chtype));

m_BlockhHeaderOfProcessing.clear();
m_BlockhHeaderOfProcessing.emplace_back(&targetfunction.statement[0]);
m_defaultBlockChoicetypeStack.clear();
m_defaultBlockChoicetypeStack.emplace_back(CSelecter::GetDefaultBlockChoicetype(chtype));

return vm.function_parse().func.size() - 1;
return index;
}

/* -----------------------------------------------------------------------
Expand All @@ -905,20 +912,22 @@ char CParser0::StoreInternalStatement(size_t targetfunc, yaya::string_t &str, si
if(!str.size())
return 1;
// {
if (str[str.size()-1]==L'{') {
if(str.back() == L'{') {
// blockと重複回避オプションを取得
choicetype_t chtype = CSelecter::GetDefaultBlockChoicetype(m_defaultBlockChoicetypeStack[m_defaultBlockChoicetypeStack.size()-1]);
choicetype_t chtype = CSelecter::GetDefaultBlockChoicetype(m_defaultBlockChoicetypeStack.back());
yaya::string_t d0, d1;
if (Split(str, d0, d1, L":")){
chtype = CSelecter::StringToChoiceType(d0, vm, dicfilename, linecount);
}
m_defaultBlockChoicetypeStack.emplace_back(chtype);
depth++;
targetfunction.statement.emplace_back(CStatement(ST_OPEN, linecount, std_make_shared<CDuplEvInfo>(chtype)));
targetfunction.statement.emplace_back(ST_OPEN, linecount, std::make_shared<CDuplEvInfo>(chtype));
m_BlockhHeaderOfProcessing.push_back(&targetfunction.statement.back());
return 1;
}
// }
else if (str == L"}") {
m_BlockhHeaderOfProcessing.pop_back();
m_defaultBlockChoicetypeStack.pop_back();
depth--;
targetfunction.statement.emplace_back(CStatement(ST_CLOSE, linecount));
Expand Down Expand Up @@ -951,7 +960,8 @@ char CParser0::StoreInternalStatement(size_t targetfunc, yaya::string_t &str, si
}
// --
else if (str == L"--") {
targetfunction.statement.emplace_back(CStatement(ST_COMBINE, linecount));
m_BlockhHeaderOfProcessing.back()->ismutiarea = true;
targetfunction.statement.emplace_back(ST_COMBINE, linecount);
return 1;
}

Expand Down
1 change: 1 addition & 0 deletions parser0.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class CParser0
CParser0(void);

std::vector<choicetype_t> m_defaultBlockChoicetypeStack;
std::vector<CStatement*> m_BlockhHeaderOfProcessing;

public:
CParser0(CAyaVM &vmr) : vm(vmr) {
Expand Down
8 changes: 0 additions & 8 deletions sysfunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7273,10 +7273,6 @@ CValue CSystemFunction::LINT_GetLocalVarUsedBy(CSF_FUNCPARAM &p)
//no local variable detected. clear all and return empty array.
array.clear();
}
else {
//erase last "}", because all user function has terminator ST_CLOSE.
array.pop_back();
}

return result;
}
Expand Down Expand Up @@ -7390,10 +7386,6 @@ CValue CSystemFunction::LINT_GetLocalVarLetted(CSF_FUNCPARAM &p)
//no local variable detected. clear all and return empty array.
array.clear();
}
else {
//erase last "}", because all user function has terminator ST_CLOSE.
array.pop_back();
}

return result;
}

0 comments on commit 49d1adf

Please sign in to comment.