about summary refs log tree commit diff
path: root/src/instruction.c
blob: 4189dd17a1155407f063539c4d23ccc1b104b6d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include "instruction.h"
#include "instructions.h"

#include <stdbool.h>
#include <stdio.h>

#include "readchar.h"
#include "3cl.h"


struct CCLFrame *ccl_instruction(struct CCL *ccl, struct CCLFrame *frame)
{
    CCLInstruction instruction;
    char chr = ccl_readchar(ccl, frame, CCL_RC_CCL_INSTR);

    if (chr == '\0')
    {
        ccl->stopped = true;
        return INST(nop)(ccl, frame);
    }

#define ISSW(NAME) instruction = INST(NAME); break
    switch (chr)
    {
    case '\n': /* FALLTHROUGH */
    case ' ' : /* FALLTHROUGH */
    case '\t': ISSW(nop);
    case '^' : ISSW(pushzero);
    case '+' : ISSW(increment);
    case '-' : ISSW(decrement);
    case '*' : ISSW(add);
    case '~' : ISSW(subtract);
    case '%' : ISSW(reverse);
    case '=' : ISSW(assign);
    default  : ISSW(invalid);
    }
#undef INSW
    return instruction(ccl, frame);
    puts("aboba");
}