#include #include #include #include "config.h" unsigned int stack[100]; unsigned int current = 0; unsigned int programmSpeicher[100]; #define IMMEDIATE(x) ((x) & 0x00FFFFFF) #define HALT 0 #define PUSHC 1 #define ADD 2 #define SUB 3 #define MUL 4 #define DIV 5 #define MOD 6 #define RDINT 7 #define WRINT 8 #define RDCHR 9 #define WRCHR 10 void stackPush(unsigned int value){ if(current > 100) { fprintf(stderr, "stack overflow\n"); exit(EXIT_FAILURE); } stack[current] = value; current++; } unsigned int stackPop(){ if(current < 1) { fprintf(stderr, "stack underflow\n"); exit(EXIT_FAILURE); } return --current; } void version() { printf("Ninja Virtual Machine version %i (compiled %s, %s)\n", PROJECT_VERSION, __DATE__, __TIME__); } void help() { printf("usage: ./njvm [option] [option] ...\n\t--version\tshow version and exit\n\t--help\t\tshow this help and exit\n"); } void printArgs(int argc, char *argv[]){ for (int i = 0; i < argc; ++i) { printf("%s\n", argv[i]); } } void useption(int argc, char *argv[]){ if (argc > 1) { if (strcmp(argv[1], "--version") == 0) { version(); } else if (strcmp(argv[1], "--help") == 0) { help(); } else if (argc != 0) { printf("unknown command line argument '%s', try './njvm --help'", argv[1]); } } } int main(int argc, char *argv[]) { printArgs(argc,argv); if (argc > 1) useption(argc,argv); else { // Started printf("Ninja Virtual Machine started\n"); // Stopped printf("Ninja Virtual Machine stopped\n"); return 0; } }