diff --git a/njvm.c b/njvm.c index 95cf57c..7e9fd70 100644 --- a/njvm.c +++ b/njvm.c @@ -1,13 +1,33 @@ #include #include +#include #include "config.h" +unsigned int stack[100]; +unsigned int current = 0; + +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"); + 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) { @@ -34,8 +54,6 @@ int main(int argc, char *argv[]) { // Started printf("Ninja Virtual Machine started\n"); - - // Stopped printf("Ninja Virtual Machine stopped\n"); return 0;