Added the Stack
This commit is contained in:
parent
a64471ed41
commit
1b742e0007
24
njvm.c
24
njvm.c
@ -1,13 +1,33 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include "config.h"
|
#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() {
|
void version() {
|
||||||
printf("Ninja Virtual Machine version %i (compiled %s, %s)\n", PROJECT_VERSION, __DATE__, __TIME__);
|
printf("Ninja Virtual Machine version %i (compiled %s, %s)\n", PROJECT_VERSION, __DATE__, __TIME__);
|
||||||
}
|
}
|
||||||
|
|
||||||
void help() {
|
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[]){
|
void printArgs(int argc, char *argv[]){
|
||||||
for (int i = 0; i < argc; ++i) {
|
for (int i = 0; i < argc; ++i) {
|
||||||
@ -34,8 +54,6 @@ int main(int argc, char *argv[]) {
|
|||||||
// Started
|
// Started
|
||||||
printf("Ninja Virtual Machine started\n");
|
printf("Ninja Virtual Machine started\n");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Stopped
|
// Stopped
|
||||||
printf("Ninja Virtual Machine stopped\n");
|
printf("Ninja Virtual Machine stopped\n");
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user