示例#1
0
        private GSharpMethod CompileMethod(FunctionDeclarationNode funcDecl, bool isInstanceMethod)
        {
            symbolTable.CurrentScope = symbolTable.CurrentScope.ChildScopes[currentScope++];
            GSharpMethod     methodBuilder = new GSharpMethod(funcDecl.Name, funcDecl.Parameters.Count, symbolTable.CurrentScope.SymbolCount, module);
            FunctionCompiler compiler      = new FunctionCompiler(symbolTable, methodBuilder);

            for (int i = 0; i < funcDecl.Parameters.Count; i++)
            {
                methodBuilder.Parameters[funcDecl.Parameters[i]] = symbolTable.GetSymbol(funcDecl.Parameters[i]).Index;
            }
            methodBuilder.IsInstanceMethod = isInstanceMethod;
            compiler.Visit(funcDecl.Children[0]);
            symbolTable.CurrentScope = symbolTable.CurrentScope.ParentScope;
            methodBuilder.EmitInstruction(OperationCode.LoadNull);
            methodBuilder.FinalizeLabels();
            return(methodBuilder);
        }
示例#2
0
 public FunctionCompiler(SymbolTable symbolTable, GSharpMethod methodBuilder)
 {
     this.symbolTable   = symbolTable;
     this.methodBuilder = methodBuilder;
 }
示例#3
0
 public GSharpClass(string name, GSharpMethod constructor) : base(name)
 {
     this.constructor = constructor;
 }
示例#4
0
 public void AddInstanceMethod(GSharpMethod method)
 {
     instanceMethods.Add(method);
 }