public static void Main(string[] args) { if (args.Length < 1) { Console.WriteLine("GSharp Compiler\r\nUsage: gsharp <file>"); } else { ProgramArguments arguments = new ProgramArguments(); arguments.Parse(args); try { GSharpModule module = GSharpModule.CompileModule(arguments.FilesToCompile[0]); VirtualMachine vm = new VirtualMachine(); if (!module.HasAttribute("main")) { throw new Exception("Entry point 'main' not found."); } else { module.GetAttribute("main").Invoke(vm, ((GSharpMethod)module.GetAttribute("main")).ParameterCount == 0 ? null : new GSharpObject[] { new GSharpString(arguments.ArgumentsToProgram) }); } } catch (Exception ex) { Console.WriteLine("Unhandled Exception:\r\n" + ex.Message); Environment.Exit(-1); } } }
public void Visit(Node node) { if (node is ClassDeclarationNode) { GSharpClass clazz = new GSharpClass(((ClassDeclarationNode)node).Name, CompileMethod(((ClassDeclarationNode)node).Constructor, true)); for (int i = 1; i < node.Children.Count; i++) { clazz.AddInstanceMethod(CompileMethod((FunctionDeclarationNode)node.Children[i], true)); } module.SetAttribute(((ClassDeclarationNode)node).Name, clazz); } else if (node is CodeBlock) { VisitSubnodes(node); } else if (node is EnumDeclarationNode) { GSharpEnum ienum = new GSharpEnum(); foreach (string name in ((EnumDeclarationNode)node).Items.Keys) { ienum.AddItem(name, ((EnumDeclarationNode)node).Items[name]); } module.SetAttribute(((EnumDeclarationNode)node).Name, ienum); } else if (node is FunctionDeclarationNode) { module.AddMethod(CompileMethod((FunctionDeclarationNode)node, false)); } else if (node is ScopeNode) { VisitSubnodes(node); } else if (node is UseNode) { GSharpModule import = GSharpModule.CompileModule(((UseNode)node).Module); if (import != null) { module.SetAttribute(((UseNode)node).Module, import); } } }