File outputting while embedding GroundVM

This commit is contained in:
2025-12-21 11:41:14 +11:00
parent 13b07e0042
commit 579720015a
4 changed files with 19 additions and 3 deletions

View File

@@ -122,6 +122,7 @@ extern "C" {
GroundProgram groundCreateProgram();
void groundAddInstructionToProgram(GroundProgram* program, GroundInstruction instruction);
GroundValue groundRunProgram(GroundProgram* program);
void groundPrintProgram(GroundProgram* program);
GroundInstruction groundCreateInstruction(GroundInstType type);
void groundAddValueToInstruction(GroundInstruction* inst, GroundValue value);

View File

@@ -79,3 +79,10 @@ GroundValue groundCreateValue(GroundValueType type, ...) {
GroundValue groundRunProgram(GroundProgram* program) {
return interpretGroundProgram(program, NULL);
}
void groundPrintProgram(GroundProgram* program) {
for (size_t i = 0; i < program->size; i++) {
printGroundInstruction(&program->instructions[i]);
printf("\n");
}
}

View File

@@ -372,15 +372,20 @@ void printGroundInstruction(GroundInstruction* gi) {
printf("extern");
break;
case CREATELABEL:
printf("createlabel");
break;
default:
printf("FIXME");
break;
}
printf(" ");
if (gi->type != CREATELABEL) printf(" ");
for (int i = 0; i < gi->args.length; i++) {
if (gi->args.args[i].type == VALUE && gi->args.args[i].value.value.type == STRING) {
printf("\"");
printGroundArg(&gi->args.args[i]);
printf("\"");
} else {
printGroundArg(&gi->args.args[i]);
}
printf(" ");
}
}

3
tests/convs.grnd Normal file
View File

@@ -0,0 +1,3 @@
tostring 32 &int
println $int