private HassiumModule resolveModuleFromDll(string path) { var module = new HassiumModule(); var ass = Assembly.LoadFrom(path); foreach (var type in ass.GetTypes()) { if (type.IsSubclassOf(typeof(InternalModule))) { foreach (var pair in ((InternalModule)Activator.CreateInstance(type)).BoundAttributes) { module.AddAttribute(pair.Key, pair.Value); } } } return(module); }
public static void EnforceCasing(HassiumModule module, SourceLocation location, string identifier, HassiumCasingType casing) { if (CheckCasing(identifier, casing)) { return; } switch (casing) { case HassiumCasingType.Camel: module.AddWarning(location, "Expected casing type 'camelCase'!"); break; case HassiumCasingType.Lower: module.AddWarning(location, "Expected casing type 'lowercase' for locals, funcs, and properties!"); break; case HassiumCasingType.Pascal: module.AddWarning(location, "Expected casing type 'PascalCase' for classes, traits, and enums!"); break; } }
public HassiumModule Compile(AstNode ast, HassiumModule module = null) { methodStack = new Stack <HassiumMethod>(); classStack = new Stack <HassiumClass>(); table = new SymbolTable(); this.module = module == null ? new HassiumModule() : module; classStack.Push(new HassiumClass("__global__")); methodStack.Push(new HassiumMethod(module, "__init__") { Parent = classStack.Peek() }); ast.Visit(this); var globalClass = classStack.Pop(); globalClass.AddAttribute("__init__", methodStack.Pop()); this.module.AddAttribute("__global__", globalClass); return(this.module); }
public static void Run(HassiumConfig config) { HassiumModule module = new HassiumModule(); module.AddAttribute("__global__", new HassiumClass("__global__")); var attribs = new Dictionary <string, HassiumObject>(); VirtualMachine vm = new VirtualMachine(module); while (true) { Console.Write("(1)> "); string code = Console.ReadLine(); try { // Read var tokens = new Scanner().Scan("stdin", code); // If we missed a closing ), }, or ], keep reading and appending lines until the code is good. int line = 2; while (countOpenTokens(tokens) > countCloseTokens(tokens)) { Console.Write("({0})> ", line++); string temp = Console.ReadLine(); foreach (var token in new Scanner().Scan("stdin", temp)) { tokens.Add(token); } code += temp + System.Environment.NewLine; } var ast = new Parser().Parse(tokens); module = new HassiumCompiler(config.SuppressWarnings).Compile(ast, module); // Import foreach (var attrib in module.BoundAttributes["__global__"].BoundAttributes) { if (attribs.ContainsKey(attrib.Key)) { attribs.Remove(attrib.Key); } attribs.Add(attrib.Key, attrib.Value); } module.BoundAttributes["__global__"].BoundAttributes = attribs; var init = (module.BoundAttributes["__global__"].BoundAttributes["__init__"] as HassiumMethod); init.Module = module; // Eval vm.ImportGlobals(); var ret = vm.ExecuteMethod(init); // PrintLine if (!(ret is HassiumNull)) { Console.WriteLine(ret.ToString(vm, ret, vm.CurrentSourceLocation).String); } else { Console.WriteLine(); } } catch (CompilerException ex) { Console.WriteLine(ex.Message); if (config.Dev) { Console.WriteLine(ex); } } catch (ParserException ex) { Console.WriteLine(ex.Message); if (config.Dev) { Console.WriteLine(ex); } } catch (ScannerException ex) { Console.WriteLine(ex.Message); if (config.Dev) { Console.WriteLine(ex); } } catch (UnhandledException ex) { Console.WriteLine("Unhandled Exception:"); Console.WriteLine(ex.Message); Console.WriteLine("\nNear:"); ex.SourceLocation.PrintLocation(new System.IO.MemoryStream(System.Text.Encoding.ASCII.GetBytes(code))); Console.WriteLine(ex.CallStack); } } }