diff options
| author | Mistivia <i@mistivia.com> | 2024-12-05 21:49:00 +0800 |
|---|---|---|
| committer | Mistivia <i@mistivia.com> | 2024-12-05 21:49:00 +0800 |
| commit | cd818993399f1fc8fa000b4144730affd291761f (patch) | |
| tree | 13d546dd873ad37e850cf089c322b91a20d25ccf /src | |
| parent | 79194983d0331d632bd094370a410fa0aaefe6aa (diff) | |
add syscall
Diffstat (limited to 'src')
| -rw-r--r-- | src/fvm.h | 2 | ||||
| -rw-r--r-- | src/main.c | 7 |
2 files changed, 8 insertions, 1 deletions
@@ -9,7 +9,7 @@ typedef double fvm_float_t;; struct fvm; // return non-zero if vm should be suspended -typedef int64_t (*fvm_syscall_fn_t)(struct fvm* vm); +typedef void (*fvm_syscall_fn_t)(struct fvm* vm); struct fvm { fvm_word_t sp; // stack pointer @@ -3,12 +3,19 @@ #include "fvm.h" +static void printnum(struct fvm *vm) { + int64_t n = fvm_pop(vm); + printf("%lld\n", n); +} + int main(int argc, char **argv) { struct fvm vm; if (argc < 2) { fprintf(stderr, "Usage: fvm <program-file>\n"); return -1; } + vm.syscall_table = malloc(256 * sizeof(fvm_syscall_fn_t)); + vm.syscall_table[1] = &printnum; FILE* fp = fopen(argv[1], "rb"); if (fp == NULL) { fprintf(stderr, "Failed to open file.\n"); |
