From 306cb5f5fd37d12e244f90aa40b6989ec819cc0f Mon Sep 17 00:00:00 2001 From: arookas Date: Sat, 13 Feb 2016 18:32:53 -0500 Subject: [PATCH] Added full data/symbol table information to results I felt this is better than having 5 count properties. --- frontend/main.cs | 11 +++++---- readme.md | 7 ++---- ssc/compiler.cs | 61 ++++++++++++++++++++++++++++++++++++------------ 3 files changed, 54 insertions(+), 25 deletions(-) diff --git a/frontend/main.cs b/frontend/main.cs index f138e52..ba16340 100644 --- a/frontend/main.cs +++ b/frontend/main.cs @@ -1,6 +1,7 @@ using System; using System.Diagnostics; using System.IO; +using System.Linq; using System.Text; namespace arookas @@ -22,11 +23,11 @@ namespace arookas var results = compiler.Compile(inputFile, output); if (results.Success) { Message("Finished compiling in {0:F2}ms.\n", results.CompileTime.TotalMilliseconds); - Message(" Data count: {0}\n", results.DataCount); - Message("Symbol count: {0}\n", results.SymbolCount); - Message(" - builtins: {0}\n", results.BuiltinCount); - Message(" - functions: {0}\n", results.FunctionCount); - Message(" - variables: {0}\n", results.VariableCount); + Message(" Data count: {0}\n", results.Data.Length); + Message("Symbol count: {0}\n", results.Symbols.Length); + Message(" - builtins: {0}\n", results.Symbols.Count(i => i.Type == sunSymbolType.Builtin)); + Message(" - functions: {0}\n", results.Symbols.Count(i => i.Type == sunSymbolType.Function)); + Message(" - variables: {0}\n", results.Symbols.Count(i => i.Type == sunSymbolType.Variable)); } else { if (results.Error is sunSourceException) { diff --git a/readme.md b/readme.md index a5fc975..0cb4f9b 100644 --- a/readme.md +++ b/readme.md @@ -30,11 +30,8 @@ Use the various properties on this type to gather the information of the compila |`Success`|Whether the script was compiled successfully. If not, the `Error` property will be non-`null`.| |`Error`|The fatal error which occured during compilation. If compilation was successful, this will be `null`.| |`CompileTime`|The time it took to compile, measured as a `TimeSpan` instance.| -|`DataCount`|The total number of data-table entries created.| -|`SymbolCount`|The total number of symbols (builtins, functions, and variables) created.| -|`BuiltinCount`|The total number of builtin symbols created.| -|`FunctionCount`|The total number of function symbols created.| -|`VariableCount`|The total number of global-scope variable symbols created.| +|`Data`|An array containing the data-table entries.| +|`Symbols`|An array containing the symbol-table entries.| If the error is of the type `sunSourceException`, you can cast and retrieve the script name, line, and column of the error. diff --git a/ssc/compiler.cs b/ssc/compiler.cs index 2dc9e3d..8ff892d 100644 --- a/ssc/compiler.cs +++ b/ssc/compiler.cs @@ -1,6 +1,7 @@ using System; using System.Diagnostics; using System.IO; +using System.Linq; namespace arookas { public class sunCompiler { @@ -63,11 +64,8 @@ namespace arookas { mBinary.EndSymbol(); mBinary.Close(); - results.DataCount = mContext.DataTable.Count; - results.SymbolCount = mContext.SymbolTable.Count; - results.BuiltinCount = mContext.SymbolTable.GetCount(); - results.FunctionCount = mContext.SymbolTable.GetCount(); - results.VariableCount = mContext.SymbolTable.GetCount(); + results.Data = mContext.DataTable.ToArray(); + results.Symbols = mContext.SymbolTable.Select(i => new sunSymbolInfo(i.Type, i.Name)).ToArray(); } catch (sunCompilerException ex) { results.Error = ex; @@ -168,17 +166,50 @@ namespace arookas { } public class sunCompilerResults { - // success - public bool Success { get { return Error == null; } } - public sunCompilerException Error { get; internal set; } + sunCompilerException mError; + TimeSpan mTime; + string[] mData; + sunSymbolInfo[] mSymbols; - // statistics - public int DataCount { get; internal set; } - public int SymbolCount { get; internal set; } - public int BuiltinCount { get; internal set; } - public int FunctionCount { get; internal set; } - public int VariableCount { get; internal set; } + public bool Success { + get { return mError == null; } + } - public TimeSpan CompileTime { get; internal set; } + public sunCompilerException Error { + get { return mError; } + internal set { mError = value; } + } + public TimeSpan CompileTime { + get { return mTime; } + internal set { mTime = value; } + } + public string[] Data { + get { return mData; } + internal set { mData = value; } + } + public sunSymbolInfo[] Symbols { + get { return mSymbols; } + internal set { mSymbols = value; } + } + } + + public class sunSymbolInfo { + sunSymbolType mType; + string mName; + + public sunSymbolType Type { + get { return mType; } + } + public string Name { + get { return mName; } + } + + internal sunSymbolInfo(sunSymbolType type, string name) { + if (name == null) { + throw new ArgumentNullException("name"); + } + mType = type; + mName = name; + } } }