-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnjvm.c
109 lines (95 loc) · 2.58 KB
/
njvm.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
* njvm.c
*
* Created on: 03.11.2010
* Author: Frank Kevin Zey
*/
/* Includes */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "instr.h"
#include "makros.h"
#include "njvm.h"
#include "interpreter.h"
/* Variables */
int args = 0;
boolean HELP = FALSE;
boolean VERS = FALSE;
boolean DEBUG = FALSE;
boolean DEBUGHELP = FALSE;
boolean INPUT = FALSE;
int af = -1;
/* Main */
int main(int argc, char *argv[]) {
printf("Ninja virtual machine started\n");
if (argc > 1) {
/* Scanning program arguments */
for (args = 1; args < argc; args++) {
if (strcmp(argv[args],"--help") == 0) {
HELP = TRUE;
} else if (strcmp(argv[args],"--debug") == 0) {
DEBUG = TRUE;
} else if (strcmp(argv[args],"--version") == 0) {
VERS = TRUE;
} else if (strcmp(argv[args],"--debughelp") == 0) {
DEBUGHELP = TRUE;
} else {
INPUT = TRUE;
af = args;
}
}
/* Executing */
if (VERS == TRUE) {
printf("Actual version:%s\n",VERSNR);
printf("\n");
}
if (HELP == TRUE) {
showHelp();
printf("\n");
}
if (DEBUGHELP == TRUE) {
showDebugHelp();
printf("\n");
}
if (DEBUG == TRUE) {
if (af > 0) {
loadFile(argv[af]);
execute(1);
printf("\n");
} else {
printf("no input file\n");
}
}
if (INPUT == TRUE) {
loadFile(argv[af]);
execute(0);
printf("\n");
}
/* case of no program arguments */
} else {
printf("no flag or input file\n");
}
printf("Ninja virtual machine stopped\n");
return (EXIT_SUCCESS);
}
/* Printing functions */
void showHelp() {
printf("by Frank Kevin Zey\n");
printf("Usage: ./njvm [Option] <code file>\n");
printf("Options:\n");
printf(" --debug <cf> : start NJVM in debug mode\n");
printf(" --debughelp : start help for debug modes\n");
printf(" --version : show version and exit\n");
printf(" --help : show this help and exit\n");
}
void showDebugHelp() {
printf("Debugger %s \nDebugger Helpfunction %s\ncopyright by Frank Kevin Zey\n\n",DEBUGVERS,DEBUGHVERS);
printf("Usage: [Option]\n");
printf("inspect stack : shows the current stack values\n");
printf("list : list the program memory (program intructions)\n");
printf("step : step instruction for instruction\n");
printf("run : close debug mode and run program\n");
printf("quit : cancel program and exit Ninja Virtual Machine\n");
printf("inspect_all : shows stack values after every step (optional)\n\n");
}