-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatement.h
More file actions
90 lines (77 loc) · 1.52 KB
/
statement.h
File metadata and controls
90 lines (77 loc) · 1.52 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#pragma once
#include <stdint.h>
#include "slice2.h"
#include "expression.h"
enum type_of_s
{
s_declare,
s_func,
s_var,
s_print,
s_if,
s_while,
s_return
};
struct declare
{
Slice *name;
Slice *parameters;
statement **body;
uint16_t args;
uint32_t size_body;
};
struct func
{
Slice *name;
expression **parameters;
uint16_t args;
};
struct var
{
Slice *name;
expression *expr;
};
struct print
{
expression *expr;
};
struct if_statement
{
expression *condition;
statement **body;
statement **else_body;
bool has_else;
uint32_t size_body;
uint32_t size_else;
};
struct while_statement
{
expression *condition;
statement **body;
uint32_t size_body;
};
struct return_statement
{
expression *expr;
};
union internal
{
struct declare *declare;
struct func *func;
struct var *var;
struct print *print;
struct if_statement *if_statement;
struct while_statement *while_statement;
struct return_statement *return_statement;
};
struct statement
{
union internal *internal;
enum type_of_s type;
};
void compile_statement(emitter_t*, statement*, struct declare *declare);
void call_function(emitter_t *emitter, struct func *func);
void free_function(struct func *func);
void free_statement(statement *s);
bool evaluate_statement(Interpreter *in, struct map *map, statement *s, uint64_t *return_value);
uint64_t evaluate_function(Interpreter *in, struct map *map, struct func *func, struct declare *declare);