-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd.h
76 lines (74 loc) · 1.79 KB
/
cmd.h
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
#pragma once
#include "list.h"
#include "ast.h"
#include "scope.h"
#define ARG_REGISTER_COUNT 4
typedef List CmdList;
struct _Cmd {
enum {
C_DECLARATION,
C_INCREMENT,
C_IF_ELSE,
C_FOR,
C_FUNC_CALL,
C_FUNC,
C_FUNC_RETURN,
C_RETURN
} kind;
union {
struct {
Expr* variable;
char* operator;
Expr* expr;
} declaration;
struct {
Expr* variable;
char* operator;
Expr* expr;
} increment;
struct {
struct _Expr* condition;
CmdList* iftrue;
CmdList* iffalse;
} ifelse;
struct {
struct _Cmd* initial;
struct _Expr* condition;
struct _Cmd* afterIteration;
CmdList* body;
} forCmd;
struct {
char* funcName;
ExprList* variables;
} funcCall;
struct {
Expr* variable;
char* operator;
struct _Cmd* funcCall;
} funcReturn;
struct {
char* funcName;
ExprList* argList;
CmdList* commandList;
Scope* scope;
} func;
struct {
Expr* value;
} _return;
} attr;
};
typedef struct _Cmd Cmd;
CmdList* makeCmdList(Cmd* firstCmd);
CmdList* appendCmd(CmdList* list, Cmd* value);
CmdList* prependCmd(CmdList* list, Cmd* value);
Cmd* getCmd(CmdList* list);
void printCmd(Cmd* cmd, int level, int lastChild);
void printCmdList(CmdList* cmdlist, int level, int lastChild);
Cmd* makeDeclarationCmd(Expr* variable, char* operator, Expr* expr);
Cmd* makeIncrementCmd(Expr* variable, char* operator, Expr* expr );
Cmd* makeIfElseCmd(Expr* expr, CmdList* iftrue, CmdList* iffalse );
Cmd* makeFor(Cmd* initial, Expr* condition, Cmd* afterIteration, CmdList* body );
Cmd* makeFuncCall(char* funcName, ExprList* variables) ;
Cmd* makeFunc(char* funcName, ExprList* arglist, CmdList* cmdlist) ;
Cmd* makeFunctionReturn(Expr* variable, char* operator, Cmd* funcCall) ;
Cmd* makeReturn(Expr* expr);