Ejemplo n.º 1
0
		public override void Accept (FunctionDeclaration funcDecl)
		{
			symbolTable.NextScope ();
			IodineMethod anonMethod = new IodineMethod (methodBuilder, methodBuilder.Module, null, funcDecl.InstanceMethod, 
				                          funcDecl.Parameters.Count, methodBuilder.LocalCount);
			FunctionCompiler compiler = new FunctionCompiler (symbolTable, anonMethod);
			for (int i = 0; i < funcDecl.Parameters.Count; i++) {
				anonMethod.Parameters [funcDecl.Parameters [i]] = symbolTable.GetSymbol
					(funcDecl.Parameters [i]).Index;
			}
			funcDecl.Children [0].Visit (compiler);
			anonMethod.EmitInstruction (funcDecl.Location, Opcode.LoadNull);
			anonMethod.Variadic = funcDecl.Variadic;
			anonMethod.AcceptsKeywordArgs = funcDecl.AcceptsKeywordArgs;
			anonMethod.FinalizeLabels ();
			methodBuilder.EmitInstruction (funcDecl.Location, Opcode.LoadConst,
				methodBuilder.Module.DefineConstant (anonMethod));
			methodBuilder.EmitInstruction (funcDecl.Location, Opcode.BuildClosure);
			methodBuilder.EmitInstruction (funcDecl.Location, Opcode.StoreLocal, symbolTable.GetSymbol (funcDecl.Name).Index);
			symbolTable.LeaveScope ();
		}
Ejemplo n.º 2
0
		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 ();
		}
Ejemplo n.º 3
0
 private IodineMethod compileMethod(FunctionDeclaration funcDecl)
 {
     symbolTable.NextScope ();
     IodineMethod methodBuilder = new IodineMethod (module, funcDecl.Name, funcDecl.InstanceMethod,
                                      funcDecl.Parameters.Count,
                                      symbolTable.CurrentScope.SymbolCount);
     FunctionCompiler compiler = new FunctionCompiler (errorLog, symbolTable,
                                     methodBuilder);
     methodBuilder.Variadic = funcDecl.Variadic;
     methodBuilder.AcceptsKeywordArgs = funcDecl.AcceptsKeywordArgs;
     for (int i = 0; i < funcDecl.Parameters.Count; i++) {
         methodBuilder.Parameters [funcDecl.Parameters [i]] = symbolTable.GetSymbol
             (funcDecl.Parameters [i]).Index;
     }
     funcDecl.Children [0].Visit (compiler);
     methodBuilder.EmitInstruction (Opcode.LoadNull);
     methodBuilder.FinalizeLabels ();
     symbolTable.LeaveScope ();
     return methodBuilder;
 }