├── .gitignore ├── License.txt ├── README.md ├── StandaloneTests ├── App.config ├── Program.cs ├── Properties │ └── AssemblyInfo.cs └── StandaloneTests.csproj ├── ZScript.sln ├── ZScript ├── Builders │ ├── ClassTypeBuilder.cs │ └── TypeBuildingContext.cs ├── CodeGeneration │ ├── Analysis │ │ ├── ClassDefinitionExpander.cs │ │ ├── CodeScope.cs │ │ ├── ControlFlowAnalyzer.cs │ │ ├── DefinitionAnalyzer.cs │ │ ├── Definitions │ │ │ ├── FunctionParametersAnalyzer.cs │ │ │ └── UnusedDefinitionsAnalyzer.cs │ │ ├── ExpressionConstantResolver.cs │ │ ├── ExpressionTypeAnalyzer.cs │ │ ├── ExpressionTypeResolver+BinaryExpression.cs │ │ ├── ExpressionTypeResolver.cs │ │ ├── ReturnStatementAnalyzer.cs │ │ └── StaticTypeAnalyzer.cs │ ├── DefinitionGenerator.cs │ ├── Definitions │ │ ├── ClassDefinition.cs │ │ ├── ClosureDefinition.cs │ │ ├── Definition.cs │ │ ├── DefinitionUsage.cs │ │ ├── ExportFunctionDefinition.cs │ │ ├── Expression.cs │ │ ├── FunctionArgumentDefinition.cs │ │ ├── FunctionDefinition.cs │ │ ├── GlobalVariableDefinition.cs │ │ ├── LocalVariableDefinition.cs │ │ ├── MethodDefinition.cs │ │ ├── SequenceDefinition.cs │ │ ├── SequenceFrameDefinition.cs │ │ ├── TopLevelFunctionDefinition.cs │ │ ├── TypeAliasDefinition.cs │ │ ├── TypeAliasMethodDefinition.cs │ │ ├── TypeContainerDefinition.cs │ │ ├── TypeFieldDefinition.cs │ │ └── ValueHolderDefinition.cs │ ├── DefinitionsCollector.cs │ ├── Messages │ │ ├── CodeError.cs │ │ ├── CodeMessage.cs │ │ ├── MessageContainer.cs │ │ ├── SyntaxError.cs │ │ └── Warning.cs │ ├── RuntimeGenerationContext.cs │ ├── Sourcing │ │ ├── SourceProvider.cs │ │ ├── ZScriptDefinitionsSource.cs │ │ ├── ZScriptFileSource.cs │ │ └── ZScriptStringSource.cs │ ├── Tokenization │ │ ├── FunctionBodyTokenizer.cs │ │ ├── Helpers │ │ │ ├── JumpTargetToken.cs │ │ │ ├── JumpToken.cs │ │ │ ├── JumpTokenOptimizer.cs │ │ │ ├── TypedToken.cs │ │ │ ├── TypedTokenExpander.cs │ │ │ ├── VariableToken.cs │ │ │ └── VariableTokenExpander.cs │ │ ├── IntermediaryTokenList.cs │ │ ├── PostfixExpressionTokenizer.cs │ │ └── Statements │ │ │ ├── BreakStatementTokenizer.cs │ │ │ ├── ContinueStatementTokenizer.cs │ │ │ ├── ForStatementTokenizer.cs │ │ │ ├── IfStatementTokenizer.cs │ │ │ ├── ReturnStatementTokenizer.cs │ │ │ ├── StatementTokenizerContext.cs │ │ │ ├── SwitchStatementTokenizer.cs │ │ │ ├── VariableDeclarationStatementTokenizer.cs │ │ │ └── WhileStatementTokenizer.cs │ ├── TypeAliasDefinitionGenerator.cs │ ├── ZRuntimeGenerator.cs │ └── ZScriptSyntaxErrorListener.cs ├── Elements │ ├── Token.cs │ ├── TokenFactory.cs │ ├── TokenList.cs │ ├── ValueHolding │ │ ├── FunctionArgument.cs │ │ ├── GlobalVariable.cs │ │ ├── ValueHolder.cs │ │ └── Variable.cs │ ├── ZClass.cs │ ├── ZClosureFunction.cs │ ├── ZConstructor.cs │ ├── ZExportFunction.cs │ ├── ZFunction.cs │ ├── ZMethod.cs │ └── ZObject.cs ├── Parsing │ ├── ANTLR │ │ ├── ZScript.tokens │ │ ├── ZScriptBaseListener.cs │ │ ├── ZScriptLexer.cs │ │ ├── ZScriptLexer.tokens │ │ ├── ZScriptListener.cs │ │ └── ZScriptParser.cs │ ├── ANTLRExtend │ │ └── ParserExtensions.cs │ ├── ConstantAtomParser.cs │ └── ValueParser.cs ├── Properties │ └── AssemblyInfo.cs ├── Runtime │ ├── Execution │ │ ├── FunctionVM.cs │ │ ├── VirtualMemory │ │ │ ├── IMemory.cs │ │ │ ├── IntegerMemory.cs │ │ │ ├── Memory.cs │ │ │ └── MemoryMapper.cs │ │ ├── VmContext.cs │ │ └── Wrappers │ │ │ ├── Callables │ │ │ ├── ClassMethod.cs │ │ │ └── ZClassMethod.cs │ │ │ ├── ICallableWrapper.cs │ │ │ ├── IMemberWrapper.cs │ │ │ ├── ISubscripterWrapper.cs │ │ │ ├── IValueHolder.cs │ │ │ ├── IndexedSubscripter.cs │ │ │ ├── MemberWrapperHelper.cs │ │ │ ├── Members │ │ │ ├── ClassMember.cs │ │ │ ├── FieldClassMember.cs │ │ │ ├── PropertyClassMember.cs │ │ │ ├── ZClassMember.cs │ │ │ └── ZObjectMember.cs │ │ │ └── Subscripters │ │ │ ├── ListSubscripterWrapper.cs │ │ │ └── PropertySubscripterWrapper.cs │ ├── IRuntimeOwner.cs │ ├── Typing │ │ ├── BinaryExpressionTypeProvider.cs │ │ ├── Elements │ │ │ ├── AnyTypeDef.cs │ │ │ ├── CallableTypeDef.cs │ │ │ ├── DictionaryTypeDef.cs │ │ │ ├── ICallableTypeDef.cs │ │ │ ├── IListTypeDef.cs │ │ │ ├── ListTypeDef.cs │ │ │ ├── NativeTypeDef.cs │ │ │ ├── ObjectTypeDef.cs │ │ │ ├── OptionalTypeDef.cs │ │ │ ├── StringTypeDef.cs │ │ │ └── TypeDef.cs │ │ ├── ICustomTypeSource.cs │ │ ├── ITypeOperator.cs │ │ ├── Operators │ │ │ ├── DoubleOperator.cs │ │ │ ├── IntegerOperator.cs │ │ │ └── LongOperator.cs │ │ ├── TypeOperationProvider.cs │ │ └── TypeProvider.cs │ ├── ZClassInstance.cs │ ├── ZRuntime.cs │ └── ZRuntimeDefinition.cs ├── Utils │ ├── ExpressionUtils.cs │ ├── ListUtils.cs │ └── TokenUtils.cs ├── ZScript.csproj ├── ZScript.g4 ├── ZScript.licenseheader ├── gen │ ├── ZScript.tokens │ ├── ZScriptBaseListener.cs │ ├── ZScriptLexer.cs │ ├── ZScriptLexer.tokens │ ├── ZScriptListener.cs │ └── ZScriptParser.cs └── generate.cmd └── ZScriptTests ├── Builders ├── ClassTypeBuilderTests.cs └── TypeBuildingContextTests.cs ├── CodeGeneration ├── Analysis │ ├── CodeScopeTests.cs │ ├── ControlFlowAnalyzerTests.cs │ ├── DefinitionsAnalyzerTests.cs │ ├── ExpressionConstantResolverTests.cs │ ├── ExpressionTypeResolver+OptionalTests.cs │ ├── ExpressionTypeResolverTests.cs │ ├── FunctionParametersAnalyzerTests.cs │ ├── ReturnStatementAnalyzerTests.cs │ ├── StaticTypeAnalyzerTests.cs │ └── UnusedDefinitionAnalyzerTests.cs ├── Definitions │ └── ClassDefinitionTests.cs ├── DefinitionsCollectorTests.cs ├── MultipleSourcesTests.cs ├── Sourcing │ ├── SourceProviderTests.cs │ └── ZScriptFileSourceTests.cs └── Tokenization │ ├── Helpers │ ├── JumpTokenOptimizerTests.cs │ └── TypedTokenExpanderTests.cs │ ├── IntermediaryTokenListTests.cs │ ├── PostfixExpressionTokenizerTests.cs │ └── StatementTokenizerTests.cs ├── Elements ├── TokenFactoryTests.cs └── ZObjectTests.cs ├── Parsing ├── ConstantAtomParserTests.cs └── ValueParserTests.cs ├── Performance └── PerformanceTests.cs ├── Properties └── AssemblyInfo.cs ├── Runtime ├── ArrayTests.cs ├── ClassTests.cs ├── ClosureTests.cs ├── DictionaryTests.cs ├── Execution │ ├── FunctionVmArrayTests.cs │ ├── FunctionVmCallableTests.cs │ ├── FunctionVmDictionaryTests.cs │ ├── FunctionVmMemberTests.cs │ ├── FunctionVmNewTests.cs │ ├── FunctionVmObjectTests.cs │ ├── FunctionVmSubscriptingTests.cs │ ├── FunctionVmTests.cs │ ├── VirtualMemory │ │ └── MemoryTests.cs │ └── Wrappers │ │ ├── IndexedSubscripterTests.cs │ │ ├── MemberWrapperHelperTests.cs │ │ ├── Members │ │ ├── ClassMemberTests.cs │ │ ├── ZClassMemberTests.cs │ │ └── ZObjectMemberTests.cs │ │ └── Subscripters │ │ ├── ListSubscripterTests.cs │ │ └── PropertySubscripterWrapperTests.cs ├── ExportFunctionTests.cs ├── FunctionAccessTests.cs ├── MemberTests.cs ├── ObjectLiteralTests.cs ├── SubscriptingTests.cs ├── TopLevelFunctionTests.cs ├── Typing │ ├── Operators │ │ ├── DoubleOperatorTests.cs │ │ ├── IntegerOperatorTests.cs │ │ └── LongOperatorTests.cs │ ├── OptionalTypeTests.cs │ └── TypeProviderTests.cs └── ZRuntimeTests.cs ├── Utils ├── TestDefinitionTypeProvider.cs ├── TestRuntimeOwner.cs └── TestUtils.cs ├── ZScript sample.zs ├── ZScript.licenseheader ├── ZScriptTests.cs ├── ZScriptTests.csproj ├── acknowledgements.txt ├── license.txt └── packages.config /README.md: -------------------------------------------------------------------------------- 1 | ![](http://i.imgur.com/YR3ejlH.png) 2 | An (once) game scripting programming language implemented in C#. 3 | 4 | 5 | ## Some considerations, beforehand 6 | 7 | I did this mostly for fun and to learn about implementations of real programming languages, and also to use in my games. It contains a mish-mash of features of other languages that I find cool and useful, like static typing, type inferring and closures. I don't intend on this becoming in the future a "real" game/general scripting language in any way, and this is mostly a personal hobby project. 8 | 9 | I'm also really not proud nor do I know exactly why I re-implemented a (very dysfunctional and incomplete) type system when .NET offers a tested and working one, pretty much for free. Other than that, most of the stuff I did was solely so I could learn about the ins and outs of writing an interpreted language that is run via a VM. Apart from the syntax tree parser library I used for this project (ANTLR v4.5), most of the features I ended up implementing where not really researched prior to execution, so some things are a bit janky when it comes to stability. The language is not completely implemented yet, and a full list of features with implementation and stability information are found in the next sessions of this file. 10 | 11 | 12 | ## About the language 13 | 14 | ZScript is a static (albeit weakly) typed, imperative, object-oriented programming language inspired by other imperative "C-style" languages like .NET C#, Apple's Swift and JavaScript. In ZScript you can define functions, variables, objects and sequences (more about what sequences are later), and have the code executed by calling one of the defined functions through the runtime's `CallFunction(string functionName, object[] arguments)` method in C# code. 15 | 16 | Supposedly, a few snippets of code talk louder than paragraphs of text to programmers, so here are examples of recursive and iterative implementations of fibonacci in ZScript: 17 | 18 | Recursive: 19 | 20 | ```csharp 21 | func fib(n:int) : int 22 | { 23 | if(n <= 0) 24 | return 0; 25 | if(n == 1) 26 | return 1; 27 | 28 | return fib(n - 1) + fib(n - 2); 29 | } 30 | ``` 31 | 32 | And iterative, showing local variables and ```for``` loops: 33 | 34 | ```csharp 35 | func fib(n:int) : int 36 | { 37 | if(n == 0) return 0; 38 | if(n == 1) return 1; 39 | 40 | var prevPrev = 0; 41 | var prev = 1; 42 | var result = 0; 43 | 44 | for (var i = 2; i <= n; i++) 45 | { 46 | result = prev + prevPrev; 47 | prevPrev = prev; 48 | prev = result; 49 | } 50 | 51 | return result; 52 | } 53 | ``` 54 | 55 | These short examples showcase a few of the features of the language: 56 | 57 | * Functions 58 | Statements to be executed in ZScript must be contained within functions that can be called either by other functions in the code, or directly by calling the ZRuntime.CallFunction() at C# code level. 59 | 60 | * Type inferring 61 | Variables and constants in ZScript are typed, and a type must be provided at time of creation of the value holders, but if the type is omitted, it is inferred from the value it was assigned at time of creation: `prevPrev`, `prev`, `result` and `i` have their value inferred as integer because that's the value that was provided when they where created. 62 | 63 | ##### About the VM 64 | 65 | The VM (FunctionVM) is a stack-based virtual machine that utilizes special token stream constructs as instructions to execute. The function VM itself has no memory access, requiring an external object (VmContext) that provides access for memory and the runtime to call functions on. 66 | 67 | ## Licensing 68 | 69 | The project is licensed under LGPL 2.1. The license can be found in the [License.txt](https://github.com/LuizZak/ZScript/blob/master/License.txt) file in the root of the repository tree. 70 | 71 | ## More Information 72 | 73 | For more information about the language, please visit the [project's wiki](https://github.com/LuizZak/ZScript/wiki) which contains an assortment of documentation related to the language. 74 | -------------------------------------------------------------------------------- /StandaloneTests/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /StandaloneTests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("StandaloneTests")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("StandaloneTests")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("028d138b-6716-4c09-8ad7-da7e0e327c84")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /StandaloneTests/StandaloneTests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {7F56D173-FC01-4BF2-B0B7-18557AF27182} 8 | Exe 9 | Properties 10 | StandaloneTests 11 | StandaloneTests 12 | v4.5 13 | 512 14 | 15 | 16 | AnyCPU 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | true 25 | true 26 | 27 | 28 | AnyCPU 29 | pdbonly 30 | true 31 | bin\Release\ 32 | TRACE 33 | prompt 34 | 4 35 | true 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | {95358b27-d30c-437f-a0a4-4782d46e2520} 57 | ZScriptTests 58 | 59 | 60 | {5130543b-1447-48f2-96a5-c3fa0a018800} 61 | ZScript 62 | 63 | 64 | 65 | 72 | -------------------------------------------------------------------------------- /ZScript.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.31101.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZScript", "ZScript\ZScript.csproj", "{5130543B-1447-48F2-96A5-C3FA0A018800}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZScriptTests", "ZScriptTests\ZScriptTests.csproj", "{95358B27-D30C-437F-A0A4-4782D46E2520}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StandaloneTests", "StandaloneTests\StandaloneTests.csproj", "{7F56D173-FC01-4BF2-B0B7-18557AF27182}" 11 | EndProject 12 | Global 13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 14 | Debug|Any CPU = Debug|Any CPU 15 | Release|Any CPU = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {5130543B-1447-48F2-96A5-C3FA0A018800}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {5130543B-1447-48F2-96A5-C3FA0A018800}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {5130543B-1447-48F2-96A5-C3FA0A018800}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {5130543B-1447-48F2-96A5-C3FA0A018800}.Release|Any CPU.Build.0 = Release|Any CPU 22 | {95358B27-D30C-437F-A0A4-4782D46E2520}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 23 | {95358B27-D30C-437F-A0A4-4782D46E2520}.Debug|Any CPU.Build.0 = Debug|Any CPU 24 | {95358B27-D30C-437F-A0A4-4782D46E2520}.Release|Any CPU.ActiveCfg = Release|Any CPU 25 | {95358B27-D30C-437F-A0A4-4782D46E2520}.Release|Any CPU.Build.0 = Release|Any CPU 26 | {7F56D173-FC01-4BF2-B0B7-18557AF27182}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {7F56D173-FC01-4BF2-B0B7-18557AF27182}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {7F56D173-FC01-4BF2-B0B7-18557AF27182}.Release|Any CPU.ActiveCfg = Release|Any CPU 29 | {7F56D173-FC01-4BF2-B0B7-18557AF27182}.Release|Any CPU.Build.0 = Release|Any CPU 30 | EndGlobalSection 31 | GlobalSection(SolutionProperties) = preSolution 32 | HideSolutionNode = FALSE 33 | EndGlobalSection 34 | EndGlobal 35 | -------------------------------------------------------------------------------- /ZScript/Builders/TypeBuildingContext.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | using System; 22 | using System.Reflection; 23 | using System.Reflection.Emit; 24 | 25 | namespace ZScript.Builders 26 | { 27 | /// 28 | /// Specifies context for dynamic building of types during compilation 29 | /// 30 | public class TypeBuildingContext 31 | { 32 | /// 33 | /// The name of the assembly to build on 34 | /// 35 | public AssemblyName AssemblyName { get; private set; } 36 | 37 | /// 38 | /// The the assembly builder to build on 39 | /// 40 | public AssemblyBuilder AssemblyBuilder { get; private set; } 41 | 42 | /// 43 | /// The module builder to build on 44 | /// 45 | public ModuleBuilder ModuleBuilder { get; private set; } 46 | 47 | /// 48 | /// Private constructor 49 | /// 50 | private TypeBuildingContext() 51 | { 52 | 53 | } 54 | 55 | /// 56 | /// Resets the assembly context of this type building context 57 | /// 58 | public void ResetContext() 59 | { 60 | AssemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess.RunAndSave); 61 | ModuleBuilder = AssemblyBuilder.DefineDynamicModule(AssemblyName.Name, AssemblyName.Name + ".dll"); 62 | } 63 | 64 | /// 65 | /// Creates a new type builder context with a given assembly name 66 | /// 67 | /// The name of the assembly to generate 68 | /// A new TypeBuildingContext to use on type builders 69 | public static TypeBuildingContext CreateBuilderContext(string name) 70 | { 71 | var context = new TypeBuildingContext 72 | { 73 | AssemblyName = new AssemblyName(name) 74 | }; 75 | 76 | context.ResetContext(); 77 | 78 | return context; 79 | } 80 | } 81 | } -------------------------------------------------------------------------------- /ZScript/CodeGeneration/Analysis/Definitions/FunctionParametersAnalyzer.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | using ZScript.CodeGeneration.Definitions; 22 | using ZScript.CodeGeneration.Messages; 23 | 24 | namespace ZScript.CodeGeneration.Analysis.Definitions 25 | { 26 | /// 27 | /// Provides functionalities for checking the validity of function parameters 28 | /// 29 | public class FunctionParametersAnalyzer 30 | { 31 | /// 32 | /// The context for this analysis 33 | /// 34 | private readonly RuntimeGenerationContext _context; 35 | 36 | /// 37 | /// Initializes a new instance of the FunctionParametersAnalyzer class 38 | /// 39 | /// The context for the analysis 40 | public FunctionParametersAnalyzer(RuntimeGenerationContext context) 41 | { 42 | _context = context; 43 | } 44 | 45 | /// 46 | /// Analysis the definitions sotred on a given context 47 | /// 48 | public void Analyze() 49 | { 50 | var definitions = _context.BaseScope.GetDefinitionsByTypeRecursive(); 51 | 52 | // Analyze each function parameter individually 53 | foreach (var functionDefinition in definitions) 54 | { 55 | AnalyzeFunction(functionDefinition); 56 | } 57 | } 58 | 59 | /// 60 | /// Analyzes a given function's parameters 61 | /// 62 | /// The function definition to analyze 63 | public void AnalyzeFunction(FunctionDefinition func) 64 | { 65 | bool endRequiredList = false; 66 | for (int i = 0; i < func.Parameters.Length; i++) 67 | { 68 | // Check for non-last parameter variadic arguments 69 | if (i < func.Parameters.Length - 1) 70 | { 71 | if (func.Parameters[i].IsVariadic) 72 | { 73 | _context.MessageContainer.RegisterError(func.Parameters[i].Context, "Functions can contain only one variadic parameter that must be defined as the last paramter", ErrorCode.InvalidParameters); 74 | } 75 | } 76 | 77 | // Check for required/optional parameter order 78 | if (func.Parameters[i].HasValue && !endRequiredList) 79 | { 80 | endRequiredList = true; 81 | continue; 82 | } 83 | 84 | if (!endRequiredList) 85 | continue; 86 | 87 | if (!func.Parameters[i].HasValue && !func.Parameters[i].IsVariadic) 88 | { 89 | _context.MessageContainer.RegisterError(func.Parameters[i].Context, "All required parameters must appear before the first required optional parameter", ErrorCode.InvalidParameters); 90 | } 91 | } 92 | } 93 | } 94 | } -------------------------------------------------------------------------------- /ZScript/CodeGeneration/Analysis/ExpressionTypeAnalyzer.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | namespace ZScript.CodeGeneration.Analysis 22 | { 23 | /// 24 | /// Provides facilities for analyzing the validity of expression types 25 | /// 26 | public class ExpressionTypeAnalyzer 27 | { 28 | 29 | } 30 | } -------------------------------------------------------------------------------- /ZScript/CodeGeneration/Definitions/ClosureDefinition.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | namespace ZScript.CodeGeneration.Definitions 22 | { 23 | /// 24 | /// Specifies a closure definition 25 | /// 26 | public class ClosureDefinition : FunctionDefinition 27 | { 28 | /// 29 | /// The prefix used in closure names, used during operations that replace closure expressions with closure accesses 30 | /// 31 | public static readonly string ClosureNamePrefix = "$__closure"; 32 | 33 | /// 34 | /// Initializes a new instance of the ClosureDefinition class 35 | /// 36 | /// The name for this closure 37 | /// The body context containing the closure's statements 38 | /// The list of arguments for the closure 39 | public ClosureDefinition(string name, ZScriptParser.FunctionBodyContext bodyContext, FunctionArgumentDefinition[] parameters) 40 | : base(name, bodyContext, parameters) 41 | { 42 | 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /ZScript/CodeGeneration/Definitions/Definition.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | 22 | using Antlr4.Runtime; 23 | 24 | namespace ZScript.CodeGeneration.Definitions 25 | { 26 | /// 27 | /// Specifies a common definition 28 | /// 29 | public class Definition 30 | { 31 | /// 32 | /// Gets or sets the name for this definition 33 | /// 34 | public string Name { get; set; } 35 | 36 | /// 37 | /// Gets or sets the context for the definition 38 | /// 39 | public ParserRuleContext Context { get; set; } 40 | 41 | /// 42 | /// Gets or sets the parse rule context that specifies the identifier name for the definition 43 | /// 44 | public ParserRuleContext IdentifierContext { get; set; } 45 | } 46 | } -------------------------------------------------------------------------------- /ZScript/CodeGeneration/Definitions/DefinitionUsage.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | 22 | using Antlr4.Runtime; 23 | 24 | namespace ZScript.CodeGeneration.Definitions 25 | { 26 | /// 27 | /// Declares the usage context of a definition 28 | /// 29 | public class DefinitionUsage 30 | { 31 | /// 32 | /// The definition that was used 33 | /// 34 | private readonly Definition _definition; 35 | 36 | /// 37 | /// The parser rule context that represents the definition's usage 38 | /// 39 | private readonly ParserRuleContext _context; 40 | 41 | /// 42 | /// Gets the definition that was used 43 | /// 44 | public Definition Definition 45 | { 46 | get { return _definition; } 47 | } 48 | 49 | /// 50 | /// Gets the parser rule context that represents the definition's usage 51 | /// 52 | public ParserRuleContext Context 53 | { 54 | get { return _context; } 55 | } 56 | 57 | /// 58 | /// Initializes a new instance of the DefinitionUsage class 59 | /// 60 | /// The definition that was used 61 | /// The context in which the definition was used 62 | public DefinitionUsage(Definition definition, ParserRuleContext context) 63 | { 64 | _definition = definition; 65 | _context = context; 66 | } 67 | } 68 | } -------------------------------------------------------------------------------- /ZScript/CodeGeneration/Definitions/ExportFunctionDefinition.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | namespace ZScript.CodeGeneration.Definitions 22 | { 23 | /// 24 | /// Specifies a function definition 25 | /// 26 | public class ExportFunctionDefinition : FunctionDefinition 27 | { 28 | /// 29 | /// Initializes a new instance of the ExportFunctionDefinition class 30 | /// 31 | /// The name for the definition 32 | /// The list of arguments for the definition 33 | public ExportFunctionDefinition(string name, FunctionArgumentDefinition[] parameters) 34 | : base(name, null, parameters) 35 | { 36 | 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /ZScript/CodeGeneration/Definitions/Expression.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | namespace ZScript.CodeGeneration.Definitions 22 | { 23 | /// 24 | /// Specifies an expression composed from an expression context read from a script parser 25 | /// 26 | public class Expression 27 | { 28 | /// 29 | /// The expression context for this expression 30 | /// 31 | private readonly ZScriptParser.ExpressionContext _expressionContext; 32 | 33 | /// 34 | /// Gets the expression context for this expression 35 | /// 36 | public ZScriptParser.ExpressionContext ExpressionContext 37 | { 38 | get { return _expressionContext; } 39 | } 40 | 41 | /// 42 | /// Initializes a new instance of the Expression class 43 | /// 44 | /// An expression context read from a script parser 45 | public Expression(ZScriptParser.ExpressionContext expressionContext) 46 | { 47 | _expressionContext = expressionContext; 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /ZScript/CodeGeneration/Definitions/FunctionArgumentDefinition.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | 22 | using System.Text; 23 | using ZScript.Runtime.Typing.Elements; 24 | 25 | namespace ZScript.CodeGeneration.Definitions 26 | { 27 | /// 28 | /// Specifies a variable definition 29 | /// 30 | public class FunctionArgumentDefinition : ValueHolderDefinition 31 | { 32 | /// 33 | /// Gets or sets a value specifying whether the function argument represented by this definition is variadic in nature. 34 | /// Variadic arguments allow for the caller to specify as many values as desired, separated by commas like normal arguments. 35 | /// Functions can only have one variadic argument, appearing at the end of the argument list 36 | /// 37 | public bool IsVariadic { get; set; } 38 | 39 | /// 40 | /// The compile-time constant defining the value for the function argument 41 | /// 42 | public ZScriptParser.CompileConstantContext DefaultValue { get; set; } 43 | 44 | /// 45 | /// Gets a value specifying whether this function argument is optional and can be omitted when calling the function 46 | /// 47 | public bool IsOptional 48 | { 49 | get { return IsVariadic || HasValue; } 50 | } 51 | 52 | /// 53 | /// Creates an argument information based on the information of this function argument 54 | /// 55 | /// A callble argument information generated from this function argument 56 | public CallableTypeDef.CallableParameterInfo ToArgumentInfo() 57 | { 58 | return new CallableTypeDef.CallableParameterInfo(Type, HasType, HasValue, IsVariadic); 59 | } 60 | 61 | /// 62 | /// Returns a string representation of this function argument 63 | /// 64 | /// A string representation of this function argument 65 | public override string ToString() 66 | { 67 | var builder = new StringBuilder(); 68 | 69 | builder.Append(Name); 70 | 71 | // Type 72 | builder.Append(": "); 73 | if (IsVariadic && Type is IListTypeDef) 74 | { 75 | builder.Append(((IListTypeDef)Type).EnclosingType); 76 | builder.Append("..."); 77 | } 78 | else 79 | { 80 | builder.Append(Type); 81 | } 82 | 83 | // Return type 84 | if (HasValue) 85 | { 86 | builder.Append(" = "); 87 | builder.Append(DefaultValue); 88 | } 89 | 90 | return builder.ToString(); 91 | } 92 | } 93 | } -------------------------------------------------------------------------------- /ZScript/CodeGeneration/Definitions/GlobalVariableDefinition.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | namespace ZScript.CodeGeneration.Definitions 22 | { 23 | /// 24 | /// Specifies a globally-scoped variable variable 25 | /// 26 | public class GlobalVariableDefinition : ValueHolderDefinition 27 | { 28 | 29 | } 30 | } -------------------------------------------------------------------------------- /ZScript/CodeGeneration/Definitions/LocalVariableDefinition.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | namespace ZScript.CodeGeneration.Definitions 22 | { 23 | /// 24 | /// Represents a local variable in a function context 25 | /// 26 | public class LocalVariableDefinition : ValueHolderDefinition 27 | { 28 | 29 | } 30 | } -------------------------------------------------------------------------------- /ZScript/CodeGeneration/Definitions/MethodDefinition.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | namespace ZScript.CodeGeneration.Definitions 22 | { 23 | /// 24 | /// Specifies a method definition from a class 25 | /// 26 | public class MethodDefinition : FunctionDefinition 27 | { 28 | /// 29 | /// Whether this is an override of a method defined in a base class 30 | /// 31 | public bool IsOverride { get; set; } 32 | 33 | /// 34 | /// Gets or sets the clas this method was defined in 35 | /// 36 | public ClassDefinition Class { get; set; } 37 | 38 | /// 39 | /// Gets or sets the method this method definition is overriding 40 | /// 41 | public MethodDefinition BaseMethod { get; set; } 42 | 43 | /// 44 | /// Initializes a new instance of the MethodDefinition class 45 | /// 46 | /// The name of the method to create 47 | /// The context containing the body of the method 48 | /// The parameters for the method 49 | public MethodDefinition(string name, ZScriptParser.FunctionBodyContext bodyContext, FunctionArgumentDefinition[] parameters) 50 | : base(name, bodyContext, parameters) 51 | { 52 | 53 | } 54 | } 55 | } -------------------------------------------------------------------------------- /ZScript/CodeGeneration/Definitions/SequenceDefinition.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | using System.Collections.Generic; 22 | 23 | namespace ZScript.CodeGeneration.Definitions 24 | { 25 | /// 26 | /// Specifies a sequence definition 27 | /// 28 | public class SequenceDefinition : TypeContainerDefinition 29 | { 30 | /// 31 | /// The list of frame definitions for this sequence definition 32 | /// 33 | private readonly List _frameDefinitions; 34 | 35 | /// 36 | /// Gets or sets the context containing the sequence definition 37 | /// 38 | public ZScriptParser.SequenceBlockContext SequenceContext { get; set; } 39 | 40 | /// 41 | /// Get an array of frame definitions for this sequence definition 42 | /// 43 | public SequenceFrameDefinition[] FrameDefinitions { get { return _frameDefinitions.ToArray(); } } 44 | 45 | /// 46 | /// Gets all the fields defined in this sequence definition 47 | /// 48 | public override TypeFieldDefinition[] Fields 49 | { 50 | get { return fields.ToArray(); } 51 | } 52 | 53 | /// 54 | /// Initializes a new instance of the SequenceDefinition class 55 | /// 56 | /// The name to define the sequence with 57 | public SequenceDefinition(string sequenceName) 58 | { 59 | Name = sequenceName; 60 | fields = new List(); 61 | 62 | _frameDefinitions = new List(); 63 | } 64 | 65 | /// 66 | /// Adds a field to this sequence definition 67 | /// 68 | /// The field to add to this definition 69 | public override void AddField(TypeFieldDefinition field) 70 | { 71 | fields.Add(field); 72 | } 73 | 74 | /// 75 | /// Adds a frame to this sequence definition 76 | /// 77 | /// The frame to add to this definition 78 | public void AddFrame(SequenceFrameDefinition frame) 79 | { 80 | _frameDefinitions.Add(frame); 81 | } 82 | 83 | /// 84 | /// Gets all the fields visible in this sequence definition, optionally fetching only the inherited fields 85 | /// 86 | /// The attributes to use when searching the members to fetch 87 | /// A list of all fields visible in this sequence definition 88 | public override List GetAllFields(TypeMemberAttribute attributes = TypeMemberAttribute.CompleteInheritance) 89 | { 90 | return fields; 91 | } 92 | } 93 | } -------------------------------------------------------------------------------- /ZScript/CodeGeneration/Definitions/TopLevelFunctionDefinition.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | namespace ZScript.CodeGeneration.Definitions 22 | { 23 | /// 24 | /// Specifies a top-level function definition 25 | /// 26 | public class TopLevelFunctionDefinition : FunctionDefinition 27 | { 28 | /// 29 | /// Initializes a new instance of the TopLevelFunctionDefinition class 30 | /// 31 | /// The name for the definition 32 | /// The context containing the function body's statements 33 | /// The arguments for this function definition 34 | public TopLevelFunctionDefinition(string name, ZScriptParser.FunctionBodyContext bodyContext, FunctionArgumentDefinition[] parameters) : base(name, bodyContext, parameters) 35 | { 36 | 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /ZScript/CodeGeneration/Definitions/TypeAliasMethodDefinition.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | namespace ZScript.CodeGeneration.Definitions 22 | { 23 | /// 24 | /// Represents a method defined in a type alias definition 25 | /// 26 | public class TypeAliasMethodDefinition : FunctionDefinition 27 | { 28 | /// 29 | /// Initialzes a new instance of the TypeMethodDefinition class 30 | /// 31 | /// The name for the method 32 | /// The parameters for the method 33 | public TypeAliasMethodDefinition(string name, FunctionArgumentDefinition[] parameters) 34 | : base(name, null, parameters) 35 | { 36 | 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /ZScript/CodeGeneration/Definitions/TypeContainerDefinition.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | 22 | using System; 23 | using System.Collections.Generic; 24 | 25 | namespace ZScript.CodeGeneration.Definitions 26 | { 27 | /// 28 | /// Specifies a definition that can hold variables and methods inside 29 | /// 30 | public abstract class TypeContainerDefinition : Definition 31 | { 32 | /// 33 | /// Internal list of fields for this class definition 34 | /// 35 | protected List fields; 36 | 37 | /// 38 | /// Gets the list of fields colelcted in this class definition 39 | /// 40 | public abstract TypeFieldDefinition[] Fields { get; } 41 | 42 | /// 43 | /// Adds a new field definition to this class 44 | /// 45 | /// The field to add to this class 46 | public abstract void AddField(TypeFieldDefinition field); 47 | 48 | /// 49 | /// Returns a list of all the fields inherited and defined by this class definition 50 | /// 51 | /// The attributes to use when searching the members to fetch 52 | /// A list of all the fields inherited and defined by this given class definition 53 | public abstract List GetAllFields(TypeMemberAttribute attributes = TypeMemberAttribute.CompleteInheritance); 54 | } 55 | 56 | /// 57 | /// Specifies attributes to use when searching members on a type container 58 | /// 59 | [Flags] 60 | public enum TypeMemberAttribute 61 | { 62 | /// Gets members defined in the current type 63 | Defined = 0x1 << 0, 64 | /// Gets members inherited in the current type 65 | Inherited = 0x1 << 1, 66 | /// Gets all members from the complete inheritance chain 67 | CompleteInheritance = 0x1 | (0x1 << 1) 68 | } 69 | } -------------------------------------------------------------------------------- /ZScript/CodeGeneration/Definitions/TypeFieldDefinition.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | namespace ZScript.CodeGeneration.Definitions 22 | { 23 | /// 24 | /// Specifies a type field definition 25 | /// 26 | public class TypeFieldDefinition : ValueHolderDefinition 27 | { 28 | /// 29 | /// Initializes a new instance of the ClassFieldDefinition class 30 | /// 31 | /// The name of the field for this class field 32 | public TypeFieldDefinition(string fieldName) 33 | { 34 | Name = fieldName; 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /ZScript/CodeGeneration/Definitions/ValueHolderDefinition.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | 22 | using System.Text; 23 | using ZScript.Runtime.Typing.Elements; 24 | 25 | namespace ZScript.CodeGeneration.Definitions 26 | { 27 | /// 28 | /// Specifies a value holder definition 29 | /// 30 | public abstract class ValueHolderDefinition : Definition 31 | { 32 | /// 33 | /// Gets or sets a value that represents the expression containing the value for this variable definition 34 | /// 35 | public Expression ValueExpression { get; set; } 36 | 37 | /// 38 | /// Gets or sets a value specifying whether this variable has a expression specifying its value 39 | /// 40 | public bool HasValue { get; set; } 41 | 42 | /// 43 | /// Gets or sets a value specifying whether this value holder definition has a type associated with it. 44 | /// If the value is false, the value holder has a type infered from the value expression 45 | /// 46 | public bool HasType { get; set; } 47 | 48 | /// 49 | /// Gets or sets the type associated with this value holder definition 50 | /// 51 | public TypeDef Type { get; set; } 52 | 53 | /// 54 | /// Gets or sets a value specifying whether the type of this value holder was inferred from context, or its expression 55 | /// 56 | public bool HasInferredType { get; set; } 57 | 58 | /// 59 | /// Gets or sets the context for the type of this value holder definition 60 | /// 61 | public ZScriptParser.TypeContext TypeContext { get; set; } 62 | 63 | /// 64 | /// Whether this value holder is constant 65 | /// 66 | public bool IsConstant { get; set; } 67 | 68 | /// 69 | /// Whether this value holder is an instance value 70 | /// 71 | public bool IsInstanceValue; 72 | 73 | /// 74 | /// Returns a string representation of this ValueHolderDefinition 75 | /// 76 | /// A string representation of this ValueHolderDefinition 77 | public override string ToString() 78 | { 79 | var builder = new StringBuilder(); 80 | 81 | builder.Append(IsConstant ? "let " : "var "); 82 | builder.Append(Name); 83 | 84 | if(Type != null) 85 | { 86 | builder.Append(":"); 87 | builder.Append(Type); 88 | } 89 | 90 | return builder.ToString(); 91 | } 92 | } 93 | } -------------------------------------------------------------------------------- /ZScript/CodeGeneration/Messages/SyntaxError.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | 22 | using Antlr4.Runtime; 23 | 24 | namespace ZScript.CodeGeneration.Messages 25 | { 26 | /// 27 | /// Represents an structure that encapsulates syntax errors that were reported during the parsing of the script 28 | /// 29 | public class SyntaxError : CodeMessage 30 | { 31 | /// 32 | /// Initializes a new instance of the SyntaxError class 33 | /// 34 | /// The token in which the syntax error occurred 35 | /// The line the error occurred at 36 | /// The offset in the line the error occurred at 37 | /// The message for the error 38 | public SyntaxError(IToken token, int line, int column, string message) 39 | { 40 | Token = token; 41 | Column = column; 42 | Line = line; 43 | Message = message; 44 | } 45 | 46 | /// 47 | /// Transforms this code message into a string 48 | /// 49 | /// The string representation of this code message 50 | public override string ToString() 51 | { 52 | if (string.IsNullOrWhiteSpace(ContextName)) 53 | { 54 | return "Sytax error at line " + Line + " position " + Column + ": " + Message; 55 | } 56 | 57 | return "Syntax error at " + ContextName + " at line " + Line + " position " + Column + ": " + Message; 58 | } 59 | } 60 | } -------------------------------------------------------------------------------- /ZScript/CodeGeneration/Messages/Warning.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | namespace ZScript.CodeGeneration.Messages 22 | { 23 | /// 24 | /// Represents a warning that was generated during the generation of the code 25 | /// 26 | public class Warning : CodeMessage 27 | { 28 | /// 29 | /// Gets or sets the warning code for this warning 30 | /// 31 | public WarningCode WarningCode { get; set; } 32 | 33 | /// 34 | /// Initializes a new instance of the Warning class 35 | /// 36 | /// The line the error occurred at 37 | /// The offset in the line the error occurred at 38 | /// The message for the error 39 | /// The code for the warning 40 | public Warning(int line, int column, string message, WarningCode warningCode) 41 | { 42 | Column = column; 43 | Line = line; 44 | Message = message; 45 | WarningCode = warningCode; 46 | } 47 | 48 | /// 49 | /// Transforms this code message into a string 50 | /// 51 | /// The string representation of this code message 52 | public override string ToString() 53 | { 54 | if (string.IsNullOrWhiteSpace(ContextName)) 55 | { 56 | return "Warning at line " + Line + " position " + Column + ": " + Message; 57 | } 58 | 59 | return "Warning at " + ContextName + " at line " + Line + " position " + Column + ": " + Message; 60 | } 61 | } 62 | 63 | /// 64 | /// Specifies the code for a warning 65 | /// 66 | public enum WarningCode 67 | { 68 | /// An undefined warning 69 | Undefined, 70 | /// A definition is created, but never user 71 | UnusedDefinition, 72 | /// A definition is created, but its value is only set and never get 73 | DefinitionOnlySet, 74 | 75 | /// Specifies a warning issued when a condition for an if statement resolves to a constant 76 | ConstantIfCondition, 77 | 78 | /// Specifies a warning issued when an expression for a switch statement resolves to a constant value that matches a constant defined in a case label 79 | ConstantSwitchExpression, 80 | 81 | /// Wraning raised whenever a redundant base() call is placed inside an inherited constructor 82 | RedundantBaseCall, 83 | 84 | /// Warning raised when the expression on the left side of a null-coalesce is a non-optional value 85 | NonOptionalNullCoalesceLeftSize, 86 | } 87 | } -------------------------------------------------------------------------------- /ZScript/CodeGeneration/Sourcing/ZScriptDefinitionsSource.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | namespace ZScript.CodeGeneration.Sourcing 22 | { 23 | /// 24 | /// Abstract class that can be used as a source of ZScript definitions 25 | /// 26 | public abstract class ZScriptDefinitionsSource 27 | { 28 | /// 29 | /// Gets or sets the definitions contained within this ZScript source 30 | /// 31 | public DefinitionsCollector Definitions { get; set; } 32 | 33 | /// 34 | /// Gets or sets a pre-parsed context for the contents of this file 35 | /// 36 | public ZScriptParser.ProgramContext Tree { get; set; } 37 | 38 | /// 39 | /// Gets or sets a value whether this script source has changed since the last definition collection and requires a re-parsing 40 | /// 41 | public virtual bool ParseRequired { get; set; } 42 | 43 | /// 44 | /// Gets the string containing the script source to parse 45 | /// 46 | /// The string containing the script source to parse 47 | public abstract string GetScriptSourceString(); 48 | } 49 | } -------------------------------------------------------------------------------- /ZScript/CodeGeneration/Sourcing/ZScriptStringSource.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | 22 | namespace ZScript.CodeGeneration.Sourcing 23 | { 24 | /// 25 | /// Represents a ZScript source that comes from a provided string 26 | /// 27 | public sealed class ZScriptStringSource : ZScriptDefinitionsSource 28 | { 29 | /// 30 | /// The script string 31 | /// 32 | private string _script; 33 | 34 | /// 35 | /// Gets or sets the script string 36 | /// 37 | public string Script 38 | { 39 | get { return _script; } 40 | set 41 | { 42 | _script = value; 43 | ParseRequired = true; 44 | } 45 | } 46 | 47 | /// 48 | /// Initializes a new instance of the ZScriptString class 49 | /// 50 | /// The string containing the script to create 51 | public ZScriptStringSource(string script) 52 | { 53 | Script = script; 54 | ParseRequired = true; 55 | } 56 | 57 | /// 58 | /// Gets the script source for this ZScriptString 59 | /// 60 | /// The script source for this ZScriptString 61 | public override string GetScriptSourceString() 62 | { 63 | return Script; 64 | } 65 | } 66 | } -------------------------------------------------------------------------------- /ZScript/CodeGeneration/Tokenization/FunctionBodyTokenizer.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | using System; 22 | 23 | using ZScript.CodeGeneration.Tokenization.Helpers; 24 | using ZScript.CodeGeneration.Tokenization.Statements; 25 | using ZScript.Elements; 26 | using ZScript.Runtime.Execution; 27 | using ZScript.Utils; 28 | 29 | namespace ZScript.CodeGeneration.Tokenization 30 | { 31 | /// 32 | /// Class capable of tokenizing a function body from an AST tree into a TokenList 33 | /// 34 | public class FunctionBodyTokenizer 35 | { 36 | /// 37 | /// Whether to print the tokens in the console 38 | /// 39 | public bool DebugTokens; 40 | 41 | /// 42 | /// The generation context for this statement tokenizer 43 | /// 44 | private readonly RuntimeGenerationContext _generationContext; 45 | 46 | /// 47 | /// Initializes a new instance of the FunctionBodyTokenizer class 48 | /// 49 | /// The context for the runtime generation 50 | public FunctionBodyTokenizer(RuntimeGenerationContext context) 51 | { 52 | _generationContext = context; 53 | } 54 | 55 | /// 56 | /// Tokenizes the contents of the given function body context, coming from a parse tree 57 | /// 58 | /// The function body to tokenize 59 | /// A token list for the givne function body 60 | public TokenList TokenizeBody(ZScriptParser.FunctionBodyContext context) 61 | { 62 | var state = context.blockStatement(); 63 | 64 | var stc = new StatementTokenizerContext(_generationContext); 65 | var tokens = stc.TokenizeBlockStatement(state); 66 | 67 | if (DebugTokens) 68 | { 69 | Console.WriteLine("Final token list, before expanding variables and jumps:"); 70 | TokenUtils.PrintTokens(tokens); 71 | } 72 | 73 | JumpTokenOptimizer.OptimizeJumps(tokens, VmInstruction.Interrupt); 74 | 75 | var finalList = tokens.ToTokenList(); 76 | 77 | var typeExpander = new TypedTokenExpander(_generationContext); 78 | typeExpander.ExpandInList(finalList); 79 | 80 | if (DebugTokens) 81 | { 82 | Console.WriteLine("Final token list:"); 83 | TokenUtils.PrintTokens(finalList); 84 | } 85 | 86 | return finalList; 87 | } 88 | } 89 | } -------------------------------------------------------------------------------- /ZScript/CodeGeneration/Tokenization/Helpers/JumpTargetToken.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | using System; 22 | using ZScript.Elements; 23 | 24 | namespace ZScript.CodeGeneration.Tokenization.Helpers 25 | { 26 | /// 27 | /// Special class that can be used as a target to jump tokens. 28 | /// This special token is analyzed by the JumpTokenExpander and is removed, moving the jump 29 | /// target of all jump tokens pointing to it to the immediate next instruction in the token list 30 | /// 31 | public class JumpTargetToken : Token, IEquatable 32 | { 33 | /// 34 | /// Initializes a new instance of the JumpTokenTarget class 35 | /// 36 | public JumpTargetToken() 37 | : base(TokenType.Value, null) 38 | { 39 | 40 | } 41 | 42 | /// 43 | /// Returns a string representation of this JumpTargetToken 44 | /// 45 | /// A string representation of this JumpTargetToken 46 | public override string ToString() 47 | { 48 | return "{ JumpTargetToken }"; 49 | } 50 | 51 | #region Equality members 52 | 53 | public bool Equals(JumpTargetToken other) 54 | { 55 | return ReferenceEquals(this, other); 56 | } 57 | 58 | public override bool Equals(object obj) 59 | { 60 | if (ReferenceEquals(null, obj)) return false; 61 | if (ReferenceEquals(this, obj)) return true; 62 | if (obj.GetType() != GetType()) return false; 63 | return Equals((JumpTargetToken)obj); 64 | } 65 | 66 | public override int GetHashCode() 67 | { 68 | return base.GetHashCode(); 69 | } 70 | 71 | public static bool operator==(JumpTargetToken left, JumpTargetToken right) 72 | { 73 | return Equals(left, right); 74 | } 75 | 76 | public static bool operator!=(JumpTargetToken left, JumpTargetToken right) 77 | { 78 | return !Equals(left, right); 79 | } 80 | 81 | #endregion 82 | } 83 | } -------------------------------------------------------------------------------- /ZScript/CodeGeneration/Tokenization/Helpers/TypedTokenExpander.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | using System; 22 | 23 | using ZScript.Elements; 24 | 25 | namespace ZScript.CodeGeneration.Tokenization.Helpers 26 | { 27 | /// 28 | /// Class capable of expanding TypedTokens in a token stream 29 | /// 30 | public class TypedTokenExpander 31 | { 32 | /// 33 | /// The runtime context associated with this typed token expander 34 | /// 35 | private readonly RuntimeGenerationContext _context; 36 | 37 | /// 38 | /// Initializes a new instance of the TypedTokenExpander class with a context associated 39 | /// 40 | /// The context to associate with this typed token expander 41 | public TypedTokenExpander(RuntimeGenerationContext context) 42 | { 43 | _context = context; 44 | } 45 | 46 | /// 47 | /// Expands the tokens in the given token list. 48 | /// Throws an Exception, if any token has a type that cannot be converted 49 | /// 50 | /// The list of tokens to expand 51 | /// A type context could not be converted to an appropriate type 52 | public void ExpandInList(TokenList tokenList) 53 | { 54 | var tokens = tokenList.Tokens; 55 | 56 | for (int i = 0; i < tokens.Length; i++) 57 | { 58 | var typedToken = tokens[i] as TypedToken; 59 | if (typedToken == null) 60 | continue; 61 | 62 | var typeDef = typedToken.TypeDef; 63 | 64 | if(typedToken.TypeContext != null) 65 | { 66 | // Substitute the token 67 | typeDef = _context.ContextTypeProvider.TypeForContext(typedToken.TypeContext); 68 | } 69 | 70 | Type type = _context.TypeProvider.NativeTypeForTypeDef(typeDef, true); 71 | if (type == null) 72 | throw new Exception("Could not expand type token " + typedToken); 73 | 74 | // Replace the token 75 | tokens[i] = new Token(typedToken.Type, type, typedToken.Instruction); 76 | } 77 | } 78 | } 79 | } -------------------------------------------------------------------------------- /ZScript/CodeGeneration/Tokenization/Helpers/VariableToken.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | 22 | using ZScript.CodeGeneration.Definitions; 23 | using ZScript.Elements; 24 | 25 | namespace ZScript.CodeGeneration.Tokenization.Helpers 26 | { 27 | /// 28 | /// Specifies a token that points to a local/global variable in the memory 29 | /// 30 | public class VariableToken : Token 31 | { 32 | /// 33 | /// The name of the variable this token is referring to 34 | /// 35 | public string VariableName; 36 | 37 | /// 38 | /// Whether this variable token is pointing at a global (variable or function) definition 39 | /// 40 | public bool GlobalDefinition; 41 | 42 | /// 43 | /// The definition this variable token is pointing at 44 | /// 45 | public Definition PointingDefinition; 46 | 47 | /// 48 | /// Whether the variable is currently being get 49 | /// 50 | public bool IsGet; 51 | 52 | /// 53 | /// Initializes a new instance of the VariableToken class 54 | /// 55 | /// The name of the variable this token is referring to 56 | /// Whether the variable is currently being get 57 | public VariableToken(string variableName, bool isGet = true) : base(TokenType.MemberName, variableName) 58 | { 59 | VariableName = variableName; 60 | IsGet = isGet; 61 | } 62 | } 63 | } -------------------------------------------------------------------------------- /ZScript/CodeGeneration/Tokenization/Statements/BreakStatementTokenizer.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | 22 | using ZScript.CodeGeneration.Tokenization.Helpers; 23 | 24 | namespace ZScript.CodeGeneration.Tokenization.Statements 25 | { 26 | /// 27 | /// Class capable of tokenizing break statements 28 | /// 29 | public class BreakStatementTokenizer 30 | { 31 | /// 32 | /// The context used to tokenize the statements, in case a different statement appears 33 | /// 34 | private readonly StatementTokenizerContext _context; 35 | 36 | /// 37 | /// Initializes a new instance of the BreakStatementTokenizer class 38 | /// 39 | /// The context used during tokenization 40 | public BreakStatementTokenizer(StatementTokenizerContext context) 41 | { 42 | _context = context; 43 | } 44 | 45 | /// 46 | /// Tokenizes a given Break statement into a list of tokens 47 | /// 48 | /// The context to tokenize 49 | /// A list of tokens tokenized from the given context 50 | public IntermediaryTokenList TokenizeStatement(ZScriptParser.BreakStatementContext context) 51 | { 52 | var tokenList = new IntermediaryTokenList(); 53 | 54 | if (_context.CurrentBreakTarget != null) 55 | { 56 | tokenList.Add(new JumpToken(_context.CurrentBreakTarget)); 57 | } 58 | 59 | return tokenList; 60 | } 61 | } 62 | } -------------------------------------------------------------------------------- /ZScript/CodeGeneration/Tokenization/Statements/ContinueStatementTokenizer.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | 22 | using ZScript.CodeGeneration.Tokenization.Helpers; 23 | 24 | namespace ZScript.CodeGeneration.Tokenization.Statements 25 | { 26 | /// 27 | /// Class capable of tokenizing Continue statements 28 | /// 29 | public class ContinueStatementTokenizer 30 | { 31 | /// 32 | /// The context used to tokenize the statements, in case a different statement appears 33 | /// 34 | private readonly StatementTokenizerContext _context; 35 | 36 | /// 37 | /// Initializes a new instance of the BreakStatementTokenizer class 38 | /// 39 | /// The context used during tokenization 40 | public ContinueStatementTokenizer(StatementTokenizerContext context) 41 | { 42 | _context = context; 43 | } 44 | 45 | /// 46 | /// Tokenizes a given Continue statement into a list of tokens 47 | /// 48 | /// The context to tokenize 49 | /// A list of tokens tokenized from the given context 50 | public IntermediaryTokenList TokenizeStatement(ZScriptParser.ContinueStatementContext context) 51 | { 52 | var tokenList = new IntermediaryTokenList(); 53 | 54 | if (_context.CurrentContinueTarget != null) 55 | { 56 | tokenList.Add(new JumpToken(_context.CurrentContinueTarget)); 57 | } 58 | 59 | return tokenList; 60 | } 61 | } 62 | } -------------------------------------------------------------------------------- /ZScript/CodeGeneration/Tokenization/Statements/ReturnStatementTokenizer.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | using ZScript.Elements; 22 | using ZScript.Runtime.Execution; 23 | 24 | namespace ZScript.CodeGeneration.Tokenization.Statements 25 | { 26 | /// 27 | /// Class capable of tokenizing return statements 28 | /// 29 | public class ReturnStatementTokenizer 30 | { 31 | /// 32 | /// The context used to tokenize the statements, in case a different statement appears 33 | /// 34 | private readonly StatementTokenizerContext _context; 35 | 36 | /// 37 | /// Initializes a new instance of the ReturnStatementTokenizer class 38 | /// 39 | /// The context used during tokenization 40 | public ReturnStatementTokenizer(StatementTokenizerContext context) 41 | { 42 | _context = context; 43 | } 44 | 45 | /// 46 | /// Tokenizes a given For loop statement into a list of tokens 47 | /// 48 | /// The context to tokenize 49 | /// A list of tokens tokenized from the given context 50 | public IntermediaryTokenList TokenizeStatement(ZScriptParser.ReturnStatementContext context) 51 | { 52 | IntermediaryTokenList tokens = new IntermediaryTokenList(); 53 | 54 | if(context.expression() != null) 55 | tokens.AddRange(_context.TokenizeExpression(context.value)); 56 | 57 | tokens.Add(TokenFactory.CreateInstructionToken(VmInstruction.Ret)); 58 | 59 | return tokens; 60 | } 61 | } 62 | } -------------------------------------------------------------------------------- /ZScript/CodeGeneration/Tokenization/Statements/VariableDeclarationStatementTokenizer.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | using ZScript.Elements; 22 | using ZScript.CodeGeneration.Tokenization.Helpers; 23 | using ZScript.Runtime.Execution; 24 | 25 | namespace ZScript.CodeGeneration.Tokenization.Statements 26 | { 27 | /// 28 | /// Class capable of tokenizing VAR and LET statements 29 | /// 30 | public class VariableDeclarationStatementTokenizer 31 | { 32 | /// 33 | /// The context used to tokenize the statements, in case a different statement appears 34 | /// 35 | private readonly StatementTokenizerContext _context; 36 | 37 | /// 38 | /// Initializes a new instance of the VariableDeclarationStatementTokenizer class 39 | /// 40 | /// The context used during tokenization 41 | public VariableDeclarationStatementTokenizer(StatementTokenizerContext context) 42 | { 43 | _context = context; 44 | } 45 | 46 | /// 47 | /// Tokenizes a given value declaration into a list of tokens 48 | /// 49 | /// The context to tokenize 50 | /// A list of tokens that were tokenized from the given context 51 | public IntermediaryTokenList TokenizeValueHolderDeclaration(ZScriptParser.ValueHolderDeclContext context) 52 | { 53 | var expression = context.expression(); 54 | var name = context.valueHolderName().memberName().IDENT().GetText(); 55 | 56 | if (expression != null) 57 | { 58 | if (context.Definition != null && context.Definition.IsConstant && expression.IsConstant && expression.IsConstantPrimitive) 59 | { 60 | return new IntermediaryTokenList(); 61 | } 62 | 63 | IntermediaryTokenList tokens = _context.TokenizeExpression(expression); 64 | tokens.Add(new VariableToken(name, false) { GlobalDefinition = false }); 65 | tokens.Add(TokenFactory.CreateInstructionToken(VmInstruction.Set)); 66 | 67 | return tokens; 68 | } 69 | 70 | return new IntermediaryTokenList(); 71 | } 72 | } 73 | } -------------------------------------------------------------------------------- /ZScript/CodeGeneration/ZScriptSyntaxErrorListener.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | 22 | using Antlr4.Runtime; 23 | 24 | using ZScript.CodeGeneration.Messages; 25 | 26 | namespace ZScript.CodeGeneration 27 | { 28 | /// 29 | /// Error listener for parsing of script snippets 30 | /// 31 | public class ZScriptSyntaxErrorListener : BaseErrorListener 32 | { 33 | /// 34 | /// The container errors will be reported to 35 | /// 36 | private MessageContainer _messageContainer; 37 | 38 | /// 39 | /// Gets or sets the container errors will be reported to 40 | /// 41 | public MessageContainer MessageContainer 42 | { 43 | get { return _messageContainer; } 44 | set { _messageContainer = value; } 45 | } 46 | 47 | /// 48 | /// Initializes a new instance of the ZScriptErrorListener class 49 | /// 50 | /// The container errors will be reported to 51 | public ZScriptSyntaxErrorListener(MessageContainer messageContainer) 52 | { 53 | _messageContainer = messageContainer; 54 | } 55 | 56 | // 57 | // SintaxError listener 58 | // 59 | public override void SyntaxError(IRecognizer recognizer, IToken offendingSymbol, int line, int charPositionInLine, string msg, RecognitionException e) 60 | { 61 | _messageContainer.RegisterSyntaxError(new SyntaxError(offendingSymbol, line, charPositionInLine, msg)); 62 | } 63 | } 64 | } -------------------------------------------------------------------------------- /ZScript/Elements/TokenList.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | using System.Collections.Generic; 22 | using System.Linq; 23 | using System.Text; 24 | 25 | namespace ZScript.Elements 26 | { 27 | /// 28 | /// Specifies a set of tokens that defines a line of script 29 | /// 30 | public class TokenList 31 | { 32 | /// 33 | /// The list of tokens 34 | /// 35 | public Token[] Tokens; 36 | 37 | /// 38 | /// Gets a string representation of this TokenList object 39 | /// 40 | public string StringFormat 41 | { 42 | get 43 | { 44 | StringBuilder outS = new StringBuilder(); 45 | 46 | foreach (Token token in Tokens) 47 | { 48 | if (token.TokenObject == null) 49 | { 50 | outS.Append("null "); 51 | } 52 | else 53 | { 54 | if (token.Type == TokenType.String) 55 | { 56 | outS.Append("\"" + token.TokenObject + "\" "); 57 | } 58 | else 59 | { 60 | outS.Append(token.TokenObject + " "); 61 | } 62 | } 63 | } 64 | 65 | return outS.ToString(); 66 | } 67 | } 68 | 69 | /// 70 | /// Initializes a new instance of the TokenList class 71 | /// 72 | public TokenList() 73 | { 74 | Tokens = new Token[0]; 75 | } 76 | 77 | /// 78 | /// Initializes a new instance of the TokenList class 79 | /// 80 | /// An enumerable containing the tokens to create 81 | public TokenList(IEnumerable tokens) 82 | { 83 | Tokens = tokens.ToArray(); 84 | } 85 | } 86 | } -------------------------------------------------------------------------------- /ZScript/Elements/ValueHolding/FunctionArgument.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | namespace ZScript.Elements.ValueHolding 22 | { 23 | /// 24 | /// Specifies a function argument 25 | /// 26 | public class FunctionArgument : Variable 27 | { 28 | /// 29 | /// Gets a value specifying whether the function argument represented by this definition is variadic in nature. 30 | /// Variadic arguments allow for the caller to specify as many values as desired, separated by commas like normal arguments. 31 | /// Functions can only have one variadic argument, appearing at the end of the argument list 32 | /// 33 | public bool IsVariadic { get; protected set; } 34 | 35 | /// 36 | /// Initializes a new instance of the FunctionArgument class 37 | /// 38 | /// The name for the function argument 39 | /// Whether the function argument is variadic in nature 40 | /// Whether the argument has a default value 41 | /// The default value for the function argument 42 | public FunctionArgument(string name, bool isVariadic = false, bool hasValue = false, object value = null) 43 | { 44 | Name = name; 45 | IsVariadic = isVariadic; 46 | HasValue = hasValue; 47 | DefaultValue = value; 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /ZScript/Elements/ValueHolding/GlobalVariable.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | namespace ZScript.Elements.ValueHolding 22 | { 23 | /// 24 | /// Specifies a variable that is globally scoped 25 | /// 26 | public class GlobalVariable : Variable 27 | { 28 | /// 29 | /// Gets or sets the token list containing the expression for the global variable 30 | /// 31 | public TokenList ExpressionTokens { get; set; } 32 | } 33 | } -------------------------------------------------------------------------------- /ZScript/Elements/ValueHolding/ValueHolder.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | 22 | using System; 23 | 24 | namespace ZScript.Elements.ValueHolding 25 | { 26 | /// 27 | /// Specifies a definition for an object that points to a value 28 | /// 29 | public class ValueHolder 30 | { 31 | /// 32 | /// Gets or sets the name for this value holder 33 | /// 34 | public string Name { get; set; } 35 | 36 | /// 37 | /// Gets or sets the type of the value contained within this value holder definition 38 | /// 39 | public Type Type { get; set; } 40 | } 41 | } -------------------------------------------------------------------------------- /ZScript/Elements/ValueHolding/Variable.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | namespace ZScript.Elements.ValueHolding 22 | { 23 | /// 24 | /// Specifies a variable definition 25 | /// 26 | public class Variable : ValueHolder 27 | { 28 | /// 29 | /// Gets or sets whether this variable definition has a default value binded to it 30 | /// 31 | public bool HasValue { get; set; } 32 | 33 | /// 34 | /// Gets or sets the default value for this variable definition 35 | /// 36 | public object DefaultValue { get; set; } 37 | } 38 | } -------------------------------------------------------------------------------- /ZScript/Elements/ZClosureFunction.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | using ZScript.Elements.ValueHolding; 22 | using ZScript.Runtime.Execution; 23 | using ZScript.Runtime.Execution.VirtualMemory; 24 | using ZScript.Runtime.Execution.Wrappers; 25 | using ZScript.Runtime.Typing.Elements; 26 | 27 | namespace ZScript.Elements 28 | { 29 | /// 30 | /// Specifies a closure function 31 | /// 32 | public class ZClosureFunction : ZFunction, ICallableWrapper 33 | { 34 | /// 35 | /// Gets or sets the currently captured memory for this closure function 36 | /// 37 | public MemoryMapper CapturedMemory { get; set; } 38 | 39 | /// 40 | /// The name for this closure 41 | /// 42 | public string CallableName 43 | { 44 | get { return Name; } 45 | } 46 | 47 | /// 48 | /// The local memory for this closure 49 | /// 50 | public IMemory LocalMemory 51 | { 52 | get { return CapturedMemory; } 53 | } 54 | 55 | /// 56 | /// Initializes a new instance of the ZClosureFunction class 57 | /// 58 | /// The name for the closure 59 | /// The list of tokens representing the closure's body 60 | /// The list of arguments for the closure 61 | public ZClosureFunction(string name, TokenList tokens, FunctionArgument[] arguments) 62 | : base(name, tokens, arguments) 63 | { 64 | IsClosure = true; 65 | } 66 | 67 | /// 68 | /// Performs a shallow clone of this ZClosureFunction object 69 | /// 70 | /// A shallow copy of this ZClosureFunction object 71 | public ZClosureFunction Clone() 72 | { 73 | var clone = (ZClosureFunction)MemberwiseClone(); 74 | 75 | clone.CapturedMemory = CapturedMemory == null ? null : CapturedMemory.Clone(); 76 | 77 | return clone; 78 | } 79 | 80 | // 81 | // ICallableWrapper.CallableTypeWithArguments implementation 82 | // 83 | public CallableTypeDef CallableTypeWithArguments(params object[] arguments) 84 | { 85 | return Signature; 86 | } 87 | 88 | // 89 | // ICallableWrapper.Call implementation 90 | // 91 | public object Call(VmContext context, params object[] arguments) 92 | { 93 | return context.Runtime.CallFunction(this, arguments); 94 | } 95 | } 96 | } -------------------------------------------------------------------------------- /ZScript/Elements/ZExportFunction.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | using ZScript.Elements.ValueHolding; 22 | 23 | namespace ZScript.Elements 24 | { 25 | /// 26 | /// Specifies a function that when called fires a method call to the runtime owner 27 | /// 28 | public class ZExportFunction : ZFunction 29 | { 30 | /// 31 | /// Initializes a new instance of the ZExportFunction class 32 | /// 33 | /// The name for the export function 34 | /// The arguments for the export function 35 | public ZExportFunction(string name, FunctionArgument[] arguments) : base(name, null, arguments) 36 | { 37 | 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /ZScript/Elements/ZFunction.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | using ZScript.Elements.ValueHolding; 22 | using ZScript.Runtime.Typing.Elements; 23 | 24 | namespace ZScript.Elements 25 | { 26 | /// 27 | /// Describes a function that can be executed by the runtime 28 | /// 29 | public class ZFunction 30 | { 31 | /// 32 | /// Creates a new function definition with a given name 33 | /// 34 | /// The name for this function definition 35 | /// A list of tokens containing the instructions this function will perform 36 | /// An array of the arguments for this function 37 | public ZFunction(string name, TokenList tokens, FunctionArgument[] arguments) 38 | { 39 | Name = name; 40 | Tokens = tokens; 41 | _arguments = arguments; 42 | } 43 | 44 | /// 45 | /// The name for this function definition 46 | /// 47 | public string Name { get; set; } 48 | 49 | /// 50 | /// Gets the tokens associated with this function definition 51 | /// 52 | public TokenList Tokens { get; private set; } 53 | 54 | /// 55 | /// Gets or sets a value specifying whether this function is a closure function type 56 | /// 57 | public bool IsClosure { get; set; } 58 | 59 | /// 60 | /// Gets or sets the signature for this function 61 | /// 62 | public CallableTypeDef Signature { get; set; } 63 | 64 | /// 65 | /// An array of the arguments for this function 66 | /// 67 | private readonly FunctionArgument[] _arguments; 68 | 69 | /// 70 | /// Gets an array of the arguments for this function 71 | /// 72 | public FunctionArgument[] Arguments { get { return _arguments; } } 73 | } 74 | } -------------------------------------------------------------------------------- /ZScript/Elements/ZMethod.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | using ZScript.Elements.ValueHolding; 22 | using ZScript.Runtime.Execution.VirtualMemory; 23 | 24 | namespace ZScript.Elements 25 | { 26 | /// 27 | /// Represents a class method 28 | /// 29 | public class ZMethod : ZFunction 30 | { 31 | /// 32 | /// Gets or sets the local memory for the class running this method 33 | /// 34 | public Memory LocalMemory { get; set; } 35 | 36 | /// 37 | /// Gets or sets the base method for this ZMethod 38 | /// 39 | public ZMethod BaseMethod { get; set; } 40 | 41 | /// 42 | /// Initializes a new instance of the ZMethod class 43 | /// 44 | /// The name for the method 45 | /// The tokens for the method 46 | /// The arguments for the method call 47 | public ZMethod(string name, TokenList tokens, FunctionArgument[] arguments) 48 | : base(name, tokens, arguments) 49 | { 50 | 51 | } 52 | 53 | /// 54 | /// Performs a shallow clone of this ZMethod class, copying field values 55 | /// 56 | /// A shallow clone of this ZMethod class 57 | public ZMethod Clone() 58 | { 59 | var newMethod = (ZMethod)MemberwiseClone(); 60 | 61 | return newMethod; 62 | } 63 | } 64 | } -------------------------------------------------------------------------------- /ZScript/Elements/ZObject.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | using System; 22 | using System.Collections.Generic; 23 | 24 | using ZScript.Runtime.Execution.Wrappers; 25 | 26 | namespace ZScript.Elements 27 | { 28 | /// 29 | /// Specifies an dynamic object that can store values in subscripting and direct field access fashions 30 | /// 31 | public class ZObject : Dictionary, ISubscripterWrapper 32 | { 33 | /// 34 | /// Gets or sets a value on this ZObject 35 | /// 36 | /// The object to index this ZObject with 37 | /// The value corresponding to the indexer 38 | public object this[object indexer] 39 | { 40 | get 41 | { 42 | CheckType(indexer); 43 | 44 | if (!ContainsKey((string)indexer)) 45 | return null; 46 | 47 | return base[(string)indexer]; 48 | } 49 | set 50 | { 51 | CheckType(indexer); 52 | 53 | base[(string)indexer] = value; 54 | } 55 | } 56 | 57 | /// 58 | /// Checks the type of the given object, raising an exception in case it is not a valid subscripter value for a ZObject 59 | /// 60 | /// The object to check 61 | /// The given object is not a string type 62 | /// The provided obj argument is null 63 | private static void CheckType(object obj) 64 | { 65 | if (obj == null) 66 | throw new ArgumentNullException("obj"); 67 | 68 | if (!(obj is string)) 69 | { 70 | throw new ArgumentException("ZObjects can only be indexed with string types"); 71 | } 72 | } 73 | 74 | // 75 | // CanSubscriptWithIndexType override 76 | // 77 | public bool CanSubscriptWithIndexType(Type type) 78 | { 79 | return type == typeof(string); 80 | } 81 | } 82 | } -------------------------------------------------------------------------------- /ZScript/Parsing/ANTLR/ZScript.tokens: -------------------------------------------------------------------------------- 1 | T__0=1 2 | T__1=2 3 | T__2=3 4 | StringLiteral=4 5 | DoubleQuoteEscape=5 6 | SingleQuoteEscape=6 7 | T_EXPORT=7 8 | T_FUNCTION=8 9 | T_OVERRIDE=9 10 | T_OBJECT=10 11 | T_SEQUENCE=11 12 | T_THIS=12 13 | T_BASE=13 14 | T_VAR=14 15 | T_LET=15 16 | T_CONST=16 17 | T_NEW=17 18 | T_IS=18 19 | T_IF=19 20 | T_ELSE=20 21 | T_WHILE=21 22 | T_FOR=22 23 | T_BREAK=23 24 | T_CONTINUE=24 25 | T_SWITCH=25 26 | T_CASE=26 27 | T_DEFAULT=27 28 | T_RETURN=28 29 | T_LEFT_PAREN=29 30 | T_RIGHT_PAREN=30 31 | T_LEFT_BRACKET=31 32 | T_RIGHT_BRACKET=32 33 | T_LEFT_CURLY=33 34 | T_RIGHT_CURLY=34 35 | T_CLOSURE_RETURN=35 36 | T_CLOSURE_CALL=36 37 | T_NULL_COALESCE=37 38 | T_NULL_CONDITIONAL=38 39 | T_INT=39 40 | T_FLOAT=40 41 | T_VOID=41 42 | T_ANY=42 43 | T_STRING=43 44 | T_BOOL=44 45 | INT=45 46 | HEX=46 47 | BINARY=47 48 | FLOAT=48 49 | T_FALSE=49 50 | T_TRUE=50 51 | T_NULL=51 52 | T_QUOTES=52 53 | T_DOUBLE_QUOTES=53 54 | T_TRIPPLE_DOT=54 55 | T_DOUBLE_COLON=55 56 | T_SEMICOLON=56 57 | T_PERIOD=57 58 | T_COMMA=58 59 | T_MULT=59 60 | T_DIV=60 61 | T_MOD=61 62 | T_NOT=62 63 | T_PLUS=63 64 | T_MINUS=64 65 | T_INCREMENT=65 66 | T_DECREMENT=66 67 | T_BITWISE_AND=67 68 | T_BITWISE_XOR=68 69 | T_BITWISE_OR=69 70 | T_SHIFTLEFT=70 71 | T_SHIFTRIGHT=71 72 | T_EQUALITY=72 73 | T_UNEQUALITY=73 74 | T_MORE_THAN_OR_EQUALS=74 75 | T_LESS_THAN_OR_EQUALS=75 76 | T_MORE_THAN=76 77 | T_LESS_THAN=77 78 | T_LOGICAL_AND=78 79 | T_LOGICAL_OR=79 80 | T_EQUALS=80 81 | T_PLUS_EQUALS=81 82 | T_MINUS_EQUALS=82 83 | T_TIMES_EQUALS=83 84 | T_DIV_EQUALS=84 85 | T_MOD_EQUALS=85 86 | T_XOR_EQUALS=86 87 | T_AND_EQUALS=87 88 | T_TILDE_EQUALS=88 89 | T_OR_EQUALS=89 90 | T_SHIFTLEFT_EQUALS=90 91 | T_SHIFTRIGHT_EQUALS=91 92 | IDENT=92 93 | Whitespace=93 94 | Newline=94 95 | BlockComment=95 96 | LineComment=96 97 | ImportDirective=97 98 | 'class'=1 99 | 'typeAlias'=2 100 | '<-'=3 101 | '@'=7 102 | 'func'=8 103 | 'override'=9 104 | 'object'=10 105 | 'sequence'=11 106 | 'this'=12 107 | 'base'=13 108 | 'var'=14 109 | 'let'=15 110 | 'const'=16 111 | 'new'=17 112 | 'is'=18 113 | 'if'=19 114 | 'else'=20 115 | 'while'=21 116 | 'for'=22 117 | 'break'=23 118 | 'continue'=24 119 | 'switch'=25 120 | 'case'=26 121 | 'default'=27 122 | 'return'=28 123 | '('=29 124 | ')'=30 125 | '['=31 126 | ']'=32 127 | '{'=33 128 | '}'=34 129 | '->'=35 130 | '=>'=36 131 | '?:'=37 132 | '?'=38 133 | 'int'=39 134 | 'float'=40 135 | 'void'=41 136 | 'any'=42 137 | 'string'=43 138 | 'bool'=44 139 | 'false'=49 140 | 'true'=50 141 | 'null'=51 142 | '\''=52 143 | '"'=53 144 | '...'=54 145 | ':'=55 146 | ';'=56 147 | '.'=57 148 | ','=58 149 | '*'=59 150 | '/'=60 151 | '%'=61 152 | '!'=62 153 | '+'=63 154 | '-'=64 155 | '++'=65 156 | '--'=66 157 | '&'=67 158 | '^'=68 159 | '|'=69 160 | '=='=72 161 | '!='=73 162 | '>='=74 163 | '<='=75 164 | '>'=76 165 | '<'=77 166 | '&&'=78 167 | '||'=79 168 | '='=80 169 | '+='=81 170 | '-='=82 171 | '*='=83 172 | '/='=84 173 | '%='=85 174 | '^='=86 175 | '&='=87 176 | '~='=88 177 | '|='=89 178 | '<<='=90 179 | '>>='=91 180 | -------------------------------------------------------------------------------- /ZScript/Parsing/ANTLR/ZScriptLexer.tokens: -------------------------------------------------------------------------------- 1 | T__0=1 2 | T__1=2 3 | T__2=3 4 | StringLiteral=4 5 | DoubleQuoteEscape=5 6 | SingleQuoteEscape=6 7 | T_EXPORT=7 8 | T_FUNCTION=8 9 | T_OVERRIDE=9 10 | T_OBJECT=10 11 | T_SEQUENCE=11 12 | T_THIS=12 13 | T_BASE=13 14 | T_VAR=14 15 | T_LET=15 16 | T_CONST=16 17 | T_NEW=17 18 | T_IS=18 19 | T_IF=19 20 | T_ELSE=20 21 | T_WHILE=21 22 | T_FOR=22 23 | T_BREAK=23 24 | T_CONTINUE=24 25 | T_SWITCH=25 26 | T_CASE=26 27 | T_DEFAULT=27 28 | T_RETURN=28 29 | T_LEFT_PAREN=29 30 | T_RIGHT_PAREN=30 31 | T_LEFT_BRACKET=31 32 | T_RIGHT_BRACKET=32 33 | T_LEFT_CURLY=33 34 | T_RIGHT_CURLY=34 35 | T_CLOSURE_RETURN=35 36 | T_CLOSURE_CALL=36 37 | T_NULL_COALESCE=37 38 | T_NULL_CONDITIONAL=38 39 | T_INT=39 40 | T_FLOAT=40 41 | T_VOID=41 42 | T_ANY=42 43 | T_STRING=43 44 | T_BOOL=44 45 | INT=45 46 | HEX=46 47 | BINARY=47 48 | FLOAT=48 49 | T_FALSE=49 50 | T_TRUE=50 51 | T_NULL=51 52 | T_QUOTES=52 53 | T_DOUBLE_QUOTES=53 54 | T_TRIPPLE_DOT=54 55 | T_DOUBLE_COLON=55 56 | T_SEMICOLON=56 57 | T_PERIOD=57 58 | T_COMMA=58 59 | T_MULT=59 60 | T_DIV=60 61 | T_MOD=61 62 | T_NOT=62 63 | T_PLUS=63 64 | T_MINUS=64 65 | T_INCREMENT=65 66 | T_DECREMENT=66 67 | T_BITWISE_AND=67 68 | T_BITWISE_XOR=68 69 | T_BITWISE_OR=69 70 | T_SHIFTLEFT=70 71 | T_SHIFTRIGHT=71 72 | T_EQUALITY=72 73 | T_UNEQUALITY=73 74 | T_MORE_THAN_OR_EQUALS=74 75 | T_LESS_THAN_OR_EQUALS=75 76 | T_MORE_THAN=76 77 | T_LESS_THAN=77 78 | T_LOGICAL_AND=78 79 | T_LOGICAL_OR=79 80 | T_EQUALS=80 81 | T_PLUS_EQUALS=81 82 | T_MINUS_EQUALS=82 83 | T_TIMES_EQUALS=83 84 | T_DIV_EQUALS=84 85 | T_MOD_EQUALS=85 86 | T_XOR_EQUALS=86 87 | T_AND_EQUALS=87 88 | T_TILDE_EQUALS=88 89 | T_OR_EQUALS=89 90 | T_SHIFTLEFT_EQUALS=90 91 | T_SHIFTRIGHT_EQUALS=91 92 | IDENT=92 93 | Whitespace=93 94 | Newline=94 95 | BlockComment=95 96 | LineComment=96 97 | ImportDirective=97 98 | 'class'=1 99 | 'typeAlias'=2 100 | '<-'=3 101 | '@'=7 102 | 'func'=8 103 | 'override'=9 104 | 'object'=10 105 | 'sequence'=11 106 | 'this'=12 107 | 'base'=13 108 | 'var'=14 109 | 'let'=15 110 | 'const'=16 111 | 'new'=17 112 | 'is'=18 113 | 'if'=19 114 | 'else'=20 115 | 'while'=21 116 | 'for'=22 117 | 'break'=23 118 | 'continue'=24 119 | 'switch'=25 120 | 'case'=26 121 | 'default'=27 122 | 'return'=28 123 | '('=29 124 | ')'=30 125 | '['=31 126 | ']'=32 127 | '{'=33 128 | '}'=34 129 | '->'=35 130 | '=>'=36 131 | '?:'=37 132 | '?'=38 133 | 'int'=39 134 | 'float'=40 135 | 'void'=41 136 | 'any'=42 137 | 'string'=43 138 | 'bool'=44 139 | 'false'=49 140 | 'true'=50 141 | 'null'=51 142 | '\''=52 143 | '"'=53 144 | '...'=54 145 | ':'=55 146 | ';'=56 147 | '.'=57 148 | ','=58 149 | '*'=59 150 | '/'=60 151 | '%'=61 152 | '!'=62 153 | '+'=63 154 | '-'=64 155 | '++'=65 156 | '--'=66 157 | '&'=67 158 | '^'=68 159 | '|'=69 160 | '=='=72 161 | '!='=73 162 | '>='=74 163 | '<='=75 164 | '>'=76 165 | '<'=77 166 | '&&'=78 167 | '||'=79 168 | '='=80 169 | '+='=81 170 | '-='=82 171 | '*='=83 172 | '/='=84 173 | '%='=85 174 | '^='=86 175 | '&='=87 176 | '~='=88 177 | '|='=89 178 | '<<='=90 179 | '>>='=91 180 | -------------------------------------------------------------------------------- /ZScript/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | using System.Reflection; 22 | using System.Runtime.InteropServices; 23 | 24 | // General Information about an assembly is controlled through the following 25 | // set of attributes. Change these attribute values to modify the information 26 | // associated with an assembly. 27 | [assembly: AssemblyTitle("ZScript")] 28 | [assembly: AssemblyDescription("")] 29 | [assembly: AssemblyConfiguration("")] 30 | [assembly: AssemblyCompany("")] 31 | [assembly: AssemblyProduct("ZScript")] 32 | [assembly: AssemblyCopyright("Copyright © 2015")] 33 | [assembly: AssemblyTrademark("")] 34 | [assembly: AssemblyCulture("")] 35 | 36 | // Setting ComVisible to false makes the types in this assembly not visible 37 | // to COM components. If you need to access a type in this assembly from 38 | // COM, set the ComVisible attribute to true on that type. 39 | [assembly: ComVisible(false)] 40 | 41 | // The following GUID is for the ID of the typelib if this project is exposed to COM 42 | [assembly: Guid("f9c854ff-b081-4472-9c3b-f4e328bf1388")] 43 | 44 | // Version information for an assembly consists of the following four values: 45 | // 46 | // Major Version 47 | // Minor Version 48 | // Build Number 49 | // Revision 50 | // 51 | // You can specify all the values or you can default the Build and Revision Numbers 52 | // by using the '*' as shown below: 53 | // [assembly: AssemblyVersion("1.0.*")] 54 | [assembly: AssemblyVersion("1.0.0.0")] 55 | [assembly: AssemblyFileVersion("1.0.0.0")] 56 | -------------------------------------------------------------------------------- /ZScript/Runtime/Execution/VirtualMemory/IMemory.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | namespace ZScript.Runtime.Execution.VirtualMemory 22 | { 23 | /// 24 | /// Interface to be implemented by objects that simmulate memory access 25 | /// 26 | /// The type used to map between the variable and the value 27 | public interface IMemory 28 | { 29 | /// 30 | /// Returns whether the given varID exists in the memory 31 | /// 32 | /// The variable to seek in the memory 33 | /// Whether the variable exists or not 34 | bool HasVariable(T identifier); 35 | 36 | /// 37 | /// Tries to get a variable on this IMemory object, returing a boolean value 38 | /// that specifies whether the fetch was successful or not 39 | /// 40 | /// The identifier of the variable to try to get 41 | /// The value that was fetched. Will be null, if the fetch fails 42 | /// Whether the fetch was successful 43 | bool TryGetVariable(T identifier, out object value); 44 | 45 | /// 46 | /// Gets the desired variable from the memory 47 | /// 48 | /// The variable ID to get the value form 49 | /// The current value stored on the variable 50 | object GetVariable(T identifier); 51 | 52 | /// 53 | /// Sets the desired variable to the given value on the memory 54 | /// 55 | /// The variable ID to change 56 | /// The new value to set the variable to 57 | void SetVariable(T identifier, object value); 58 | 59 | /// 60 | /// Clears this memory of all its contents 61 | /// 62 | void Clear(); 63 | 64 | /// 65 | /// Returns the count of items inside this Memory object 66 | /// 67 | /// The count of items inside this Memory object 68 | int GetCount(); 69 | } 70 | } -------------------------------------------------------------------------------- /ZScript/Runtime/Execution/Wrappers/ICallableWrapper.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | 22 | using ZScript.Runtime.Execution.VirtualMemory; 23 | using ZScript.Runtime.Typing.Elements; 24 | 25 | namespace ZScript.Runtime.Execution.Wrappers 26 | { 27 | /// 28 | /// Represents a wrapper for callable members of objects 29 | /// 30 | public interface ICallableWrapper 31 | { 32 | /// 33 | /// Gets the name of the callable wrapped by this ICallableWrapper 34 | /// 35 | string CallableName { get; } 36 | 37 | /// 38 | /// Gets the local memory for this ICallableWrapper. 39 | /// May be null, if no local memory is available 40 | /// 41 | IMemory LocalMemory { get; } 42 | 43 | /// 44 | /// Returns the type for the callable wrapped by this ICallableWrapper when presented with a given list of arguments 45 | /// 46 | /// The list of arguments to get the callable type info of 47 | /// A CallableTypeDef for a given argument list 48 | CallableTypeDef CallableTypeWithArguments(params object[] arguments); 49 | 50 | /// 51 | /// Performs a call of the callable, utilizing a given array as arguments 52 | /// 53 | /// The arguments for the call 54 | /// A VM context to use when executing the method 55 | /// The return of the call. Will be null, if the wrapped callable's return type is void 56 | object Call(VmContext context, params object[] arguments); 57 | } 58 | } -------------------------------------------------------------------------------- /ZScript/Runtime/Execution/Wrappers/IMemberWrapper.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | using System; 22 | 23 | namespace ZScript.Runtime.Execution.Wrappers 24 | { 25 | /// 26 | /// Represents a wrapper for members of objects 27 | /// 28 | public interface IMemberWrapper : IValueHolder 29 | { 30 | /// 31 | /// Gets the name of the member wrapped by this IMemberWrapper 32 | /// 33 | string MemberName { get; } 34 | 35 | /// 36 | /// Gets the type for the member wrapped by this IMemberWrapper 37 | /// 38 | Type MemberType { get; } 39 | } 40 | } -------------------------------------------------------------------------------- /ZScript/Runtime/Execution/Wrappers/ISubscripterWrapper.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | using System; 22 | 23 | namespace ZScript.Runtime.Execution.Wrappers 24 | { 25 | /// 26 | /// Interface for objects that wrap a subscript-capable object into a common access point 27 | /// 28 | public interface ISubscripterWrapper 29 | { 30 | /// 31 | /// Gets or sets a subscript value on this ISubscripter object 32 | /// 33 | /// The value to use when subscripting 34 | /// An object that is subscripted into the given index 35 | object this[object indexer] { get; set; } 36 | 37 | /// 38 | /// Returns boolean value specifying whether this ISubscripter value can subscript with the specified value type 39 | /// 40 | /// The type of the value to use as an indexer on subscript operations 41 | /// A boolean value specifying whether this ISubscripter value can subscript with the specified value type 42 | bool CanSubscriptWithIndexType(Type type); 43 | } 44 | } -------------------------------------------------------------------------------- /ZScript/Runtime/Execution/Wrappers/IValueHolder.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | namespace ZScript.Runtime.Execution.Wrappers 22 | { 23 | /// 24 | /// Interface to be implemented by objects that have values that can be get/set 25 | /// 26 | public interface IValueHolder 27 | { 28 | /// 29 | /// Sets the value of the member wrapped by this IValueHolder 30 | /// 31 | /// The value to set the member as 32 | void SetValue(object value); 33 | 34 | /// 35 | /// Gets the value of the member wrapped by this IValueHolder 36 | /// 37 | /// The value of the member wrapped by this IValueHolder 38 | object GetValue(); 39 | } 40 | } -------------------------------------------------------------------------------- /ZScript/Runtime/Execution/Wrappers/Members/ClassMember.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | using System; 22 | using System.Reflection; 23 | 24 | namespace ZScript.Runtime.Execution.Wrappers.Members 25 | { 26 | /// 27 | /// Wraps a class member (field or property) 28 | /// 29 | public abstract class ClassMember : IMemberWrapper 30 | { 31 | /// 32 | /// The target for the get/set operations to perform 33 | /// 34 | protected readonly object target; 35 | 36 | public abstract string MemberName { get; } 37 | public abstract Type MemberType { get; } 38 | 39 | /// 40 | /// Gets the target for the get/set operations to perform 41 | /// 42 | public object Target 43 | { 44 | get { return target; } 45 | } 46 | 47 | /// 48 | /// Initializes a new instance of ClassMember object 49 | /// 50 | /// The target for the get/set operations to perform 51 | protected ClassMember(object target) 52 | { 53 | this.target = target; 54 | } 55 | 56 | public abstract void SetValue(object value); 57 | public abstract object GetValue(); 58 | 59 | /// 60 | /// Returns a ClassMember that wraps a member from a target class. 61 | /// The name must point to either a public property or public field. 62 | /// If the method fails to find a valid field, an exception is raised 63 | /// 64 | /// The target to get the member from 65 | /// The name of the member to get 66 | /// A ClassMember that wraps the member 67 | /// The member name provided does not points to a valid visible field or property 68 | public static ClassMember CreateMemberWrapper(object target, string memberName) 69 | { 70 | FieldInfo field = target.GetType().GetField(memberName); 71 | if (field != null) 72 | { 73 | return new FieldClassMember(target, field); 74 | } 75 | 76 | PropertyInfo prop = target.GetType().GetProperty(memberName); 77 | if (prop != null) 78 | { 79 | return new PropertyClassMember(target, prop); 80 | } 81 | 82 | throw new ArgumentException("No public member of name '" + memberName + "' found on object of type '" + target.GetType() + "'", "memberName"); 83 | } 84 | } 85 | } -------------------------------------------------------------------------------- /ZScript/Runtime/Execution/Wrappers/Members/FieldClassMember.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | using System; 22 | using System.Reflection; 23 | 24 | namespace ZScript.Runtime.Execution.Wrappers.Members 25 | { 26 | /// 27 | /// Wraps a class's field 28 | /// 29 | public class FieldClassMember : ClassMember 30 | { 31 | /// 32 | /// The field wrapped in this FieldClassMember 33 | /// 34 | private readonly FieldInfo _field; 35 | 36 | /// 37 | /// Gets the name of the field pointed by this FieldClassMember 38 | /// 39 | public override string MemberName 40 | { 41 | get { return _field.Name; } 42 | } 43 | 44 | /// 45 | /// Gets the type of the field pointed by this FieldClassMember 46 | /// 47 | public override Type MemberType 48 | { 49 | get { return _field.FieldType; } 50 | } 51 | 52 | /// 53 | /// Gets the field wrapped in this FieldClassMember 54 | /// 55 | public FieldInfo Field 56 | { 57 | get { return _field; } 58 | } 59 | 60 | /// 61 | /// Initializes a new instance of the FieldClassMember class 62 | /// 63 | /// The target for the get/set operations to perform 64 | /// The field to wrap on this FieldClassMember 65 | public FieldClassMember(object target, FieldInfo field) : base(target) 66 | { 67 | _field = field; 68 | } 69 | 70 | /// 71 | /// Sets the value of the field pointed by this FieldClassMember 72 | /// 73 | /// The value to set for the field pointed by this FieldClassMember 74 | public override void SetValue(object value) 75 | { 76 | _field.SetValue(target, value); 77 | } 78 | 79 | /// 80 | /// Gets the value of the field pointed by this FieldClassMember 81 | /// 82 | /// The value of the field pointed by this FieldClassMember 83 | public override object GetValue() 84 | { 85 | return _field.GetValue(target); 86 | } 87 | } 88 | } -------------------------------------------------------------------------------- /ZScript/Runtime/Execution/Wrappers/Members/PropertyClassMember.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | using System; 22 | using System.Reflection; 23 | 24 | namespace ZScript.Runtime.Execution.Wrappers.Members 25 | { 26 | /// 27 | /// Wraps a class's property 28 | /// 29 | public class PropertyClassMember : ClassMember 30 | { 31 | /// 32 | /// The property wrapped in this PropertyClassMember 33 | /// 34 | private readonly PropertyInfo _property; 35 | 36 | /// 37 | /// Gets the name of the property pointed by this PropertyClassMember 38 | /// 39 | public override string MemberName 40 | { 41 | get { return _property.Name; } 42 | } 43 | 44 | /// 45 | /// Gets the type of the property pointed by this PropertyClassMember 46 | /// 47 | public override Type MemberType 48 | { 49 | get { return _property.PropertyType; } 50 | } 51 | 52 | /// 53 | /// Gets the property wrapped in this PropertyClassMember 54 | /// 55 | public PropertyInfo Property 56 | { 57 | get { return _property; } 58 | } 59 | 60 | /// 61 | /// Initializes a new instance of the PropertyClassMember class 62 | /// 63 | /// The target for the get/set operations to perform 64 | /// The property to wrap on this PropertyClassMember 65 | public PropertyClassMember(object target, PropertyInfo property) 66 | : base(target) 67 | { 68 | _property = property; 69 | } 70 | 71 | /// 72 | /// Sets the value of the property pointed by this PropertyClassMember 73 | /// 74 | /// The value to set for the property pointed by this PropertyClassMember 75 | public override void SetValue(object value) 76 | { 77 | _property.SetValue(target, value); 78 | } 79 | 80 | /// 81 | /// Gets the value of the property pointed by this PropertyClassMember 82 | /// 83 | /// The value of the field property by this PropertyClassMember 84 | public override object GetValue() 85 | { 86 | return _property.GetValue(target); 87 | } 88 | } 89 | } -------------------------------------------------------------------------------- /ZScript/Runtime/Execution/Wrappers/Members/ZObjectMember.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | using System; 22 | 23 | using ZScript.Elements; 24 | 25 | namespace ZScript.Runtime.Execution.Wrappers.Members 26 | { 27 | /// 28 | /// Wraps a ZObject member 29 | /// 30 | public class ZObjectMember : IMemberWrapper 31 | { 32 | /// 33 | /// The ZObject wrapped in this ZObjectMember 34 | /// 35 | private readonly ZObject _target; 36 | 37 | /// 38 | /// The name of the ZObject member wrapped 39 | /// 40 | private readonly string _name; 41 | 42 | /// 43 | /// Initializes a new instance of the ZObjectMember class 44 | /// 45 | /// The ZObject to wrap on ZObjectMember 46 | /// The name of the ZObject member to wrap 47 | public ZObjectMember(ZObject target, string name) 48 | { 49 | _target = target; 50 | _name = name; 51 | } 52 | 53 | /// 54 | /// Sets the value of the member 55 | /// 56 | /// The value to set 57 | public void SetValue(object value) 58 | { 59 | _target[_name] = value; 60 | } 61 | 62 | /// 63 | /// Gets the value of the member referenced by this ZObjectMember instance. 64 | /// If no member with the specified name exists, an exception is raised 65 | /// 66 | /// The value referenced by this ZObjectMember 67 | /// No member with the name referenced by this ZObjectMember exists 68 | public object GetValue() 69 | { 70 | return _target[_name]; 71 | } 72 | 73 | /// 74 | /// The name of the member referenced by this ZObjectMember 75 | /// 76 | public string MemberName 77 | { 78 | get { return _name; } 79 | } 80 | 81 | /// 82 | /// Gets the type of this member. 83 | /// This value is always typeof(object) 84 | /// 85 | public Type MemberType 86 | { 87 | get { return typeof(object); } 88 | } 89 | } 90 | } -------------------------------------------------------------------------------- /ZScript/Runtime/Execution/Wrappers/Subscripters/PropertySubscripterWrapper.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | using System; 22 | using System.Reflection; 23 | 24 | namespace ZScript.Runtime.Execution.Wrappers.Subscripters 25 | { 26 | /// 27 | /// Wraps a subscripter that binds to a public indexed property of a target object 28 | /// 29 | public class PropertySubscripterWrapper : ISubscripterWrapper 30 | { 31 | /// 32 | /// The object being subscripted 33 | /// 34 | private readonly object _target; 35 | 36 | /// 37 | /// The property being subscripted in 38 | /// 39 | private readonly PropertyInfo _property; 40 | 41 | /// 42 | /// Gets the object being subscripted by this ListSubscripter 43 | /// 44 | public object Target 45 | { 46 | get { return _target; } 47 | } 48 | 49 | /// 50 | /// Gets or sets an index on the object being subscripted 51 | /// 52 | /// The index to subscript into the object 53 | /// The object that was in the given index on the underlying list 54 | public object this[object indexer] 55 | { 56 | get 57 | { 58 | return _property.GetValue(_target, new[] { indexer }); 59 | } 60 | set 61 | { 62 | _property.SetValue(_target, value, new[] { indexer }); 63 | } 64 | } 65 | 66 | /// 67 | /// Initializes a new instance of the ProperySubscripterWrapper class 68 | /// 69 | /// The object to subscript 70 | /// The indexed property to index with 71 | public PropertySubscripterWrapper(object target, PropertyInfo property) 72 | { 73 | _target = target; 74 | _property = property; 75 | } 76 | 77 | /// 78 | /// Returns boolean value specifying whether this ISubscripter value can subscript with the specified value type 79 | /// 80 | /// The type of the value to use as an indexer on subscript operations 81 | /// A boolean value specifying whether this ISubscripter value can subscript with the specified value type 82 | public bool CanSubscriptWithIndexType(Type type) 83 | { 84 | return _property.GetIndexParameters()[0].ParameterType.IsAssignableFrom(type); 85 | } 86 | } 87 | } -------------------------------------------------------------------------------- /ZScript/Runtime/IRuntimeOwner.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | using ZScript.Elements; 22 | 23 | namespace ZScript.Runtime 24 | { 25 | /// 26 | /// Represents an interface to be implemented by objects that will provide interop between a ZRuntime and the program 27 | /// 28 | public interface IRuntimeOwner 29 | { 30 | /// 31 | /// Called by the runtime when an export function was invoked by the script 32 | /// 33 | /// The function that was invoked 34 | /// The list of parameters the function was called with 35 | /// The return value for the function call 36 | object CallFunction(ZExportFunction func, params object[] parameters); 37 | 38 | /// 39 | /// Called by the runtime when an export function was invoked by the script, used to verify whether 40 | /// the runtime owner can atually respond to a given export function 41 | /// 42 | /// The export function to verify 43 | /// Whether the runtime owner responds to this function 44 | bool RespondsToFunction(ZExportFunction func); 45 | 46 | /// 47 | /// Called by the runtime when a 'new' instruction has been hit 48 | /// 49 | /// The name of the type trying to be instantiated 50 | /// The parameters collected from the function call 51 | /// The newly created object 52 | object CreateType(string typeName, params object[] parameters); 53 | } 54 | } -------------------------------------------------------------------------------- /ZScript/Runtime/Typing/Elements/AnyTypeDef.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | namespace ZScript.Runtime.Typing.Elements 22 | { 23 | /// 24 | /// Represents a type that can be used to hold any value 25 | /// 26 | public class AnyTypeDef : TypeDef 27 | { 28 | /// 29 | /// Initializes a new instance of the 'any' type 30 | /// 31 | public AnyTypeDef() : base("any", false) 32 | { 33 | 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /ZScript/Runtime/Typing/Elements/ICallableTypeDef.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | namespace ZScript.Runtime.Typing.Elements 22 | { 23 | /// 24 | /// Represents an interface to be implemented by types whose values can be a function-like manner 25 | /// 26 | public interface ICallableTypeDef 27 | { 28 | /// 29 | /// Gets the types for the parameters of this callable type definition 30 | /// 31 | TypeDef[] ParameterTypes { get; } 32 | 33 | /// 34 | /// Gets the information for the parameters of this callable type definition 35 | /// 36 | CallableTypeDef.CallableParameterInfo[] ParameterInfos { get; } 37 | 38 | /// 39 | /// Gets the count of arguments required by this callable type definition 40 | /// 41 | int RequiredArgumentsCount { get; } 42 | 43 | /// 44 | /// Gets the total count of arguments accepted by this callable type definition. 45 | /// If there is at least one variadic argument, the value returned is int.MaxValue 46 | /// 47 | int MaximumArgumentsCount { get; } 48 | 49 | /// 50 | /// Gets a value specifying whether a return type has been provided 51 | /// 52 | bool HasReturnType { get; } 53 | 54 | /// 55 | /// Gets the return type for this callable 56 | /// 57 | TypeDef ReturnType { get; } 58 | } 59 | } -------------------------------------------------------------------------------- /ZScript/Runtime/Typing/Elements/IListTypeDef.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | namespace ZScript.Runtime.Typing.Elements 22 | { 23 | /// 24 | /// Interface to be implemented by types that enclose other values and can be subscripted like arrays 25 | /// 26 | public interface IListTypeDef 27 | { 28 | /// 29 | /// Gets the type of items enclosed in this list type 30 | /// 31 | TypeDef EnclosingType { get; } 32 | 33 | /// 34 | /// Gets the type of object that is accepted by the subscripting syntax of the list 35 | /// 36 | TypeDef SubscriptType { get; } 37 | } 38 | } -------------------------------------------------------------------------------- /ZScript/Runtime/Typing/Elements/NativeTypeDef.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | using System; 22 | 23 | namespace ZScript.Runtime.Typing.Elements 24 | { 25 | /// 26 | /// Represents a type definition that has a direct native equivalent 27 | /// 28 | public class NativeTypeDef : TypeDef 29 | { 30 | /// 31 | /// The type this native type is equivalent of 32 | /// 33 | protected Type nativeType; 34 | 35 | /// 36 | /// Gets the type this native type is equivalent of 37 | /// 38 | public Type NativeType 39 | { 40 | get { return nativeType; } 41 | } 42 | 43 | /// 44 | /// Initializes a new instance of the NativeTypeDef class 45 | /// 46 | /// The type to create this native type out of 47 | public NativeTypeDef(Type type) : base(type.Name, true) 48 | { 49 | nativeType = type; 50 | } 51 | 52 | /// 53 | /// Initializes a new instance of the NativeTypeDef class 54 | /// 55 | /// The type to create this native type out of 56 | /// The usage name for the type 57 | public NativeTypeDef(Type type, string name) 58 | : base(name, true) 59 | { 60 | nativeType = type; 61 | } 62 | } 63 | } -------------------------------------------------------------------------------- /ZScript/Runtime/Typing/Elements/ObjectTypeDef.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | 22 | using ZScript.Elements; 23 | 24 | namespace ZScript.Runtime.Typing.Elements 25 | { 26 | /// 27 | /// Specifies the type for a ZObject 28 | /// 29 | public class ObjectTypeDef : NativeTypeDef, IListTypeDef 30 | { 31 | /// 32 | /// Cached object representing the type of objects subscript on this ObjectTypeDef 33 | /// 34 | private readonly OptionalTypeDef _optionalTypeDef = new OptionalTypeDef(AnyType); 35 | 36 | /// 37 | /// Gets the type of objects subscript on this ObjectTypeDef 38 | /// 39 | public TypeDef EnclosingType 40 | { 41 | get { return _optionalTypeDef; } 42 | } 43 | 44 | /// 45 | /// Gets the type accepted by the subscript of the ObjectTypeDef 46 | /// 47 | public TypeDef SubscriptType 48 | { 49 | get { return StringType; } 50 | } 51 | 52 | /// 53 | /// Initializes a new instance of the ObjectTypeDef class 54 | /// 55 | public ObjectTypeDef() : base(typeof(ZObject), "object") 56 | { 57 | 58 | } 59 | } 60 | } -------------------------------------------------------------------------------- /ZScript/Runtime/Typing/ICustomTypeSource.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | using ZScript.Runtime.Typing.Elements; 22 | 23 | namespace ZScript.Runtime.Typing 24 | { 25 | /// 26 | /// Represents a custom type source for a type provider 27 | /// 28 | public interface ICustomTypeSource 29 | { 30 | /// 31 | /// Returns whether this custom type source contains a type with a specified name 32 | /// 33 | /// The name to search the custom type 34 | /// true if this ICustomTypeSource contains the given type name; false otherwise 35 | bool HasType(string typeName); 36 | 37 | /// 38 | /// Returns a custom type on this custom type source with the given name; or null, if none exist 39 | /// 40 | /// The name to search the custom type 41 | /// A custom type from this ICustomTypeSource that matches the given name; or null, if none exist 42 | TypeDef TypeNamed(string typeName); 43 | } 44 | } -------------------------------------------------------------------------------- /ZScript/Runtime/Typing/Operators/DoubleOperator.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | using System; 22 | 23 | namespace ZScript.Runtime.Typing.Operators 24 | { 25 | /// 26 | /// Provides double precision doubleing point type operations 27 | /// 28 | public class DoubleOperator : ITypeOperator 29 | { 30 | public double Sum(double v1, double v2) 31 | { 32 | return v1 + v2; 33 | } 34 | 35 | public double Subtract(double v1, double v2) 36 | { 37 | return v1 - v2; 38 | } 39 | 40 | public double Multiply(double v1, double v2) 41 | { 42 | return v1 * v2; 43 | } 44 | 45 | public double Divide(double v1, double v2) 46 | { 47 | return v1 / v2; 48 | } 49 | 50 | public double Modulo(double v1, double v2) 51 | { 52 | return v1 % v2; 53 | } 54 | 55 | public double BitwiseAnd(double v1, double v2) 56 | { 57 | throw new InvalidOperationException("Cannot apply bitwise and to doubles"); 58 | } 59 | 60 | public double BitwiseXOr(double v1, double v2) 61 | { 62 | throw new InvalidOperationException("Cannot apply bitwise xor to doubles"); 63 | } 64 | 65 | public double BitwiseOr(double v1, double v2) 66 | { 67 | throw new InvalidOperationException("Cannot apply bitwise or to doubles"); 68 | } 69 | 70 | public double ShiftLeft(double v1, double v2) 71 | { 72 | throw new InvalidOperationException("Cannot apply shift left to doubles"); 73 | } 74 | 75 | public double ShiftRight(double v1, double v2) 76 | { 77 | throw new InvalidOperationException("Cannot apply shift right to doubles"); 78 | } 79 | 80 | public bool Greater(double v1, double v2) 81 | { 82 | return v1 > v2; 83 | } 84 | 85 | public bool GreaterOrEquals(double v1, double v2) 86 | { 87 | return v1 >= v2; 88 | } 89 | 90 | public bool Less(double v1, double v2) 91 | { 92 | return v1 < v2; 93 | } 94 | 95 | public bool LessOrEquals(double v1, double v2) 96 | { 97 | return v1 <= v2; 98 | } 99 | 100 | public bool Equals(double v1, double v2) 101 | { 102 | return v1.Equals(v2); 103 | } 104 | 105 | public double ArithmeticNegate(double v1) 106 | { 107 | return -v1; 108 | } 109 | } 110 | } -------------------------------------------------------------------------------- /ZScript/Runtime/Typing/Operators/IntegerOperator.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | namespace ZScript.Runtime.Typing.Operators 22 | { 23 | /// 24 | /// Provides integer type operations 25 | /// 26 | public class IntegerOperator : ITypeOperator 27 | { 28 | public int Sum(int v1, int v2) 29 | { 30 | return v1 + v2; 31 | } 32 | 33 | public int Subtract(int v1, int v2) 34 | { 35 | return v1 - v2; 36 | } 37 | 38 | public int Multiply(int v1, int v2) 39 | { 40 | return v1 * v2; 41 | } 42 | 43 | public int Divide(int v1, int v2) 44 | { 45 | return v1 / v2; 46 | } 47 | 48 | public int Modulo(int v1, int v2) 49 | { 50 | return v1 % v2; 51 | } 52 | 53 | public int BitwiseAnd(int v1, int v2) 54 | { 55 | return v1 & v2; 56 | } 57 | 58 | public int BitwiseXOr(int v1, int v2) 59 | { 60 | return v1 ^ v2; 61 | } 62 | 63 | public int BitwiseOr(int v1, int v2) 64 | { 65 | return v1 | v2; 66 | } 67 | 68 | public int ShiftLeft(int v1, int v2) 69 | { 70 | return v1 << v2; 71 | } 72 | 73 | public int ShiftRight(int v1, int v2) 74 | { 75 | return v1 >> v2; 76 | } 77 | 78 | public bool Greater(int v1, int v2) 79 | { 80 | return v1 > v2; 81 | } 82 | 83 | public bool GreaterOrEquals(int v1, int v2) 84 | { 85 | return v1 >= v2; 86 | } 87 | 88 | public bool Less(int v1, int v2) 89 | { 90 | return v1 < v2; 91 | } 92 | 93 | public bool LessOrEquals(int v1, int v2) 94 | { 95 | return v1 <= v2; 96 | } 97 | 98 | public bool Equals(int v1, int v2) 99 | { 100 | return v1 == v2; 101 | } 102 | 103 | public int ArithmeticNegate(int v1) 104 | { 105 | return -v1; 106 | } 107 | } 108 | } -------------------------------------------------------------------------------- /ZScript/Runtime/Typing/Operators/LongOperator.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | namespace ZScript.Runtime.Typing.Operators 22 | { 23 | /// 24 | /// Provides Int64 type operations 25 | /// 26 | public class LongOperator : ITypeOperator 27 | { 28 | public long Sum(long v1, long v2) 29 | { 30 | return v1 + v2; 31 | } 32 | 33 | public long Subtract(long v1, long v2) 34 | { 35 | return v1 - v2; 36 | } 37 | 38 | public long Multiply(long v1, long v2) 39 | { 40 | return v1 * v2; 41 | } 42 | 43 | public long Divide(long v1, long v2) 44 | { 45 | return v1 / v2; 46 | } 47 | 48 | public long Modulo(long v1, long v2) 49 | { 50 | return v1 % v2; 51 | } 52 | 53 | public long BitwiseAnd(long v1, long v2) 54 | { 55 | return v1 & v2; 56 | } 57 | 58 | public long BitwiseXOr(long v1, long v2) 59 | { 60 | return v1 ^ v2; 61 | } 62 | 63 | public long BitwiseOr(long v1, long v2) 64 | { 65 | return v1 | v2; 66 | } 67 | 68 | public long ShiftLeft(long v1, long v2) 69 | { 70 | return v1 << (int)v2; 71 | } 72 | 73 | public long ShiftRight(long v1, long v2) 74 | { 75 | return v1 >> (int)v2; 76 | } 77 | 78 | public bool Greater(long v1, long v2) 79 | { 80 | return v1 > v2; 81 | } 82 | 83 | public bool GreaterOrEquals(long v1, long v2) 84 | { 85 | return v1 >= v2; 86 | } 87 | 88 | public bool Less(long v1, long v2) 89 | { 90 | return v1 < v2; 91 | } 92 | 93 | public bool LessOrEquals(long v1, long v2) 94 | { 95 | return v1 <= v2; 96 | } 97 | 98 | public bool Equals(long v1, long v2) 99 | { 100 | return v1 == v2; 101 | } 102 | 103 | public long ArithmeticNegate(long v1) 104 | { 105 | return -v1; 106 | } 107 | } 108 | } -------------------------------------------------------------------------------- /ZScript/Runtime/ZClassInstance.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | using ZScript.Elements; 22 | using ZScript.Runtime.Execution.VirtualMemory; 23 | 24 | namespace ZScript.Runtime 25 | { 26 | /// 27 | /// Represents an instance of a ZClass 28 | /// 29 | public class ZClassInstance 30 | { 31 | /// 32 | /// The class this object is an instance of 33 | /// 34 | private readonly ZClass _class; 35 | 36 | /// 37 | /// The local memory for this class instance 38 | /// 39 | private readonly Memory _localMemory; 40 | 41 | /// 42 | /// Gets the class this object is an instance of 43 | /// 44 | public ZClass Class 45 | { 46 | get { return _class; } 47 | } 48 | 49 | /// 50 | /// Gets the local memory for this class instance 51 | /// 52 | public Memory LocalMemory 53 | { 54 | get { return _localMemory; } 55 | } 56 | 57 | /// 58 | /// Initializes a new instance of the ZClassInstance class 59 | /// 60 | /// The class this object is an instance of 61 | public ZClassInstance(ZClass zClass) 62 | { 63 | _class = zClass; 64 | _localMemory = new Memory(); 65 | 66 | // Init the local memory with null values for the variables 67 | foreach (var field in zClass.Fields) 68 | { 69 | _localMemory.SetVariable(field.Name, null); 70 | } 71 | 72 | // Init special variables 73 | _localMemory.SetVariable("this", this); 74 | } 75 | } 76 | } -------------------------------------------------------------------------------- /ZScript/Utils/ListUtils.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | using System.Collections.Generic; 22 | 23 | namespace ZScript.Utils 24 | { 25 | /// 26 | /// Collection of List utility extension methods 27 | /// 28 | public static class ListUtils 29 | { 30 | /// 31 | /// Returns whether a list contains the reference of one object in it 32 | /// 33 | /// The type of object contained in the list 34 | /// The list of items to search in 35 | /// The object to find in the list 36 | /// True if the item is in the list, false otherwise 37 | public static bool ContainsReference(this IList list, T obj) 38 | { 39 | return list.IndexOfReference(obj) != -1; 40 | } 41 | 42 | /// 43 | /// Removes an element from an array by reference and returns whether the item was in the list 44 | /// 45 | /// The type of object contained in the list 46 | /// The list of items to operate on 47 | /// The object to remove from the list 48 | /// True if the item was in the list and was removed, false otherwise 49 | public static bool RemoveReference(this IList list, T obj) 50 | { 51 | int index = list.IndexOfReference(obj); 52 | 53 | if (index == -1) 54 | return false; 55 | 56 | list.RemoveAt(index); 57 | 58 | return true; 59 | } 60 | 61 | /// 62 | /// Returns the index of the first item that matches the reference of another given object 63 | /// 64 | /// The type of object contained in the list 65 | /// The list of items to search in 66 | /// The object to find in the list 67 | /// Returns a zero-based index of the first item that matches the reference of another object, or -1, if none is found 68 | public static int IndexOfReference(this IList list, T obj) 69 | { 70 | for (int i = 0; i < list.Count; i++) 71 | { 72 | if (ReferenceEquals(list[i], obj)) 73 | return i; 74 | } 75 | 76 | return -1; 77 | } 78 | } 79 | } -------------------------------------------------------------------------------- /ZScript/ZScript.licenseheader: -------------------------------------------------------------------------------- 1 | extensions: designer.cs generated.cs 2 | extensions: .cs .cpp .h 3 | #region License information 4 | /* 5 | ZScript Game Scripting Programming Language 6 | Copyright (C) 2015 Luiz Fernando Silva 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 2.1 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library; if not, write to the Free Software 20 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 21 | */ 22 | #endregion 23 | -------------------------------------------------------------------------------- /ZScript/gen/ZScript.tokens: -------------------------------------------------------------------------------- 1 | T__0=1 2 | T__1=2 3 | T__2=3 4 | StringLiteral=4 5 | DoubleQuoteEscape=5 6 | SingleQuoteEscape=6 7 | T_EXPORT=7 8 | T_FUNCTION=8 9 | T_OVERRIDE=9 10 | T_OBJECT=10 11 | T_SEQUENCE=11 12 | T_THIS=12 13 | T_BASE=13 14 | T_VAR=14 15 | T_LET=15 16 | T_CONST=16 17 | T_NEW=17 18 | T_IS=18 19 | T_IF=19 20 | T_ELSE=20 21 | T_WHILE=21 22 | T_FOR=22 23 | T_BREAK=23 24 | T_CONTINUE=24 25 | T_SWITCH=25 26 | T_CASE=26 27 | T_DEFAULT=27 28 | T_RETURN=28 29 | T_LEFT_PAREN=29 30 | T_RIGHT_PAREN=30 31 | T_LEFT_BRACKET=31 32 | T_RIGHT_BRACKET=32 33 | T_LEFT_CURLY=33 34 | T_RIGHT_CURLY=34 35 | T_CLOSURE_RETURN=35 36 | T_CLOSURE_CALL=36 37 | T_NULL_COALESCE=37 38 | T_NULL_CONDITIONAL=38 39 | T_INT=39 40 | T_FLOAT=40 41 | T_VOID=41 42 | T_ANY=42 43 | T_STRING=43 44 | T_BOOL=44 45 | INT=45 46 | HEX=46 47 | BINARY=47 48 | FLOAT=48 49 | T_FALSE=49 50 | T_TRUE=50 51 | T_NULL=51 52 | T_QUOTES=52 53 | T_DOUBLE_QUOTES=53 54 | T_TRIPPLE_DOT=54 55 | T_DOUBLE_COLON=55 56 | T_SEMICOLON=56 57 | T_PERIOD=57 58 | T_COMMA=58 59 | T_MULT=59 60 | T_DIV=60 61 | T_MOD=61 62 | T_NOT=62 63 | T_PLUS=63 64 | T_MINUS=64 65 | T_INCREMENT=65 66 | T_DECREMENT=66 67 | T_BITWISE_AND=67 68 | T_BITWISE_XOR=68 69 | T_BITWISE_OR=69 70 | T_SHIFTLEFT=70 71 | T_SHIFTRIGHT=71 72 | T_EQUALITY=72 73 | T_UNEQUALITY=73 74 | T_MORE_THAN_OR_EQUALS=74 75 | T_LESS_THAN_OR_EQUALS=75 76 | T_MORE_THAN=76 77 | T_LESS_THAN=77 78 | T_LOGICAL_AND=78 79 | T_LOGICAL_OR=79 80 | T_EQUALS=80 81 | T_PLUS_EQUALS=81 82 | T_MINUS_EQUALS=82 83 | T_TIMES_EQUALS=83 84 | T_DIV_EQUALS=84 85 | T_MOD_EQUALS=85 86 | T_XOR_EQUALS=86 87 | T_AND_EQUALS=87 88 | T_TILDE_EQUALS=88 89 | T_OR_EQUALS=89 90 | T_SHIFTLEFT_EQUALS=90 91 | T_SHIFTRIGHT_EQUALS=91 92 | IDENT=92 93 | Whitespace=93 94 | Newline=94 95 | BlockComment=95 96 | LineComment=96 97 | ImportDirective=97 98 | 'class'=1 99 | 'typeAlias'=2 100 | '<-'=3 101 | '@'=7 102 | 'func'=8 103 | 'override'=9 104 | 'object'=10 105 | 'sequence'=11 106 | 'this'=12 107 | 'base'=13 108 | 'var'=14 109 | 'let'=15 110 | 'const'=16 111 | 'new'=17 112 | 'is'=18 113 | 'if'=19 114 | 'else'=20 115 | 'while'=21 116 | 'for'=22 117 | 'break'=23 118 | 'continue'=24 119 | 'switch'=25 120 | 'case'=26 121 | 'default'=27 122 | 'return'=28 123 | '('=29 124 | ')'=30 125 | '['=31 126 | ']'=32 127 | '{'=33 128 | '}'=34 129 | '->'=35 130 | '=>'=36 131 | '?:'=37 132 | '?'=38 133 | 'int'=39 134 | 'float'=40 135 | 'void'=41 136 | 'any'=42 137 | 'string'=43 138 | 'bool'=44 139 | 'false'=49 140 | 'true'=50 141 | 'null'=51 142 | '\''=52 143 | '"'=53 144 | '...'=54 145 | ':'=55 146 | ';'=56 147 | '.'=57 148 | ','=58 149 | '*'=59 150 | '/'=60 151 | '%'=61 152 | '!'=62 153 | '+'=63 154 | '-'=64 155 | '++'=65 156 | '--'=66 157 | '&'=67 158 | '^'=68 159 | '|'=69 160 | '=='=72 161 | '!='=73 162 | '>='=74 163 | '<='=75 164 | '>'=76 165 | '<'=77 166 | '&&'=78 167 | '||'=79 168 | '='=80 169 | '+='=81 170 | '-='=82 171 | '*='=83 172 | '/='=84 173 | '%='=85 174 | '^='=86 175 | '&='=87 176 | '~='=88 177 | '|='=89 178 | '<<='=90 179 | '>>='=91 180 | -------------------------------------------------------------------------------- /ZScript/gen/ZScriptLexer.tokens: -------------------------------------------------------------------------------- 1 | T__0=1 2 | T__1=2 3 | T__2=3 4 | StringLiteral=4 5 | DoubleQuoteEscape=5 6 | SingleQuoteEscape=6 7 | T_EXPORT=7 8 | T_FUNCTION=8 9 | T_OVERRIDE=9 10 | T_OBJECT=10 11 | T_SEQUENCE=11 12 | T_THIS=12 13 | T_BASE=13 14 | T_VAR=14 15 | T_LET=15 16 | T_CONST=16 17 | T_NEW=17 18 | T_IS=18 19 | T_IF=19 20 | T_ELSE=20 21 | T_WHILE=21 22 | T_FOR=22 23 | T_BREAK=23 24 | T_CONTINUE=24 25 | T_SWITCH=25 26 | T_CASE=26 27 | T_DEFAULT=27 28 | T_RETURN=28 29 | T_LEFT_PAREN=29 30 | T_RIGHT_PAREN=30 31 | T_LEFT_BRACKET=31 32 | T_RIGHT_BRACKET=32 33 | T_LEFT_CURLY=33 34 | T_RIGHT_CURLY=34 35 | T_CLOSURE_RETURN=35 36 | T_CLOSURE_CALL=36 37 | T_NULL_COALESCE=37 38 | T_NULL_CONDITIONAL=38 39 | T_INT=39 40 | T_FLOAT=40 41 | T_VOID=41 42 | T_ANY=42 43 | T_STRING=43 44 | T_BOOL=44 45 | INT=45 46 | HEX=46 47 | BINARY=47 48 | FLOAT=48 49 | T_FALSE=49 50 | T_TRUE=50 51 | T_NULL=51 52 | T_QUOTES=52 53 | T_DOUBLE_QUOTES=53 54 | T_TRIPPLE_DOT=54 55 | T_DOUBLE_COLON=55 56 | T_SEMICOLON=56 57 | T_PERIOD=57 58 | T_COMMA=58 59 | T_MULT=59 60 | T_DIV=60 61 | T_MOD=61 62 | T_NOT=62 63 | T_PLUS=63 64 | T_MINUS=64 65 | T_INCREMENT=65 66 | T_DECREMENT=66 67 | T_BITWISE_AND=67 68 | T_BITWISE_XOR=68 69 | T_BITWISE_OR=69 70 | T_SHIFTLEFT=70 71 | T_SHIFTRIGHT=71 72 | T_EQUALITY=72 73 | T_UNEQUALITY=73 74 | T_MORE_THAN_OR_EQUALS=74 75 | T_LESS_THAN_OR_EQUALS=75 76 | T_MORE_THAN=76 77 | T_LESS_THAN=77 78 | T_LOGICAL_AND=78 79 | T_LOGICAL_OR=79 80 | T_EQUALS=80 81 | T_PLUS_EQUALS=81 82 | T_MINUS_EQUALS=82 83 | T_TIMES_EQUALS=83 84 | T_DIV_EQUALS=84 85 | T_MOD_EQUALS=85 86 | T_XOR_EQUALS=86 87 | T_AND_EQUALS=87 88 | T_TILDE_EQUALS=88 89 | T_OR_EQUALS=89 90 | T_SHIFTLEFT_EQUALS=90 91 | T_SHIFTRIGHT_EQUALS=91 92 | IDENT=92 93 | Whitespace=93 94 | Newline=94 95 | BlockComment=95 96 | LineComment=96 97 | ImportDirective=97 98 | 'class'=1 99 | 'typeAlias'=2 100 | '<-'=3 101 | '@'=7 102 | 'func'=8 103 | 'override'=9 104 | 'object'=10 105 | 'sequence'=11 106 | 'this'=12 107 | 'base'=13 108 | 'var'=14 109 | 'let'=15 110 | 'const'=16 111 | 'new'=17 112 | 'is'=18 113 | 'if'=19 114 | 'else'=20 115 | 'while'=21 116 | 'for'=22 117 | 'break'=23 118 | 'continue'=24 119 | 'switch'=25 120 | 'case'=26 121 | 'default'=27 122 | 'return'=28 123 | '('=29 124 | ')'=30 125 | '['=31 126 | ']'=32 127 | '{'=33 128 | '}'=34 129 | '->'=35 130 | '=>'=36 131 | '?:'=37 132 | '?'=38 133 | 'int'=39 134 | 'float'=40 135 | 'void'=41 136 | 'any'=42 137 | 'string'=43 138 | 'bool'=44 139 | 'false'=49 140 | 'true'=50 141 | 'null'=51 142 | '\''=52 143 | '"'=53 144 | '...'=54 145 | ':'=55 146 | ';'=56 147 | '.'=57 148 | ','=58 149 | '*'=59 150 | '/'=60 151 | '%'=61 152 | '!'=62 153 | '+'=63 154 | '-'=64 155 | '++'=65 156 | '--'=66 157 | '&'=67 158 | '^'=68 159 | '|'=69 160 | '=='=72 161 | '!='=73 162 | '>='=74 163 | '<='=75 164 | '>'=76 165 | '<'=77 166 | '&&'=78 167 | '||'=79 168 | '='=80 169 | '+='=81 170 | '-='=82 171 | '*='=83 172 | '/='=84 173 | '%='=85 174 | '^='=86 175 | '&='=87 176 | '~='=88 177 | '|='=89 178 | '<<='=90 179 | '>>='=91 180 | -------------------------------------------------------------------------------- /ZScript/generate.cmd: -------------------------------------------------------------------------------- 1 | SET /P FILENAME=Enter the grammar file name: 2 | SET /P OUTPUTDIR=Enter the output directory: 3 | 4 | java -jar antlr-4.5-complete.jar -Dlanguage=CSharp %FILENAME% -o "%OUTPUTDIR%" 5 | pause -------------------------------------------------------------------------------- /ZScriptTests/Builders/TypeBuildingContextTests.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | using Microsoft.VisualStudio.TestTools.UnitTesting; 22 | using ZScript.Builders; 23 | 24 | namespace ZScriptTests.Builders 25 | { 26 | /// 27 | /// Tests the functionality of the TypeBuildingContext class and related components 28 | /// 29 | [TestClass] 30 | public class TypeBuildingContextTests 31 | { 32 | /// 33 | /// Tests the creation of a new TypeBuildingContext 34 | /// 35 | [TestMethod] 36 | public void TestCreateContext() 37 | { 38 | const string name = "TestAssembly"; 39 | var context = TypeBuildingContext.CreateBuilderContext(name); 40 | 41 | Assert.AreEqual(name, context.AssemblyName.Name, "The assembly failed to be generated with the expected name"); 42 | Assert.IsNotNull(context.AssemblyBuilder.FullName, "Failed to create the assembly builder as expected"); 43 | Assert.IsNotNull(context.ModuleBuilder, "Failed to create the module builder as expected"); 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /ZScriptTests/CodeGeneration/Definitions/ClassDefinitionTests.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | using Microsoft.VisualStudio.TestTools.UnitTesting; 22 | using ZScript.CodeGeneration.Definitions; 23 | using ZScript.Runtime.Typing.Elements; 24 | 25 | namespace ZScriptTests.CodeGeneration.Definitions 26 | { 27 | /// 28 | /// Tests the functionality of the ClassDefinition and related components 29 | /// 30 | [TestClass] 31 | public class ClassDefinitionTests 32 | { 33 | /// 34 | /// Tests setup of an empty class definition 35 | /// 36 | [TestMethod] 37 | public void TestEmptyDefinition() 38 | { 39 | var definition = new ClassDefinition("test1"); 40 | 41 | definition.FinishDefinition(); 42 | 43 | Assert.IsNotNull(definition.PublicConstructor, "When no constructor is provided, calling FinishDefinition() should create a new parameterless constructor"); 44 | } 45 | 46 | /// 47 | /// Tests fetching a field's information with the ClassTypeDef property 48 | /// 49 | [TestMethod] 50 | public void TestClassTypeDefField() 51 | { 52 | var definition = new ClassDefinition("test1"); 53 | 54 | definition.AddField(new TypeFieldDefinition("field1") { Type = TypeDef.IntegerType }); 55 | 56 | definition.FinishDefinition(); 57 | 58 | var classTypeDef = definition.ClassTypeDef; 59 | 60 | Assert.AreEqual(TypeDef.IntegerType, classTypeDef.GetField("field1").FieldType); 61 | } 62 | 63 | /// 64 | /// Tests fetching a method's information with the ClassTypeDef property 65 | /// 66 | [TestMethod] 67 | public void TestClassTypeDefMethod() 68 | { 69 | var definition = new ClassDefinition("test1"); 70 | 71 | definition.AddMethod(new MethodDefinition("func1", null, 72 | new[] {new FunctionArgumentDefinition {Name = "param1", Type = TypeDef.IntegerType}}) 73 | { 74 | ReturnType = TypeDef.BooleanType 75 | }); 76 | 77 | definition.FinishDefinition(); 78 | 79 | var classTypeDef = definition.ClassTypeDef; 80 | 81 | Assert.AreEqual(TypeDef.IntegerType, classTypeDef.GetMethod("func1").Parameters[0].ParameterType); 82 | Assert.AreEqual("param1", classTypeDef.GetMethod("func1").Parameters[0].ParameterName); 83 | Assert.AreEqual(TypeDef.BooleanType, classTypeDef.GetMethod("func1").ReturnType); 84 | } 85 | } 86 | } -------------------------------------------------------------------------------- /ZScriptTests/Elements/ZObjectTests.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | using System; 22 | using Microsoft.VisualStudio.TestTools.UnitTesting; 23 | using ZScript.Elements; 24 | 25 | namespace ZScriptTests.Elements 26 | { 27 | /// 28 | /// Tests the functionality of the ZObject class 29 | /// 30 | [TestClass] 31 | public class ZObjectTests 32 | { 33 | /// 34 | /// Tests the CanSubscriptWithType implementation 35 | /// 36 | [TestMethod] 37 | public void TestCanSubscriptWithType() 38 | { 39 | var obj = new ZObject(); 40 | 41 | Assert.IsTrue(obj.CanSubscriptWithIndexType(typeof(string))); 42 | Assert.IsFalse(obj.CanSubscriptWithIndexType(typeof(void))); 43 | Assert.IsFalse(obj.CanSubscriptWithIndexType(typeof(int))); 44 | } 45 | 46 | /// 47 | /// Tests subscription with ZObjects 48 | /// 49 | [TestMethod] 50 | public void TestSubcript() 51 | { 52 | var obj = new ZObject(); 53 | 54 | obj["a"] = 10; 55 | obj["b"] = "bcd"; 56 | 57 | Assert.AreEqual(10, obj["a"]); 58 | Assert.AreEqual("bcd", obj["b"]); 59 | Assert.AreEqual(null, obj["c"]); 60 | } 61 | 62 | /// 63 | /// Tests subscription with non string objects on ZObjects 64 | /// 65 | [TestMethod] 66 | [ExpectedException(typeof(ArgumentException), "Trying to subscripts a ZObjcect with a non-string value should raise an exception")] 67 | public void TestSubcriptWithNonString() 68 | { 69 | var obj = new ZObject(); 70 | obj[10] = 10; 71 | } 72 | 73 | /// 74 | /// Tests subscription with null objects on ZObjects 75 | /// 76 | [TestMethod] 77 | [ExpectedException(typeof(ArgumentNullException), "Trying to subscripts a ZObjcect with a null value should raise an exception")] 78 | public void TestSubcriptWithNullException() 79 | { 80 | var obj = new ZObject(); 81 | 82 | obj[null] = 10; 83 | } 84 | } 85 | } -------------------------------------------------------------------------------- /ZScriptTests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | using System.Reflection; 22 | using System.Runtime.CompilerServices; 23 | using System.Runtime.InteropServices; 24 | 25 | // General Information about an assembly is controlled through the following 26 | // set of attributes. Change these attribute values to modify the information 27 | // associated with an assembly. 28 | [assembly: AssemblyTitle("ZScriptTests")] 29 | [assembly: AssemblyDescription("")] 30 | [assembly: AssemblyConfiguration("")] 31 | [assembly: AssemblyCompany("")] 32 | [assembly: AssemblyProduct("ZScriptTests")] 33 | [assembly: AssemblyCopyright("Copyright © 2015")] 34 | [assembly: AssemblyTrademark("")] 35 | [assembly: AssemblyCulture("")] 36 | 37 | // Setting ComVisible to false makes the types in this assembly not visible 38 | // to COM components. If you need to access a type in this assembly from 39 | // COM, set the ComVisible attribute to true on that type. 40 | [assembly: ComVisible(false)] 41 | 42 | // The following GUID is for the ID of the typelib if this project is exposed to COM 43 | [assembly: Guid("1942a761-3183-43e1-9406-5fa07aa59f7e")] 44 | 45 | // Version information for an assembly consists of the following four values: 46 | // 47 | // Major Version 48 | // Minor Version 49 | // Build Number 50 | // Revision 51 | // 52 | // You can specify all the values or you can default the Build and Revision Numbers 53 | // by using the '*' as shown below: 54 | // [assembly: AssemblyVersion("1.0.*")] 55 | [assembly: AssemblyVersion("1.0.0.0")] 56 | [assembly: AssemblyFileVersion("1.0.0.0")] 57 | -------------------------------------------------------------------------------- /ZScriptTests/Runtime/Execution/FunctionVmNewTests.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | using System.Collections; 22 | 23 | using Microsoft.VisualStudio.TestTools.UnitTesting; 24 | using ZScript.CodeGeneration.Tokenization; 25 | using ZScript.Elements; 26 | using ZScript.Runtime.Execution; 27 | using ZScript.Runtime.Execution.VirtualMemory; 28 | using ZScriptTests.Utils; 29 | 30 | namespace ZScriptTests.Runtime.Execution 31 | { 32 | /// 33 | /// Tests usage of the New instruction on the VM 34 | /// 35 | [TestClass] 36 | public class FunctionVmNewTests 37 | { 38 | /// 39 | /// Tests the New instruction 40 | /// 41 | [TestMethod] 42 | public void TestCreateInteger() 43 | { 44 | // Create the set of tokens 45 | IntermediaryTokenList t = new IntermediaryTokenList 46 | { 47 | new Token(TokenType.String, "System.Collections.ArrayList"), 48 | new Token(TokenType.Value, 24), 49 | new Token(TokenType.Value, 1), 50 | TokenFactory.CreateInstructionToken(VmInstruction.New) 51 | }; 52 | 53 | var owner = new TestRuntimeOwner(); 54 | 55 | var tokenList = new TokenList(t); 56 | var memory = new Memory(); 57 | var context = new VmContext(memory, new IntegerMemory(), null, owner, null); // ZRuntime can be null, as long as we don't try to call a function 58 | 59 | var functionVm = new FunctionVM(tokenList, context); 60 | 61 | functionVm.Execute(); 62 | 63 | Assert.AreEqual(24, ((ArrayList)functionVm.Stack.Peek()).Capacity, 64 | "The ArrayList created should have the capacity specified by the instructions, as passed to its constructor"); 65 | 66 | Assert.IsInstanceOfType(functionVm.Stack.Peek(), typeof(ArrayList), 67 | "The New instruction failed to execute as expected"); 68 | } 69 | } 70 | } -------------------------------------------------------------------------------- /ZScriptTests/Runtime/Execution/Wrappers/Members/ZClassMemberTests.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | using Microsoft.VisualStudio.TestTools.UnitTesting; 22 | 23 | using ZScript.Runtime.Execution.Wrappers.Members; 24 | using ZScriptTests.Utils; 25 | 26 | namespace ZScriptTests.Runtime.Execution.Wrappers.Members 27 | { 28 | /// 29 | /// Tests the functionality of the ZClassMember class and related components 30 | /// 31 | [TestClass] 32 | public class ZClassMemberTests 33 | { 34 | [TestMethod] 35 | public void TestCreation() 36 | { 37 | const string memberName = "field1"; 38 | 39 | var obj = TestUtils.CreateTestClassInstance(); 40 | var wrap = new ZClassMember(obj, memberName); 41 | 42 | Assert.AreEqual(memberName, wrap.MemberName, "The member name returned by the MemberName must match the member name the ZClassMember was created with"); 43 | Assert.AreEqual(typeof(long), wrap.MemberType, "ZClassMember.MemberType must always return typeof(object)"); 44 | } 45 | 46 | [TestMethod] 47 | public void TestMemberGet() 48 | { 49 | const string memberName = "field1"; 50 | 51 | var obj = TestUtils.CreateTestClassInstance(); 52 | var wrap = new ZClassMember(obj, memberName); 53 | 54 | Assert.AreEqual(obj.LocalMemory.GetVariable(memberName), wrap.GetValue(), "The value returned by the ZClassMember must match the underlying field in the ZClassInstance"); 55 | } 56 | 57 | [TestMethod] 58 | public void TestMemberSet() 59 | { 60 | const string memberName = "field1"; 61 | 62 | var obj = TestUtils.CreateTestClassInstance(); 63 | var wrap = new ZClassMember(obj, memberName); 64 | 65 | wrap.SetValue(10); 66 | 67 | Assert.AreEqual(obj.LocalMemory.GetVariable(memberName), wrap.GetValue(), "The SetValue() method did not se the value correctly"); 68 | } 69 | } 70 | } -------------------------------------------------------------------------------- /ZScriptTests/Runtime/Execution/Wrappers/Members/ZObjectMemberTests.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | using Microsoft.VisualStudio.TestTools.UnitTesting; 22 | using ZScript.Elements; 23 | using ZScript.Runtime.Execution.Wrappers.Members; 24 | 25 | namespace ZScriptTests.Runtime.Execution.Wrappers.Members 26 | { 27 | /// 28 | /// Tests the ZObjectMember class functionality 29 | /// 30 | [TestClass] 31 | public class ZObjectMemberTests 32 | { 33 | [TestMethod] 34 | public void TestCreation() 35 | { 36 | const string memberName = "member"; 37 | 38 | var obj = new ZObject { { memberName, 10 } }; 39 | var wrap = new ZObjectMember(obj, memberName); 40 | 41 | Assert.AreEqual(memberName, wrap.MemberName, "The member name returned by the MemberName must match the member name the ZObjectMember was created with"); 42 | Assert.AreEqual(typeof(object), wrap.MemberType, "ZObjectMember.MemberType must always return typeof(object)"); 43 | } 44 | 45 | [TestMethod] 46 | public void TestMemberGet() 47 | { 48 | const string memberName = "member"; 49 | 50 | var obj = new ZObject { { memberName, 10 } }; 51 | var wrap = new ZObjectMember(obj, memberName); 52 | 53 | Assert.AreEqual(obj[memberName], wrap.GetValue(), "The value returned by the ZObjectMember must match the underlying field in the ZObject"); 54 | } 55 | 56 | [TestMethod] 57 | public void TestMemberSet() 58 | { 59 | const string memberName = "member"; 60 | 61 | var obj = new ZObject(); 62 | var wrap = new ZObjectMember(obj, memberName); 63 | 64 | wrap.SetValue(10); 65 | 66 | Assert.AreEqual(obj[memberName], wrap.GetValue(), "The SetValue() method did not se the value correctly"); 67 | } 68 | } 69 | } -------------------------------------------------------------------------------- /ZScriptTests/Runtime/Execution/Wrappers/Subscripters/PropertySubscripterWrapperTests.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | using System.Collections.Generic; 22 | using System.Linq; 23 | using System.Reflection; 24 | using Microsoft.VisualStudio.TestTools.UnitTesting; 25 | using ZScript.Runtime.Execution.Wrappers.Subscripters; 26 | 27 | namespace ZScriptTests.Runtime.Execution.Wrappers.Subscripters 28 | { 29 | /// 30 | /// Tests the functionality of the PropertySubscripterWrapper and related components 31 | /// 32 | [TestClass] 33 | public class PropertySubscripterWrapperTests 34 | { 35 | /// 36 | /// Tests the 37 | /// 38 | [TestMethod] 39 | public void TestCanSubscript() 40 | { 41 | var target = new List(); 42 | var properties = typeof(List).GetProperties(); 43 | PropertyInfo property = properties.First(p => p.GetIndexParameters().Length == 1 && p.GetIndexParameters()[0].ParameterType == typeof(int)); 44 | 45 | var wrapper = new PropertySubscripterWrapper(target, property); 46 | 47 | Assert.AreEqual(target, wrapper.Target, "The target pointed by the Target propert must be the same provided in the cosntructor"); 48 | 49 | Assert.IsTrue(wrapper.CanSubscriptWithIndexType(typeof(int))); 50 | Assert.IsFalse(wrapper.CanSubscriptWithIndexType(typeof(string))); 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /ZScriptTests/Runtime/ExportFunctionTests.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | using System.Linq; 22 | using Microsoft.VisualStudio.TestTools.UnitTesting; 23 | using ZScriptTests.Utils; 24 | 25 | namespace ZScriptTests.Runtime 26 | { 27 | /// 28 | /// Tests export function calls 29 | /// 30 | [TestClass] 31 | public class ExportFunctionTests 32 | { 33 | #region Parsing 34 | 35 | [TestMethod] 36 | public void TestExportFunctionParse() 37 | { 38 | const string input = "@f2(i)"; 39 | var generator = TestUtils.CreateGenerator(input); 40 | generator.ParseSources(); 41 | var definition = generator.GenerateRuntimeDefinition(); 42 | 43 | Assert.IsTrue(definition.ZExportFunctionDefinitions.Any(f => f.Name == "f2")); 44 | } 45 | 46 | [TestMethod] 47 | public void TestExportFunctionCallInFunctionParse() 48 | { 49 | const string input = "@f2(i:int) func f() { f2(10); }"; 50 | var generator = TestUtils.CreateGenerator(input); 51 | generator.ParseSources(); 52 | var definition = generator.GenerateRuntimeDefinition(); 53 | 54 | Assert.IsTrue(definition.ZExportFunctionDefinitions.Any(f => f.Name == "f2")); 55 | } 56 | 57 | [TestMethod] 58 | public void TestForwardExportFunctionCall() 59 | { 60 | const string input = "func f() { f2(10); } @f2(i:int)"; 61 | var generator = TestUtils.CreateGenerator(input); 62 | generator.ParseSources(); 63 | var definition = generator.GenerateRuntimeDefinition(); 64 | 65 | Assert.IsTrue(definition.ZExportFunctionDefinitions.Any(f => f.Name == "f2")); 66 | } 67 | 68 | #endregion 69 | 70 | #region Execution 71 | 72 | [TestMethod] 73 | public void TestExportFunctionCall() 74 | { 75 | const string input = "@__trace(i) func f() { __trace(10); __trace(11); }"; 76 | 77 | var owner = new TestRuntimeOwner(); 78 | var generator = TestUtils.CreateGenerator(input); 79 | generator.ParseSources(); 80 | var runtime = generator.GenerateRuntime(owner); 81 | 82 | runtime.CallFunction("f"); 83 | 84 | Assert.AreEqual(10L, owner.TraceObjects[0], "The export function was not called correctly"); 85 | Assert.AreEqual(11L, owner.TraceObjects[1], "The export function was not called correctly"); 86 | } 87 | 88 | #endregion 89 | } 90 | } -------------------------------------------------------------------------------- /ZScriptTests/Runtime/FunctionAccessTests.cs: -------------------------------------------------------------------------------- 1 | #region License information 2 | /* 3 | ZScript Game Scripting Programming Language 4 | Copyright (C) 2015 Luiz Fernando Silva 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #endregion 21 | 22 | using Microsoft.VisualStudio.TestTools.UnitTesting; 23 | 24 | using ZScriptTests.Utils; 25 | 26 | namespace ZScriptTests.Runtime 27 | { 28 | /// 29 | /// Tests the parsing and execution of function accesses 30 | /// 31 | [TestClass] 32 | public class FunctionAccessTests 33 | { 34 | /// 35 | /// Tests basic function calling 36 | /// 37 | [TestMethod] 38 | public void TestBasicFunctionCall() 39 | { 40 | const string input = "var a = ''; var b = 10; func funca(){ a = b.ToString(); }"; 41 | 42 | // Setup owner call 43 | var owner = new TestRuntimeOwner(); 44 | 45 | var generator = TestUtils.CreateGenerator(input); 46 | generator.ParseSources(); 47 | var runtime = generator.GenerateRuntime(owner); 48 | var memory = runtime.GlobalMemory; 49 | 50 | runtime.CallFunction("funca"); 51 | 52 | // Assert the correct call was made 53 | Assert.AreEqual("10", memory.GetVariable("a"), "The function call did not occur as expected"); 54 | } 55 | 56 | /// 57 | /// Tests chained function calling 58 | /// 59 | [TestMethod] 60 | public void TestChainedFunctionCall() 61 | { 62 | const string input = "var a:any?; func funca(){ a = 1234.ToString().IndexOf('4'); }"; 63 | 64 | // Setup owner call 65 | var owner = new TestRuntimeOwner(); 66 | 67 | var generator = TestUtils.CreateGenerator(input); 68 | generator.ParseSources(); 69 | var runtime = generator.GenerateRuntime(owner); 70 | var memory = runtime.GlobalMemory; 71 | 72 | runtime.CallFunction("funca"); 73 | 74 | // Assert the correct call was made 75 | Assert.AreEqual(3, memory.GetVariable("a"), "The function call did not occur as expected"); 76 | } 77 | } 78 | } -------------------------------------------------------------------------------- /ZScriptTests/ZScript.licenseheader: -------------------------------------------------------------------------------- 1 | extensions: designer.cs generated.cs 2 | extensions: .cs .cpp .h 3 | #region License information 4 | /* 5 | ZScript Game Scripting Programming Language 6 | Copyright (C) 2015 Luiz Fernando Silva 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 2.1 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library; if not, write to the Free Software 20 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 21 | */ 22 | #endregion 23 | -------------------------------------------------------------------------------- /ZScriptTests/acknowledgements.txt: -------------------------------------------------------------------------------- 1 | Rhino Mocks is using Castle Dynamic Proxy (http://www.castleproject.org/dynamicproxy/index.html) to handle proxying the types it needs to mock. 2 | The Dynamic Proxy project has been invaluable resource and made creating Rhino Mocks possible. -------------------------------------------------------------------------------- /ZScriptTests/license.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 - 2014 Mike Meisinger (mike.meisinger@gmail.com) 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | * Neither the name of Mike Meisinger nor the names of its 13 | contributors may be used to endorse or promote products derived from this 14 | software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | Copyright (c) 2005 - 2009 Ayende Rahien (ayende@ayende.com) 28 | All rights reserved. 29 | 30 | Redistribution and use in source and binary forms, with or without modification, 31 | are permitted provided that the following conditions are met: 32 | 33 | * Redistributions of source code must retain the above copyright notice, 34 | this list of conditions and the following disclaimer. 35 | * Redistributions in binary form must reproduce the above copyright notice, 36 | this list of conditions and the following disclaimer in the documentation 37 | and/or other materials provided with the distribution. 38 | * Neither the name of Ayende Rahien nor the names of its 39 | contributors may be used to endorse or promote products derived from this 40 | software without specific prior written permission. 41 | 42 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 43 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 44 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 45 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 46 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 47 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 48 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 49 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 50 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 51 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /ZScriptTests/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | --------------------------------------------------------------------------------