-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbytecodes.h
More file actions
75 lines (58 loc) · 1.49 KB
/
bytecodes.h
File metadata and controls
75 lines (58 loc) · 1.49 KB
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
69
70
71
72
73
74
75
/*
* Code and types for handling bytecodes, the stuff from which all Derp programs are made
*/
#pragma once
#include "list.h"
#include <stdlib.h>
// any updates to this MUST be mirrored in the string array in bytecodes.c
typedef enum {
CODE_NULL, // dummy code, does nothing
CODE_PUSH,
CODE_PUSH_INT,
CODE_PUSH_FLOAT,
CODE_PUSH_STR,
CODE_PUSH_BOOL,
CODE_PUSH_ARRAY,
CODE_PUSH_FN,
// mathematical and logical operations
CODE_ADD,
CODE_SUB,
CODE_MUL,
CODE_DIV,
CODE_CMP_EQ,
CODE_CMP_NEQ,
CODE_CMP_LT,
CODE_CMP_LT_EQ,
CODE_CMP_GT,
CODE_CMP_GT_EQ,
CODE_CALL,
CODE_REGISTER,
CODE_PUSH_LOOKUP,
CODE_ASSIGN,
CODE_RET,
// control flow handlers
CODE_JUMP_IF_FALSE,
CODE_JUMP,
CODE_REPEAT
} Derp_code_type;
typedef struct {
Derp_code_type code;
// TODO: compress with union
char* arg1;
int arg2; // interestingly, the second arg is always an integer
double float_val;
} instr;
typedef List BCList;
typedef instr* BCVec;
/*
* returns a pointer to a string representation of a bytecode's type
* example: CODE_ADD -> "add"
*/
const char* code_type_to_str(Derp_code_type code);
// Prints an individual bytecode
void bytecode_print(instr* code);
// Prints a bytecode vector
void bytecode_vec_print(instr* instrv, int instrc);
// compress the bytecodes in `input` into a contiguous block
// of memory. Return pointer to that block if successful. NULL otherwise.
instr* bytecodes_compress(List* input);