aboutsummaryrefslogtreecommitdiff
path: root/vm
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2023-10-26 10:18:33 +0100
committerAryadev Chavali <aryadev@aryadevchavali.com>2023-10-26 10:18:53 +0100
commitc8c5381cf23d175f70e24ddf33319712999d2442 (patch)
tree58181bd0c9edfdfa29c803f2d2a166ccb1521392 /vm
parenta07b571da2156bb0d151f20121a485ebfc62c0af (diff)
downloadovm-c8c5381cf23d175f70e24ddf33319712999d2442.tar.gz
ovm-c8c5381cf23d175f70e24ddf33319712999d2442.tar.bz2
ovm-c8c5381cf23d175f70e24ddf33319712999d2442.zip
vm/main takes a filename as input to execute bytecode
Also prints a usage for incorrect usage.
Diffstat (limited to 'vm')
-rw-r--r--vm/main.c29
1 files 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);
}