Added push and pop commands
This commit is contained in:
parent
253bc13ce3
commit
0e5fa6c854
3
.gitignore
vendored
3
.gitignore
vendored
@ -1 +1,2 @@
|
|||||||
build/
|
build/
|
||||||
|
.vscode/
|
3
Makefile
3
Makefile
@ -18,6 +18,9 @@ run.o:
|
|||||||
stack.o:
|
stack.o:
|
||||||
$(CC) -c stack.c $(CFLAG) -o $(BUILD_DIR)/$@
|
$(CC) -c stack.c $(CFLAG) -o $(BUILD_DIR)/$@
|
||||||
|
|
||||||
|
command.o:
|
||||||
|
$(CC) -c command.c $(CFLAG) -o $(BUILD_DIR)/$@
|
||||||
|
|
||||||
clear:
|
clear:
|
||||||
rm -rf $(BUILD_DIR)
|
rm -rf $(BUILD_DIR)
|
||||||
|
|
||||||
|
6
command.c
Normal file
6
command.c
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#include "./command.h"
|
||||||
|
|
||||||
|
cmd_desc_t cmd_desc[] = {
|
||||||
|
{PUSH, 1, "PUSH"},
|
||||||
|
{POP, 0, "POP"},
|
||||||
|
{NONE, 0, "NONE"}}
|
19
command.h
19
command.h
@ -3,9 +3,26 @@
|
|||||||
|
|
||||||
enum command_e
|
enum command_e
|
||||||
{
|
{
|
||||||
|
PUSH,
|
||||||
|
POP,
|
||||||
NONE
|
NONE
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef enum command_e command_t;
|
typedef enum command_e cmd_code_t;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
cmd_code_t command;
|
||||||
|
int argc;
|
||||||
|
char name[10];
|
||||||
|
} cmd_desc_t;
|
||||||
|
|
||||||
|
cmd_desc_t cmd_desc[];
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
cmd_code_t code;
|
||||||
|
int args[];
|
||||||
|
} command_t;
|
||||||
|
|
||||||
#endif
|
#endif
|
16
run.c
16
run.c
@ -1,22 +1,30 @@
|
|||||||
#include "./run.h"
|
#include "./run.h"
|
||||||
|
|
||||||
int run(command_t *buff, stack_t stack)
|
int run(command_t **buff, stack_t *stack)
|
||||||
{
|
{
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
int res = 0;
|
int res = 0;
|
||||||
|
|
||||||
while (buff[pos] != NULL)
|
while (buff[pos] != NULL)
|
||||||
{
|
{
|
||||||
res = exec(buff[pos], stack);
|
res = exec(*(buff[pos]), stack);
|
||||||
|
if (res)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
int exec(command_t cmd, stack_t stack)
|
int exec(command_t cmd, stack_t *stack)
|
||||||
{
|
{
|
||||||
switch (cmd)
|
switch (cmd.code)
|
||||||
{
|
{
|
||||||
|
case PUSH:
|
||||||
|
stack_push(stack, cmd.args[0]);
|
||||||
|
break;
|
||||||
|
case POP:
|
||||||
|
stack_pop(stack);
|
||||||
|
break;
|
||||||
case NONE:
|
case NONE:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user