Instraction.Child.cs 77 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Text;
  5. using NTERA.Core.Interop;
  6. using NTERA.EmuEra.Game.EraEmu.Display;
  7. using NTERA.EmuEra.Game.EraEmu.GameData;
  8. using NTERA.EmuEra.Game.EraEmu.GameData.Expression;
  9. using NTERA.EmuEra.Game.EraEmu.GameData.Function;
  10. using NTERA.EmuEra.Game.EraEmu.GameData.Variable;
  11. using NTERA.EmuEra.Game.EraEmu.Sub;
  12. using NTERA.EmuEra.Game.EraEmu._Library;
  13. namespace NTERA.EmuEra.Game.EraEmu.GameProc.Function
  14. {
  15. internal sealed partial class FunctionIdentifier
  16. {
  17. #region normalFunction
  18. private sealed class PRINT_Instruction : AbstractInstruction
  19. {
  20. public PRINT_Instruction(string name)
  21. {
  22. //PRINT(|V|S|FORM|FORMS)(|K)(|D)(|L|W) コレと
  23. //PRINTSINGLE(|V|S|FORM|FORMS)(|K)(|D) コレと
  24. //PRINT(|FORM)(C|LC)(|K)(|D) コレ
  25. //PRINTDATA(|K)(|D)(|L|W) ←は別クラス
  26. flag = IS_PRINT;
  27. var st = new StringStream(name);
  28. st.Jump(5);//PRINT
  29. if (st.CurrentEqualTo("SINGLE"))
  30. {
  31. flag |= PRINT_SINGLE | EXTENDED;
  32. st.Jump(6);
  33. }
  34. if (st.CurrentEqualTo("V"))
  35. {
  36. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.SP_PRINTV);
  37. isPrintV = true;
  38. st.Jump(1);
  39. }
  40. else if (st.CurrentEqualTo("S"))
  41. {
  42. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.STR_EXPRESSION);
  43. st.Jump(1);
  44. }
  45. else if (st.CurrentEqualTo("FORMS"))
  46. {
  47. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.STR_EXPRESSION);
  48. isForms = true;
  49. st.Jump(5);
  50. }
  51. else if (st.CurrentEqualTo("FORM"))
  52. {
  53. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.FORM_STR_NULLABLE);
  54. st.Jump(4);
  55. }
  56. else
  57. {
  58. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.STR_NULLABLE);
  59. }
  60. if (st.CurrentEqualTo("LC"))
  61. {
  62. flag |= EXTENDED;
  63. isLC = true;
  64. st.Jump(2);
  65. }
  66. else if (st.CurrentEqualTo("C"))
  67. {
  68. if (name == "PRINTFORMC")
  69. flag |= EXTENDED;
  70. isC = true;
  71. st.Jump(1);
  72. }
  73. if (st.CurrentEqualTo("K"))
  74. {
  75. flag |= ISPRINTKFUNC | EXTENDED;
  76. st.Jump(1);
  77. }
  78. if (st.CurrentEqualTo("D"))
  79. {
  80. flag |= ISPRINTDFUNC | EXTENDED;
  81. st.Jump(1);
  82. }
  83. if (st.CurrentEqualTo("L"))
  84. {
  85. flag |= PRINT_NEWLINE;
  86. flag |= METHOD_SAFE;
  87. st.Jump(1);
  88. }
  89. else if (st.CurrentEqualTo("W"))
  90. {
  91. flag |= PRINT_NEWLINE | PRINT_WAITINPUT;
  92. st.Jump(1);
  93. }
  94. else
  95. {
  96. flag |= METHOD_SAFE;
  97. }
  98. if ((ArgBuilder == null) || (!st.EOS))
  99. throw new ExeEE("PRINT異常");
  100. }
  101. private readonly bool isPrintV;
  102. private readonly bool isLC;
  103. private readonly bool isC;
  104. private readonly bool isForms;
  105. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  106. {
  107. //Changes by Bartoum
  108. //All print lines are going trough here.
  109. //This is where our chain of booleans is set to true.
  110. //A lot of function have tryTranslate or translate in their signatures
  111. //This was added in the goal to know when translating is required or not.
  112. if (GlobalStatic.Process.SkipPrint)
  113. return;
  114. exm.Console.UseUserStyle = true;
  115. exm.Console.UseSetColorStyle = !func.Function.IsPrintDFunction();
  116. string str = null;
  117. if (func.Argument.IsConst) {
  118. //Need to rework that part
  119. str = func.Argument.ConstStr;
  120. }
  121. else if (isPrintV)
  122. {
  123. var builder = new StringBuilder();
  124. var terms = ((SpPrintVArgument)func.Argument).Terms;
  125. foreach (var termV in terms)
  126. {
  127. builder.Append(termV.GetOperandType() == typeof(long)
  128. ? termV.GetIntValue(exm).ToString()
  129. : termV.GetStrValue(exm, translate));
  130. }
  131. str = builder.ToString();
  132. }
  133. else
  134. {
  135. str = ((ExpressionArgument)func.Argument).Term.GetStrValue(exm, translate);
  136. if (isForms)
  137. {
  138. str = exm.CheckEscape(str);
  139. var wt = LexicalAnalyzer.AnalyseFormattedString(new StringStream(str), FormStrEndWith.EoL, false);
  140. var strForm = StrForm.FromWordToken(wt);
  141. str = strForm.GetString(exm, translate);
  142. }
  143. }
  144. if (func.Function.IsPrintKFunction())
  145. str = exm.ConvertStringType(str);
  146. if (isC)
  147. exm.Console.PrintC(str, true);
  148. else if (isLC)
  149. exm.Console.PrintC(str, false);
  150. else
  151. exm.OutputToConsole(str, func.Function);
  152. exm.Console.UseSetColorStyle = true;
  153. }
  154. }
  155. private sealed class PRINT_DATA_Instruction : AbstractInstruction
  156. {
  157. public PRINT_DATA_Instruction(string name)
  158. {
  159. //PRINTDATA(|K)(|D)(|L|W)
  160. flag = EXTENDED | IS_PRINT | IS_PRINTDATA | PARTIAL;
  161. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.VAR_INT);
  162. var st = new StringStream(name);
  163. st.Jump(9);//PRINTDATA
  164. if (st.CurrentEqualTo("K"))
  165. {
  166. flag |= ISPRINTKFUNC | EXTENDED;
  167. st.Jump(1);
  168. }
  169. if (st.CurrentEqualTo("D"))
  170. {
  171. flag |= ISPRINTDFUNC | EXTENDED;
  172. st.Jump(1);
  173. }
  174. if (st.CurrentEqualTo("L"))
  175. {
  176. flag |= PRINT_NEWLINE;
  177. flag |= METHOD_SAFE;
  178. st.Jump(1);
  179. }
  180. else if (st.CurrentEqualTo("W"))
  181. {
  182. flag |= PRINT_NEWLINE | PRINT_WAITINPUT;
  183. st.Jump(1);
  184. }
  185. else
  186. {
  187. flag |= METHOD_SAFE;
  188. }
  189. if ((ArgBuilder == null) || (!st.EOS))
  190. throw new ExeEE("PRINTDATA error");
  191. }
  192. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  193. {
  194. if (GlobalStatic.Process.SkipPrint)
  195. return;
  196. exm.Console.UseUserStyle = true;
  197. exm.Console.UseSetColorStyle = !func.Function.IsPrintDFunction();
  198. //表示データが空なら何もしないで飛ぶ
  199. if (func.dataList.Count == 0)
  200. {
  201. state.JumpTo(func.JumpTo);
  202. return;
  203. }
  204. var count = func.dataList.Count;
  205. var choice = (int)exm.VEvaluator.GetNextRand(count);
  206. var iTerm = ((PrintDataArgument)func.Argument).Var;
  207. iTerm?.SetValue(choice, exm); // this is a null propogation, though it looks extra weird here --Sworve
  208. var iList = func.dataList[choice];
  209. var i = 0;
  210. foreach (var selectedLine in iList)
  211. {
  212. state.CurrentLine = selectedLine;
  213. if (selectedLine.Argument == null)
  214. ArgumentParser.SetArgumentTo(selectedLine);
  215. var term = ((ExpressionArgument)selectedLine.Argument).Term;
  216. var str = term.GetStrValue(exm);
  217. if (func.Function.IsPrintKFunction())
  218. str = exm.ConvertStringType(str);
  219. exm.Console.Write(str);
  220. if (++i < iList.Count)
  221. exm.Console.NewLine();
  222. }
  223. if (func.Function.IsNewLine() || func.Function.IsWaitInput())
  224. {
  225. exm.Console.NewLine();
  226. if (func.Function.IsWaitInput())
  227. exm.Console.ReadAnyKey();
  228. }
  229. exm.Console.UseSetColorStyle = true;
  230. //ジャンプするが、流れが連続であることを保証。
  231. state.JumpTo(func.JumpTo);
  232. //state.RunningLine = null;
  233. }
  234. }
  235. private sealed class HTML_PRINT_Instruction : AbstractInstruction
  236. {
  237. private readonly bool _noNewLine;
  238. public HTML_PRINT_Instruction(bool noLineBreaks = false)
  239. {
  240. flag = EXTENDED | METHOD_SAFE;
  241. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.STR_EXPRESSION);
  242. _noNewLine = noLineBreaks;
  243. }
  244. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  245. {
  246. if (GlobalStatic.Process.SkipPrint)
  247. return;
  248. string str = null;
  249. str = func.Argument.IsConst
  250. ? func.Argument.ConstStr
  251. : ((ExpressionArgument)func.Argument).Term.GetStrValue(exm, translate);
  252. exm.Console.PrintHtml(str, _noNewLine);
  253. }
  254. }
  255. private sealed class HTML_TAGSPLIT_Instruction : AbstractInstruction
  256. {
  257. public HTML_TAGSPLIT_Instruction()
  258. {
  259. flag = EXTENDED | METHOD_SAFE;
  260. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.SP_HTMLSPLIT);
  261. }
  262. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  263. {
  264. var spSplitArg = (SpHtmlSplitArgument)func.Argument;
  265. var str = spSplitArg.TargetStr.GetStrValue(exm);
  266. var strs = HtmlManager.HtmlTagSplit(str);
  267. if (strs == null)
  268. {
  269. spSplitArg.Num.SetValue(-1, exm);
  270. return;
  271. }
  272. spSplitArg.Num.SetValue(strs.Length, exm);
  273. var output = (string[])spSplitArg.Var.GetArray();
  274. var outputlength = Math.Min(output.Length, strs.Length);
  275. Array.Copy(strs, output, outputlength);
  276. }
  277. }
  278. private sealed class PRINT_IMG_Instruction : AbstractInstruction
  279. {
  280. public PRINT_IMG_Instruction()
  281. {
  282. flag = EXTENDED | METHOD_SAFE;
  283. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.STR_EXPRESSION);
  284. }
  285. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  286. {
  287. if (GlobalStatic.Process.SkipPrint)
  288. return;
  289. var str = func.Argument.IsConst
  290. ? func.Argument.ConstStr
  291. : ((ExpressionArgument)func.Argument).Term.GetStrValue(exm);
  292. exm.Console.PrintImg(str);
  293. }
  294. }
  295. private sealed class PRINT_RECT_Instruction : AbstractInstruction
  296. {
  297. public PRINT_RECT_Instruction()
  298. {
  299. flag = EXTENDED | METHOD_SAFE;
  300. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.INT_ANY);
  301. }
  302. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  303. {
  304. if (GlobalStatic.Process.SkipPrint)
  305. return;
  306. var intExpArg = (ExpressionArrayArgument)func.Argument;
  307. var param = new int[intExpArg.TermList.Length];
  308. for (int i = 0; i < intExpArg.TermList.Length; i++)
  309. param[i] = toUInt32inArg(intExpArg.TermList[i].GetIntValue(exm), "PRINT_RECT", i + 1);
  310. exm.Console.PrintShape("rect", param);
  311. }
  312. }
  313. private sealed class PRINT_SPACE_Instruction : AbstractInstruction
  314. {
  315. public PRINT_SPACE_Instruction()
  316. {
  317. flag = EXTENDED | METHOD_SAFE;
  318. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.INT_EXPRESSION);
  319. }
  320. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  321. {
  322. if (GlobalStatic.Process.SkipPrint)
  323. return;
  324. var param = func.Argument.IsConst
  325. ? func.Argument.ConstInt
  326. : ((ExpressionArgument)func.Argument).Term.GetIntValue(exm);
  327. var param32 = toUInt32inArg(param, "PRINT_SPACE", 1);
  328. exm.Console.PrintShape("space", new[] { param32 });
  329. }
  330. }
  331. private sealed class DEBUGPRINT_Instruction : AbstractInstruction
  332. {
  333. public DEBUGPRINT_Instruction(bool form, bool newline)
  334. {
  335. ArgBuilder = ArgumentParser.GetArgumentBuilder(form
  336. ? FunctionArgType.FORM_STR_NULLABLE
  337. : FunctionArgType.STR_NULLABLE);
  338. flag = METHOD_SAFE | EXTENDED | DEBUG_FUNC;
  339. if (newline)
  340. flag |= PRINT_NEWLINE;
  341. }
  342. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  343. {
  344. string str = null;
  345. str = func.Argument.IsConst
  346. ? func.Argument.ConstStr
  347. : ((ExpressionArgument)func.Argument).Term.GetStrValue(exm);
  348. exm.Console.DebugPrint(str);
  349. if (func.Function.IsNewLine())
  350. exm.Console.DebugNewLine();
  351. }
  352. }
  353. private sealed class DEBUGCLEAR_Instruction : AbstractInstruction
  354. {
  355. public DEBUGCLEAR_Instruction()
  356. {
  357. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.VOID);
  358. flag = METHOD_SAFE | EXTENDED | DEBUG_FUNC;
  359. }
  360. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  361. {
  362. exm.Console.DebugClear();
  363. }
  364. }
  365. private sealed class METHOD_Instruction : AbstractInstruction
  366. {
  367. public METHOD_Instruction()
  368. {
  369. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.METHOD);
  370. flag = METHOD_SAFE | EXTENDED;
  371. }
  372. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  373. {
  374. IOperandTerm term = ((MethodArgument)func.Argument).MethodTerm;
  375. Type type = term.GetOperandType();
  376. if (term.GetOperandType() == typeof(Int64))
  377. exm.VEvaluator.RESULT = term.GetIntValue(exm);
  378. else// if (func.Argument.MethodTerm.GetOperandType() == typeof(string))
  379. exm.VEvaluator.RESULTS = term.GetStrValue(exm);
  380. //これら以外の型は現状ない
  381. //else
  382. // throw new ExeEE(func.Function.Name + "命令の型が不明");
  383. }
  384. }
  385. private sealed class SET_Instruction : AbstractInstruction
  386. {
  387. public SET_Instruction()
  388. {
  389. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.SP_SET);
  390. flag = METHOD_SAFE;
  391. }
  392. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  393. {
  394. if (func.Argument is SpSetArrayArgument)
  395. {
  396. SpSetArrayArgument arg = (SpSetArrayArgument)func.Argument;
  397. if (arg.VariableDest.IsInteger)
  398. {
  399. if (arg.IsConst)
  400. arg.VariableDest.SetValue(arg.ConstIntList, exm);
  401. else
  402. {
  403. Int64[] values = new Int64[arg.TermList.Length];
  404. for (int i = 0; i < values.Length; i++)
  405. {
  406. values[i] = arg.TermList[i].GetIntValue(exm);
  407. }
  408. arg.VariableDest.SetValue(values, exm);
  409. }
  410. }
  411. else
  412. {
  413. if (arg.IsConst)
  414. arg.VariableDest.SetValue(arg.ConstStrList, exm);
  415. else
  416. {
  417. string[] values = new string[arg.TermList.Length];
  418. for (int i = 0; i < values.Length; i++)
  419. {
  420. values[i] = arg.TermList[i].GetStrValue(exm, translate);
  421. }
  422. arg.VariableDest.SetValue(values, exm);
  423. }
  424. }
  425. return;
  426. }
  427. SpSetArgument spsetarg = (SpSetArgument)func.Argument;
  428. if (spsetarg.VariableDest.IsInteger)
  429. {
  430. Int64 src = spsetarg.IsConst ? spsetarg.ConstInt : spsetarg.Term.GetIntValue(exm);
  431. if (spsetarg.AddConst)
  432. spsetarg.VariableDest.PlusValue(src, exm);
  433. else
  434. spsetarg.VariableDest.SetValue(src, exm);
  435. }
  436. else
  437. {
  438. string src = spsetarg.IsConst ? spsetarg.ConstStr : spsetarg.Term.GetStrValue(exm, translate); // JVN: Should fix wrong STRLENS count for TR translated strings
  439. spsetarg.VariableDest.SetValue(src, exm);
  440. }
  441. }
  442. }
  443. private sealed class REUSELASTLINE_Instruction : AbstractInstruction
  444. {
  445. public REUSELASTLINE_Instruction()
  446. {
  447. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.FORM_STR_NULLABLE);
  448. flag = METHOD_SAFE | EXTENDED | IS_PRINT;
  449. }
  450. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  451. {
  452. IOperandTerm term = ((ExpressionArgument)func.Argument).Term;
  453. string str = term.GetStrValue(exm);
  454. exm.Console.PrintTemporaryLine(str);
  455. }
  456. }
  457. private sealed class CLEARLINE_Instruction : AbstractInstruction
  458. {
  459. public CLEARLINE_Instruction()
  460. {
  461. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.INT_EXPRESSION);
  462. flag = METHOD_SAFE | EXTENDED | IS_PRINT;
  463. }
  464. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  465. {
  466. ExpressionArgument intExpArg = (ExpressionArgument)func.Argument;
  467. Int32 delNum = (Int32)intExpArg.Term.GetIntValue(exm);
  468. exm.Console.ClearLine(delNum);
  469. exm.Console.RefreshStrings(false);
  470. }
  471. }
  472. private sealed class STRLEN_Instruction : AbstractInstruction
  473. {
  474. public STRLEN_Instruction(bool argisform, bool unicode)
  475. {
  476. if (argisform)
  477. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.FORM_STR_NULLABLE);
  478. else
  479. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.STR_NULLABLE);
  480. flag = METHOD_SAFE | EXTENDED;
  481. this.unicode = unicode;
  482. }
  483. bool unicode;
  484. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  485. {
  486. string str = null;
  487. if (func.Argument.IsConst)
  488. str = func.Argument.ConstStr;
  489. else
  490. str = ((ExpressionArgument)func.Argument).Term.GetStrValue(exm);
  491. if (unicode)
  492. exm.VEvaluator.RESULT = str.Length;
  493. else
  494. exm.VEvaluator.RESULT = LangManager.GetStrlenLang(str);
  495. }
  496. }
  497. private sealed class SETBIT_Instruction : AbstractInstruction
  498. {
  499. public SETBIT_Instruction(int op)
  500. {
  501. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.BIT_ARG);
  502. flag = METHOD_SAFE | EXTENDED;
  503. this.op = op;
  504. }
  505. int op;
  506. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  507. {
  508. BitArgument spsetarg = (BitArgument)func.Argument;
  509. VariableTerm varTerm = spsetarg.VariableDest;
  510. IOperandTerm[] terms = spsetarg.Term;
  511. for (int i = 0; i < terms.Length; i++)
  512. {
  513. Int64 x = terms[i].GetIntValue(exm);
  514. if ((x < 0) || (x > 63))
  515. throw new CodeEE("第2引数がビットのレンジ(0から63)を超えています");
  516. Int64 baseValue = varTerm.GetIntValue(exm);
  517. Int64 shift = 1L << (int)x;
  518. if (op == 1)
  519. baseValue |= shift;
  520. else if (op == 0)
  521. baseValue &= ~shift;
  522. else
  523. baseValue ^= shift;
  524. varTerm.SetValue(baseValue, exm);
  525. }
  526. }
  527. }
  528. private sealed class WAIT_Instruction : AbstractInstruction
  529. {
  530. public WAIT_Instruction(bool force)
  531. {
  532. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.VOID);
  533. flag = IS_PRINT;
  534. isForce = force;
  535. }
  536. bool isForce;
  537. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  538. {
  539. if (isForce)
  540. exm.Console.ReadAnyKey(false, true);
  541. else
  542. exm.Console.ReadAnyKey();
  543. }
  544. }
  545. private sealed class WAITANYKEY_Instruction : AbstractInstruction
  546. {
  547. public WAITANYKEY_Instruction()
  548. {
  549. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.VOID);
  550. flag = IS_PRINT;
  551. }
  552. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  553. {
  554. exm.Console.ReadAnyKey(true,false);
  555. }
  556. }
  557. private sealed class TWAIT_Instruction : AbstractInstruction
  558. {
  559. public TWAIT_Instruction()
  560. {
  561. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.SP_SWAP);
  562. flag = IS_PRINT | EXTENDED;
  563. }
  564. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  565. {
  566. exm.Console.ReadAnyKey();
  567. SpSwapCharaArgument arg = (SpSwapCharaArgument)func.Argument;
  568. Int64 time = arg.X.GetIntValue(exm);
  569. Int64 flag = arg.Y.GetIntValue(exm);
  570. InputRequest req = new InputRequest();
  571. req.InputType = InputType.EnterKey;
  572. if (flag != 0)
  573. req.InputType = InputType.Void;
  574. req.Timelimit = time;
  575. exm.Console.WaitInput(req);
  576. }
  577. }
  578. private sealed class INPUT_Instruction : AbstractInstruction
  579. {
  580. public INPUT_Instruction()
  581. {
  582. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.SP_INPUT);
  583. flag = IS_PRINT | IS_INPUT;
  584. }
  585. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  586. {
  587. ExpressionArgument arg = (ExpressionArgument)func.Argument;
  588. InputRequest req = new InputRequest();
  589. req.InputType = InputType.IntValue;
  590. if (arg.Term != null)
  591. {
  592. Int64 def;
  593. if (arg.IsConst)
  594. def = arg.ConstInt;
  595. else
  596. def = arg.Term.GetIntValue(exm);
  597. req.HasDefValue = true;
  598. req.DefIntValue = def;
  599. }
  600. exm.Console.WaitInput(req);
  601. }
  602. }
  603. private sealed class INPUTS_Instruction : AbstractInstruction
  604. {
  605. public INPUTS_Instruction()
  606. {
  607. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.SP_INPUTS);
  608. flag = IS_PRINT | IS_INPUT;
  609. }
  610. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  611. {
  612. ExpressionArgument arg = (ExpressionArgument)func.Argument;
  613. InputRequest req = new InputRequest();
  614. req.InputType = InputType.StrValue;
  615. if (arg.Term != null)
  616. {
  617. string def;
  618. if (arg.IsConst)
  619. def = arg.ConstStr;
  620. else
  621. def = arg.Term.GetStrValue(exm);
  622. req.HasDefValue = true;
  623. req.DefStrValue = def;
  624. }
  625. exm.Console.WaitInput(req);
  626. }
  627. }
  628. private sealed class ONEINPUT_Instruction : AbstractInstruction
  629. {
  630. public ONEINPUT_Instruction()
  631. {
  632. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.SP_INPUT);
  633. flag = IS_PRINT | IS_INPUT | EXTENDED;
  634. }
  635. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  636. {
  637. ExpressionArgument arg = (ExpressionArgument)func.Argument;
  638. InputRequest req = new InputRequest();
  639. req.InputType = InputType.IntValue;
  640. req.OneInput = true;
  641. if (arg.Term != null)
  642. {
  643. //TODO:二文字以上セットできるようにするかエラー停止するか
  644. //少なくともONETINPUTとの仕様を統一すべき
  645. Int64 def;
  646. if (arg.IsConst)
  647. def = arg.ConstInt;
  648. else
  649. def = arg.Term.GetIntValue(exm);
  650. if (def > 9)
  651. def = Int64.Parse(def.ToString().Remove(1));
  652. if (def >= 0)
  653. {
  654. req.HasDefValue = true;
  655. req.DefIntValue = def;
  656. }
  657. }
  658. exm.Console.WaitInput(req);
  659. }
  660. }
  661. private sealed class ONEINPUTS_Instruction : AbstractInstruction
  662. {
  663. public ONEINPUTS_Instruction()
  664. {
  665. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.SP_INPUTS);
  666. flag = IS_PRINT | IS_INPUT | EXTENDED;
  667. }
  668. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  669. {
  670. ExpressionArgument arg = (ExpressionArgument)func.Argument;
  671. InputRequest req = new InputRequest();
  672. req.InputType = InputType.StrValue;
  673. req.OneInput = true;
  674. if (arg.Term != null)
  675. {
  676. string def;
  677. if (arg.IsConst)
  678. def = arg.ConstStr;
  679. else
  680. def = arg.Term.GetStrValue(exm);
  681. if (def.Length > 1)
  682. def = def.Remove(1);
  683. if (def.Length > 0)
  684. {
  685. req.HasDefValue = true;
  686. req.DefStrValue = def;
  687. }
  688. }
  689. exm.Console.WaitInput(req);
  690. }
  691. }
  692. private sealed class TINPUT_Instruction : AbstractInstruction
  693. {
  694. public TINPUT_Instruction(bool oneInput)
  695. {
  696. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.SP_TINPUT);
  697. flag = IS_PRINT | IS_INPUT | EXTENDED;
  698. isOne = oneInput;
  699. }
  700. bool isOne;
  701. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  702. {
  703. SpTInputsArgument tinputarg = (SpTInputsArgument)func.Argument;
  704. InputRequest req = new InputRequest();
  705. req.InputType = InputType.IntValue;
  706. req.HasDefValue = true;
  707. req.OneInput = isOne;
  708. Int64 x = tinputarg.Time.GetIntValue(exm);
  709. Int64 y = tinputarg.Def.GetIntValue(exm);
  710. //TODO:ONEINPUTと標準の値を統一
  711. if (isOne)
  712. {
  713. if (y < 0)
  714. y = Math.Abs(y);
  715. if (y >= 10)
  716. y = y / (long)(Math.Pow(10.0, Math.Log10(y)));
  717. }
  718. Int64 z = (tinputarg.Disp != null) ? tinputarg.Disp.GetIntValue(exm) : 1;
  719. req.Timelimit = x;
  720. req.DefIntValue = y;
  721. req.DisplayTime = z != 0;
  722. req.TimeUpMes = (tinputarg.Timeout != null) ? tinputarg.Timeout.GetStrValue(exm) : Config.Config.TimeupLabel;
  723. exm.Console.WaitInput(req);
  724. }
  725. }
  726. private sealed class TINPUTS_Instruction : AbstractInstruction
  727. {
  728. public TINPUTS_Instruction(bool oneInput)
  729. {
  730. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.SP_TINPUTS);
  731. flag = IS_PRINT | IS_INPUT | EXTENDED;
  732. isOne = oneInput;
  733. }
  734. bool isOne;
  735. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  736. {
  737. SpTInputsArgument tinputarg = (SpTInputsArgument)func.Argument;
  738. InputRequest req = new InputRequest();
  739. req.InputType = InputType.StrValue;
  740. req.HasDefValue = true;
  741. req.OneInput = isOne;
  742. Int64 x = tinputarg.Time.GetIntValue(exm);
  743. string strs = tinputarg.Def.GetStrValue(exm);
  744. if (isOne && strs.Length > 1)
  745. strs = strs.Remove(1);
  746. Int64 z = (tinputarg.Disp != null) ? tinputarg.Disp.GetIntValue(exm) : 1;
  747. req.Timelimit = x;
  748. req.DefStrValue = strs;
  749. req.DisplayTime = z != 0;
  750. req.TimeUpMes = (tinputarg.Timeout != null) ? tinputarg.Timeout.GetStrValue(exm) : Config.Config.TimeupLabel;
  751. exm.Console.WaitInput(req);
  752. }
  753. }
  754. private sealed class CALLF_Instruction : AbstractInstruction
  755. {
  756. public CALLF_Instruction(bool form)
  757. {
  758. if (form)
  759. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.SP_CALLFORMF);
  760. else
  761. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.SP_CALLF);
  762. flag = EXTENDED | METHOD_SAFE | FORCE_SETARG;
  763. }
  764. public override void SetJumpTo(ref bool useCallForm, InstructionLine func, int currentDepth, ref string FunctionoNotFoundName)
  765. {
  766. if (!func.Argument.IsConst)
  767. {
  768. useCallForm = true;
  769. return;
  770. }
  771. SpCallFArgment callfArg = (SpCallFArgment)func.Argument;
  772. if (Config.Config.ICFunction)
  773. callfArg.ConstStr = callfArg.ConstStr.ToUpper();
  774. try
  775. {
  776. callfArg.FuncTerm = GlobalStatic.IdentifierDictionary.GetFunctionMethod(GlobalStatic.LabelDictionary, callfArg.ConstStr, callfArg.RowArgs, true);
  777. }
  778. catch (CodeEE e)
  779. {
  780. ParserMediator.Warn(e.Message, func, 2, true, false);
  781. return;
  782. }
  783. if (callfArg.FuncTerm == null)
  784. {
  785. if (!Program.AnalysisMode)
  786. ParserMediator.Warn("指定された関数名\"@" + callfArg.ConstStr + "\"は存在しません", func, 2, true, false);
  787. else
  788. ParserMediator.Warn(callfArg.ConstStr, func, 2, true, false);
  789. }
  790. }
  791. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  792. {
  793. IOperandTerm mToken = null;
  794. string labelName = null;
  795. if ((!func.Argument.IsConst) || (exm.Console.RunERBFromMemory))
  796. {
  797. SpCallFArgment spCallformArg = (SpCallFArgment)func.Argument;
  798. labelName = spCallformArg.FuncnameTerm.GetStrValue(exm);
  799. mToken = GlobalStatic.IdentifierDictionary.GetFunctionMethod(GlobalStatic.LabelDictionary, labelName, spCallformArg.RowArgs, true);
  800. }
  801. else
  802. {
  803. labelName = func.Argument.ConstStr;
  804. mToken = ((SpCallFArgment)func.Argument).FuncTerm;
  805. }
  806. if (mToken == null)
  807. throw new CodeEE("式中関数\"@" + labelName + "\"が見つかりません");
  808. mToken.GetValue(exm);
  809. }
  810. }
  811. private sealed class BAR_Instruction : AbstractInstruction
  812. {
  813. public BAR_Instruction(bool newline)
  814. {
  815. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.SP_BAR);
  816. flag = IS_PRINT | METHOD_SAFE | EXTENDED;
  817. this.newline = newline;
  818. }
  819. bool newline;
  820. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  821. {
  822. SpBarArgument barArg = (SpBarArgument)func.Argument;
  823. Int64 var = barArg.Terms[0].GetIntValue(exm);
  824. Int64 max = barArg.Terms[1].GetIntValue(exm);
  825. Int64 length = barArg.Terms[2].GetIntValue(exm);
  826. exm.Console.Write(exm.CreateBar(var, max, length));
  827. if (newline)
  828. exm.Console.NewLine();
  829. }
  830. }
  831. private sealed class TIMES_Instruction : AbstractInstruction
  832. {
  833. public TIMES_Instruction()
  834. {
  835. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.SP_TIMES);
  836. flag = METHOD_SAFE;
  837. }
  838. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  839. {
  840. SpTimesArgument timesArg = (SpTimesArgument)func.Argument;
  841. VariableTerm var = timesArg.VariableDest;
  842. if (Config.Config.TimesNotRigorousCalculation)
  843. {
  844. double d = var.GetIntValue(exm) * timesArg.DoubleValue;
  845. unchecked
  846. {
  847. var.SetValue((Int64)d, exm);
  848. }
  849. }
  850. else
  851. {
  852. decimal d = var.GetIntValue(exm) * (decimal)timesArg.DoubleValue;
  853. unchecked
  854. {
  855. //decimal型は強制的にOverFlowExceptionを投げるので対策が必要
  856. //OverFlowの場合は昔の挙動に近づけてみる
  857. if (d <= Int64.MaxValue && d >= Int64.MinValue)
  858. var.SetValue((Int64)d, exm);
  859. else
  860. var.SetValue((Int64)((double)d), exm);
  861. }
  862. }
  863. }
  864. }
  865. private sealed class ADDCHARA_Instruction : AbstractInstruction
  866. {
  867. public ADDCHARA_Instruction(bool flagSp, bool flagDel)
  868. {
  869. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.INT_ANY);
  870. flag = METHOD_SAFE;
  871. isDel = flagDel;
  872. isSp = flagSp;
  873. }
  874. bool isDel;
  875. bool isSp;
  876. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  877. {
  878. if(!Config.Config.CompatiSPChara && isSp)
  879. throw new CodeEE("SPキャラ関係の機能は標準では使用できません(互換性オプション「SPキャラを使用する」をONにしてください)");
  880. ExpressionArrayArgument intExpArg = (ExpressionArrayArgument)func.Argument;
  881. Int64 integer = -1;
  882. Int64[] charaNoList = new Int64[intExpArg.TermList.Length];
  883. int i = 0;
  884. foreach (IOperandTerm int64Term in intExpArg.TermList)
  885. {
  886. integer = int64Term.GetIntValue(exm);
  887. if (isDel)
  888. {
  889. charaNoList[i] = integer;
  890. i++;
  891. }
  892. else
  893. {
  894. if(!Config.Config.CompatiSPChara)
  895. exm.VEvaluator.AddCharacter_UseSp(integer, isSp);
  896. else
  897. exm.VEvaluator.AddCharacter(integer);
  898. }
  899. }
  900. if (isDel)
  901. {
  902. if(charaNoList.Length == 1)
  903. exm.VEvaluator.DelCharacter(charaNoList[0]);
  904. else
  905. exm.VEvaluator.DelCharacter(charaNoList);
  906. }
  907. }
  908. }
  909. private sealed class ADDVOIDCHARA_Instruction : AbstractInstruction
  910. {
  911. public ADDVOIDCHARA_Instruction()
  912. {
  913. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.VOID);
  914. flag = METHOD_SAFE | EXTENDED;
  915. }
  916. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  917. {
  918. exm.VEvaluator.AddPseudoCharacter();
  919. }
  920. }
  921. private sealed class SWAPCHARA_Instruction : AbstractInstruction
  922. {
  923. public SWAPCHARA_Instruction()
  924. {
  925. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.SP_SWAP);
  926. flag = METHOD_SAFE | EXTENDED;
  927. }
  928. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  929. {
  930. SpSwapCharaArgument arg = (SpSwapCharaArgument)func.Argument;
  931. long x = arg.X.GetIntValue(exm);
  932. long y = arg.Y.GetIntValue(exm);
  933. exm.VEvaluator.SwapChara(x, y);
  934. }
  935. }
  936. private sealed class COPYCHARA_Instruction : AbstractInstruction
  937. {
  938. public COPYCHARA_Instruction()
  939. {
  940. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.SP_SWAP);
  941. flag = METHOD_SAFE | EXTENDED;
  942. }
  943. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  944. {
  945. SpSwapCharaArgument arg = (SpSwapCharaArgument)func.Argument;
  946. long x = arg.X.GetIntValue(exm);
  947. long y = arg.Y.GetIntValue(exm);
  948. exm.VEvaluator.CopyChara(x, y);
  949. }
  950. }
  951. private sealed class ADDCOPYCHARA_Instruction : AbstractInstruction
  952. {
  953. public ADDCOPYCHARA_Instruction()
  954. {
  955. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.INT_ANY);
  956. flag = METHOD_SAFE;
  957. }
  958. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  959. {
  960. ExpressionArrayArgument intExpArg = (ExpressionArrayArgument)func.Argument;
  961. foreach (IOperandTerm int64Term in intExpArg.TermList)
  962. exm.VEvaluator.AddCopyChara(int64Term.GetIntValue(exm));
  963. }
  964. }
  965. private sealed class SORTCHARA_Instruction : AbstractInstruction
  966. {
  967. public SORTCHARA_Instruction()
  968. {
  969. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.SP_SORTCHARA);
  970. flag = METHOD_SAFE | EXTENDED;
  971. }
  972. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  973. {
  974. SpSortcharaArgument spSortArg = (SpSortcharaArgument)func.Argument;
  975. Int64 elem = 0;
  976. VariableTerm sortKey = spSortArg.SortKey;
  977. if (sortKey.Identifier.IsArray1D)
  978. elem = sortKey.GetElementInt(1, exm);
  979. else if (sortKey.Identifier.IsArray2D)
  980. {
  981. elem = sortKey.GetElementInt(1, exm) << 32;
  982. elem += sortKey.GetElementInt(2, exm);
  983. }
  984. exm.VEvaluator.SortChara(sortKey.Identifier, elem, spSortArg.SortOrder, true);
  985. }
  986. }
  987. private sealed class RESETCOLOR_Instruction : AbstractInstruction
  988. {
  989. public RESETCOLOR_Instruction()
  990. {
  991. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.VOID);
  992. flag = METHOD_SAFE | EXTENDED;
  993. }
  994. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  995. {
  996. exm.Console.SetStringStyle(Config.Config.ForeColor);
  997. }
  998. }
  999. private sealed class RESETBGCOLOR_Instruction : AbstractInstruction
  1000. {
  1001. public RESETBGCOLOR_Instruction()
  1002. {
  1003. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.VOID);
  1004. flag = METHOD_SAFE | EXTENDED;
  1005. }
  1006. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  1007. {
  1008. exm.Console.SetBgColor(Config.Config.BackColor);
  1009. }
  1010. }
  1011. private sealed class FONTBOLD_Instruction : AbstractInstruction
  1012. {
  1013. public FONTBOLD_Instruction()
  1014. {
  1015. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.VOID);
  1016. flag = METHOD_SAFE | EXTENDED;
  1017. }
  1018. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  1019. {
  1020. exm.Console.SetStringStyle(FontStyle.Bold);
  1021. }
  1022. }
  1023. private sealed class FONTITALIC_Instruction : AbstractInstruction
  1024. {
  1025. public FONTITALIC_Instruction()
  1026. {
  1027. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.VOID);
  1028. flag = METHOD_SAFE | EXTENDED;
  1029. }
  1030. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  1031. {
  1032. exm.Console.SetStringStyle(FontStyle.Italic);
  1033. }
  1034. }
  1035. private sealed class FONTREGULAR_Instruction : AbstractInstruction
  1036. {
  1037. public FONTREGULAR_Instruction()
  1038. {
  1039. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.VOID);
  1040. flag = METHOD_SAFE | EXTENDED;
  1041. }
  1042. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  1043. {
  1044. exm.Console.SetStringStyle(FontStyle.Regular);
  1045. }
  1046. }
  1047. private sealed class VARSET_Instruction : AbstractInstruction
  1048. {
  1049. public VARSET_Instruction()
  1050. {
  1051. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.SP_VAR_SET);
  1052. flag = METHOD_SAFE | EXTENDED;
  1053. }
  1054. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  1055. {
  1056. SpVarSetArgument spvarsetarg = (SpVarSetArgument)func.Argument;
  1057. VariableTerm var = spvarsetarg.VariableDest;
  1058. FixedVariableTerm p = var.GetFixedVariableTerm(exm);
  1059. int start = 0;
  1060. int end = 0;
  1061. //endを先に取って判定の処理変更
  1062. if (spvarsetarg.End != null)
  1063. end = (int)spvarsetarg.End.GetIntValue(exm);
  1064. else if (var.Identifier.IsArray1D)
  1065. end = var.GetLength();
  1066. if (spvarsetarg.Start != null)
  1067. {
  1068. start = (int)spvarsetarg.Start.GetIntValue(exm);
  1069. if (start > end)
  1070. {
  1071. int temp = start;
  1072. start = end;
  1073. end = start;
  1074. }
  1075. }
  1076. if (var.IsString)
  1077. {
  1078. string src = spvarsetarg.Term.GetStrValue(exm);
  1079. exm.VEvaluator.SetValueAll(p, src, start, end);
  1080. }
  1081. else
  1082. {
  1083. long src = spvarsetarg.Term.GetIntValue(exm);
  1084. exm.VEvaluator.SetValueAll(p, src, start, end);
  1085. }
  1086. }
  1087. }
  1088. private sealed class CVARSET_Instruction : AbstractInstruction
  1089. {
  1090. public CVARSET_Instruction()
  1091. {
  1092. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.SP_CVAR_SET);
  1093. flag = METHOD_SAFE | EXTENDED;
  1094. }
  1095. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  1096. {
  1097. SpCVarSetArgument spvarsetarg = (SpCVarSetArgument)func.Argument;
  1098. FixedVariableTerm p = spvarsetarg.VariableDest.GetFixedVariableTerm(exm);
  1099. SingleTerm index = spvarsetarg.Index.GetValue(exm);
  1100. int charaNum = (int)exm.VEvaluator.CHARANUM;
  1101. int start = 0;
  1102. if (spvarsetarg.Start != null)
  1103. {
  1104. start = (int)spvarsetarg.Start.GetIntValue(exm);
  1105. if (start < 0 || start >= charaNum)
  1106. throw new CodeEE("命令CVARSETの第4引数(" + start + ")がキャラクタの範囲外です");
  1107. }
  1108. int end = 0;
  1109. if (spvarsetarg.End != null)
  1110. {
  1111. end = (int)spvarsetarg.End.GetIntValue(exm);
  1112. if (end < 0 || end > charaNum)
  1113. throw new CodeEE("命令CVARSETの第5引数(" + end + ")がキャラクタの範囲外です");
  1114. }
  1115. else
  1116. end = charaNum;
  1117. if (start > end)
  1118. {
  1119. int temp = start;
  1120. start = end;
  1121. end = start;
  1122. }
  1123. if (!p.Identifier.IsCharacterData)
  1124. throw new CodeEE("命令CVARSETにキャラクタ変数でない変数" + p.Identifier.Name + "が渡されました");
  1125. if (index.GetOperandType() == typeof(string) && p.Identifier.IsArray1D)
  1126. {
  1127. if (!GlobalStatic.ConstantData.isDefined(p.Identifier.Code, index.Str))
  1128. throw new CodeEE("文字列" + index.Str + "は配列変数" + p.Identifier.Name + "の要素ではありません");
  1129. }
  1130. if (p.Identifier.IsString)
  1131. {
  1132. string src = spvarsetarg.Term.GetStrValue(exm);
  1133. exm.VEvaluator.SetValueAllEachChara(p, index, src, start, end);
  1134. }
  1135. else
  1136. {
  1137. long src = spvarsetarg.Term.GetIntValue(exm);
  1138. exm.VEvaluator.SetValueAllEachChara(p, index, src, start, end);
  1139. }
  1140. }
  1141. }
  1142. private sealed class RANDOMIZE_Instruction : AbstractInstruction
  1143. {
  1144. public RANDOMIZE_Instruction()
  1145. {
  1146. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.INT_EXPRESSION_NULLABLE);
  1147. flag = METHOD_SAFE | EXTENDED;
  1148. }
  1149. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  1150. {
  1151. Int64 iValue;
  1152. if (func.Argument.IsConst)
  1153. iValue = func.Argument.ConstInt;
  1154. else
  1155. iValue = ((ExpressionArgument)func.Argument).Term.GetIntValue(exm);
  1156. exm.VEvaluator.Randomize(iValue);
  1157. }
  1158. }
  1159. private sealed class INITRAND_Instruction : AbstractInstruction
  1160. {
  1161. public INITRAND_Instruction()
  1162. {
  1163. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.VOID);
  1164. flag = METHOD_SAFE | EXTENDED;
  1165. }
  1166. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  1167. {
  1168. exm.VEvaluator.InitRanddata();
  1169. }
  1170. }
  1171. private sealed class DUMPRAND_Instruction : AbstractInstruction
  1172. {
  1173. public DUMPRAND_Instruction()
  1174. {
  1175. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.VOID);
  1176. flag = METHOD_SAFE | EXTENDED;
  1177. }
  1178. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  1179. {
  1180. exm.VEvaluator.DumpRanddata();
  1181. }
  1182. }
  1183. private sealed class SAVEGLOBAL_Instruction : AbstractInstruction
  1184. {
  1185. public SAVEGLOBAL_Instruction()
  1186. {
  1187. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.VOID);
  1188. flag = METHOD_SAFE | EXTENDED;
  1189. }
  1190. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  1191. {
  1192. exm.VEvaluator.SaveGlobal();
  1193. }
  1194. }
  1195. private sealed class LOADGLOBAL_Instruction : AbstractInstruction
  1196. {
  1197. public LOADGLOBAL_Instruction()
  1198. {
  1199. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.VOID);
  1200. flag = METHOD_SAFE | EXTENDED;
  1201. }
  1202. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  1203. {
  1204. if (exm.VEvaluator.LoadGlobal())
  1205. exm.VEvaluator.RESULT = 1;
  1206. else
  1207. exm.VEvaluator.RESULT = 0;
  1208. }
  1209. }
  1210. private sealed class RESETDATA_Instruction : AbstractInstruction
  1211. {
  1212. public RESETDATA_Instruction()
  1213. {
  1214. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.VOID);
  1215. flag = METHOD_SAFE | EXTENDED;
  1216. }
  1217. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  1218. {
  1219. exm.VEvaluator.ResetData();
  1220. exm.Console.ResetStyle();
  1221. }
  1222. }
  1223. private sealed class RESETGLOBAL_Instruction : AbstractInstruction
  1224. {
  1225. public RESETGLOBAL_Instruction()
  1226. {
  1227. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.VOID);
  1228. flag = METHOD_SAFE | EXTENDED;
  1229. }
  1230. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  1231. {
  1232. exm.VEvaluator.ResetGlobalData();
  1233. }
  1234. }
  1235. private static int toUInt32inArg(Int64 value, string funcName, int argnum)
  1236. {
  1237. if (value < 0)
  1238. throw new CodeEE(funcName + "の第" + argnum + "引数に負の値(" + value + ")が指定されました");
  1239. if (value > Int32.MaxValue)
  1240. throw new CodeEE(funcName + "の第" + argnum + "引数の値(" + value + ")が大きすぎます");
  1241. return (int)value;
  1242. }
  1243. private sealed class SAVECHARA_Instruction : AbstractInstruction
  1244. {
  1245. public SAVECHARA_Instruction()
  1246. {
  1247. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.SP_SAVECHARA);
  1248. flag = METHOD_SAFE | EXTENDED;
  1249. }
  1250. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  1251. {
  1252. ExpressionArrayArgument arg = (ExpressionArrayArgument)func.Argument;
  1253. IOperandTerm[] terms = arg.TermList;
  1254. string datFilename = terms[0].GetStrValue(exm);
  1255. string savMes = terms[1].GetStrValue(exm);
  1256. int[] savCharaList = new int[terms.Length - 2];
  1257. int charanum = (int)exm.VEvaluator.CHARANUM;
  1258. for (int i = 0; i < savCharaList.Length; i++)
  1259. {
  1260. Int64 v = terms[i + 2].GetIntValue(exm);
  1261. savCharaList[i] = toUInt32inArg(v, "SAVECHARA", i + 3);
  1262. if (savCharaList[i] >= charanum)
  1263. throw new CodeEE("SAVECHARAの第" + (i + 3) + "引数の値がキャラ登録番号の範囲を超えています");
  1264. for (int j = 0; j < i; j++)
  1265. {
  1266. if (savCharaList[i] == savCharaList[j])
  1267. throw new CodeEE("同一のキャラ登録番号(" + (savCharaList[i]) + ")が複数回指定されました");
  1268. }
  1269. }
  1270. exm.VEvaluator.SaveChara(datFilename, savMes, savCharaList);
  1271. }
  1272. }
  1273. private sealed class LOADCHARA_Instruction : AbstractInstruction
  1274. {
  1275. public LOADCHARA_Instruction()
  1276. {
  1277. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.STR_EXPRESSION);
  1278. flag = METHOD_SAFE | EXTENDED;
  1279. }
  1280. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  1281. {
  1282. ExpressionArgument arg = (ExpressionArgument)func.Argument;
  1283. string datFilename = null;
  1284. if (arg.IsConst)
  1285. datFilename = arg.ConstStr;
  1286. else
  1287. datFilename = arg.Term.GetStrValue(exm);
  1288. exm.VEvaluator.LoadChara(datFilename);
  1289. }
  1290. }
  1291. private sealed class SAVEVAR_Instruction : AbstractInstruction
  1292. {
  1293. public SAVEVAR_Instruction()
  1294. {
  1295. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.SP_SAVEVAR);
  1296. flag = METHOD_SAFE | EXTENDED;
  1297. }
  1298. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  1299. {
  1300. throw new NotImplCodeEE();
  1301. //SpSaveVarArgument arg = (SpSaveVarArgument)func.Argument;
  1302. //VariableToken[] vars = arg.VarTokens;
  1303. //string datFilename = arg.Term.GetStrValue(exm);
  1304. //string savMes = arg.SavMes.GetStrValue(exm);
  1305. //exm.VEvaluator.SaveVariable(datFilename, savMes, vars);
  1306. }
  1307. }
  1308. private sealed class LOADVAR_Instruction : AbstractInstruction
  1309. {
  1310. public LOADVAR_Instruction()
  1311. {
  1312. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.STR_EXPRESSION);
  1313. flag = METHOD_SAFE | EXTENDED;
  1314. }
  1315. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  1316. {
  1317. throw new NotImplCodeEE();
  1318. //ExpressionArgument arg = (ExpressionArgument)func.Argument;
  1319. //string datFilename = null;
  1320. //if (arg.IsConst)
  1321. // datFilename = arg.ConstStr;
  1322. //else
  1323. // datFilename = arg.Term.GetStrValue(exm);
  1324. //exm.VEvaluator.LoadVariable(datFilename);
  1325. }
  1326. }
  1327. private sealed class DELDATA_Instruction : AbstractInstruction
  1328. {
  1329. public DELDATA_Instruction()
  1330. {
  1331. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.INT_EXPRESSION);
  1332. flag = METHOD_SAFE | EXTENDED;
  1333. }
  1334. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  1335. {
  1336. Int64 target;
  1337. if (func.Argument.IsConst)
  1338. target = func.Argument.ConstInt;
  1339. else
  1340. target = ((ExpressionArgument)func.Argument).Term.GetIntValue(exm);
  1341. int target32 = toUInt32inArg(target, "DELDATA", 1);
  1342. exm.VEvaluator.DelData(target32);
  1343. }
  1344. }
  1345. private sealed class DO_NOTHING_Instruction : AbstractInstruction
  1346. {
  1347. public DO_NOTHING_Instruction()
  1348. {
  1349. //事実上ENDIFの非フローコントロール版
  1350. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.VOID);
  1351. flag = METHOD_SAFE | EXTENDED | PARTIAL;
  1352. }
  1353. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  1354. {
  1355. //何もしない
  1356. }
  1357. }
  1358. private sealed class REF_Instruction : AbstractInstruction
  1359. {
  1360. public REF_Instruction(bool byname)
  1361. {
  1362. this.byname = byname;
  1363. if (byname)
  1364. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.SP_REFBYNAME);
  1365. else
  1366. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.SP_REF);
  1367. flag = METHOD_SAFE | EXTENDED;
  1368. }
  1369. bool byname;
  1370. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  1371. {
  1372. throw new NotImplCodeEE();
  1373. RefArgument arg = (RefArgument)func.Argument;
  1374. string str = null;
  1375. if (arg.SrcTerm != null)
  1376. str = arg.SrcTerm.GetStrValue(exm);
  1377. if (arg.RefMethodToken != null)
  1378. {
  1379. UserDefinedRefMethod srcRef = arg.SrcRefMethodToken;
  1380. CalledFunction call = arg.SrcCalledFunction;
  1381. if (str != null)//REFBYNAMEかつ第二引数が定数でない
  1382. {
  1383. srcRef = GlobalStatic.IdentifierDictionary.GetRefMethod(str);
  1384. if (srcRef == null)
  1385. {
  1386. FunctionLabelLine label = GlobalStatic.LabelDictionary.GetNonEventLabel(str);
  1387. //if (label == null)
  1388. // throw new CodeEE("式中関数" + str + "が見つかりません");
  1389. //if (!label.IsMethod)
  1390. // throw new CodeEE("#FUNCTION(S)属性を持たない関数" + str + "は参照できません");
  1391. if (label != null && label.IsMethod)
  1392. call = CalledFunction.CreateCalledFunctionMethod(label, str);
  1393. }
  1394. }
  1395. if (srcRef != null)
  1396. call = srcRef.CalledFunction;//第二引数が関数参照。callがnullならエラー
  1397. if (call == null || !arg.RefMethodToken.MatchType(call))
  1398. {
  1399. arg.RefMethodToken.SetReference(null);
  1400. exm.VEvaluator.RESULT = 0;
  1401. }
  1402. arg.RefMethodToken.SetReference(call);
  1403. exm.VEvaluator.RESULT = 1;
  1404. return;
  1405. }
  1406. ReferenceToken refVar = arg.RefVarToken;
  1407. VariableToken srcVar = arg.SrcVarToken;
  1408. string errmes;
  1409. if (str != null)
  1410. {
  1411. srcVar = GlobalStatic.IdentifierDictionary.GetVariableToken(str, null, true);
  1412. //if (srcVar == null)
  1413. // throw new CodeEE("変数" + str + "が見つかりません");
  1414. }
  1415. if (srcVar == null || !refVar.MatchType(srcVar, false, out errmes))
  1416. {
  1417. refVar.SetRef(null);
  1418. exm.VEvaluator.RESULT = 0;
  1419. }
  1420. refVar.SetRef((Array)srcVar.GetArray());
  1421. exm.VEvaluator.RESULT = 1;
  1422. return;
  1423. }
  1424. }
  1425. private sealed class TOOLTIP_SETCOLOR_Instruction : AbstractInstruction
  1426. {
  1427. public TOOLTIP_SETCOLOR_Instruction()
  1428. {
  1429. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.SP_SWAP);
  1430. flag = METHOD_SAFE | EXTENDED;
  1431. }
  1432. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  1433. {
  1434. SpSwapCharaArgument arg = (SpSwapCharaArgument)func.Argument;
  1435. long foreColor = arg.X.GetIntValue(exm);
  1436. long backColor = arg.Y.GetIntValue(exm);
  1437. if (foreColor < 0 || foreColor > 0xFFFFFF)
  1438. throw new CodeEE("第1引数が色を表す整数の範囲外です");
  1439. if (backColor < 0 || backColor > 0xFFFFFF)
  1440. throw new CodeEE("第2引数が色を表す整数の範囲外です");
  1441. Color fc = Color.FromArgb((int)foreColor >>16, (int)foreColor>>8 &0xFF,(int)foreColor &0xFF);
  1442. Color bc = Color.FromArgb((int)backColor >>16, (int)backColor>>8 &0xFF,(int)backColor &0xFF);
  1443. exm.Console.SetToolTipColor(fc, bc);
  1444. }
  1445. }
  1446. private sealed class TOOLTIP_SETDELAY_Instruction : AbstractInstruction
  1447. {
  1448. public TOOLTIP_SETDELAY_Instruction()
  1449. {
  1450. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.INT_EXPRESSION);
  1451. flag = METHOD_SAFE | EXTENDED;
  1452. }
  1453. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  1454. {
  1455. ExpressionArgument arg = (ExpressionArgument)func.Argument;
  1456. long delay = 0;
  1457. if(arg.IsConst)
  1458. delay = arg.ConstInt;
  1459. else
  1460. delay = arg.Term.GetIntValue(exm);
  1461. if (delay < 0 || delay > int.MaxValue)
  1462. throw new CodeEE("引数の値が適切な範囲外です");
  1463. exm.Console.SetToolTipDelay((int)delay);
  1464. }
  1465. }
  1466. private sealed class TOOLTIP_SETDURATION_Instruction : AbstractInstruction
  1467. {
  1468. public TOOLTIP_SETDURATION_Instruction()
  1469. {
  1470. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.INT_EXPRESSION);
  1471. flag = METHOD_SAFE | EXTENDED;
  1472. }
  1473. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  1474. {
  1475. ExpressionArgument arg = (ExpressionArgument)func.Argument;
  1476. long duration = 0;
  1477. if (arg.IsConst)
  1478. duration = arg.ConstInt;
  1479. else
  1480. duration = arg.Term.GetIntValue(exm);
  1481. if (duration < 0 || duration > int.MaxValue)
  1482. throw new CodeEE("引数の値が適切な範囲外です");
  1483. if (duration > short.MaxValue)
  1484. duration = short.MaxValue;
  1485. exm.Console.SetToolTipDuration((int)duration);
  1486. }
  1487. }
  1488. #endregion
  1489. #region flowControlFunction
  1490. private sealed class BEGIN_Instruction : AbstractInstruction
  1491. {
  1492. public BEGIN_Instruction()
  1493. {
  1494. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.STR);
  1495. flag = FLOW_CONTROL;
  1496. }
  1497. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  1498. {
  1499. string keyword = func.Argument.ConstStr;
  1500. if (Config.Config.ICFunction)//1756 BEGINのキーワードは関数扱いらしい
  1501. keyword = keyword.ToUpper();
  1502. state.SetBegin(keyword);
  1503. state.Return(0);
  1504. exm.Console.ResetStyle();
  1505. }
  1506. }
  1507. private sealed class SAVELOADGAME_Instruction : AbstractInstruction
  1508. {
  1509. public SAVELOADGAME_Instruction(bool isSave)
  1510. {
  1511. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.VOID);
  1512. flag = FLOW_CONTROL;
  1513. this.isSave = isSave;
  1514. }
  1515. readonly bool isSave;
  1516. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  1517. {
  1518. if ((state.SystemState & SystemStateCode.__CAN_SAVE__) != SystemStateCode.__CAN_SAVE__)
  1519. {
  1520. string funcName = state.Scope;
  1521. if (funcName == null)
  1522. funcName = "";
  1523. throw new CodeEE("@" + funcName + "中でSAVEGAME/LOADGAME命令を実行することはできません");
  1524. }
  1525. GlobalStatic.Process.saveCurrentState(true);
  1526. //バックアップに入れた旧ProcessStateの方を参照するため、ここでstateは使えない
  1527. GlobalStatic.Process.getCurrentState.SaveLoadData(isSave);
  1528. }
  1529. }
  1530. private sealed class REPEAT_Instruction : AbstractInstruction
  1531. {
  1532. public REPEAT_Instruction(bool fornext)
  1533. {
  1534. flag = METHOD_SAFE | FLOW_CONTROL | PARTIAL;
  1535. if (fornext)
  1536. {
  1537. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.SP_FOR_NEXT);
  1538. flag |= EXTENDED;
  1539. }
  1540. else
  1541. {
  1542. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.INT_EXPRESSION);
  1543. }
  1544. }
  1545. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  1546. {
  1547. SpForNextArgment forArg = (SpForNextArgment)func.Argument;
  1548. func.LoopCounter = forArg.Cnt;
  1549. //1.725 順序変更。REPEATにならう。
  1550. func.LoopCounter.SetValue(forArg.Start.GetIntValue(exm), exm);
  1551. func.LoopEnd = forArg.End.GetIntValue(exm);
  1552. func.LoopStep = forArg.Step.GetIntValue(exm);
  1553. if ((func.LoopStep > 0) && (func.LoopEnd > func.LoopCounter.GetIntValue(exm)))//まだ回数が残っているなら、
  1554. return;//そのまま次の行へ
  1555. if ((func.LoopStep < 0) && (func.LoopEnd < func.LoopCounter.GetIntValue(exm)))//まだ回数が残っているなら、
  1556. return;//そのまま次の行へ
  1557. state.JumpTo(func.JumpTo);
  1558. }
  1559. }
  1560. private sealed class WHILE_Instruction : AbstractInstruction
  1561. {
  1562. public WHILE_Instruction()
  1563. {
  1564. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.INT_EXPRESSION);
  1565. flag = METHOD_SAFE | EXTENDED | FLOW_CONTROL | PARTIAL;
  1566. }
  1567. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  1568. {
  1569. ExpressionArgument expArg = (ExpressionArgument)func.Argument;
  1570. if (expArg.Term.GetIntValue(exm) != 0)//式が真
  1571. return;//そのまま中の処理へ
  1572. state.JumpTo(func.JumpTo);
  1573. }
  1574. }
  1575. private sealed class SIF_Instruction : AbstractInstruction
  1576. {
  1577. public SIF_Instruction()
  1578. {
  1579. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.INT_EXPRESSION);
  1580. flag = METHOD_SAFE | FLOW_CONTROL | PARTIAL | FORCE_SETARG;
  1581. }
  1582. public override void SetJumpTo(ref bool useCallForm, InstructionLine func, int currentDepth, ref string FunctionoNotFoundName)
  1583. {
  1584. LogicalLine jumpto = func.NextLine;
  1585. if ((jumpto == null) || (jumpto.NextLine == null) ||
  1586. (jumpto is FunctionLabelLine) || (jumpto is NullLine))
  1587. {
  1588. ParserMediator.Warn("SIF文の次の行がありません", func, 2, true, false);
  1589. return;
  1590. }
  1591. if (jumpto is InstructionLine)
  1592. {
  1593. InstructionLine sifFunc = (InstructionLine)jumpto;
  1594. if (sifFunc.Function.IsPartial())
  1595. ParserMediator.Warn("SIF文の次の行を" + sifFunc.Function.Name + "文にすることはできません", func, 2, true, false);
  1596. else
  1597. func.JumpTo = func.NextLine.NextLine;
  1598. }
  1599. else if (jumpto is GotoLabelLine)
  1600. ParserMediator.Warn("SIF文の次の行をラベル行にすることはできません", func, 2, true, false);
  1601. else
  1602. func.JumpTo = func.NextLine.NextLine;
  1603. if ((func.JumpTo != null) && (func.Position.LineNo + 1 != func.NextLine.Position.LineNo))
  1604. ParserMediator.Warn("SIF文の次の行が空行またはコメント行です(eramaker:SIF文は意味を失います)", func, 0, false, true);
  1605. }
  1606. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  1607. {
  1608. ExpressionArgument expArg = (ExpressionArgument)func.Argument;
  1609. if (expArg.Term.GetIntValue(exm) == 0)//評価式が真ならそのまま流れ落ちる
  1610. state.ShiftNextLine();//偽なら一行とばす。順に来たときと同じ扱いにする
  1611. }
  1612. }
  1613. private sealed class ELSEIF_Instruction : AbstractInstruction
  1614. {
  1615. public ELSEIF_Instruction(FunctionArgType argtype)
  1616. {
  1617. ArgBuilder = ArgumentParser.GetArgumentBuilder(argtype);
  1618. flag = METHOD_SAFE | FLOW_CONTROL | PARTIAL | FORCE_SETARG;
  1619. }
  1620. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  1621. {
  1622. //if (iFuncCode == FunctionCode.ELSE || iFuncCode == FunctionCode.ELSEIF
  1623. // || iFuncCode == FunctionCode.CASE || iFuncCode == FunctionCode.CASEELSE)
  1624. //チェック済み
  1625. //if (func.JumpTo == null)
  1626. // throw new ExeEE(func.Function.Name + "のジャンプ先が設定されていない");
  1627. state.JumpTo(func.JumpTo);
  1628. }
  1629. }
  1630. private sealed class ENDIF_Instruction : AbstractInstruction
  1631. {
  1632. public ENDIF_Instruction()
  1633. {
  1634. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.VOID);
  1635. flag = FLOW_CONTROL | PARTIAL | FORCE_SETARG;
  1636. }
  1637. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  1638. {
  1639. }
  1640. }
  1641. private sealed class IF_Instruction : AbstractInstruction
  1642. {
  1643. public IF_Instruction()
  1644. {
  1645. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.INT_EXPRESSION);
  1646. flag = METHOD_SAFE | FLOW_CONTROL | PARTIAL | FORCE_SETARG;
  1647. }
  1648. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  1649. {
  1650. LogicalLine ifJumpto = func.JumpTo;//ENDIF
  1651. //チェック済み
  1652. //if (func.IfCaseList == null)
  1653. // throw new ExeEE("IFのIF-ELSEIFリストが適正に作成されていない");
  1654. //if (func.JumpTo == null)
  1655. // throw new ExeEE("IFに対応するENDIFが設定されていない");
  1656. InstructionLine line = null;
  1657. for (int i = 0; i < func.IfCaseList.Count; i++)
  1658. {
  1659. line = func.IfCaseList[i];
  1660. if (line.IsError)
  1661. continue;
  1662. if (line.FunctionCode == FunctionCode.ELSE)
  1663. {
  1664. ifJumpto = line;
  1665. break;
  1666. }
  1667. //ExpressionArgument expArg = (ExpressionArgument)(line.Argument);
  1668. //チェック済み
  1669. //if (expArg == null)
  1670. // throw new ExeEE("IFチェック中。引数が解析されていない。", func.IfCaseList[i].Position);
  1671. //1730 ELSEIFが出したエラーがIFのエラーとして検出されていた
  1672. state.CurrentLine = line;
  1673. Int64 value = ((ExpressionArgument)(line.Argument)).Term.GetIntValue(exm);
  1674. if (value != 0)//式が真
  1675. {
  1676. ifJumpto = line;
  1677. break;
  1678. }
  1679. }
  1680. if (ifJumpto != func)//自分自身がジャンプ先ならそのまま
  1681. state.JumpTo(ifJumpto);
  1682. //state.RunningLine = null;
  1683. }
  1684. }
  1685. private sealed class SELECTCASE_Instruction : AbstractInstruction
  1686. {
  1687. public SELECTCASE_Instruction()
  1688. {
  1689. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.EXPRESSION);
  1690. flag = METHOD_SAFE | EXTENDED | FLOW_CONTROL | PARTIAL | FORCE_SETARG;
  1691. }
  1692. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  1693. {
  1694. LogicalLine caseJumpto = func.JumpTo;//ENDSELECT
  1695. IOperandTerm selectValue = ((ExpressionArgument)func.Argument).Term;
  1696. string sValue = null;
  1697. Int64 iValue = 0;
  1698. if (selectValue.IsInteger)
  1699. iValue = selectValue.GetIntValue(exm);
  1700. else
  1701. sValue = selectValue.GetStrValue(exm);
  1702. //チェック済み
  1703. //if (func.IfCaseList == null)
  1704. // throw new ExeEE("SELECTCASEのCASEリストが適正に作成されていない");
  1705. //if (func.JumpTo == null)
  1706. // throw new ExeEE("SELECTCASEに対応するENDSELECTが設定されていない");
  1707. InstructionLine line = null;
  1708. for (int i = 0; i < func.IfCaseList.Count; i++)
  1709. {
  1710. line = func.IfCaseList[i];
  1711. if (line.IsError)
  1712. continue;
  1713. if (line.FunctionCode == FunctionCode.CASEELSE)
  1714. {
  1715. caseJumpto = line;
  1716. break;
  1717. }
  1718. CaseArgument caseArg = (CaseArgument)(line.Argument);
  1719. //チェック済み
  1720. //if (caseArg == null)
  1721. // throw new ExeEE("CASEチェック中。引数が解析されていない。", func.IfCaseList[i].Position);
  1722. state.CurrentLine = line;
  1723. if (selectValue.IsInteger)
  1724. {
  1725. Int64 Is = iValue;
  1726. foreach (CaseExpression caseExp in caseArg.CaseExps)
  1727. {
  1728. if (caseExp.GetBool(Is, exm))
  1729. {
  1730. caseJumpto = line;
  1731. goto casefound;
  1732. }
  1733. }
  1734. }
  1735. else
  1736. {
  1737. string Is = sValue;
  1738. foreach (CaseExpression caseExp in caseArg.CaseExps)
  1739. {
  1740. if (caseExp.GetBool(Is, exm))
  1741. {
  1742. caseJumpto = line;
  1743. goto casefound;
  1744. }
  1745. }
  1746. }
  1747. }
  1748. casefound:
  1749. state.JumpTo(caseJumpto);
  1750. //state.RunningLine = null;
  1751. }
  1752. }
  1753. private sealed class RETURNFORM_Instruction : AbstractInstruction
  1754. {
  1755. public RETURNFORM_Instruction()
  1756. {
  1757. //ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.FORM_STR_ANY);
  1758. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.FORM_STR);
  1759. flag = EXTENDED | FLOW_CONTROL;
  1760. }
  1761. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  1762. {
  1763. //int termnum = 0;
  1764. //foreach (IOperandTerm term in ((ExpressionArrayArgument)func.Argument).TermList)
  1765. //{
  1766. // string arg = term.GetStrValue(exm);
  1767. // StringStream aSt = new StringStream(arg);
  1768. // WordCollection wc = LexicalAnalyzer.Analyse(aSt, LexEndWith.EoL, LexAnalyzeFlag.None);
  1769. // exm.VEvaluator.SetResultX((ExpressionParser.ReduceIntegerTerm(wc, TermEndWith.EoL).GetIntValue(exm)), termnum);
  1770. // termnum++;
  1771. //}
  1772. //state.Return(exm.VEvaluator.RESULT);
  1773. //if (state.ScriptEnd)
  1774. // return;
  1775. //int termnum = 0;
  1776. StringStream aSt = new StringStream(((ExpressionArgument)func.Argument).Term.GetStrValue(exm));
  1777. List<long> termList = new List<long>();
  1778. while (!aSt.EOS)
  1779. {
  1780. WordCollection wc = LexicalAnalyzer.Analyse(aSt, LexEndWith.Comma, LexAnalyzeFlag.None);
  1781. //exm.VEvaluator.SetResultX(ExpressionParser.ReduceIntegerTerm(wc, TermEndWith.EoL).GetIntValue(exm), termnum++);
  1782. termList.Add(ExpressionParser.ReduceIntegerTerm(wc, TermEndWith.EoL).GetIntValue(exm));
  1783. aSt.ShiftNext();
  1784. LexicalAnalyzer.SkipHalfSpace(aSt);
  1785. //termnum++;
  1786. }
  1787. if (termList.Count == 0)
  1788. termList.Add(0);
  1789. exm.VEvaluator.SetResultX(termList);
  1790. state.Return(exm.VEvaluator.RESULT);
  1791. if (state.ScriptEnd)
  1792. return;
  1793. }
  1794. }
  1795. private sealed class RETURN_Instruction : AbstractInstruction
  1796. {
  1797. public RETURN_Instruction()
  1798. {
  1799. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.INT_ANY);
  1800. flag = FLOW_CONTROL;
  1801. }
  1802. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  1803. {
  1804. //int termnum = 0;
  1805. ExpressionArrayArgument expArrayArg = (ExpressionArrayArgument)func.Argument;
  1806. if (expArrayArg.TermList.Length == 0)
  1807. {
  1808. exm.VEvaluator.RESULT = 0;
  1809. state.Return(0);
  1810. return;
  1811. }
  1812. List<long> termList = new List<long>();
  1813. foreach (IOperandTerm term in expArrayArg.TermList)
  1814. {
  1815. termList.Add(term.GetIntValue(exm));
  1816. //exm.VEvaluator.SetResultX(term.GetIntValue(exm), termnum++);
  1817. }
  1818. if (termList.Count == 0)
  1819. termList.Add(0);
  1820. exm.VEvaluator.SetResultX(termList);
  1821. state.Return(exm.VEvaluator.RESULT);
  1822. }
  1823. }
  1824. private sealed class CATCH_Instruction : AbstractInstruction
  1825. {
  1826. public CATCH_Instruction()
  1827. {
  1828. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.VOID);
  1829. flag = METHOD_SAFE | EXTENDED | FLOW_CONTROL | PARTIAL;
  1830. }
  1831. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  1832. {
  1833. //if (sequential)//上から流れてきたなら何もしないでENDCATCHに飛ぶ
  1834. state.JumpTo(func.JumpToEndCatch);
  1835. }
  1836. }
  1837. private sealed class RESTART_Instruction : AbstractInstruction
  1838. {
  1839. public RESTART_Instruction()
  1840. {
  1841. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.VOID);
  1842. flag = METHOD_SAFE | FLOW_CONTROL | EXTENDED;
  1843. }
  1844. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  1845. {
  1846. state.JumpTo(func.ParentLabelLine);
  1847. }
  1848. }
  1849. private sealed class BREAK_Instruction : AbstractInstruction
  1850. {
  1851. public BREAK_Instruction()
  1852. {
  1853. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.VOID);
  1854. flag = METHOD_SAFE | FLOW_CONTROL;
  1855. }
  1856. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  1857. {
  1858. ////BREAKのJUMP先はRENDまたはNEXT。そのジャンプ先であるREPEATかFORをiLineに代入。
  1859. //1.723 仕様変更。BREAKのJUMP先にはREPEAT、FOR、WHILEを記憶する。そのJUMP先が本当のJUMP先。
  1860. InstructionLine jumpTo = (InstructionLine)func.JumpTo;
  1861. InstructionLine iLine = (InstructionLine)jumpTo.JumpTo;
  1862. //WHILEとDOはカウンタがないので、即ジャンプ
  1863. if (jumpTo.FunctionCode != FunctionCode.WHILE && jumpTo.FunctionCode != FunctionCode.DO)
  1864. {
  1865. //eramakerではBREAK時にCOUNTが回る
  1866. jumpTo.LoopCounter.PlusValue(jumpTo.LoopStep, exm);
  1867. }
  1868. state.JumpTo(iLine);
  1869. }
  1870. }
  1871. private sealed class CONTINUE_Instruction : AbstractInstruction
  1872. {
  1873. public CONTINUE_Instruction()
  1874. {
  1875. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.VOID);
  1876. flag = METHOD_SAFE | FLOW_CONTROL;
  1877. }
  1878. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  1879. {
  1880. InstructionLine jumpTo = (InstructionLine)func.JumpTo;
  1881. if ((jumpTo.FunctionCode == FunctionCode.REPEAT) || (jumpTo.FunctionCode == FunctionCode.FOR))
  1882. {
  1883. //ループ変数が不明(REPEAT、FORを経由せずにループしようとした場合は無視してループを抜ける(eramakerがこういう仕様だったりする))
  1884. if (jumpTo.LoopCounter == null)
  1885. {
  1886. state.JumpTo(jumpTo.JumpTo);
  1887. return;
  1888. }
  1889. jumpTo.LoopCounter.PlusValue(jumpTo.LoopStep, exm);
  1890. Int64 counter = jumpTo.LoopCounter.GetIntValue(exm);
  1891. //まだ回数が残っているなら、
  1892. if (((jumpTo.LoopStep > 0) && (jumpTo.LoopEnd > counter))
  1893. || ((jumpTo.LoopStep < 0) && (jumpTo.LoopEnd < counter)))
  1894. state.JumpTo(func.JumpTo);
  1895. else
  1896. state.JumpTo(jumpTo.JumpTo);
  1897. return;
  1898. }
  1899. if (jumpTo.FunctionCode == FunctionCode.WHILE)
  1900. {
  1901. if (((ExpressionArgument)jumpTo.Argument).Term.GetIntValue(exm) != 0)
  1902. state.JumpTo(func.JumpTo);
  1903. else
  1904. state.JumpTo(jumpTo.JumpTo);
  1905. return;
  1906. }
  1907. if (jumpTo.FunctionCode == FunctionCode.DO)
  1908. {
  1909. //こいつだけはCONTINUEよりも後ろに判定行があるため、判定行にエラーがあった場合に問題がある
  1910. InstructionLine tFunc = (InstructionLine)((InstructionLine)func.JumpTo).JumpTo;//LOOP
  1911. if (tFunc.IsError)
  1912. throw new CodeEE(tFunc.ErrMes, tFunc.Position);
  1913. ExpressionArgument expArg = (ExpressionArgument)tFunc.Argument;
  1914. if (expArg.Term.GetIntValue(exm) != 0)//式が真
  1915. state.JumpTo(jumpTo);//DO
  1916. else
  1917. state.JumpTo(tFunc);//LOOP
  1918. return;
  1919. }
  1920. throw new ExeEE("異常なCONTINUE");
  1921. }
  1922. }
  1923. private sealed class REND_Instruction : AbstractInstruction
  1924. {
  1925. public REND_Instruction()
  1926. {
  1927. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.VOID);
  1928. flag = METHOD_SAFE | FLOW_CONTROL | PARTIAL;
  1929. }
  1930. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  1931. {
  1932. InstructionLine jumpTo = (InstructionLine)func.JumpTo;
  1933. //ループ変数が不明(REPEAT、FORを経由せずにループしようとした場合は無視してループを抜ける(eramakerがこういう仕様だったりする))
  1934. if (jumpTo.LoopCounter == null)
  1935. {
  1936. state.JumpTo(jumpTo.JumpTo);
  1937. return;
  1938. }
  1939. jumpTo.LoopCounter.PlusValue(jumpTo.LoopStep, exm);
  1940. Int64 counter = jumpTo.LoopCounter.GetIntValue(exm);
  1941. //まだ回数が残っているなら、
  1942. if (((jumpTo.LoopStep > 0) && (jumpTo.LoopEnd > counter))
  1943. || ((jumpTo.LoopStep < 0) && (jumpTo.LoopEnd < counter)))
  1944. state.JumpTo(func.JumpTo);
  1945. }
  1946. }
  1947. private sealed class WEND_Instruction : AbstractInstruction
  1948. {
  1949. public WEND_Instruction()
  1950. {
  1951. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.VOID);
  1952. flag = METHOD_SAFE | EXTENDED | FLOW_CONTROL | PARTIAL;
  1953. }
  1954. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  1955. {
  1956. InstructionLine jumpTo = (InstructionLine)func.JumpTo;
  1957. if (((ExpressionArgument)jumpTo.Argument).Term.GetIntValue(exm) != 0)
  1958. state.JumpTo(func.JumpTo);
  1959. }
  1960. }
  1961. private sealed class LOOP_Instruction : AbstractInstruction
  1962. {
  1963. public LOOP_Instruction()
  1964. {
  1965. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.INT_EXPRESSION);
  1966. flag = METHOD_SAFE | EXTENDED | FLOW_CONTROL | PARTIAL | FORCE_SETARG;
  1967. }
  1968. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  1969. {
  1970. ExpressionArgument expArg = (ExpressionArgument)func.Argument;
  1971. if (expArg.Term.GetIntValue(exm) != 0)//式が真
  1972. state.JumpTo(func.JumpTo);
  1973. }
  1974. }
  1975. private sealed class RETURNF_Instruction : AbstractInstruction
  1976. {
  1977. public RETURNF_Instruction()
  1978. {
  1979. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.EXPRESSION_NULLABLE);
  1980. flag = METHOD_SAFE | EXTENDED | FLOW_CONTROL;
  1981. }
  1982. public override void SetJumpTo(ref bool useCallForm, InstructionLine func, int currentDepth, ref string FunctionoNotFoundName)
  1983. {
  1984. FunctionLabelLine label = func.ParentLabelLine;
  1985. if (!label.IsMethod)
  1986. {
  1987. ParserMediator.Warn("RETURNFは#FUNCTION以外では使用できません", func, 2, true, false);
  1988. }
  1989. if (func.Argument != null)
  1990. {
  1991. IOperandTerm term = ((ExpressionArgument)func.Argument).Term;
  1992. if (term != null)
  1993. {
  1994. if (label.MethodType != term.GetOperandType())
  1995. {
  1996. if (label.MethodType == typeof(Int64))
  1997. ParserMediator.Warn("#FUNCTIONで始まる関数の戻り値に文字列型が指定されました", func, 2, true, false);
  1998. else if (label.MethodType == typeof(string))
  1999. ParserMediator.Warn("#FUCNTIONSで始まる関数の戻り値に数値型が指定されました", func, 2, true, false);
  2000. }
  2001. }
  2002. }
  2003. }
  2004. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  2005. {
  2006. IOperandTerm term = ((ExpressionArgument)func.Argument).Term;
  2007. SingleTerm ret = null;
  2008. if (term != null)
  2009. {
  2010. ret = term.GetValue(exm, translate);
  2011. }
  2012. state.ReturnF(ret);
  2013. }
  2014. }
  2015. private sealed class CALL_Instruction : AbstractInstruction
  2016. {
  2017. public CALL_Instruction(bool form, bool isJump, bool isTry, bool isTryCatch)
  2018. {
  2019. if (form)
  2020. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.SP_CALLFORM);
  2021. else
  2022. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.SP_CALL);
  2023. flag = FLOW_CONTROL | FORCE_SETARG;
  2024. if (isJump)
  2025. flag |= IS_JUMP;
  2026. if (isTry)
  2027. flag |= IS_TRY;
  2028. if (isTryCatch)
  2029. flag |= IS_TRYC | PARTIAL;
  2030. this.isJump = isJump;
  2031. this.isTry = isTry;
  2032. }
  2033. readonly bool isJump;
  2034. readonly bool isTry;
  2035. public override void SetJumpTo(ref bool useCallForm, InstructionLine func, int currentDepth, ref string FunctionoNotFoundName)
  2036. {
  2037. if (!func.Argument.IsConst)
  2038. {
  2039. useCallForm = true;
  2040. return;
  2041. }
  2042. SpCallArgment callArg = (SpCallArgment)func.Argument;
  2043. string labelName = callArg.ConstStr;
  2044. if (Config.Config.ICFunction)
  2045. labelName = labelName.ToUpper();
  2046. CalledFunction call = CalledFunction.CallFunction(GlobalStatic.Process, labelName, func);
  2047. if ((call == null) && (!func.Function.IsTry()))
  2048. {
  2049. FunctionoNotFoundName = labelName;
  2050. return;
  2051. }
  2052. if (call != null)
  2053. {
  2054. func.JumpTo = call.TopLabel;
  2055. if (call.TopLabel.Depth < 0)
  2056. call.TopLabel.Depth = currentDepth + 1;
  2057. if (call.TopLabel.IsError)
  2058. {
  2059. func.IsError = true;
  2060. func.ErrMes = call.TopLabel.ErrMes;
  2061. return;
  2062. }
  2063. string errMes;
  2064. callArg.UDFArgument = call.ConvertArg(callArg.RowArgs, out errMes);
  2065. if (callArg.UDFArgument == null)
  2066. {
  2067. ParserMediator.Warn(errMes, func, 2, true, false);
  2068. return;
  2069. }
  2070. }
  2071. callArg.CallFunc = call;
  2072. }
  2073. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  2074. {
  2075. SpCallArgment spCallArg = (SpCallArgment)func.Argument;
  2076. CalledFunction call = null;
  2077. string labelName = null;
  2078. UserDefinedFunctionArgument arg = null;
  2079. if (spCallArg.IsConst)
  2080. {
  2081. call = spCallArg.CallFunc;
  2082. labelName = spCallArg.ConstStr;
  2083. arg = spCallArg.UDFArgument;
  2084. }
  2085. else
  2086. {
  2087. labelName = spCallArg.FuncnameTerm.GetStrValue(exm);
  2088. if (Config.Config.ICFunction)
  2089. labelName = labelName.ToUpper();
  2090. call = CalledFunction.CallFunction(GlobalStatic.Process, labelName, func);
  2091. }
  2092. if (call == null)
  2093. {
  2094. if (!isTry)
  2095. throw new CodeEE("関数\"@" + labelName + "\"が見つかりません");
  2096. if (func.JumpToEndCatch != null)
  2097. state.JumpTo(func.JumpToEndCatch);
  2098. return;
  2099. }
  2100. call.IsJump = isJump;
  2101. if (arg == null)
  2102. {
  2103. string errMes;
  2104. arg = call.ConvertArg(spCallArg.RowArgs, out errMes);
  2105. if (arg == null)
  2106. throw new CodeEE(errMes);
  2107. }
  2108. state.IntoFunction(call, arg, exm);
  2109. }
  2110. }
  2111. private sealed class CALLEVENT_Instruction : AbstractInstruction
  2112. {
  2113. public CALLEVENT_Instruction()
  2114. {
  2115. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.STR);
  2116. flag = FLOW_CONTROL | EXTENDED;
  2117. }
  2118. public override void SetJumpTo(ref bool useCallForm, InstructionLine func, int currentDepth, ref string FunctionoNotFoundName)
  2119. {
  2120. //EVENT関数からCALLされた先でCALLEVENTされるようなパターンはIntoFunctionで捕まえる
  2121. FunctionLabelLine label = func.ParentLabelLine;
  2122. if (label.IsEvent)
  2123. {
  2124. ParserMediator.Warn("EVENT関数中にCALLEVENT命令は使用できません", func, 2, true, false);
  2125. }
  2126. }
  2127. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  2128. {
  2129. string labelName = func.Argument.ConstStr;
  2130. if (Config.Config.ICFunction)
  2131. labelName = labelName.ToUpper();
  2132. CalledFunction call = CalledFunction.CallEventFunction(GlobalStatic.Process, labelName, func);
  2133. if (call == null)
  2134. return;
  2135. state.IntoFunction(call, null, null);
  2136. }
  2137. }
  2138. private sealed class GOTO_Instruction : AbstractInstruction
  2139. {
  2140. public GOTO_Instruction(bool form, bool isTry, bool isTryCatch)
  2141. {
  2142. if (form)
  2143. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.SP_CALLFORM);
  2144. else
  2145. ArgBuilder = ArgumentParser.GetArgumentBuilder(FunctionArgType.SP_CALL);
  2146. this.isTry = isTry;
  2147. flag = METHOD_SAFE | FLOW_CONTROL | FORCE_SETARG;
  2148. if (isTry)
  2149. flag |= IS_TRY;
  2150. if (isTryCatch)
  2151. flag |= IS_TRYC | PARTIAL;
  2152. }
  2153. readonly bool isTry;
  2154. public override void SetJumpTo(ref bool useCallForm, InstructionLine func, int currentDepth, ref string FunctionoNotFoundName)
  2155. {
  2156. GotoLabelLine jumpto = null;
  2157. func.JumpTo = null;
  2158. if (func.Argument.IsConst)
  2159. {
  2160. string labelName = func.Argument.ConstStr;
  2161. if (Config.Config.ICVariable)//eramakerではGOTO文は大文字小文字を区別しない
  2162. labelName = labelName.ToUpper();
  2163. jumpto = GlobalStatic.LabelDictionary.GetLabelDollar(labelName, func.ParentLabelLine);
  2164. if (jumpto == null)
  2165. {
  2166. if (!func.Function.IsTry())
  2167. ParserMediator.Warn("指定されたラベル名\"$" + labelName + "\"は現在の関数内に存在しません", func, 2, true, false);
  2168. else
  2169. return;
  2170. }
  2171. else if (jumpto.IsError)
  2172. ParserMediator.Warn("指定されたラベル名\"$" + labelName + "\"は無効な$ラベル行です", func, 2, true, false);
  2173. else if (jumpto != null)
  2174. {
  2175. func.JumpTo = jumpto;
  2176. }
  2177. }
  2178. }
  2179. public override void DoInstruction(ExpressionMediator exm, InstructionLine func, ProcessState state, bool translate = false)
  2180. {
  2181. string label = null;
  2182. LogicalLine jumpto = null;
  2183. if (func.Argument.IsConst)
  2184. {
  2185. label = func.Argument.ConstStr;
  2186. if (func.JumpTo != null)
  2187. jumpto = func.JumpTo;
  2188. else
  2189. return;
  2190. }
  2191. else
  2192. {
  2193. label = ((SpCallArgment)func.Argument).FuncnameTerm.GetStrValue(exm);
  2194. if (Config.Config.ICVariable)
  2195. label = label.ToUpper();
  2196. jumpto = state.CurrentCalled.CallLabel(GlobalStatic.Process, label);
  2197. }
  2198. if (jumpto == null)
  2199. {
  2200. if (!func.Function.IsTry())
  2201. throw new CodeEE("指定されたラベル名\"$" + label + "\"は現在の関数内に存在しません");
  2202. if (func.JumpToEndCatch != null)
  2203. state.JumpTo(func.JumpToEndCatch);
  2204. return;
  2205. }
  2206. if (jumpto.IsError)
  2207. throw new CodeEE("指定されたラベル名\"$" + label + "\"は無効な$ラベル行です");
  2208. state.JumpTo(jumpto);
  2209. }
  2210. }
  2211. #endregion
  2212. }
  2213. }