123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683 |
- #include <stdarg.h>
- #include <stdbool.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include "Operation.h"
- #include "Script.h"
- static void sError(Script* sc, const char* format, ...) {
- va_list args;
- va_start(args, format);
- vsnprintf(sc->error, SCRIPT_ERROR_SIZE, format, args);
- va_end(args);
- }
- static bool sPrinter(Object* o) {
- switch(o->type) {
- case OT_INT: printf("%d\n", o->as.intValue); return false;
- case OT_FLOAT: printf("%.2f\n", o->as.floatValue); return false;
- case OT_CONST_STRING: printf("%s\n", o->as.stringValue); return false;
- case OT_NULL: printf("null\n"); return false;
- case OT_BOOL:
- printf(o->as.intValue ? "true\n" : "false\n");
- return false;
- case OT_ARRAY: printf("array\n"); return false;
- default: return true;
- }
- }
- static ObjectPrinter printer = sPrinter;
- static bool sRead(Script* sc, void* buffer, int length) {
- if(sc->readIndex + length > sc->code->length) {
- sError(sc,
- "cannot read expected %d bytes of data from bytecode on line %d",
- sc->line);
- return true;
- }
- memcpy(buffer, sc->code->code + sc->readIndex, length);
- sc->readIndex += length;
- return false;
- }
- static Operation sReadOperation(Script* sc) {
- unsigned char c;
- if(sRead(sc, &c, 1)) {
- return OP_NOTHING;
- }
- return c;
- }
- static bool sReadInt(Script* sc, int* i) {
- return !sRead(sc, i, sizeof(int));
- }
- static bool sCheckType(Script* sc, Object* o, ObjectType ot) {
- if(o->type == ot) {
- return true;
- }
- sError(sc, "object is not of type %s on line %d", oGetName(ot), sc->line);
- return false;
- }
- static bool sPush(Script* sc, Object* o) {
- if(sc->stackIndex >= SCRIPT_STACK_SIZE) {
- sError(sc, "stack overflow on line %d", sc->line);
- return false;
- }
- sc->stack[sc->stackIndex++] = *o;
- return true;
- }
- static bool sPop(Script* sc, Object* o) {
- if(sc->stackIndex <= 0) {
- sError(sc, "stack underflow on line %d", sc->line);
- return true;
- }
- *o = sc->stack[--sc->stackIndex];
- return false;
- }
- static void sPopEmpty(Script* sc) {
- Object o;
- sPop(sc, &o);
- }
- static Object* sPeek(Script* sc) {
- if(sc->stackIndex <= 0) {
- sError(sc, "stack underflow on line %d", sc->line);
- return NULL;
- }
- return sc->stack + (sc->stackIndex - 1);
- }
- static bool sPushInt(Script* sc, int value) {
- Object o = {.type = OT_INT, .as.intValue = value};
- return sPush(sc, &o);
- }
- static void sPushFloat(Script* sc, float value) {
- Object o = {.type = OT_FLOAT, .as.floatValue = value};
- sPush(sc, &o);
- }
- static void sPushNull(Script* sc) {
- Object o = {.type = OT_NULL};
- sPush(sc, &o);
- }
- static void sPushBool(Script* sc, bool value) {
- Object o = {.type = OT_BOOL, .as.intValue = value};
- sPush(sc, &o);
- }
- static void sPushReference(Script* sc, int pointer, int index) {
- Object o = {.type = OT_REFERENCE,
- .as.reference.pointer = pointer,
- .as.reference.index = index};
- sPush(sc, &o);
- }
- static void sPushVars(Script* sc) {
- int vars = 0;
- int offset = 0;
- if(sReadInt(sc, &vars) && sReadInt(sc, &offset)) {
- int stackVarIndex = sc->stackVarIndex;
- sc->stackVarIndex = sc->stackIndex - offset;
- for(int i = 0; i < vars - offset; i++) {
- sPushNull(sc);
- }
- sPushInt(sc, stackVarIndex);
- }
- }
- static void sPopVars(Script* sc) {
- int value = 0;
- Object o;
- if(sReadInt(sc, &value) && !sPop(sc, &o) && sCheckType(sc, &o, OT_INT)) {
- sc->stackVarIndex = o.as.intValue;
- if(sc->stackIndex < value) {
- sError(sc, "stack underflow on line %d", sc->line);
- } else {
- sc->stackIndex -= value;
- }
- }
- }
- static void sReferenceFromVar(Script* sc) {
- int value = 0;
- if(sReadInt(sc, &value)) {
- sPushReference(sc, -1, value + sc->stackVarIndex);
- }
- }
- static void sReferenceFromArray(Script* sc) {
- int value = 0;
- Object o;
- if(sReadInt(sc, &value) && !sPop(sc, &o) && sCheckType(sc, &o, OT_INT)) {
- sPushReference(sc, value, o.as.intValue);
- }
- }
- static Object* sDereference(Script* sc, Object* reference) {
- int pointer = reference->as.reference.pointer;
- int index = reference->as.reference.index;
- if(pointer == -1) {
- if(index < 0 || index >= sc->stackIndex) {
- sError(sc, "variable reference index exceeds stack on line %d",
- sc->line);
- return NULL;
- }
- return sc->stack + index;
- } else {
- if(pointer < 0 || pointer >= sc->allocator.capacity) {
- sError(sc, "array reference pointer is out of range on line %d\n",
- sc->line);
- return NULL;
- } else if(index < 0 || index >= sc->allocator.data[pointer].length) {
- sError(sc, "array reference index is out of bounds on line %d\n",
- sc->line);
- return NULL;
- }
- return sc->allocator.data[pointer].data + index;
- }
- }
- static Object* sPopAndDereference(Script* sc) {
- Object o;
- if(!sPop(sc, &o) && sCheckType(sc, &o, OT_REFERENCE)) {
- return sDereference(sc, &o);
- }
- return NULL;
- }
- static void sDereferencePush(Script* sc) {
- Object* o = sPopAndDereference(sc);
- if(o != NULL) {
- sPush(sc, o);
- }
- }
- static void sSet(Script* sc) {
- Object value;
- if(sPop(sc, &value)) {
- return;
- }
- Object* o = sPopAndDereference(sc);
- if(o != NULL) {
- *o = value;
- }
- }
- static void sAllocateArray(Script* sc) {
- Object length;
- if(!sPop(sc, &length) && sCheckType(sc, &length, OT_INT)) {
- if(length.as.intValue < 0) {
- sError(sc, "negative array length on line %d", sc->line);
- return;
- }
- Object o = {.type = OT_ARRAY,
- .as.intValue =
- aAllocate(&sc->allocator, length.as.intValue)};
- sPush(sc, &o);
- }
- }
- static void sArrayLength(Script* sc) {
- Object* o = sPopAndDereference(sc);
- if(o != NULL && sCheckType(sc, o, OT_ARRAY)) {
- int arrayPointer = o->as.intValue;
- if(arrayPointer < 0 || arrayPointer >= sc->allocator.capacity) {
- sError(sc, "array pointer is out of range on line %d\n", sc->line);
- return;
- }
- sPushInt(sc, sc->allocator.data[arrayPointer].length);
- }
- }
- static void sPreChange(Script* sc, int change) {
- Object* o = sPopAndDereference(sc);
- if(o != NULL) {
- if(o->type == OT_INT) {
- o->as.intValue += change;
- } else if(o->type == OT_FLOAT) {
- o->as.floatValue += change;
- } else {
- sError(sc, "variable is '%s' not a number on line %d",
- oGetName(o->type), sc->line);
- return;
- }
- sPush(sc, o);
- }
- }
- static void sPreIncrement(Script* sc) {
- sPreChange(sc, 1);
- }
- static void sPreDecrement(Script* sc) {
- sPreChange(sc, -1);
- }
- static void sPostChange(Script* sc, int change) {
- Object* o = sPopAndDereference(sc);
- if(o != NULL) {
- if(o->type == OT_INT) {
- sPush(sc, o);
- o->as.intValue += change;
- } else if(o->type == OT_FLOAT) {
- sPush(sc, o);
- o->as.floatValue += change;
- } else {
- sError(sc, "variable is '%s' not a number on line %d",
- oGetName(o->type), sc->line);
- }
- }
- }
- static void sPostIncrement(Script* sc) {
- sPostChange(sc, 1);
- }
- static void sPostDecrement(Script* sc) {
- sPostChange(sc, -1);
- }
- static void sPushCodeInt(Script* sc) {
- int value = 0;
- if(sReadInt(sc, &value)) {
- sPushInt(sc, value);
- }
- }
- static void sPushCodeFloat(Script* sc) {
- float value = 0;
- if(sRead(sc, &value, sizeof(float))) {
- sError(sc, "cannot read a float from the bytecode on line %d",
- sc->line);
- return;
- }
- sPushFloat(sc, value);
- }
- static void sPushCodeString(Script* sc) {
- int value = 0;
- if(sReadInt(sc, &value)) {
- char* s = (char*)(sc->code->code + sc->readIndex);
- sc->readIndex += value;
- Object o = {.type = OT_CONST_STRING, .as.stringValue = s};
- sPush(sc, &o);
- }
- }
- #define CHECKED_NUMBER_OP(check, op, typeA, typeB) \
- { \
- Object o[2]; \
- if(sPop(sc, o) || sPop(sc, o + 1)) { \
- return; \
- } else if(o[0].type == OT_INT && o[1].type == OT_INT) { \
- check sPush##typeA(sc, o[1].as.intValue op o[0].as.intValue); \
- } else if(o[0].type == OT_INT && o[1].type == OT_FLOAT) { \
- sPush##typeB(sc, o[1].as.floatValue op o[0].as.intValue); \
- } else if(o[0].type == OT_FLOAT && o[1].type == OT_INT) { \
- sPush##typeB(sc, o[1].as.intValue op o[0].as.floatValue); \
- } else if(o[0].type == OT_FLOAT && o[1].type == OT_FLOAT) { \
- sPush##typeB(sc, o[1].as.floatValue op o[0].as.floatValue); \
- } else { \
- sError(sc, "object is not a number on line %d", sc->line); \
- } \
- }
- #define NUMBER_NUMBER_OP(op) CHECKED_NUMBER_OP(, op, Int, Float)
- #define NUMBER_BOOL_OP(op) CHECKED_NUMBER_OP(, op, Bool, Bool)
- #define CHECKED_INT_OP(check, op) \
- { \
- Object o[2]; \
- if(!sPop(sc, o) && !sPop(sc, o + 1) && sCheckType(sc, o, OT_INT) && \
- sCheckType(sc, o + 1, OT_INT)) { \
- check sPushInt(sc, o[1].as.intValue op o[0].as.intValue); \
- } \
- }
- #define INT_OP(op) CHECKED_INT_OP(, op)
- #define ZERO_CHECK(op) \
- if(o[0].as.intValue == 0) { \
- sError(sc, op " by 0 on line %d", sc->line); \
- return; \
- }
- #define DIVISION CHECKED_NUMBER_OP(ZERO_CHECK("division"), /, Int, Float)
- #define MODULE CHECKED_INT_OP(ZERO_CHECK("module"), %);
- static void sInvertSign(Script* sc) {
- Object* o = sPeek(sc);
- if(o == NULL) {
- return;
- } else if(o->type == OT_INT) {
- o->as.intValue = -o->as.intValue;
- } else if(o->type == OT_FLOAT) {
- o->as.floatValue = -o->as.floatValue;
- } else {
- sError(sc, "object is not a number on line %d", sc->line);
- }
- }
- static void sEqual(Script* sc) {
- Object o[2];
- if(sPop(sc, o) || sPop(sc, o + 1)) {
- return;
- } else if(o[0].type == OT_INT && o[1].type == OT_INT) {
- sPushBool(sc, o[0].as.intValue == o[1].as.intValue);
- } else if(o[0].type == OT_INT && o[1].type == OT_FLOAT) {
- sPushBool(sc, o[0].as.intValue == o[1].as.floatValue);
- } else if(o[0].type == OT_FLOAT && o[1].type == OT_INT) {
- sPushBool(sc, o[0].as.floatValue == o[1].as.intValue);
- } else if(o[0].type == OT_FLOAT && o[1].type == OT_FLOAT) {
- sPushBool(sc, o[0].as.floatValue == o[1].as.floatValue);
- } else if(o[0].type == OT_BOOL && o[1].type == OT_BOOL) {
- sPushBool(sc, o[0].as.intValue == o[1].as.intValue);
- } else if(o[0].type == OT_NULL && o[1].type == OT_NULL) {
- sPushBool(sc, true);
- } else {
- sError(sc, "object types do not match on line %d", sc->line);
- }
- }
- static void sNot(Script* sc) {
- Object* o = sPeek(sc);
- if(o != NULL && sCheckType(sc, o, OT_BOOL)) {
- o->as.intValue = !o->as.intValue;
- }
- }
- static void sBitNot(Script* sc) {
- Object* o = sPeek(sc);
- if(o != NULL && sCheckType(sc, o, OT_INT)) {
- o->as.intValue = ~o->as.intValue;
- }
- }
- static void sAnd(Script* sc) {
- Object o[2];
- if(!sPop(sc, o) && !sPop(sc, o + 1) && sCheckType(sc, o, OT_BOOL) &&
- sCheckType(sc, o + 1, OT_BOOL)) {
- sPushBool(sc, o[0].as.intValue && o[1].as.intValue);
- }
- }
- static void sOr(Script* sc) {
- Object o[2];
- if(!sPop(sc, o) && !sPop(sc, o + 1) && sCheckType(sc, o, OT_BOOL) &&
- sCheckType(sc, o + 1, OT_BOOL)) {
- sPushBool(sc, o[0].as.intValue || o[1].as.intValue);
- }
- }
- static void sPrint(Script* sc) {
- Object o;
- if(!sPop(sc, &o) && printer(&o)) {
- sError(sc, "cannot print given object on line %d", sc->line);
- }
- }
- static void sLine(Script* sc) {
- if(sRead(sc, &sc->line, 2)) {
- sError(sc, "line operation without a line near line %d", sc->line);
- }
- }
- static void sGoTo(Script* sc) {
- int gotoIndex;
- if(sReadInt(sc, &gotoIndex)) {
- sc->readIndex = gotoIndex;
- }
- }
- static void sGoSub(Script* sc) {
- int gotoIndex;
- int arguments;
- if(sReadInt(sc, &gotoIndex) && sReadInt(sc, &arguments)) {
- int returnStackIndex = sc->stackIndex - arguments - 1;
- if(returnStackIndex < 0 || sc->stack[returnStackIndex].type != OT_INT) {
- sError(sc, "cannot find return address entry on stack on line %d",
- sc->line);
- return;
- }
- sc->stack[returnStackIndex].as.intValue = sc->readIndex;
- sc->readIndex = gotoIndex;
- }
- }
- static void sIfGoTo(Script* sc) {
- int gotoIndex;
- Object o;
- if(sReadInt(sc, &gotoIndex) && !sPop(sc, &o) &&
- sCheckType(sc, &o, OT_BOOL) && !o.as.intValue) {
- sc->readIndex = gotoIndex;
- }
- }
- static void sSetReturn(Script* sc) {
- sPop(sc, &sc->returnValue);
- }
- static void sReturn(Script* sc) {
- Object o;
- if(!sPop(sc, &o) && sCheckType(sc, &o, OT_INT)) {
- sc->readIndex = o.as.intValue;
- if(sc->returnValue.type != OT_VOID) {
- sPush(sc, &sc->returnValue);
- sc->returnValue.type = OT_VOID;
- }
- }
- }
- static void sDuplicate(Script* sc) {
- Object* o = sPeek(sc);
- if(o != NULL) {
- sPush(sc, o);
- }
- }
- static void sConsumeInstruction(Script* sc) {
- switch(sReadOperation(sc)) {
- case OP_NOTHING: break;
- case OP_PUSH_INT: sPushCodeInt(sc); break;
- case OP_PUSH_FLOAT: sPushCodeFloat(sc); break;
- case OP_PUSH_CONST_STRING: sPushCodeString(sc); break;
- case OP_PUSH_NULL: sPushNull(sc); break;
- case OP_PUSH_TRUE: sPushBool(sc, true); break;
- case OP_PUSH_FALSE: sPushBool(sc, false); break;
- case OP_PUSH_VARS: sPushVars(sc); break;
- case OP_POP_VARS: sPopVars(sc); break;
- case OP_POP: sPopEmpty(sc); break;
- case OP_SET: sSet(sc); break;
- case OP_PRE_INCREMENT: sPreIncrement(sc); break;
- case OP_POST_INCREMENT: sPostIncrement(sc); break;
- case OP_PRE_DECREMENT: sPreDecrement(sc); break;
- case OP_POST_DECREMENT: sPostDecrement(sc); break;
- case OP_ADD: NUMBER_NUMBER_OP(+); break;
- case OP_SUB: NUMBER_NUMBER_OP(-); break;
- case OP_MUL: NUMBER_NUMBER_OP(*); break;
- case OP_DIV: DIVISION; break;
- case OP_MOD: MODULE; break;
- case OP_INVERT_SIGN: sInvertSign(sc); break;
- case OP_LESS: NUMBER_BOOL_OP(<); break;
- case OP_GREATER: NUMBER_BOOL_OP(>); break;
- case OP_EQUAL: sEqual(sc); break;
- case OP_NOT: sNot(sc); break;
- case OP_AND: sAnd(sc); break;
- case OP_OR: sOr(sc); break;
- case OP_BIT_NOT: sBitNot(sc); break;
- case OP_BIT_AND: INT_OP(&); break;
- case OP_BIT_OR: INT_OP(|); break;
- case OP_BIT_XOR: INT_OP(^); break;
- case OP_LEFT_SHIFT: INT_OP(<<); break;
- case OP_RIGHT_SHIFT: INT_OP(>>); break;
- case OP_PRINT: sPrint(sc); break;
- case OP_LINE: sLine(sc); break;
- case OP_GOTO: sGoTo(sc); break;
- case OP_GOSUB: sGoSub(sc); break;
- case OP_IF_GOTO: sIfGoTo(sc); break;
- case OP_SET_RETURN: sSetReturn(sc); break;
- case OP_RETURN: sReturn(sc); break;
- case OP_DUPLICATE: sDuplicate(sc); break;
- case OP_ALLOCATE_ARRAY: sAllocateArray(sc); break;
- case OP_ARRAY_LENGTH: sArrayLength(sc); break;
- case OP_REFERENCE_FROM_VAR: sReferenceFromVar(sc); break;
- case OP_REFERENCE_FROM_ARRAY: sReferenceFromArray(sc); break;
- case OP_DEREFERENCE: sDereferencePush(sc); break;
- }
- sCollectGarbage(sc);
- }
- static bool sHasData(Script* sc) {
- return sc->readIndex < sc->code->length;
- }
- Script* sInit(ByteCode* code) {
- Script* sc = malloc(sizeof(Script));
- sc->error[0] = '\0';
- sc->code = code;
- sc->readIndex = 0;
- sc->returnValue.type = OT_VOID;
- sc->stackIndex = 0;
- sc->stackVarIndex = 0;
- sc->line = 0;
- aInit(&sc->allocator);
- return sc;
- }
- void sDelete(Script* sc) {
- bcDelete(sc->code);
- aDelete(&sc->allocator);
- free(sc);
- }
- void sRun(Script* sc) {
- while(sHasData(sc)) {
- sConsumeInstruction(sc);
- if(sc->error[0] != '\0') {
- puts(sc->error);
- return;
- }
- }
- }
- void sSetPrinter(ObjectPrinter p) {
- printer = p;
- }
- static void sMark(Script* sc, Object* o) {
- if(o->type == OT_ARRAY) {
- Array* a = sc->allocator.data + o->as.intValue;
- a->marked = true;
- for(int i = 0; i < a->length; i++) {
- sMark(sc, a->data + i);
- }
- }
- }
- void sCollectGarbage(Script* sc) {
- aClearMarker(&sc->allocator);
- for(int i = 0; i < sc->stackIndex; i++) {
- sMark(sc, sc->stack + i);
- }
- aRemoveUnmarked(&sc->allocator);
- }
- static void sPrintInt(Script* sc, const char* msg) {
- int value = 0;
- sReadInt(sc, &value);
- printf("%s %d\n", msg, value);
- }
- static void sPrint2Int(Script* sc, const char* msg) {
- int a = 0;
- sReadInt(sc, &a);
- int b = 0;
- sReadInt(sc, &b);
- printf("%s %d %d\n", msg, a, b);
- }
- static void sPrintInt16(Script* sc, const char* msg) {
- int value = 0;
- sRead(sc, &value, 2);
- printf("%s %d\n", msg, value);
- }
- static void sPrintFloat(Script* sc, const char* msg) {
- float value = 0;
- sRead(sc, &value, sizeof(float));
- printf("%s %.2f\n", msg, value);
- }
- static void sPrintString(Script* sc, const char* msg) {
- int length = 0;
- sReadInt(sc, &length);
- char* s = (char*)(sc->code->code + sc->readIndex);
- sc->readIndex += length;
- printf("%s %d \"%s\"\n", msg, length, s);
- }
- void sPrintCode(Script* sc) {
- int oldRead = sc->readIndex;
- sc->readIndex = 0;
- while(sHasData(sc)) {
- printf(" %3d | ", sc->readIndex);
- switch(sReadOperation(sc)) {
- case OP_NOTHING: puts("Nothing"); break;
- case OP_PUSH_INT: sPrintInt(sc, "Push Int"); break;
- case OP_PUSH_FLOAT: sPrintFloat(sc, "Push Float"); break;
- case OP_PUSH_CONST_STRING:
- sPrintString(sc, "Push Const String");
- break;
- case OP_PUSH_NULL: puts("Push null"); break;
- case OP_PUSH_TRUE: puts("Push true"); break;
- case OP_PUSH_FALSE: puts("Push false"); break;
- case OP_PUSH_VARS: sPrint2Int(sc, "Push Vars"); break;
- case OP_POP_VARS: sPrintInt(sc, "Pop Vars"); break;
- case OP_POP: puts("Pop"); break;
- case OP_SET: puts("Set"); break;
- case OP_PRE_INCREMENT: puts("Pre Increment"); break;
- case OP_POST_INCREMENT: puts("Post Increment"); break;
- case OP_PRE_DECREMENT: puts("Pre Decrement"); break;
- case OP_POST_DECREMENT: puts("Post Decrement"); break;
- case OP_ADD: puts("Add"); break;
- case OP_SUB: puts("Sub"); break;
- case OP_MUL: puts("Mul"); break;
- case OP_DIV: puts("Div"); break;
- case OP_MOD: puts("Mod"); break;
- case OP_INVERT_SIGN: puts("Invert Sign"); break;
- case OP_LESS: puts("Less"); break;
- case OP_GREATER: puts("Greater"); break;
- case OP_EQUAL: puts("Equal"); break;
- case OP_NOT: puts("Not"); break;
- case OP_AND: puts("And"); break;
- case OP_OR: puts("Or"); break;
- case OP_BIT_NOT: puts("Bit Not"); break;
- case OP_BIT_AND: puts("Bit And"); break;
- case OP_BIT_OR: puts("Bit Or"); break;
- case OP_BIT_XOR: puts("Bit Xor"); break;
- case OP_LEFT_SHIFT: puts("Left Shift"); break;
- case OP_RIGHT_SHIFT: puts("Right Shift"); break;
- case OP_PRINT: puts("Print"); break;
- case OP_LINE: sPrintInt16(sc, "------------ Line"); break;
- case OP_GOTO: sPrintInt(sc, "GoTo"); break;
- case OP_GOSUB: sPrint2Int(sc, "GoSub"); break;
- case OP_IF_GOTO: sPrintInt(sc, "If GoTo"); break;
- case OP_SET_RETURN: puts("Set Return"); break;
- case OP_RETURN: puts("Return"); break;
- case OP_DUPLICATE: puts("Duplicate"); break;
- case OP_ALLOCATE_ARRAY: puts("Allocate Array"); break;
- case OP_ARRAY_LENGTH: puts("Array Length"); break;
- case OP_REFERENCE_FROM_VAR:
- sPrintInt(sc, "Reference From Var");
- break;
- case OP_REFERENCE_FROM_ARRAY:
- sPrintInt(sc, "Reference From Array");
- break;
- case OP_DEREFERENCE: puts("Dereference"); break;
- }
- }
- sc->readIndex = oldRead;
- }
|