41 return chunk->code[ip++];
45 return chunk->constants[ReadInstruction()];
49 if (a.
val != b.
val)
return false;
66 #define BINARY_OP(op) \
68 if (IS_NUMBER(Peek(0)) && IS_NUMBER(Peek(1))) { \
69 double b = AS_NUMBER(Pop()); \
70 double a = AS_NUMBER(Pop()); \
71 Push(NUMBER_VAL(a op b)); \
73 else if (IS_INTEGER(Peek(0)) && IS_INTEGER(Peek(1))) { \
74 int b = AS_INTEGER(Pop()); \
75 int a = AS_INTEGER(Pop()); \
76 Push(INTEGER_VAL(a op b)); \
79 RuntimeError("Operands must be both integers or both numbers."); \
80 return uscript::INTERPRET_RUNTIME_ERROR; \
86 if (IS_NUMBER(Peek(0)) && IS_NUMBER(Peek(1))) { \
87 double b = AS_NUMBER(Pop()); \
88 double a = AS_NUMBER(Pop()); \
89 Push(BOOL_VAL(a op b)); \
91 else if (IS_INTEGER(Peek(0)) && IS_INTEGER(Peek(1))) { \
92 int b = AS_INTEGER(Pop()); \
93 int a = AS_INTEGER(Pop()); \
94 Push(BOOL_VAL(a op b)); \
97 RuntimeError("Operands must be both integers or both numbers."); \
98 return uscript::INTERPRET_RUNTIME_ERROR; \
104 #define READ_STRING() AS_CSTRING(ReadConstant())
105 #define READ_SHORT() (ip += 2, (uint16_t)((chunk->code[ip-2] << 8) | chunk->code[ip-1]))
107 #ifdef DEBUG_TRACE_EXECUTION
115 chunk->DisassembleInstruction(ip);
117 uint8_t instruction = ReadInstruction();
118 switch (instruction) {
123 if (!AccessValue(instance, name, &result)) {
132 RuntimeError(
"Cannot index with non-integer.");
136 Value callee = Pop();
137 if (!IndexValue(callee, ind)) {
143 int argCount = ReadInstruction();
144 if (!CallValue(Peek(argCount), argCount)) {
161 if (!Peek(0)) ip +=
offset;
165 if (ret) *ret = Pop();
182 RuntimeError(
"Cannot access length of non-tinstance.");
199 std::cout <<
"Indexable with length: " << length << std::endl;
204 RuntimeError(
"Cannot access fields of non-tinstance.");
213 Value constant = ReadConstant();
223 uint8_t slot = ReadInstruction();
228 uint8_t slot = ReadInstruction();
229 stack[slot] = Peek();
234 if (globals.count(name)) {
235 Push(globals.at(name));
238 RuntimeError(
"Undefined variable '%s'", name);
245 if (!globals.count(name)) {
246 RuntimeError(
"Undefined variable '%s'", name);
249 globals[
name] = Peek();
272 RuntimeError(
"Operand must be a number.");
288 if (index >= 0 && index < inst.
data.
len) {
297 RuntimeError(
"Cannot index with value (%i) into instance of size (%i)", index, inst.
data.
len);
305 RuntimeError(
"Functions are not implemented.");
316 uint8_t **vec = (uint8_t**)loc;
317 uint8_t *start = vec[0];
318 uint8_t *
end = vec[1];
324 data.
len = (end - start) / data.
Size();
364 bool success = GetTField(
AS_TINSTANCE(instance), name, result);
368 RuntimeError(
"Could not find value %s.", name);
373 RuntimeError(
"Cannot access on non-TInstance.");
379 if (!instance.
loc)
return false;
380 if (!instance.
data.
info)
return false;
383 if (instance.
data.
len >= 0)
return false;
386 if (classinfo->
fields.count(name)) {
411 va_start(args, format);
412 vfprintf(stderr, format, args);
414 fprintf(stderr,
"\nIn source: %s\n", chunk->source.c_str());
420 void uscript::VM::AddGlobal<int>(
const char *
name,
const int *obj) {
426 void uscript::VM::AddGlobal<unsigned>(
const char *
name,
const unsigned *obj) {
432 void uscript::VM::AddGlobal<float>(
const char *
name,
const float *obj) {
438 void uscript::VM::AddGlobal<double>(
const char *
name,
const double *obj) {
444 void uscript::VM::AddGlobal<bool>(
const char *
name,
const bool *obj) {
#define IS_INTEGER(value)
void SetChunk(const Chunk *_chunk)
BEGIN_PROLOG TPC Trig offset(g4 rise time) ProjectToHeight
void RuntimeError(const char *format,...)
#define AS_TINSTANCE(value)
static std::string format(PyObject *obj, unsigned int pos, unsigned int indent, unsigned int maxlen, unsigned int depth)
#define IS_TINSTANCE(value)
const std::string instance
std::map< const char *, TField > fields
bool AccessValue(Value instance, const char *name, Value *result)
void DoAddGlobal(const char *classname, const char *name, uint8_t *data)
InterpretResult Interpret(const char *source)
bool GetTField(ObjTInstance instance, const char *name, Value *ret)
#define AS_CSTRING(value)
static bool valuesEqual(uscript::Value a, uscript::Value b)
auto end(FixedBins< T, C > const &) noexcept
then echo echo For and will not be changed by echo further linking echo echo B echo The symbol is in the uninitialized data multiple common symbols may appear with the echo same name If the symbol is defined the common echo symbols are treated as undefined references For more echo details on common see the discussion of warn common echo in *Note Linker see the discussion of warn common echo in *Note Linker such as a global int variable echo as opposed to a large global array echo echo I echo The symbol is an indirect reference to another symbol This echo is a GNU extension to the a out object file format which is echo rarely used echo echo N echo The symbol is a debugging symbol echo echo R echo The symbol is in a read only data section echo echo S echo The symbol is in an uninitialized data section for small echo objects echo echo T echo The symbol is in the the normal defined echo symbol is used with no error When a weak undefined symbol echo is linked and the symbol is not the value of the echo weak symbol becomes zero with no error echo echo W echo The symbol is a weak symbol that has not been specifically echo tagged as a weak object symbol When a weak defined symbol echo is linked with a normal defined the normal defined echo symbol is used with no error When a weak undefined symbol echo is linked and the symbol is not the value of the echo weak symbol becomes zero with no error echo echo echo The symbol is a stabs symbol in an a out object file In echo this the next values printed are the stabs other field
InterpretResult Run(Value *ret=NULL)
#define NUMBER_VAL(value)
#define INTEGER_VAL(value)
#define AS_INTEGER(value)
static const char * Intern(const std::string &str)
void AddGlobal(const char *name, const TObj *object)
static TClassInfo * GetClassInfo(const char *classname)
uint8_t ReadInstruction()
Value GetTValue(uint8_t *loc, TData data)
static bool Compile(const char *source, Chunk *chunk)
bool CallValue(Value callee, int argCount)
#define TINSTANCE_VAL(value)
BEGIN_PROLOG could also be cout
bool IndexValue(Value callee, int index)