From 579720015a5181a7ec85f3299211a4807eb1d1fe Mon Sep 17 00:00:00 2001 From: Maxwell Jeffress Date: Sun, 21 Dec 2025 11:41:14 +1100 Subject: [PATCH] File outputting while embedding GroundVM --- include/groundvm.h | 1 + src/interface.c | 7 +++++++ src/types.c | 11 ++++++++--- tests/convs.grnd | 3 +++ 4 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 tests/convs.grnd diff --git a/include/groundvm.h b/include/groundvm.h index 35c29f2..1187341 100644 --- a/include/groundvm.h +++ b/include/groundvm.h @@ -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); diff --git a/src/interface.c b/src/interface.c index 0346ed9..78788ba 100644 --- a/src/interface.c +++ b/src/interface.c @@ -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"); + } +} diff --git a/src/types.c b/src/types.c index ed7e41a..f22d478 100644 --- a/src/types.c +++ b/src/types.c @@ -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++) { - printGroundArg(&gi->args.args[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(" "); } } diff --git a/tests/convs.grnd b/tests/convs.grnd new file mode 100644 index 0000000..28ac13e --- /dev/null +++ b/tests/convs.grnd @@ -0,0 +1,3 @@ +tostring 32 &int + +println $int