mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
I've also added a new literal type called 'identifier'. This will be used for variable names, and has a type mask embedded in it.
67 lines
1.3 KiB
C
67 lines
1.3 KiB
C
#pragma once
|
|
|
|
#include "literal.h"
|
|
#include "opcodes.h"
|
|
|
|
//nodes are the intermediaries between parsers and compilers
|
|
typedef union _node Node;
|
|
|
|
typedef enum NodeType {
|
|
NODE_ERROR,
|
|
NODE_LITERAL, //a simple value
|
|
NODE_UNARY, //one child
|
|
NODE_BINARY, //two children, left and right
|
|
NODE_GROUPING, //one child
|
|
NODE_BLOCK, //contains bytecode
|
|
// NODE_CONDITIONAL, //three children: conditional, then path, else path
|
|
} NodeType;
|
|
|
|
typedef struct NodeLiteral {
|
|
NodeType type;
|
|
Literal literal;
|
|
} NodeLiteral;
|
|
|
|
typedef struct NodeUnary {
|
|
NodeType type;
|
|
Opcode opcode;
|
|
Node* child;
|
|
} NodeUnary;
|
|
|
|
typedef struct NodeBinary {
|
|
NodeType type;
|
|
Opcode opcode;
|
|
Node* left;
|
|
Node* right;
|
|
} NodeBinary;
|
|
|
|
typedef struct NodeGrouping {
|
|
NodeType type;
|
|
Node* child;
|
|
} NodeGrouping;
|
|
|
|
typedef struct NodeBlock {
|
|
NodeType type;
|
|
Node* nodes;
|
|
int capacity;
|
|
int count;
|
|
} NodeBlock;
|
|
|
|
union _node {
|
|
NodeType type;
|
|
NodeLiteral atomic;
|
|
NodeUnary unary;
|
|
NodeBinary binary;
|
|
NodeGrouping grouping;
|
|
NodeBlock block;
|
|
};
|
|
|
|
void freeNode(Node* node);
|
|
void emitNodeLiteral(Node** nodeHandle, Literal literal);
|
|
void emitNodeUnary(Node** nodeHandle, Opcode opcode);
|
|
void emitNodeBinary(Node** nodeHandle, Node* rhs, Opcode opcode);
|
|
void emitNodeGrouping(Node** nodeHandle);
|
|
void emitNodeBlock(Node** nodeHandle);
|
|
|
|
void printNode(Node* node);
|
|
|