Fixed errors
This commit is contained in:
parent
073adaa6cf
commit
ec82349ce2
6
Makefile
6
Makefile
@ -3,8 +3,9 @@ TARGET_EXEC ?= stack_vm
|
||||
BUILD_DIR ?= ./build
|
||||
SRC_DIRS ?= ./src
|
||||
|
||||
SRCS := $(shell find $(SRC_DIRS) -name *.c)
|
||||
SRCS := $(shell find $(SRC_DIRS) -name "*.c")
|
||||
OBJS := $(SRCS:%=$(BUILD_DIR)/%.o)
|
||||
DEPS := $(OBJS:.o=.d)
|
||||
|
||||
INC_DIRS := $(shell find $(SRC_DIRS) -type d)
|
||||
INC_FLAGS := $(addprefix -I,$(INC_DIRS))
|
||||
@ -12,6 +13,7 @@ INC_FLAGS := $(addprefix -I,$(INC_DIRS))
|
||||
CPPFLAGS ?= $(INC_FLAGS) -MMD -MP -D IO_OPERATIONS
|
||||
|
||||
$(BUILD_DIR)/$(TARGET_EXEC): $(OBJS)
|
||||
echo $(SRC_DIRS)
|
||||
$(CC) -ggdb3 $(OBJS) -o $@ $(LDFLAGS)
|
||||
|
||||
$(BUILD_DIR)/%.c.o: %.c
|
||||
@ -25,4 +27,6 @@ all: $(BUILD_DIR)/$(TARGET_EXEC)
|
||||
clean:
|
||||
$(RM) -r $(BUILD_DIR)
|
||||
|
||||
-include $(DEPS)
|
||||
|
||||
MKDIR_P ?= mkdir -p
|
@ -4,6 +4,7 @@ Stack based virtual machine and assembly code compiler
|
||||
|
||||
## Features
|
||||
|
||||
- Binary code execution (assembly language compilation coming soon)
|
||||
- Assembly
|
||||
- Stack operations (push & pop)
|
||||
- Arithmetics operations
|
||||
@ -36,7 +37,6 @@ Stack based virtual machine and assembly code compiler
|
||||
|
||||
## TODO
|
||||
|
||||
- VM running
|
||||
- Assembly compiler
|
||||
- Variables
|
||||
- Arithmetics operators
|
||||
|
@ -67,7 +67,10 @@ int main(int argc, char *argv[])
|
||||
|
||||
command_t **commands = read_bin_file(argv[2], res);
|
||||
if (commands == NULL)
|
||||
{
|
||||
fprintf(stderr, "Couldn't read file\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return run(commands, stack);
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ command_t **read_bin_file(char src[], int *res)
|
||||
int size = -1;
|
||||
fread(&size, sizeof(int), 1, file);
|
||||
|
||||
command_t **buffer = malloc(sizeof(command_t *) * size);
|
||||
command_t **buffer = malloc(sizeof(command_t *) * (size + 1));
|
||||
if (buffer == NULL)
|
||||
{
|
||||
*res = -1;
|
||||
@ -20,11 +20,16 @@ command_t **read_bin_file(char src[], int *res)
|
||||
{
|
||||
buffer[i] = malloc(sizeof(command_t));
|
||||
|
||||
fread(buffer[i]->code, sizeof(int), 1, file);
|
||||
fread(&buffer[i]->code, sizeof(int), 1, file);
|
||||
|
||||
buffer[i]->arg_v = malloc(sizeof(int) * cmd_desc[buffer[i]->code].argc);
|
||||
fread(buffer[i]->arg_v, sizeof(int), cmd_desc[buffer[i]->code].argc, file);
|
||||
if (cmd_desc[buffer[i]->code].argc)
|
||||
{
|
||||
buffer[i]->arg_v = malloc(sizeof(int) * cmd_desc[buffer[i]->code].argc);
|
||||
fread(buffer[i]->arg_v, sizeof(int), cmd_desc[buffer[i]->code].argc, file);
|
||||
}
|
||||
}
|
||||
|
||||
buffer[size] = NULL;
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
@ -151,7 +151,7 @@ int exec(command_t cmd, stack_t *stack)
|
||||
if (res != NULL)
|
||||
return *res;
|
||||
|
||||
while (ch != NULL)
|
||||
while (ch != '\0')
|
||||
{
|
||||
putchar(ch);
|
||||
ch = stack_pop(stack, res);
|
||||
|
@ -6,14 +6,14 @@ stack_t *stack_new(int size, int *result)
|
||||
if (stack == NULL)
|
||||
{
|
||||
*result = -1;
|
||||
return *result;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
stack->mem = (int *)malloc(sizeof(int) * size);
|
||||
if (stack->mem == NULL)
|
||||
{
|
||||
*result = -1;
|
||||
return *result;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
stack->size = size;
|
||||
|
@ -4,7 +4,7 @@ int str_len(char str[])
|
||||
{
|
||||
int pos = 0;
|
||||
|
||||
while (str[pos] != NULL)
|
||||
while (str[pos] != '\0')
|
||||
pos++;
|
||||
|
||||
return pos;
|
||||
|
Loading…
x
Reference in New Issue
Block a user