aboutsummaryrefslogtreecommitdiffstats
path: root/optable.h
blob: 9675678ada6f08e78611f33b3b2a89374f930928 (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <stdio.h>
#include <stdbool.h>
#include "stack.h"

#ifndef OPTABLE_H
#define OPTABLE_H

#define OPTABLE_MAX_SIZE 1024
#define DEFINED_FUNC_MAX_LENGTH 1024
#define WORD_LEN_LIMIT 255

typedef struct optable optable;
typedef struct wordop wordop;

typedef void (*stackop)(stack *);
typedef void (*directiveop)(stack *, int len, char* line, int* i, optable* optable);

#ifdef __EMSCRIPTEN__
extern char outputbuffer[1024];
extern int* outputline;
#endif

typedef struct {
    bool isliteral;
    union {
        wordop* wordop;
        stackitem literal;
    };
} compileditem;

typedef enum {
    directive = 0,
    builtin = 1,
    script = 2,
    compiled = 3,
} optype;

struct wordop {
    char* word;
    optype optype;
    union {
        directiveop directive;
        stackop op;
        struct {
            char* script;
            int scriptlen;
        };
        struct {
            compileditem* oplist;
            int oplistlen;
        };
    };
};

struct optable {
    int len;
    wordop* optable;
};

/**
 * getop returns the first wordop in the optable which is called by the word given as a parameter
 *      if none exist, returns 0
 */
wordop* optable_getop(optable* optable, char *word);

optable* optable_new();

#endif //OPTABLE_H