Пример #1
0
 public void AddLabel(string label, int instructionIndex)
 {
     if (!_labels.TryAdd(label, instructionIndex))
     {
         BasePanic.Throw($"Already define label `{label}` as {_labels[label]}: `{Instructions[_labels[label]].FunctionPointer.Method.Name}`", 2, "PreRuntime");
     }
 }
Пример #2
0
 public void AddGlobal(string id, object global)
 {
     if (!this.CacheTable.TryAdd(id, global))
     {
         BasePanic.Throw($"Already defined global variable `{id}`", 18, "Runtime");
     }
 }
Пример #3
0
 public object Pop()
 {
     if (VirtualStack.Count == 0)
     {
         BasePanic.Throw("Empty stack", 13, "Runtime");
     }
     var x0 = VirtualStack[^ 1];
Пример #4
0
 public object FindGlobal(string id)
 {
     if (CacheTable.TryGetValue(id, out object value))
     {
         return((Function)value);
     }
     BasePanic.Throw($"Undefined global variable `{id}`", 22, "Runtime");
     return(null);
 }
Пример #5
0
 public Obj FindObj(string id)
 {
     if (CacheTable.TryGetValue(id, out object value))
     {
         return((Obj)value);
     }
     BasePanic.Throw($"Undefined obj `{id}`", 23, "Runtime");
     return((Obj) new object());
 }
Пример #6
0
 public Function FindFunction(string id)
 {
     if (CacheTable.TryGetValue(id, out object value))
     {
         return((Function)value);
     }
     BasePanic.Throw($"Undefined function `{id}`", 24, "Runtime");
     return((Function) new object());
 }
Пример #7
0
 public int FindLabel(string label)
 {
     if (_labels.TryGetValue(label, out int ret))
     {
         return(ret);
     }
     BasePanic.Throw($"Undefine label `{label}`", 3, "Runtime");
     return(0);
 }
Пример #8
0
 public void AddFunction(string id, Function function)
 {
     if (function.UninstantiatedLabels())
     {
         BasePanic.Throw($"Uninstantiated labels table in function `{id}`, instantiate it in this way: `new Function(instructions: null) {{/*body*/}}", 21, "PreRuntime");
     }
     if (!this.CacheTable.TryAdd(id, function))
     {
         BasePanic.Throw($"Already defined function `{id}`", 20, "Runtime");
     }
 }
Пример #9
0
 public void AddObj(string id, Obj @object)
 {
     @object.CacheTable.TryAdd("$", id);
     if (@object.Ctor == null)
     {
         BasePanic.Throw($"Obj `{id}` does not contain a definition for ctor function", 19, "PreRuntime");
     }
     if (!this.CacheTable.TryAdd(id, @object))
     {
         BasePanic.Throw($"Already defined obj `{id}`", 18, "Runtime");
     }
 }
Пример #10
0
 public static T Cast <T>(this object self)
 {
     if (self is not T)
     {
         var inner = Runtime.RuntimeImage.FindObj("basepanic").Copy().CacheTable;
         inner["msg"]  = $"Tryed to cast {self.GetType()} to {typeof(T)}";
         inner["code"] = 41;
         inner["type"] = "CastException";
         BasePanic.Throw(inner);
     }
     return((T)self);
 }
Пример #11
0
 public object FindArgument(byte index)
 {
     if (_arguments is null)
     {
         BasePanic.Throw($"Insufficient function arguments, have not been passed {index+1} argument/s", 4, "Runtime");
     }
     if (index < 0)
     {
         BasePanic.Throw("Can not index function argument with a negative index", 5, "Runtime");
     }
     if (index < _arguments.Count)
     {
         return(_arguments[index]);
     }
     BasePanic.Throw($"Insufficient function arguments, have not been passed {index+1} argument/s", 6, "Runtime");
     return(null);
 }