public override Node Transform(ParseScope Scope) { ResultType = Scope.FindType(Typename); if (ResultType == null) throw new CompileError("Could not find type '" + Typename + "'.", Source); Value = Value.Transform(Scope); return this; }
public override Node Transform(ParseScope Scope) { ResultType = Scope.FindType(ResultTypename); if (ResultType == null) throw new CompileError("Could not find type '" + ResultTypename + "'.", Source); Parameters = new List<Node>(Parameters.Select(n => n.Transform(Scope))); return this; }
public override Node Transform(ParseScope Scope) { if (HasBeenTransformed) return this; Function.ResolveTypes(Scope); Function.Transform(Scope.EnvironmentContext.ID); //Shift all parameters down by one index to accomodate the RSO used to store captured variables. foreach (var variable in Function.DeclarationScope.Variables) if (variable.StorageMethod == VariableStorageMethod.Local && variable.Offset < 0) variable.Offset -= 1; Scope.AddChildLambda(Function); if (String.IsNullOrEmpty(ResultTypeName)) ResultType = Type.Generic; else { ResultType = Scope.FindType(ResultTypeName); if (ResultType == null) throw new CompileError("Could not find type '" + ResultTypeName + "'.", Source); } HasBeenTransformed = true; return this; }
public override Node Transform(ParseScope Scope) { if (String.IsNullOrEmpty(Typename)) ResultType = Type.Generic; else { ResultType = Scope.FindType(Typename); if (ResultType == null) throw new CompileError("Could not find type '" + Typename + "'.", Source); } return this; }
public override Node Transform(ParseScope Scope) { if (HasBeenTransformed) return this; ResultType = Scope.FindType("COMPLEXSTRING"); Function = new Declaration(); Function.Type = DeclarationType.Lambda; Function.Terms = new List<DeclarationTerm>(); Function.ReturnTypeName = "STRING"; Function.ReturnType = Scope.FindType("STRING"); Function.DeclarationScope = Scope.Push(ScopeType.Function); Function.DeclarationScope.Owner = Function; Pieces = new List<Node>(Pieces.Select(s => s.Transform(Function.DeclarationScope)).Where(n => n != null)); if (Pieces.Count < 1) Pieces.Insert(0, new StringLiteral(Source, "").Transform(Function.DeclarationScope)); if (Pieces.Count == 1) { Function.Body = new LambdaBlock(new Ast.Return(Source) { Value = Pieces[0] }); Function.Body.Transform(Function.DeclarationScope); } else { var stringType = Scope.FindType("STRING"); var binOp = Convert(Pieces[0], stringType, Scope); for (int i = 1; i < Pieces.Count; ++i) binOp = new RawBinaryOperator(Source, VirtualMachine.InstructionSet.ADD, binOp, Convert(Pieces[i], stringType, Function.DeclarationScope), stringType); Function.Body = new LambdaBlock(new Ast.Return(Source) { Value = binOp }); Function.Body.Transform(Function.DeclarationScope); } Scope.AddChildLambda(Function); HasBeenTransformed = true; return this; }
public override Node Transform(ParseScope Scope) { LHS = LHS.Transform(Scope); RHS = RHS.Transform(Scope); //Generics behave dynamically with operators. if (Object.ReferenceEquals(LHS.ResultType, Type.Generic) || Object.ReferenceEquals(RHS.ResultType, Type.Generic)) return new RawBinaryOperator(Source, Operator.instruction, LHS, RHS, Type.Generic); //Equality works with everything. if (Operator.token == "==" || Operator.token == "!=") return new RawBinaryOperator(Source, Operator.instruction, LHS, RHS, Scope.FindType("BOOLEAN")); if (Object.ReferenceEquals(LHS.ResultType, RHS.ResultType)) { PopulateRawOperators(); if (RawOperators.ContainsKey(LHS.ResultType.Name)) if (RawOperators[LHS.ResultType.Name].Contains(Operator.token)) { //Return type is always boolean for raw comparisons. if (Operator.token == ">" || Operator.token == ">=" || Operator.token == "<" || Operator.token == "<=") return new RawBinaryOperator(Source, Operator.instruction, LHS, RHS, Scope.FindType("BOOLEAN")); return new RawBinaryOperator(Source, Operator.instruction, LHS, RHS, LHS.ResultType); } } //Try to find an operator macro for these types. var operatorArguments = DummyArguments(Term(LHS.ResultType), Keyword(Operator.token), Term(RHS.ResultType)); var matchingOperator = Scope.FindAllPossibleMacroMatches(operatorArguments).Where(d => ExactDummyMatch(d.Terms, operatorArguments)).FirstOrDefault(); if (matchingOperator != null) { return StaticInvokation.CreateCorrectInvokationNode(Source, Scope, matchingOperator, new List<Node>(new Node[] { LHS, RHS })).Transform(Scope); } else throw new CompileError("No operator macro of the form " + LHS.ResultType.Name + " " + Operator.token + " " + RHS.ResultType.Name + " found.", Source); }
public override Node Transform(ParseScope Scope) { //var existingVariable = Scope.FindVariable(Name); //if (existingVariable != null) // throw new CompileError("A variable called '" + Name + // "' can't be defined here because it would hide a variable already defined with that name.", Source); if (String.IsNullOrEmpty(Typename)) ResultType = Type.Generic; else { ResultType = Scope.FindType(Typename); if (ResultType == null) throw new CompileError("Could not find type '" + Typename + "'.", Source); } if (Value != null) { Value = Value.Transform(Scope); if (!String.IsNullOrEmpty(Typename)) { var compatibilityResult = Type.AreTypesCompatible(Value.ResultType, ResultType, Scope); if (!compatibilityResult.Compatible) Type.ThrowConversionError(Value.ResultType, ResultType, Source); if (compatibilityResult.ConversionRequired) Value = Type.CreateConversionInvokation(Scope, compatibilityResult.ConversionMacro, Value) .Transform(Scope); } else //Infer the type of the variable from the expression assigned to it. ResultType = Value.ResultType; } Variable = Scope.NewLocal(Name.ToUpper(), ResultType); Variable.DeclaredTypeName = Typename; Variable.DeclaredType = ResultType; return this; }
public override Node Transform(ParseScope Scope) { this.Scope = Scope; ResultType = Scope.FindType(Typename); if (ResultType == null) throw new CompileError("Unable to find type with name '" + Typename + "'", Source); if (ResultType.Origin != TypeOrigin.Script) throw new CompileError("New cannot be used with primitive or system types", Source); var constructorArguments = DummyArguments(Keyword("CONSTRUCT"), Term(ResultType)); Constructor = Scope.FindAllPossibleMacroMatches(constructorArguments).Where(d => ExactDummyMatch(d.Terms, constructorArguments)).FirstOrDefault(); if (Initializers != null) { foreach (var initializer in Initializers) { initializer.ObjectType = ResultType; initializer.Transform(Scope); } } return this; }
public override Node Transform(ParseScope Scope) { ResultType = Scope.FindType("LIST"); Members = new List<Node>(Members.Select(s => s.Transform(Scope))); return this; }
public override Node Transform(ParseScope Scope) { ResultType = Scope.FindType("BOXED"); Value = Value.Transform(Scope); return this; }
public override Node Transform(ParseScope Scope) { if (Name.Type == TokenType.Identifier) { if (Name.Value.ToUpper() == "TRUE") return new Literal(Source, true, "BOOLEAN").Transform(Scope); else if (Name.Value.ToUpper() == "FALSE") return new Literal(Source, false, "BOOLEAN").Transform(Scope); else MatchedVariable = Scope.FindVariable(Name.Value.ToUpper()); if (MatchedVariable == null) throw new CompileError("Could not find variable named '" + Name.Value + "'.", Source); ResultType = MatchedVariable.DeclaredType; } else if (Name.Type == TokenType.String) return new StringLiteral(Source, Name.Value).Transform(Scope); else if (Name.Type == TokenType.Number) { ResultType = Scope.FindType("NUMBER"); } return this; }
public override Node Transform(ParseScope Scope) { Object = Object.Transform(Scope); if (IsAssignmentTarget) { if (Object.ResultType.Origin == TypeOrigin.System) { //Try to find an access macro for this type. var setterArguments = DummyArguments(Keyword("SET"), Keyword(Name), Keyword("ON"), Term(Object.ResultType), Keyword("TO"), TermOfAnyType()); var matchingSetter = Scope.FindAllPossibleMacroMatches(setterArguments).Where(d => ExactDummyMatch(d.Terms, setterArguments)).FirstOrDefault(); if (matchingSetter != null) return new ExplicitSetter(Source, matchingSetter, Object).Transform(Scope); else { setterArguments = DummyArguments(Keyword("SET"), Term(Scope.FindType("STRING")), Keyword("ON"), Term(Object.ResultType), Keyword("TO"), TermOfAnyType()); matchingSetter = Scope.FindAllPossibleMacroMatches(setterArguments).Where(d => ExactDummyMatch(d.Terms, setterArguments)).FirstOrDefault(); if (matchingSetter != null) return new GenericSetter(Source, matchingSetter, Name, Object).Transform(Scope); else throw new CompileError("No macro of the form SET " + Name + " ON " + Object.ResultType.Name + " TO VALUE found.", Source); } } else if (Object.ResultType.Origin == TypeOrigin.Script) return new StaticMemberAccess(Source) { MemberName = Name, Object = Object }.Transform(Scope); else throw new CompileError("Can't assign to this target", Source); } else { if (Object.ResultType.Origin == TypeOrigin.System) { //Try to find an access macro for this type. var getterArguments = DummyArguments(Keyword("GET"), Keyword(Name), Keyword("FROM"), Term(Object.ResultType)); var matchingGetter = Scope.FindAllPossibleMacroMatches(getterArguments).Where(d => ExactDummyMatch(d.Terms, getterArguments)).FirstOrDefault(); if (matchingGetter != null) return StaticInvokation.CreateCorrectInvokationNode(Source, Scope, matchingGetter, new List<Node>(new Node[] { Object })).Transform(Scope); else { getterArguments = DummyArguments(Keyword("GET"), Term(Scope.FindType("STRING")), Keyword("FROM"), Term(Object.ResultType)); matchingGetter = Scope.FindAllPossibleMacroMatches(getterArguments).Where(d => ExactDummyMatch(d.Terms, getterArguments)).FirstOrDefault(); if (matchingGetter != null) return StaticInvokation.CreateCorrectInvokationNode(Source, Scope, matchingGetter, new List<Node>(new Node[] { new Ast.StringLiteral(Source, Name), Object })).Transform(Scope); else throw new CompileError("No macro of the form GET " + Name + " FROM " + Object.ResultType.Name + " found.", Source); } } else if (Object.ResultType.Origin == TypeOrigin.Script) return new StaticMemberAccess(Source) { MemberName = Name, Object = Object }.Transform(Scope); else if (Object.ResultType.Origin == TypeOrigin.Primitive) throw new CompileError("Can't access members of primitives.", Source); else throw new CompileError("Impossible.", Source); } }
public override Node Transform(ParseScope Scope) { ResultType = Scope.FindType("STRING"); return this; }