Пример #1
0
        public HassiumObject Execute(HassiumModule module, HassiumList args, Dictionary <int, HassiumObject> frame = null)
        {
            CallStack        = new LinkedStack <string>();
            CurrentModule    = module;
            ExceptionReturns = new Dictionary <HassiumMethod, int>();
            Globals          = module.BoundAttributes["__global__"].BoundAttributes;
            Handlers         = new Stack <HassiumExceptionHandler>();
            Stack            = new LinkedStack <HassiumObject>();
            StackFrame       = new StackFrame();
            ImportGlobals();

            var globalClass = module.GetAttribute(this, "__global__");

            (globalClass.GetAttribute(this, "__init__") as HassiumMethod).Invoke(this, new SourceLocation("", 0, 0));
            GlobalFrame = StackFrame.Frames.Peek();

            if (globalClass.ContainsAttribute("main"))
            {
                var mainMethod = (globalClass.GetAttribute(this, "main") as HassiumMethod);
                if (mainMethod.Parameters.Count > 0)
                {
                    mainMethod.Invoke(this, mainMethod.SourceLocation, args);
                }
                else
                {
                    mainMethod.Invoke(this, mainMethod.SourceLocation);
                }
            }

            return(lastValuePopped);
        }
Пример #2
0
 public VirtualMachine(HassiumModule module)
 {
     CallStack        = new LinkedStack <string>();
     CurrentModule    = module;
     ExceptionReturns = new Dictionary <HassiumMethod, int>();
     Globals          = module.BoundAttributes["__global__"].BoundAttributes;
     Handlers         = new Stack <HassiumExceptionHandler>();
     Stack            = new LinkedStack <HassiumObject>();
     StackFrame       = new StackFrame();
     ImportGlobals();
 }
Пример #3
0
        public HassiumMethod(HassiumModule module, string name)
        {
            BreakLabels    = new Stack <int>();
            ContinueLabels = new Stack <int>();
            Instructions   = new List <HassiumInstruction>();
            Labels         = new Dictionary <int, int>();
            Parameters     = new Dictionary <FunctionParameter, int>();

            Module = module;
            Name   = name;
            SourceRepresentation = string.Empty;

            AddType(TypeDefinition);
        }