From c8c5381cf23d175f70e24ddf33319712999d2442 Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Thu, 26 Oct 2023 10:18:33 +0100 Subject: vm/main takes a filename as input to execute bytecode Also prints a usage for incorrect usage. --- vm/main.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/vm/main.c b/vm/main.c index db9e313..2b82cd3 100644 --- a/vm/main.c +++ b/vm/main.c @@ -51,21 +51,24 @@ int assemble_instructions(inst_t *instructions, size_t number, return 0; } -int main(int argc, char *argv[]) +void usage(const char *program_name, FILE *out) { - const char *filename = "out.bin"; - if (argc >= 2) - filename = argv[1]; - - inst_t instructions[] = { - INST_PUSH(BYTE, 0), INST_MOV(BYTE, 0), + fprintf(out, + "Usage: %s [OPTIONS] FILE\n" + "\t FILE: Bytecode file to execute\n" + "\tOptions:\n" + "\t\t To be developed...\n", + program_name); +} - INST_PUSH_REG(BYTE, 0), INST_PUSH(BYTE, 1), INST_PLUS(BYTE), - INST_MOV(BYTE, 0), +int main(int argc, char *argv[]) +{ + if (argc == 1) + { + usage(argv[0], stderr); + return 1; + } + const char *filename = argv[1]; - INST_PUSH_REG(BYTE, 0), INST_PUSH(BYTE, 5), INST_EQ(BYTE), - INST_NOT(BYTE), INST_JUMP_IF(BYTE, 2), INST_HALT, - }; - assemble_instructions(instructions, ARR_SIZE(instructions), filename); return interpret_bytecode(filename); } -- cgit v1.2.3-13-gbd6f