From 1b1a4b3fce2094ad8c0fc52e0e59fe9e02f7913a Mon Sep 17 00:00:00 2001 From: "C.Ponapalt" Date: Fri, 8 Oct 2021 10:07:27 +0900 Subject: [PATCH] merge from 500-utf8 : APPENDDEF rename from "runtime" to "_DIC_RUNTIME_DEF_" because word "runtime" is very common and may collide existing dics. --- parser0.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ parser0.h | 1 + sysfunc.cpp | 38 ++++++++++++++++++++++++++++++++------ sysfunc.h | 1 + 4 files changed, 77 insertions(+), 6 deletions(-) diff --git a/parser0.cpp b/parser0.cpp index 468c8718..2e367f05 100644 --- a/parser0.cpp +++ b/parser0.cpp @@ -191,6 +191,49 @@ int CParser0::DynamicLoadDictionary(const yaya::string_t& dicfilename, int chars } +/* ----------------------------------------------------------------------- + * 関数名 : CParser0::DynamicAppendDefines + * 機能概要: APPENDDEFの実装本体 + * + * 返値  : 0=正常 1=文法エラー + * ----------------------------------------------------------------------- + */ +int CParser0::DynamicAppendDefines(const yaya::string_t& codes) +{ + vm.func_parse_new(); + + bool isnoterror = 1; + { + std::vector factors; + int depth = 0; + int targetfunction = -1; + // {、}、;で分割 + SeparateFactor(factors, yaya::string_t(codes)); + // 分割された文字列を解析して関数を作成し、内部のステートメントを蓄積していく + if(DefineFunctions(factors, L"_DIC_RUNTIME_DEF_", 0, depth, targetfunction)) { + isnoterror = 0; + } + if( depth != 0 ) { + vm.logger().Error(E_E, 94, L"_DIC_RUNTIME_DEF_", -1); + isnoterror = 0; + } + } + + if(isnoterror) { + isnoterror &= !ParseAfterLoad(L"_DIC_RUNTIME_DEF_"); + } + + if(isnoterror) { //success + vm.func_parse_to_exec(); + } + else { //error + vm.func_parse_destruct(); + } + + return !isnoterror; +} + + /* ----------------------------------------------------------------------- * 関数名 : CParser0::DynamicUnloadDictionary * 機能概要: 特定のファイル名に関係する関数とdefineを削除します diff --git a/parser0.h b/parser0.h index bb2c2dc8..67bcf683 100644 --- a/parser0.h +++ b/parser0.h @@ -58,6 +58,7 @@ class CParser0 char ParseEmbedString(yaya::string_t& str, CStatement &st, const yaya::string_t &dicfilename, int linecount); int DynamicLoadDictionary(const yaya::string_t& dicfilename, int charset); + int DynamicAppendDefines(const yaya::string_t& codes); int DynamicUnloadDictionary(const yaya::string_t& dicfilename); int DynamicUndefFunc(const yaya::string_t& funcname); diff --git a/sysfunc.cpp b/sysfunc.cpp index bb8c80ed..e22a4163 100644 --- a/sysfunc.cpp +++ b/sysfunc.cpp @@ -91,7 +91,7 @@ extern "C" { #endif #endif -#define SYSFUNC_NUM 149 //システム関数の全数 +#define SYSFUNC_NUM 150 //システム関数の全数 #define SYSFUNC_HIS 61 //EmBeD_HiStOrY の位置(0start) static const wchar_t sysfunc[SYSFUNC_NUM][32] = { @@ -302,7 +302,7 @@ static const wchar_t sysfunc[SYSFUNC_NUM][32] = { L"SETTAMAHWND", L"ISGLOBALDEFINE", L"SETGLOBALDEFINE", - //L"DEFFUNC", + L"APPENDDEF", }; //このグローバル変数はマルチインスタンスでも共通 @@ -728,8 +728,8 @@ CValue CSystemFunction::Execute(int index, const CValue &arg, const std::vector< return ISGLOBALDEFINE(arg, d, l); case 148: return SETGLOBALDEFINE(arg, d, l); - //case 149: - // return DEFFUNC(arg, d, l); + case 149: + return APPENDDEF(arg, d, l); default: vm.logger().Error(E_E, 49, d, l); return CValue(F_TAG_NOP, 0/*dmy*/); @@ -3325,6 +3325,32 @@ CValue CSystemFunction::ISGLOBALDEFINE(const CValue &arg, yaya::string_t &d, int return CValue(0); } +/* ----------------------------------------------------------------------- + * 関数名 : CSystemFunction::APPENDDEF + * 引数  : _argv[0] = define(s) + * ----------------------------------------------------------------------- + */ +CValue CSystemFunction::APPENDDEF(const CValue &arg, yaya::string_t &d, int &l) +{ + if(!arg.array_size()) { + vm.logger().Error(E_W, 8, L"APPENDDEF", d, l); + SetError(8); + return CValue(-1); + } + + if(!arg.array()[0].IsString()) { + vm.logger().Error(E_W, 9, L"APPENDDEF", d, l); + SetError(9); + return CValue(-1); + } + + yaya::string_t def = arg.array()[0].s_value; + + int err = vm.parser0().DynamicAppendDefines(def); + + return CValue(err ? -1 : 0); +} + /* ----------------------------------------------------------------------- * 関数名 : CSystemFunction::SETGLOBALDEFINE * 引数  : _argv[0] = GLOBALDEFINE name @@ -3353,7 +3379,7 @@ CValue CSystemFunction::SETGLOBALDEFINE(const CValue &arg, yaya::string_t &d, in while (itg != gdefines.end()) { if( itg->before == defname ) { itg->after=defbody; - itg->dicfilename=L"runtime"; + itg->dicfilename=L"_DIC_RUNTIME_DEF_"; return CValue(1); } else { @@ -3361,7 +3387,7 @@ CValue CSystemFunction::SETGLOBALDEFINE(const CValue &arg, yaya::string_t &d, in } } - gdefines.push_back(CDefine(defname, defbody, L"runtime")); + gdefines.push_back(CDefine(defname, defbody, L"_DIC_RUNTIME_DEF_")); return CValue(0); } diff --git a/sysfunc.h b/sysfunc.h index 2437ea77..12b30cf1 100644 --- a/sysfunc.h +++ b/sysfunc.h @@ -250,6 +250,7 @@ class CSystemFunction CValue DICUNLOAD(const CValue &arg, yaya::string_t &d, int &l); CValue UNDEFFUNC(const CValue &arg, yaya::string_t &, int &); + CValue APPENDDEF(const CValue& arg, yaya::string_t& d, int& l); CValue UNDEFGLOBALDEFINE(const CValue &arg, yaya::string_t &, int &); CValue ISGLOBALDEFINE(const CValue& arg, yaya::string_t& d, int& l);