-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwhile.h
More file actions
41 lines (34 loc) · 658 Bytes
/
while.h
File metadata and controls
41 lines (34 loc) · 658 Bytes
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
#ifndef __while_h__
#define __while_h__
#include "stmt.h"
#include <string>
#include "expr.h"
class While : public Stmt{
public:
Expr *expr;
Stmt *stmt;
While()
{
expr = NULL;
stmt = NULL;
};
void init(Expr *x , Stmt *s)
{
expr = x;
stmt = s;
if( expr->type != Type::Bool())
{
expr->error("boolean required in while");
}
};
void gen(int b , int a)
{
after = a;
expr->jumping(0,a);
int label = newlabel();
emitlabel(label);
stmt->gen(label,b);
emit("goto L" + std::to_string(b));
}
};
#endif