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"); } }
public void AddGlobal(string id, object global) { if (!this.CacheTable.TryAdd(id, global)) { BasePanic.Throw($"Already defined global variable `{id}`", 18, "Runtime"); } }
public object Pop() { if (VirtualStack.Count == 0) { BasePanic.Throw("Empty stack", 13, "Runtime"); } var x0 = VirtualStack[^ 1];
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); }
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()); }
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()); }
public int FindLabel(string label) { if (_labels.TryGetValue(label, out int ret)) { return(ret); } BasePanic.Throw($"Undefine label `{label}`", 3, "Runtime"); return(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"); } }
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"); } }
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); }
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); }