|
@@ -18,6 +18,7 @@ static bool sPrinter(Object* o) {
|
|
switch(o->type) {
|
|
switch(o->type) {
|
|
case OT_INT: printf("%d\n", o->data.intValue); return false;
|
|
case OT_INT: printf("%d\n", o->data.intValue); return false;
|
|
case OT_FLOAT: printf("%.2f\n", o->data.floatValue); return false;
|
|
case OT_FLOAT: printf("%.2f\n", o->data.floatValue); return false;
|
|
|
|
+ case OT_CONST_STRING: printf("%s\n", o->data.stringValue); return false;
|
|
case OT_NULL: printf("null\n"); return false;
|
|
case OT_NULL: printf("null\n"); return false;
|
|
case OT_BOOL: printf(o->data.intValue ? "true\n" : "false\n"); return false;
|
|
case OT_BOOL: printf(o->data.intValue ? "true\n" : "false\n"); return false;
|
|
case OT_VOID: printf("void\n"); return false;
|
|
case OT_VOID: printf("void\n"); return false;
|
|
@@ -228,6 +229,16 @@ static void sPushCodeFloat(Script* sc) {
|
|
sPushFloat(sc, value);
|
|
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, .data.stringValue = s};
|
|
|
|
+ sPush(sc, &o);
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
static void sNumberBinary(Script* sc, int (*fInt)(Script*, int, int), float (*fFloat)(float, float)) {
|
|
static void sNumberBinary(Script* sc, int (*fInt)(Script*, int, int), float (*fFloat)(float, float)) {
|
|
Object o[2];
|
|
Object o[2];
|
|
if(sPop(sc, o) || sPop(sc, o + 1)) {
|
|
if(sPop(sc, o) || sPop(sc, o + 1)) {
|
|
@@ -488,6 +499,7 @@ static void sConsumeInstruction(Script* sc) {
|
|
case OP_NOTHING: break;
|
|
case OP_NOTHING: break;
|
|
case OP_PUSH_INT: sPushCodeInt(sc); break;
|
|
case OP_PUSH_INT: sPushCodeInt(sc); break;
|
|
case OP_PUSH_FLOAT: sPushCodeFloat(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_NULL: sPushNull(sc); break;
|
|
case OP_PUSH_TRUE: sPushBool(sc, true); break;
|
|
case OP_PUSH_TRUE: sPushBool(sc, true); break;
|
|
case OP_PUSH_FALSE: sPushBool(sc, false); break;
|
|
case OP_PUSH_FALSE: sPushBool(sc, false); break;
|
|
@@ -590,6 +602,14 @@ static void sPrintFloat(Script* sc, const char* msg) {
|
|
printf("%s %.2f\n", msg, value);
|
|
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) {
|
|
void sPrintCode(Script* sc) {
|
|
int oldRead = sc->readIndex;
|
|
int oldRead = sc->readIndex;
|
|
sc->readIndex = 0;
|
|
sc->readIndex = 0;
|
|
@@ -599,6 +619,7 @@ void sPrintCode(Script* sc) {
|
|
case OP_NOTHING: puts("Nothing"); break;
|
|
case OP_NOTHING: puts("Nothing"); break;
|
|
case OP_PUSH_INT: sPrintInt(sc, "Push Int"); break;
|
|
case OP_PUSH_INT: sPrintInt(sc, "Push Int"); break;
|
|
case OP_PUSH_FLOAT: sPrintFloat(sc, "Push Float"); 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_NULL: puts("Push null"); break;
|
|
case OP_PUSH_TRUE: puts("Push true"); break;
|
|
case OP_PUSH_TRUE: puts("Push true"); break;
|
|
case OP_PUSH_FALSE: puts("Push false"); break;
|
|
case OP_PUSH_FALSE: puts("Push false"); break;
|