/// <summary> /// Generates the static main function and parameters. /// </summary> /// <returns>a type array</returns> private Expr GenerateMainMethod( TypeBuilder typeBuilder, BlockDeclExpr functionDecl, List<Expr> parameters, Expr mainFunctionParameters, out MethodBuilder methodBuilder) { methodBuilder = null; if (parameters != null && parameters.Count == 1) { mainFunctionParameters = parameters[0]; Type[] t = GetFunctionParameterTypes(mainFunctionParameters); methodBuilder = typeBuilder.DefineMethod(functionDecl.FunctionName, MethodAttributes.HideBySig | MethodAttributes.Static | MethodAttributes.Public, typeof(void), t); //new Type[] { typeof(string[]) }); // generate the IL for the Main method ILGenerator ilGenerator = methodBuilder.GetILGenerator(); ilGenerator.EmitWriteLine("this is the main method"); ilGenerator.Emit(OpCodes.Ret); } return mainFunctionParameters; }
private void ParseProgramName() { SymbolTable st = SymbolTable.CreateInstance(); try { Token token = _scanner.GetToken(); if (token.IsIdentifier() && token.IsIdentifierProgram()) { Token temp = _scanner.GetToken(); if ((token.IsIdentifier() && token.IsReserverdWord()) && (temp.IsIdentifier() && !temp.IsReserverdWord())) { var bde = new BlockDeclExpr {FunctionName = GlobalScope}; var pde = new ProgramDeclBlock(temp); st.AddTokenToScope(bde, pde); if (_scanner.Peek().Kind == ByteCodeIdentifiers.TokenCode.LBracket) { _scanner.GetToken(); _expressionScopeStack.Push(pde); } else { throw new NireExecutionException("No beginnning left bracket"); } } else { throw new Exception("no program statement"); } } else { _bIsErrors = true; _compileErrorList.Add(string.Format("There is no program name define")); } } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex.ToString()); _bIsErrors = true; } }