Started implementing the debugger.

This commit is contained in:
2017-01-31 19:42:04 +01:00
parent 3eba81d2bd
commit e47cb247eb
13 changed files with 7188 additions and 118 deletions

View File

@@ -1,38 +1,13 @@
#include "stack.h"
#include <stdlib.h>
void stack_init(t_stack& stack, const int size) {
if (stack.data != nullptr) free(stack.data);
stack.data = (unsigned char*)malloc(size);
stack.max = size;
stack.top = -1;
}
const bool stack_isempty(t_stack& stack) {
return stack.top == -1;
}
#define TOP stack.data[0]
#define PUSH(x, y) x[++x[0]] = y
#define POP(x) (x[x[0]--])
#define PEEK(x) (x[x[0]])
const bool stack_isfull(t_stack& stack) {
return stack.top == stack.max;
}
void stack_push(t_stack& stack, const unsigned char value) { stack.data[++TOP] = value; }
const unsigned char stack_pop(t_stack& stack) { return stack.data[TOP--]; }
const unsigned char stack_peek(t_stack& stack) { return stack.data[TOP]; }
void stack_push(t_stack& stack, const unsigned char value) {
if (!stack_isfull(stack)) {
stack.data[++stack.top] = value;
}
}
const unsigned char stack_pop(t_stack& stack) {
if (!stack_isempty(stack)) {
return stack.data[stack.top--];
}
return 0;
}
const unsigned char stack_peek(t_stack& stack) {
return stack.data[stack.top];
}
void stack_delete(t_stack& stack) {
free(stack.data);
}