Fix prefix operators

This commit is contained in:
bʰedoh₂ swé 2024-06-19 06:07:41 +05:00
parent 92e7f2d95b
commit e3aa95e790
3 changed files with 17 additions and 6 deletions

View File

@ -16,6 +16,7 @@
#define NAME stack->program[stack->program_counter].name #define NAME stack->program[stack->program_counter].name
#define DATA stack->program[stack->program_counter].data #define DATA stack->program[stack->program_counter].data
#define ARG stack->program[stack->program_counter].arg #define ARG stack->program[stack->program_counter].arg
#define INST stack->program[stack->program_counter]
typedef enum typedef enum
{ {
@ -43,16 +44,14 @@ static void prefix_operator(Stack *stack, char op)
case PDRAIN: case PDRAIN:
NAME++; NAME++;
stack_push(stack, DATA); INST.isdrained = true;
DATA = 0;
break; break;
case PPIPE: case PPIPE:
NAME++; NAME++;
DATA = stack_pop(stack); INST.ispiped = true;
break; break;
} }
@ -148,6 +147,15 @@ void execute(Stack *stack, Stack *originstack, char *modname)
#endif #endif
prefix_operator(stack, NAME[0]); 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] == '$') if (NAME[0] == '#' || NAME[0] == '$')
NAME++; NAME++;
@ -601,7 +609,7 @@ void execute(Stack *stack, Stack *originstack, char *modname)
if (ARG[0] == '@' && ARG[1] == ' ') if (ARG[0] == '@' && ARG[1] == ' ')
kms(stack, "ATTEMPTED TO INSERT A LABEL"); 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; continue;
} }

View File

@ -99,7 +99,7 @@ void parse_and_process(Stack *stack, FILE *file)
inst.arg = "\n"; inst.arg = "\n";
char *duppedarg = strdup(inst.arg); 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};
} }
} }

View File

@ -1,4 +1,5 @@
#pragma once #pragma once
#include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
@ -9,6 +10,8 @@ typedef struct
char *name; char *name;
char *arg; char *arg;
uint16_t data; uint16_t data;
bool ispiped;
bool isdrained;
} Instruction; } Instruction;
typedef struct typedef struct