diff --git a/src/execute.c b/src/execute.c index 15dd456..6d526e8 100644 --- a/src/execute.c +++ b/src/execute.c @@ -16,6 +16,7 @@ #define NAME stack->program[stack->program_counter].name #define DATA stack->program[stack->program_counter].data #define ARG stack->program[stack->program_counter].arg +#define INST stack->program[stack->program_counter] typedef enum { @@ -43,16 +44,14 @@ static void prefix_operator(Stack *stack, char op) case PDRAIN: NAME++; - stack_push(stack, DATA); - - DATA = 0; + INST.isdrained = true; break; case PPIPE: NAME++; - DATA = stack_pop(stack); + INST.ispiped = true; break; } @@ -148,6 +147,15 @@ void execute(Stack *stack, Stack *originstack, char *modname) #endif prefix_operator(stack, NAME[0]); + if (INST.ispiped) + DATA = stack_pop(stack); + + if (INST.isdrained) + { + stack_push(stack, DATA); + DATA = 0; + } + if (NAME[0] == '#' || NAME[0] == '$') NAME++; @@ -601,7 +609,7 @@ void execute(Stack *stack, Stack *originstack, char *modname) if (ARG[0] == '@' && ARG[1] == ' ') kms(stack, "ATTEMPTED TO INSERT A LABEL"); - stack->program[stack->program_size++] = (Instruction){ARG, "\n", DATA}; + stack->program[stack->program_size++] = (Instruction){ARG, "\n", DATA, false, false}; continue; } diff --git a/src/stack.c b/src/stack.c index a095952..13325ca 100644 --- a/src/stack.c +++ b/src/stack.c @@ -99,7 +99,7 @@ void parse_and_process(Stack *stack, FILE *file) inst.arg = "\n"; char *duppedarg = strdup(inst.arg); - stack->program[stack->program_size++] = (Instruction){duppedname, duppedarg, inst.data}; + stack->program[stack->program_size++] = (Instruction){duppedname, duppedarg, inst.data, false, false}; } } diff --git a/src/stack.h b/src/stack.h index 3f9fe0f..ada938b 100644 --- a/src/stack.h +++ b/src/stack.h @@ -1,4 +1,5 @@ #pragma once +#include #include #include @@ -9,6 +10,8 @@ typedef struct char *name; char *arg; uint16_t data; + bool ispiped; + bool isdrained; } Instruction; typedef struct