public static void WrappedMain(string[] args) { CodeGenerator.module = LLVM.ModuleCreateWithName("psi.result"); // primitives TypeMapper.Add(typeof(bool), BuiltinType.Boolean); TypeMapper.Add(typeof(byte), BuiltinType.Byte); TypeMapper.Add(typeof(long), BuiltinType.Integer); TypeMapper.Add(typeof(ulong), BuiltinType.UnsignedInteger); TypeMapper.Add(typeof(double), BuiltinType.Real); TypeMapper.Add(typeof(string), BuiltinType.String); TypeMapper.Add(typeof(int), BuiltinType.Character); // required types TypeMapper.Add(typeof(void), Type.VoidType); TypeMapper.Add(typeof(Type), Type.MetaType); TypeMapper.Add(typeof(Intermediate.Module), Type.ModuleType); var std = CreateStd(); var syntaxModule = Load("../Sources/CompilerTest.psi"); if (syntaxModule == null) { Console.WriteLine("Failed to parse!"); return; } var printer = new ModulePrinter(Console.Out); printer.Print(syntaxModule); var declarableGlobalScope = new SimpleScope { new Symbol(Type.ModuleType, "std") { Initializer = new ModuleLiteral(std), IsConst = true, IsExported = false } }; InitializeGlobalOperators(declarableGlobalScope); // TODO: Add "linked libraries" to declarableGlobalScope var globalScope = new StackableScope(); globalScope.Push(new AutoGlobalScope()); globalScope.Push(declarableGlobalScope); var astConverter = new ASTConverter(globalScope); astConverter.AddModule(syntaxModule); astConverter.Convert(); var output = astConverter.GetModule(syntaxModule); CodeGenerator.GenerateIL(output); }
public static IScope ParseScope(ParseContext context, IAstNode parent, bool allowsSimpleScope, string terminatingKeyword) { TokenStream <RToken> tokens = context.Tokens; IScope scope; if (tokens.CurrentToken.TokenType == RTokenType.OpenCurlyBrace) { scope = new Scope(string.Empty); if (scope.Parse(context, parent)) { return(scope); } } else if (allowsSimpleScope) { // Try simple on-line scope as in 'for(...) statement # comment' scope = new SimpleScope(terminatingKeyword); if (scope.Parse(context, parent)) { return(scope); } } else { context.AddError(new MissingItemParseError(ParseErrorType.OpenCurlyBraceExpected, tokens.PreviousToken)); } return(null); }
public void ToComplexEntity_WhenSimpleEntity_ExpectMapSuccess() { // Arrange var mockPropertyMapper = new Mock<IPropertyGetSettersTyped<Scope>>(); mockPropertyMapper.Setup(r => r.GetSetters(It.IsAny<Type>())) .Returns(new Dictionary<string, TypedSetter<Scope>>()); var scopeMappers = new ScopeMappers<Scope>(mockPropertyMapper.Object); var scopeClaim = new ScopeClaim("Name", true) { Description = "Description" }; var secret = new Secret("Value", "Description", new DateTimeOffset(new DateTime(2016, 1, 1))) { Type = "Type" }; var simpleScope = new SimpleScope { Claims = new List<ScopeClaim> { scopeClaim }, Type = ScopeType.Identity, Enabled = true, AllowUnrestrictedIntrospection = true, ScopeSecrets = new List<Secret> { secret }, DisplayName = "DisplayName", Emphasize = true, ClaimsRule = "ClaimsRule", IncludeAllClaimsForUser = true, Name = "Name", Required = true, ShowInDiscoveryDocument = true, Description = "Description" }; // Act var stopwatch = Stopwatch.StartNew(); var complexEntity = scopeMappers.ToComplexEntity(simpleScope); stopwatch.Stop(); // Assert this.WriteTimeElapsed(stopwatch); Assert.That(complexEntity, Is.Not.Null); Assert.That(complexEntity.Claims, Is.Not.Null); Assert.That(complexEntity.Claims.Count, Is.EqualTo(1)); Assert.That(complexEntity.Type, Is.EqualTo(ScopeType.Identity)); Assert.That(complexEntity.Enabled, Is.True); Assert.That(complexEntity.AllowUnrestrictedIntrospection, Is.True); Assert.That(complexEntity.ScopeSecrets, Is.Not.Null); Assert.That(complexEntity.ScopeSecrets.Count, Is.EqualTo(1)); Assert.That(complexEntity.DisplayName, Is.EqualTo("DisplayName")); Assert.That(complexEntity.Emphasize, Is.True); Assert.That(complexEntity.ClaimsRule, Is.EqualTo("ClaimsRule")); Assert.That(complexEntity.IncludeAllClaimsForUser, Is.True); Assert.That(complexEntity.Name, Is.EqualTo("Name")); Assert.That(complexEntity.Required, Is.True); Assert.That(complexEntity.ShowInDiscoveryDocument, Is.True); Assert.That(complexEntity.Description, Is.EqualTo("Description")); }
public static Symbol AddOperator(this SimpleScope scope, PsiOperator op, FunctionType type) { var sym = new Symbol(type, op) { Initializer = new Intermediate.FunctionLiteral(new BuiltinFunction(type)), IsConst = true, IsExported = false, Kind = SymbolKind.Builtin }; scope.Add(sym); return(sym); }
private static void InitializeGlobalOperators(SimpleScope scope) { // Initialize numeric types foreach (var type in new[] { BuiltinType.Byte, BuiltinType.Integer, BuiltinType.UnsignedInteger, BuiltinType.Real }) { scope.AddOperator(PsiOperator.Plus, FunctionType.CreateUnaryOperator(type)); scope.AddOperator(PsiOperator.Minus, FunctionType.CreateUnaryOperator(type)); scope.AddOperator(PsiOperator.Plus, FunctionType.CreateBinaryOperator(type)); scope.AddOperator(PsiOperator.Minus, FunctionType.CreateBinaryOperator(type)); scope.AddOperator(PsiOperator.Multiply, FunctionType.CreateBinaryOperator(type)); scope.AddOperator(PsiOperator.Divide, FunctionType.CreateBinaryOperator(type)); scope.AddOperator(PsiOperator.Modulo, FunctionType.CreateBinaryOperator(type)); scope.AddOperator(PsiOperator.Equals, FunctionType.CreateBinaryOperator(BuiltinType.Boolean, type)); scope.AddOperator(PsiOperator.NotEquals, FunctionType.CreateBinaryOperator(BuiltinType.Boolean, type)); scope.AddOperator(PsiOperator.Less, FunctionType.CreateBinaryOperator(BuiltinType.Boolean, type)); scope.AddOperator(PsiOperator.LessOrEqual, FunctionType.CreateBinaryOperator(BuiltinType.Boolean, type)); scope.AddOperator(PsiOperator.More, FunctionType.CreateBinaryOperator(BuiltinType.Boolean, type)); scope.AddOperator(PsiOperator.MoreOrEqual, FunctionType.CreateBinaryOperator(BuiltinType.Boolean, type)); } // Initialize integral types foreach (var type in new[] { BuiltinType.Byte, BuiltinType.Integer, BuiltinType.UnsignedInteger }) { scope.AddOperator(PsiOperator.Invert, FunctionType.CreateUnaryOperator(type)); scope.AddOperator(PsiOperator.And, FunctionType.CreateBinaryOperator(type)); scope.AddOperator(PsiOperator.Or, FunctionType.CreateBinaryOperator(type)); scope.AddOperator(PsiOperator.Xor, FunctionType.CreateBinaryOperator(type)); scope.AddOperator(PsiOperator.ShiftRight, FunctionType.CreateBinaryOperator(type)); scope.AddOperator(PsiOperator.ArithmeticShiftRight, FunctionType.CreateBinaryOperator(type)); } // Initialize real type { scope.AddOperator(PsiOperator.Exponentiate, FunctionType.CreateBinaryOperator(BuiltinType.Real)); } // Initialize boolean type { scope.AddOperator(PsiOperator.Invert, FunctionType.CreateUnaryOperator(BuiltinType.Boolean)); scope.AddOperator(PsiOperator.And, FunctionType.CreateBinaryOperator(BuiltinType.Boolean)); scope.AddOperator(PsiOperator.Or, FunctionType.CreateBinaryOperator(BuiltinType.Boolean)); scope.AddOperator(PsiOperator.Xor, FunctionType.CreateBinaryOperator(BuiltinType.Boolean)); } }