Example #1
0
        public Image(string manifestName, ref Function entryPoint)
        {
            this.ManifestName      = manifestName;
            this.EntryPointPointer = entryPoint;
            this.CacheTable        = new CacheTable();

            AddFunction(manifestName, entryPoint);
        }
Example #2
0
 public static void Throw(CacheTable inner)
 {
     if (TryScopeTarget != null)
     {
         Runtime.ProgramCounter = (int)TryScopeTarget - 1;
         Runtime.Stack.Push(inner);
         return;
     }
     Console.WriteLine("BasePanic[{2}: {3}]: {0}\nTrace:\n   at: {1}", inner["msg"], Trace.Count == 0 ? "$(No Trace)" : string.Join("\n   in: ", Trace), inner["type"], inner["code"]);
     Environment.Exit((int)inner["code"]);
 }
Example #3
0
        public void InitializeBuiltIn()
        {
            // BasePanic
            CacheTable.Add("basepanic",
                           new Obj
            {
                Ctor = Function.New
                       (
                    4,
                    Instruction.New(Runtime.LoadFromArgs, 0),
                    Instruction.New(Runtime.LoadFromArgs, 1),
                    Instruction.New(Runtime.StoreGlobal, "msg"),
                    Instruction.New(Runtime.LoadFromArgs, 0),
                    Instruction.New(Runtime.LoadFromArgs, 2),
                    Instruction.New(Runtime.StoreGlobal, "code"),
                    Instruction.New(Runtime.LoadFromArgs, 0),
                    Instruction.New(Runtime.LoadFromArgs, 3),
                    Instruction.New(Runtime.StoreGlobal, "type"),
                    Instruction.New(Runtime.Return)
                       ),
                CacheTable = new CacheTable(new Dictionary <string, object>()
                {
                    { "$", "basepanic" },
                    { "msg", null },
                    { "code", null },
                    { "type", null },
                    { "throw()",
                      Function.New
                      (
                          1,
                          Instruction.New(Runtime.LoadFromArgs, 0),
                          Instruction.New(Runtime.RvmThrow),
                          Instruction.New(Runtime.Return)
                      ) },
                    { "tostr()",
                      Function.New
                      (
                          1,
                          Instruction.New(Extensions.SysPanic_ToString),
                          Instruction.New(Runtime.Return)
                      ) },
                    { "clone()",
                      Function.New
                      (
                          1,
                          Instruction.New(Extensions.Sys_Clone),
                          Instruction.New(Runtime.Return)
                      ) },
                })
            });

            // Vec
            CacheTable.Add("vec",
                           new Obj
            {
                Ctor = Function.New
                           (0,
                           Instruction.New(Runtime.Return)
                           ),
                CacheTable = new CacheTable(new Dictionary <string, object>()
                {
                    { "$", "vec" },
                    { "ptr", null },
                    { "tostr()",
                      Function.New
                      (
                          1,
                          Instruction.New(Extensions.SysVec_ToString),
                          Instruction.New(Runtime.Return)
                      ) },
                    { "len()",
                      Function.New
                      (
                          1,
                          Instruction.New(Extensions.SysVec_Len),
                          Instruction.New(Runtime.Return)
                      ) },
                    { "get(.)",
                      Function.New
                      (
                          2,
                          Instruction.New(Extensions.SysVec_GetValue),
                          Instruction.New(Runtime.Return)
                      ) },
                    { "has(.)",
                      Function.New
                      (
                          2,
                          Instruction.New(Extensions.SysVec_Find),
                          Instruction.New(Runtime.Return)
                      ) },
                    { "add(.)",
                      Function.New
                      (
                          2,
                          Instruction.New(Extensions.SysVec_Concat),
                          Instruction.New(Runtime.Return)
                      ) },
                    { "clear()",
                      Function.New
                      (
                          1,
                          Instruction.New(Extensions.SysVec_Clear),
                          Instruction.New(Runtime.Return)
                      ) },
                    { "clone()",
                      Function.New
                      (
                          1,
                          Instruction.New(Extensions.Sys_Clone),
                          Instruction.New(Runtime.Return)
                      ) },
                    { "addat(..)",
                      Function.New
                      (
                          3,
                          Instruction.New(Extensions.SysVec_Insert),
                          Instruction.New(Runtime.Return)
                      ) },
                })
            });
        }