Fix prefix operators
This commit is contained in:
parent
92e7f2d95b
commit
e3aa95e790
@ -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;
|
||||
}
|
||||
|
@ -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};
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
@ -9,6 +10,8 @@ typedef struct
|
||||
char *name;
|
||||
char *arg;
|
||||
uint16_t data;
|
||||
bool ispiped;
|
||||
bool isdrained;
|
||||
} Instruction;
|
||||
|
||||
typedef struct
|
||||
|
Loading…
Reference in New Issue
Block a user