Browse Source

Move base definitions from the compiler to the engine

Bepsi 6 years ago
parent
commit
373be72abf

+ 12 - 234
NTERA.Compiler/Compiler.cs

@@ -7,6 +7,7 @@ using System.Text;
 using System.Threading.Tasks;
 using NTERA.Engine;
 using NTERA.Engine.Compiler;
+using NTERA.Engine.Runtime;
 
 namespace NTERA.Compiler
 {
@@ -17,7 +18,7 @@ namespace NTERA.Compiler
 		public List<Tuple<ParserError, string>> Errors { get; } = new List<Tuple<ParserError, string>>();
 		public List<Tuple<ParserError, string>> Warnings { get; } = new List<Tuple<ParserError, string>>();
 
-		public Dictionary<FunctionDefinition, string> DeclaredFunctions = new Dictionary<FunctionDefinition, string>();
+		public Dictionary<FunctionDefinition, string> DeclaredProcedures = new Dictionary<FunctionDefinition, string>();
 
 		public int Threads { get; set; }
 
@@ -27,237 +28,12 @@ namespace NTERA.Compiler
 			Threads = threads;
 		}
 
-		protected static string[] DefaultGlobalNumberVariables =
-		{
-			"LOCAL",
-			"ABL",
-			"RESULT",
-			"SOURCE",
-			"ARG",
-			"GLOBAL",
-			"IS",
-			"CUP",
-			"CDOWN",
-			"UP",
-			"DOWN",
-			"DOWNBASE",
-			"COUNT",
-			"TCVAR",
-			"CDFLAG",
-			"ITEMPRICE",
-			"RANDDATA",
-			"LINECOUNT",
-			"ISTIMEOUT",
-			"__INT_MAX__",
-			"__INT_MIN__",
-			"RAND",
-			"CHARANUM",
-			"TALENT",
-			"FLAG",
-			"TFLAG",
-			"CFLAG",
-			"MASTER",
-			"BASE",
-			"MAXBASE",
-			"PALAM",
-			"TEQUIP",
-			"EQUIP",
-			"DAY",
-			"MARK",
-			"PALAMLV",
-			"TARGET",
-			"PLAYER",
-			"NOWEX",
-			"EX",
-			"STAIN",
-			"EXP",
-			"ASSIPLAY",
-			"ASSI",
-			"ITEM",
-			"EXPLV",
-			"TIME",
-			"MONEY",
-			"SELECTCOM",
-			"PREVCOM",
-			"NEXTCOM",
-			"DITEMTYPE",
-			"NO",
-			"RELATION",
-			"JUEL",
-			"GOTJUEL",
-			"EJAC",
-			"BOUGHT",
-			"ITEMSALES",
-			"FORWARD", //special casing for SORTCHARA
-			"BACK", //special casing for SORTCHARA
-			"LEFT", //special casing for __FORMAT
-			"RIGHT", //special casing for __FORMAT
-			"DEBUG_MODE",
-			"NOITEM",
-		};
-
-		protected static string[] DefaultGlobalStringVariables =
-		{
-			"LOCALS",
-			"ARGS",
-			"RESULTS",
-			"CSTR",
-			"GLOBALS",
-			"NICKNAME",
-			"MASTERNAME",
-			"NAME",
-			"TRAINNAME",
-			"BASENAME",
-			"EQUIPNAME",
-			"TEQUIPNAME",
-			"STAINNAME",
-			"EXNAME",
-			"SOURCENAME",
-			"CALLNAME",
-			"FLAGNAME",
-			"TFLAGNAME",
-			"CFLAGNAME",
-			"TCVARNAME",
-			"STRNAME",
-			"TSTRNAME",
-			"CSTRNAME",
-			"SAVESTRNAME",
-			"CDFLAGNAME",
-			"GLOBALNAME",
-			"GLOBALSNAME",
-			"GAMEBASE_AUTHOR",
-			"GAMEBASE_INFO",
-			"GAMEBASE_YEAR",
-			"GAMEBASE_TITLE",
-			"GAMEBASE_GAMECODE",
-			"GAMEBASE_VERSION",
-			"GAMEBASE_ALLOWVERSION",
-			"GAMEBASE_DEFAULTCHARA",
-			"GAMEBASE_NOITEM",
-			"WINDOW_TITLE",
-			"MONEYLABEL",
-			"DRAWLINESTR",
-			"LASTLOAD_VERSION",
-			"LASTLOAD_NO",
-			"LASTLOAD_TEXT",
-			"SAVEDATA_TEXT",
-			"TSTR",
-			"STR",
-			"SAVESTR",
-			"ABLNAME",
-			"MARKNAME",
-			"TALENTNAME",
-			"ITEMNAME",
-			"PALAMNAME",
-			"EXPNAME",
-		};
-
 		public void Compile(string outputDirectory)
 		{
 			var globals = new VariableDictionary();
 
-			foreach (string stringVariable in DefaultGlobalStringVariables)
-				globals.Add(stringVariable, "");
-
-			foreach (string numberVariable in DefaultGlobalNumberVariables)
-				globals.Add(numberVariable, 0);
-
-			foreach (char c in "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
-				globals[c.ToString()] = "";
-
-			var funcs = new List<FunctionDefinition>
-			{
-				new FunctionDefinition("ABS", new[] { new FunctionParameter("a", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
-				new FunctionDefinition("SQRT", new[] { new FunctionParameter("a", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
-				new FunctionDefinition("SIGN", new[] { new FunctionParameter("a", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
-				new FunctionDefinition("CSVCALLNAME", new[] { new FunctionParameter("a", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
-				new FunctionDefinition("TOFULL", new[] { new FunctionParameter("a", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
-				new FunctionDefinition("TOINT", new[] { new FunctionParameter("a", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
-				new FunctionDefinition("RAND", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("b", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
-				new FunctionDefinition("VARSIZE", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("b", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
-				new FunctionDefinition("TOSTR", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("b", new string[0], "") }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
-				new FunctionDefinition("TOUPPER", new[] { new FunctionParameter("a", new string[0]), }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
-				new FunctionDefinition("TOLOWER", new[] { new FunctionParameter("a", new string[0]), }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
-				new FunctionDefinition("TOHALF", new[] { new FunctionParameter("a", new string[0]), }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
-				new FunctionDefinition("TOFULL", new[] { new FunctionParameter("a", new string[0]), }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
-				new FunctionDefinition("TOUPPER", new[] { new FunctionParameter("a", new string[0]), }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
-				new FunctionDefinition("ISNUMERIC", new[] { new FunctionParameter("a", new string[0]), }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
-				new FunctionDefinition("LOG10", new[] { new FunctionParameter("a", new string[0]), }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
-				new FunctionDefinition("ESCAPE", new[] { new FunctionParameter("a", new string[0]), }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
-				new FunctionDefinition("STRCOUNT", new[] { new FunctionParameter("input", new string[0]), new FunctionParameter("match", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
-				new FunctionDefinition("MIN", new[] { new FunctionParameter("a", new string[0], isArrayParameter: true), }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
-				new FunctionDefinition("MAX", new[] { new FunctionParameter("a", new string[0], isArrayParameter: true), }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
-				new FunctionDefinition("POWER", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("b", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
-				new FunctionDefinition("GETPALAMLV", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("b", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
-				new FunctionDefinition("GETBIT", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("b", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
-				new FunctionDefinition("GETEXPLV", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("b", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
-				new FunctionDefinition("UNICODE", new[] { new FunctionParameter("a", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
-				new FunctionDefinition("MATCH", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("b", new string[0]), new FunctionParameter("c", new string[0], "a"), new FunctionParameter("d", new string[0], "f"), }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
-				new FunctionDefinition("INRANGE", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("b", new string[0]), new FunctionParameter("c", new string[0]), }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
-				new FunctionDefinition("HE_SHE", new[] { new FunctionParameter("a", new string[0]), }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
-				new FunctionDefinition("SUBSTRING", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
-				new FunctionDefinition("STRLENS", new[] { new FunctionParameter("a", new string[0]), }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
-				new FunctionDefinition("CSVNAME", new[] { new FunctionParameter("a", new string[0]), }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
-				new FunctionDefinition("CSVNAME", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
-				new FunctionDefinition("CSVBASE", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
-				new FunctionDefinition("CSVTALENT", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
-				new FunctionDefinition("CSVCFLAG", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
-				new FunctionDefinition("CSVRELATION", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
-				new FunctionDefinition("CSVCSTR", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
-				new FunctionDefinition("CSVEXP", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
-				new FunctionDefinition("CSVABL", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
-				new FunctionDefinition("GETNUM", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
-				new FunctionDefinition("FINDCHARA", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
-				new FunctionDefinition("LIMIT", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
-				new FunctionDefinition("SUMCARRAY", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
-				new FunctionDefinition("MAXCARRAY", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
-				new FunctionDefinition("SUBSTRINGU", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
-				new FunctionDefinition("FINDELEMENT", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]),new FunctionParameter("a", new string[0]),new FunctionParameter("a", new string[0]), }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
-				new FunctionDefinition("GROUPMATCH", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0], isArrayParameter: true), }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
-				new FunctionDefinition("GETTIME", new FunctionParameter[0], new FunctionVariable[0], true, "_GLOBAL", new Marker()),
-				new FunctionDefinition("SAVENOS", new FunctionParameter[0], new FunctionVariable[0], true, "_GLOBAL", new Marker()),
-				new FunctionDefinition("GETCOLOR", new FunctionParameter[0], new FunctionVariable[0], true, "_GLOBAL", new Marker()),
-				new FunctionDefinition("CURRENTREDRAW", new FunctionParameter[0], new FunctionVariable[0], true, "_GLOBAL", new Marker()),
-				new FunctionDefinition("GETFONT", new FunctionParameter[0], new FunctionVariable[0], true, "_GLOBAL", new Marker()),
-				new FunctionDefinition("GETMILLISECOND", new FunctionParameter[0], new FunctionVariable[0], true, "_GLOBAL", new Marker()),
-			};
-
-			var stringStatements = new List<Keyword>
-			{
-				new Keyword("DRAWLINEFORM", true, true),
-				new Keyword("PRINTFORML", true, true),
-				new Keyword("DATAFORM", true, true),
-				new Keyword("PRINTFORMD", true, true),
-				new Keyword("PRINTFORMDL", true, true),
-				new Keyword("PRINTFORMW", true, true),
-				new Keyword("PRINTFORMDW", true, true),
-				new Keyword("PRINTFORMC", true, true),
-				new Keyword("PRINTFORMLC", true, true),
-				new Keyword("PRINTFORM", true, true),
-				new Keyword("PRINTPLAINFORM", true, true),
-				new Keyword("DEBUGPRINTFORM", true, true),
-				new Keyword("DEBUGPRINTFORML", true, true),
-				new Keyword("THROW", true, true),
-
-				new Keyword("PRINT", true),
-				new Keyword("PRINTD", true),
-				new Keyword("PRINTDW", true),
-				new Keyword("PRINTDL", true),
-				new Keyword("PRINTW", true),
-				new Keyword("PRINTV", true),
-				new Keyword("PRINTL", true),
-				new Keyword("PRINTLC", true),
-				new Keyword("PRINTC", true),
-				new Keyword("ALIGNMENT", true),
-				new Keyword("CALL", true, true),
-				new Keyword("CUSTOMDRAWLINE", true),
-				new Keyword("GOTO", true),
-				new Keyword("DEBUGPRINTL", true),
-				new Keyword("REUSELASTLINE", true),
-				new Keyword("PRINTPLAIN", true),
-				new Keyword("PRINT_TRAIN_NAME", true),
-				new Keyword("PRINT_STR", true),
-			};
+			foreach (var variable in BaseDefinitions.DefaultGlobalVariables)
+				globals.Add(variable.Name, variable.CalculatedValue);
 
 			string csvPath = Path.Combine(InputDirectory, "CSV");
 			string erbPath = Path.Combine(InputDirectory, "ERB");
@@ -335,10 +111,12 @@ namespace NTERA.Compiler
 			});
 #endif
 
-			DeclaredFunctions = preprocessedFunctions.ToDictionary(kv => kv.Key, kv => kv.Value);
+			DeclaredProcedures = preprocessedFunctions.ToDictionary(kv => kv.Key, kv => kv.Value);
+
+			var declaredFunctions = BaseDefinitions.DefaultGlobalFunctions.ToList();
+			declaredFunctions.AddRange(DeclaredProcedures.Keys.Where(x => x.IsReturnFunction));
 
-			funcs.AddRange(DeclaredFunctions.Keys.Where(x => x.IsReturnFunction));
-			var procedures = DeclaredFunctions.Keys.Where(x => !x.IsReturnFunction).ToList();
+			var procedures = DeclaredProcedures.Keys.Where(x => !x.IsReturnFunction).ToList();
 
 
 			Console.WriteLine("Compiling functions...");
@@ -346,7 +124,7 @@ namespace NTERA.Compiler
 #if DEBUG
 			foreach (var kv in DeclaredFunctions)
 #else
-			Parallel.ForEach(DeclaredFunctions, new ParallelOptions
+			Parallel.ForEach(DeclaredProcedures, new ParallelOptions
 			{
 				MaxDegreeOfParallelism = Threads
 			}, kv =>
@@ -358,7 +136,7 @@ namespace NTERA.Compiler
 					foreach (var param in kv.Key.Variables)
 						locals[param.Name] = param.CalculatedValue;
 
-					Parser parser = new Parser(kv.Value, kv.Key, funcs, procedures, globals, locals, stringStatements, csvDefinition, preprocessedConstants.ToArray());
+					Parser parser = new Parser(kv.Value, kv.Key, declaredFunctions, procedures, globals, locals, BaseDefinitions.DefaultKeywords, csvDefinition, preprocessedConstants.ToArray());
 
 					var nodes = parser.Parse(out var localErrors, out var localWarnings);
 
@@ -393,7 +171,7 @@ namespace NTERA.Compiler
 			{
 				Errors = Errors.OrderBy(x => x.Item2).ToList(),
 				Warnings = Warnings.OrderBy(x => x.Item2).ToList(),
-				FunctionCount = DeclaredFunctions.Count,
+				FunctionCount = DeclaredProcedures.Count,
 				TotalFileSize = fileSize,
 				TotalFileCount = fileCount
 			};

+ 1 - 1
NTERA.Compiler/Program.cs

@@ -28,7 +28,7 @@ namespace NTERA.Compiler
 			compiler.Compile(outputPath);
 
 			Console.WriteLine();
-			Console.WriteLine($"{compiler.DeclaredFunctions.Count} total functions");
+			Console.WriteLine($"{compiler.DeclaredProcedures.Count} total functions");
 			Console.WriteLine($"{compiler.Errors.Count} errors");
 			Console.WriteLine("Report written");
 		}

+ 1 - 1
NTERA.Engine/Compiler/FunctionDefinition.cs

@@ -18,7 +18,7 @@ namespace NTERA.Engine.Compiler
 
 		public Marker Position { get; }
 
-		public FunctionDefinition(string name, FunctionParameter[] parameters, FunctionVariable[] methodVariables, bool isReturnFunction, string filename, Marker position)
+		public FunctionDefinition(string name, FunctionParameter[] parameters, FunctionVariable[] methodVariables, bool isReturnFunction, string filename, Marker position = default(Marker))
 		{
 			Name = name;
 			Parameters = parameters;

+ 3 - 3
NTERA.Engine/NTERA.Engine.csproj

@@ -51,6 +51,8 @@
     <Compile Include="Compiler\ParserException.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="Compiler\Token.cs" />
+    <Compile Include="Runtime\BaseDefinitions.cs" />
+    <Compile Include="Runtime\EraRuntime.cs" />
     <Compile Include="Utility.cs" />
     <Compile Include="Value.cs" />
     <Compile Include="Variable.cs" />
@@ -62,8 +64,6 @@
       <Name>NTERA.Core</Name>
     </ProjectReference>
   </ItemGroup>
-  <ItemGroup>
-    <Folder Include="Runtime\" />
-  </ItemGroup>
+  <ItemGroup />
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
 </Project>

+ 250 - 0
NTERA.Engine/Runtime/BaseDefinitions.cs

@@ -0,0 +1,250 @@
+using NTERA.Engine.Compiler;
+
+namespace NTERA.Engine.Runtime
+{
+	public static class BaseDefinitions
+	{
+		public static FunctionVariable[] DefaultGlobalVariables { get; } =
+		{
+			new FunctionVariable("LOCAL", ValueType.Real),
+			new FunctionVariable("ABL", ValueType.Real),
+			new FunctionVariable("RESULT", ValueType.Real),
+			new FunctionVariable("SOURCE", ValueType.Real),
+			new FunctionVariable("ARG", ValueType.Real),
+			new FunctionVariable("GLOBAL", ValueType.Real),
+			new FunctionVariable("IS", ValueType.Real),
+			new FunctionVariable("CUP", ValueType.Real),
+			new FunctionVariable("CDOWN", ValueType.Real),
+			new FunctionVariable("UP", ValueType.Real),
+			new FunctionVariable("DOWN", ValueType.Real),
+			new FunctionVariable("DOWNBASE", ValueType.Real),
+			new FunctionVariable("COUNT", ValueType.Real),
+			new FunctionVariable("TCVAR", ValueType.Real),
+			new FunctionVariable("CDFLAG", ValueType.Real),
+			new FunctionVariable("ITEMPRICE", ValueType.Real),
+			new FunctionVariable("RANDDATA", ValueType.Real),
+			new FunctionVariable("LINECOUNT", ValueType.Real),
+			new FunctionVariable("ISTIMEOUT", ValueType.Real),
+			new FunctionVariable("__INT_MAX__", ValueType.Real),
+			new FunctionVariable("__INT_MIN__", ValueType.Real),
+			new FunctionVariable("RAND", ValueType.Real),
+			new FunctionVariable("CHARANUM", ValueType.Real),
+			new FunctionVariable("TALENT", ValueType.Real),
+			new FunctionVariable("FLAG", ValueType.Real),
+			new FunctionVariable("TFLAG", ValueType.Real),
+			new FunctionVariable("CFLAG", ValueType.Real),
+			new FunctionVariable("MASTER", ValueType.Real),
+			new FunctionVariable("BASE", ValueType.Real),
+			new FunctionVariable("MAXBASE", ValueType.Real),
+			new FunctionVariable("PALAM", ValueType.Real),
+			new FunctionVariable("TEQUIP", ValueType.Real),
+			new FunctionVariable("EQUIP", ValueType.Real),
+			new FunctionVariable("DAY", ValueType.Real),
+			new FunctionVariable("MARK", ValueType.Real),
+			new FunctionVariable("PALAMLV", ValueType.Real),
+			new FunctionVariable("TARGET", ValueType.Real),
+			new FunctionVariable("PLAYER", ValueType.Real),
+			new FunctionVariable("NOWEX", ValueType.Real),
+			new FunctionVariable("EX", ValueType.Real),
+			new FunctionVariable("STAIN", ValueType.Real),
+			new FunctionVariable("EXP", ValueType.Real),
+			new FunctionVariable("ASSIPLAY", ValueType.Real),
+			new FunctionVariable("ASSI", ValueType.Real),
+			new FunctionVariable("ITEM", ValueType.Real),
+			new FunctionVariable("EXPLV", ValueType.Real),
+			new FunctionVariable("TIME", ValueType.Real),
+			new FunctionVariable("MONEY", ValueType.Real),
+			new FunctionVariable("SELECTCOM", ValueType.Real),
+			new FunctionVariable("PREVCOM", ValueType.Real),
+			new FunctionVariable("NEXTCOM", ValueType.Real),
+			new FunctionVariable("DITEMTYPE", ValueType.Real),
+			new FunctionVariable("NO", ValueType.Real),
+			new FunctionVariable("RELATION", ValueType.Real),
+			new FunctionVariable("JUEL", ValueType.Real),
+			new FunctionVariable("GOTJUEL", ValueType.Real),
+			new FunctionVariable("EJAC", ValueType.Real),
+			new FunctionVariable("BOUGHT", ValueType.Real),
+			new FunctionVariable("ITEMSALES", ValueType.Real),
+			new FunctionVariable("FORWARD", ValueType.Real), //special casing for SORTCHARA
+			new FunctionVariable("BACK", ValueType.Real), //special casing for SORTCHARA
+			new FunctionVariable("LEFT", ValueType.Real), //special casing for __FORMAT
+			new FunctionVariable("RIGHT", ValueType.Real), //special casing for __FORMAT
+			new FunctionVariable("DEBUG_MODE", ValueType.Real),
+			new FunctionVariable("NOITEM", ValueType.Real),
+
+			new FunctionVariable("A", ValueType.Real),
+			new FunctionVariable("B", ValueType.Real),
+			new FunctionVariable("C", ValueType.Real),
+			new FunctionVariable("D", ValueType.Real),
+			new FunctionVariable("E", ValueType.Real),
+			new FunctionVariable("F", ValueType.Real),
+			new FunctionVariable("G", ValueType.Real),
+			new FunctionVariable("H", ValueType.Real),
+			new FunctionVariable("I", ValueType.Real),
+			new FunctionVariable("J", ValueType.Real),
+			new FunctionVariable("K", ValueType.Real),
+			new FunctionVariable("L", ValueType.Real),
+			new FunctionVariable("M", ValueType.Real),
+			new FunctionVariable("N", ValueType.Real),
+			new FunctionVariable("O", ValueType.Real),
+			new FunctionVariable("P", ValueType.Real),
+			new FunctionVariable("Q", ValueType.Real),
+			new FunctionVariable("R", ValueType.Real),
+			new FunctionVariable("S", ValueType.Real),
+			new FunctionVariable("T", ValueType.Real),
+			new FunctionVariable("U", ValueType.Real),
+			new FunctionVariable("V", ValueType.Real),
+			new FunctionVariable("W", ValueType.Real),
+			new FunctionVariable("X", ValueType.Real),
+			new FunctionVariable("Y", ValueType.Real),
+			new FunctionVariable("Z", ValueType.Real),
+
+			new FunctionVariable("LOCALS", ValueType.String),
+			new FunctionVariable("ARGS", ValueType.String),
+			new FunctionVariable("RESULTS", ValueType.String),
+			new FunctionVariable("CSTR", ValueType.String),
+			new FunctionVariable("GLOBALS", ValueType.String),
+			new FunctionVariable("NICKNAME", ValueType.String),
+			new FunctionVariable("MASTERNAME", ValueType.String),
+			new FunctionVariable("NAME", ValueType.String),
+			new FunctionVariable("TRAINNAME", ValueType.String),
+			new FunctionVariable("BASENAME", ValueType.String),
+			new FunctionVariable("EQUIPNAME", ValueType.String),
+			new FunctionVariable("TEQUIPNAME", ValueType.String),
+			new FunctionVariable("STAINNAME", ValueType.String),
+			new FunctionVariable("EXNAME", ValueType.String),
+			new FunctionVariable("SOURCENAME", ValueType.String),
+			new FunctionVariable("CALLNAME", ValueType.String),
+			new FunctionVariable("FLAGNAME", ValueType.String),
+			new FunctionVariable("TFLAGNAME", ValueType.String),
+			new FunctionVariable("CFLAGNAME", ValueType.String),
+			new FunctionVariable("TCVARNAME", ValueType.String),
+			new FunctionVariable("STRNAME", ValueType.String),
+			new FunctionVariable("TSTRNAME", ValueType.String),
+			new FunctionVariable("CSTRNAME", ValueType.String),
+			new FunctionVariable("SAVESTRNAME", ValueType.String),
+			new FunctionVariable("CDFLAGNAME", ValueType.String),
+			new FunctionVariable("GLOBALNAME", ValueType.String),
+			new FunctionVariable("GLOBALSNAME", ValueType.String),
+			new FunctionVariable("GAMEBASE_AUTHOR", ValueType.String),
+			new FunctionVariable("GAMEBASE_INFO", ValueType.String),
+			new FunctionVariable("GAMEBASE_YEAR", ValueType.String),
+			new FunctionVariable("GAMEBASE_TITLE", ValueType.String),
+			new FunctionVariable("GAMEBASE_GAMECODE", ValueType.String),
+			new FunctionVariable("GAMEBASE_VERSION", ValueType.String),
+			new FunctionVariable("GAMEBASE_ALLOWVERSION", ValueType.String),
+			new FunctionVariable("GAMEBASE_DEFAULTCHARA", ValueType.String),
+			new FunctionVariable("GAMEBASE_NOITEM", ValueType.String),
+			new FunctionVariable("WINDOW_TITLE", ValueType.String),
+			new FunctionVariable("MONEYLABEL", ValueType.String),
+			new FunctionVariable("DRAWLINESTR", ValueType.String),
+			new FunctionVariable("LASTLOAD_VERSION", ValueType.String),
+			new FunctionVariable("LASTLOAD_NO", ValueType.String),
+			new FunctionVariable("LASTLOAD_TEXT", ValueType.String),
+			new FunctionVariable("SAVEDATA_TEXT", ValueType.String),
+			new FunctionVariable("TSTR", ValueType.String),
+			new FunctionVariable("STR", ValueType.String),
+			new FunctionVariable("SAVESTR", ValueType.String),
+			new FunctionVariable("ABLNAME", ValueType.String),
+			new FunctionVariable("MARKNAME", ValueType.String),
+			new FunctionVariable("TALENTNAME", ValueType.String),
+			new FunctionVariable("ITEMNAME", ValueType.String),
+			new FunctionVariable("PALAMNAME", ValueType.String),
+			new FunctionVariable("EXPNAME", ValueType.String)
+		};
+
+		public static FunctionDefinition[] DefaultGlobalFunctions { get; } =
+		{
+			new FunctionDefinition("ABS", new[] { new FunctionParameter("a", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL"),
+			new FunctionDefinition("SQRT", new[] { new FunctionParameter("a", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL"),
+			new FunctionDefinition("SIGN", new[] { new FunctionParameter("a", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL"),
+			new FunctionDefinition("CSVCALLNAME", new[] { new FunctionParameter("a", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL"),
+			new FunctionDefinition("TOFULL", new[] { new FunctionParameter("a", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL"),
+			new FunctionDefinition("TOINT", new[] { new FunctionParameter("a", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL"),
+			new FunctionDefinition("RAND", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("b", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL"),
+			new FunctionDefinition("VARSIZE", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("b", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL"),
+			new FunctionDefinition("TOSTR", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("b", new string[0], "") }, new FunctionVariable[0], true, "_GLOBAL"),
+			new FunctionDefinition("TOUPPER", new[] { new FunctionParameter("a", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL"),
+			new FunctionDefinition("TOLOWER", new[] { new FunctionParameter("a", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL"),
+			new FunctionDefinition("TOHALF", new[] { new FunctionParameter("a", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL"),
+			new FunctionDefinition("TOFULL", new[] { new FunctionParameter("a", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL"),
+			new FunctionDefinition("TOUPPER", new[] { new FunctionParameter("a", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL"),
+			new FunctionDefinition("ISNUMERIC", new[] { new FunctionParameter("a", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL"),
+			new FunctionDefinition("LOG10", new[] { new FunctionParameter("a", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL"),
+			new FunctionDefinition("ESCAPE", new[] { new FunctionParameter("a", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL"),
+			new FunctionDefinition("STRCOUNT", new[] { new FunctionParameter("input", new string[0]), new FunctionParameter("match", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL"),
+			new FunctionDefinition("MIN", new[] { new FunctionParameter("a", new string[0], isArrayParameter: true) }, new FunctionVariable[0], true, "_GLOBAL"),
+			new FunctionDefinition("MAX", new[] { new FunctionParameter("a", new string[0], isArrayParameter: true) }, new FunctionVariable[0], true, "_GLOBAL"),
+			new FunctionDefinition("POWER", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("b", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL"),
+			new FunctionDefinition("GETPALAMLV", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("b", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL"),
+			new FunctionDefinition("GETBIT", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("b", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL"),
+			new FunctionDefinition("GETEXPLV", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("b", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL"),
+			new FunctionDefinition("UNICODE", new[] { new FunctionParameter("a", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL"),
+			new FunctionDefinition("MATCH", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("b", new string[0]), new FunctionParameter("c", new string[0], "a"), new FunctionParameter("d", new string[0], "f") }, new FunctionVariable[0], true, "_GLOBAL"),
+			new FunctionDefinition("INRANGE", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("b", new string[0]), new FunctionParameter("c", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL"),
+			new FunctionDefinition("HE_SHE", new[] { new FunctionParameter("a", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL"),
+			new FunctionDefinition("SUBSTRING", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL"),
+			new FunctionDefinition("STRLENS", new[] { new FunctionParameter("a", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL"),
+			new FunctionDefinition("CSVNAME", new[] { new FunctionParameter("a", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL"),
+			new FunctionDefinition("CSVNAME", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL"),
+			new FunctionDefinition("CSVBASE", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL"),
+			new FunctionDefinition("CSVTALENT", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL"),
+			new FunctionDefinition("CSVCFLAG", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL"),
+			new FunctionDefinition("CSVRELATION", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL"),
+			new FunctionDefinition("CSVCSTR", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL"),
+			new FunctionDefinition("CSVEXP", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL"),
+			new FunctionDefinition("CSVABL", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL"),
+			new FunctionDefinition("GETNUM", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL"),
+			new FunctionDefinition("FINDCHARA", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL"),
+			new FunctionDefinition("LIMIT", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL"),
+			new FunctionDefinition("SUMCARRAY", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL"),
+			new FunctionDefinition("MAXCARRAY", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL"),
+			new FunctionDefinition("SUBSTRINGU", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL"),
+			new FunctionDefinition("FINDELEMENT", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL"),
+			new FunctionDefinition("GROUPMATCH", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0], isArrayParameter: true) }, new FunctionVariable[0], true, "_GLOBAL"),
+			new FunctionDefinition("GETTIME", new FunctionParameter[0], new FunctionVariable[0], true, "_GLOBAL"),
+			new FunctionDefinition("SAVENOS", new FunctionParameter[0], new FunctionVariable[0], true, "_GLOBAL"),
+			new FunctionDefinition("GETCOLOR", new FunctionParameter[0], new FunctionVariable[0], true, "_GLOBAL"),
+			new FunctionDefinition("CURRENTREDRAW", new FunctionParameter[0], new FunctionVariable[0], true, "_GLOBAL"),
+			new FunctionDefinition("GETFONT", new FunctionParameter[0], new FunctionVariable[0], true, "_GLOBAL"),
+			new FunctionDefinition("GETMILLISECOND", new FunctionParameter[0], new FunctionVariable[0], true, "_GLOBAL")
+		};
+
+		public static Keyword[] DefaultKeywords { get; } =
+		{
+			new Keyword("DRAWLINEFORM", true, true),
+			new Keyword("PRINTFORML", true, true),
+			new Keyword("DATAFORM", true, true),
+			new Keyword("PRINTFORMD", true, true),
+			new Keyword("PRINTFORMDL", true, true),
+			new Keyword("PRINTFORMW", true, true),
+			new Keyword("PRINTFORMDW", true, true),
+			new Keyword("PRINTFORMC", true, true),
+			new Keyword("PRINTFORMLC", true, true),
+			new Keyword("PRINTFORM", true, true),
+			new Keyword("PRINTPLAINFORM", true, true),
+			new Keyword("DEBUGPRINTFORM", true, true),
+			new Keyword("DEBUGPRINTFORML", true, true),
+			new Keyword("THROW", true, true),
+
+			new Keyword("PRINT", true),
+			new Keyword("PRINTD", true),
+			new Keyword("PRINTDW", true),
+			new Keyword("PRINTDL", true),
+			new Keyword("PRINTW", true),
+			new Keyword("PRINTV", true),
+			new Keyword("PRINTL", true),
+			new Keyword("PRINTLC", true),
+			new Keyword("PRINTC", true),
+			new Keyword("ALIGNMENT", true),
+			new Keyword("CALL", true, true),
+			new Keyword("CUSTOMDRAWLINE", true),
+			new Keyword("GOTO", true),
+			new Keyword("DEBUGPRINTL", true),
+			new Keyword("REUSELASTLINE", true),
+			new Keyword("PRINTPLAIN", true),
+			new Keyword("PRINT_TRAIN_NAME", true),
+			new Keyword("PRINT_STR", true),
+		};
+	}
+}

+ 12 - 0
NTERA.Engine/Runtime/EraRuntime.cs

@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace NTERA.Engine.Runtime
+{
+	public class EraRuntime
+	{
+	}
+}