Beispiel #1
0
 private static AstNode ParseWhen(TokenStream stream)
 {
     WhenStatement caseStmt = new WhenStatement (stream.Location);
     stream.Expect (TokenClass.Keyword, "when");
     AstNode value = ParseExpression (stream);
     AstNode body = ParseStatement (stream);
     AstNode lambda = new LambdaExpression (body.Location, false, false, false,
         new System.Collections.Generic.List<string> ());
     lambda.Add (body);
     caseStmt.Add (value);
     caseStmt.Add (lambda);
     return caseStmt;
 }
Beispiel #2
0
        private static AstNode ParseLambda(TokenStream stream)
        {
            stream.Expect (TokenClass.Keyword, "lambda");
            bool isInstanceMethod;
            bool isVariadic;
            bool acceptsKwargs;

            List<string> parameters = ParseFuncParameters (stream,
                out isInstanceMethod,
                out isVariadic,
                out acceptsKwargs);

            LambdaExpression decl = new LambdaExpression (stream.Location, isInstanceMethod, isVariadic, acceptsKwargs, parameters);
            if (stream.Accept (TokenClass.Operator, "=>"))
                decl.Add (new ReturnStatement (stream.Location, ParseExpression (stream)));
            else
                decl.Add (ParseStatement (stream));
            return decl;
        }
		public override void Accept (LambdaExpression lambda)
		{
			symbolTable.NextScope ();

			int locals = methodBuilder.LocalCount > 0 ? methodBuilder.LocalCount : symbolTable.CurrentScope.SymbolCount;
			IodineMethod anonMethod = new IodineMethod (methodBuilder, methodBuilder.Module, null, lambda.InstanceMethod, 
				                          lambda.Parameters.Count, locals);
			FunctionCompiler compiler = new FunctionCompiler (symbolTable, anonMethod);
			for (int i = 0; i < lambda.Parameters.Count; i++) {
				anonMethod.Parameters [lambda.Parameters [i]] = symbolTable.GetSymbol
					(lambda.Parameters [i]).Index;
			}
			lambda.Children [0].Visit (compiler);
			anonMethod.EmitInstruction (lambda.Location, Opcode.LoadNull);
			anonMethod.Variadic = lambda.Variadic;
			anonMethod.FinalizeLabels ();
			methodBuilder.EmitInstruction (lambda.Location, Opcode.LoadConst,
				methodBuilder.Module.DefineConstant (anonMethod));
			if (methodBuilder.LocalCount > 0) {
				methodBuilder.EmitInstruction (lambda.Location, Opcode.BuildClosure);
			}
			symbolTable.LeaveScope ();
		}
Beispiel #4
0
 public void Accept(LambdaExpression lambda)
 {
     lambda.Visit (functionCompiler);
 }
		public override void Accept (LambdaExpression lambda)
		{
			lambda.Visit (parentVisitor);
		}
 public virtual void Accept(LambdaExpression lambda)
 {
 }
Beispiel #7
0
 public void Accept(LambdaExpression lambda)
 {
     symbolTable.BeginScope ();
     foreach (string param in lambda.Parameters) {
         symbolTable.AddSymbol (param);
     }
     FunctionAnalyser visitor = new FunctionAnalyser (errorLog, symbolTable);
     lambda.Children [0].Visit (visitor);
     symbolTable.EndScope ();
 }