-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruntime.h
More file actions
62 lines (48 loc) · 1.34 KB
/
runtime.h
File metadata and controls
62 lines (48 loc) · 1.34 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
#ifndef RUNTIME_H
#define RUNTIME_H
#include "ast.h"
#include "env.h"
#include "value.h"
typedef enum {
FLOW_NORMAL,
FLOW_RETURN,
FLOW_BREAK,
FLOW_CONTINUE,
FLOW_ERROR
} FlowType;
typedef struct {
FlowType type;
Value value;
} ExecResult;
/*
ImportedModule stays private in runtime.c.
Runtime only stores an opaque pointer array here so runtime.h does not
need to know about TokenArray, Diagnostics, lexer.h, or parser.h.
*/
typedef struct ImportedModule ImportedModule;
typedef struct Runtime {
Environment globals;
Environment* current;
int hadError;
const char* errorFile;
int errorLine;
int errorColumn;
char errorMessage[256];
ImportedModule* imports;
int importCount;
int importCapacity;
char** fileStack;
int fileStackCount;
int fileStackCapacity;
} Runtime;
void runtimeInit(Runtime* runtime);
void runtimeFree(Runtime* runtime);
int runtimeSetEntryPath(Runtime* runtime, const char* path);
void runtimeError(Runtime* runtime, const char* message);
void runtimeErrorAt(Runtime* runtime, const AstNode* node, const char* message);
ExecResult execNormal(void);
ExecResult execError(void);
ExecResult execReturn(Value value);
Value runtimeEvalExpression(Runtime* runtime, AstNode* node);
ExecResult runtimeExecuteNode(Runtime* runtime, AstNode* node);
#endif