ADD: continue keyword.
parent
b9eb183319
commit
84b0af8090
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
enum BlockInfoHints {
|
enum BlockInfoHints {
|
||||||
HINT_END,
|
HINT_END,
|
||||||
|
HINT_START
|
||||||
};
|
};
|
||||||
|
|
||||||
enum BlockInfoKind {
|
enum BlockInfoKind {
|
||||||
|
|
|
@ -111,7 +111,6 @@ void compile_node(compiler* self, node* root, program* prog)
|
||||||
for (size_t i=0; i<info->size; i++)
|
for (size_t i=0; i<info->size; i++)
|
||||||
{
|
{
|
||||||
size_t addr = info->data[i]->addr;
|
size_t addr = info->data[i]->addr;
|
||||||
int hint = info->data[i]->hint;
|
|
||||||
program_set_param(prog, addr, prog->instrs.size);
|
program_set_param(prog, addr, prog->instrs.size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,7 +135,12 @@ void compile_node(compiler* self, node* root, program* prog)
|
||||||
|
|
||||||
for (size_t i=0; i<bi->size; i++)
|
for (size_t i=0; i<bi->size; i++)
|
||||||
{
|
{
|
||||||
if (bi->data[i]->hint == HINT_END)
|
if (bi->data[i]->hint == HINT_START)
|
||||||
|
{
|
||||||
|
program_set_param(prog, bi->data[i]->addr,
|
||||||
|
start_addr);
|
||||||
|
}
|
||||||
|
else if (bi->data[i]->hint == HINT_END)
|
||||||
{
|
{
|
||||||
program_set_param(prog, bi->data[i]->addr,
|
program_set_param(prog, bi->data[i]->addr,
|
||||||
prog->instrs.size);
|
prog->instrs.size);
|
||||||
|
@ -151,6 +155,12 @@ void compile_node(compiler* self, node* root, program* prog)
|
||||||
block_info_push(bi, prog->instrs.size, HINT_END);
|
block_info_push(bi, prog->instrs.size, HINT_END);
|
||||||
program_add_instr(prog, OP_BR, NO_PARAM);
|
program_add_instr(prog, OP_BR, NO_PARAM);
|
||||||
}
|
}
|
||||||
|
else if (root->type == NODE_CONTINUE)
|
||||||
|
{
|
||||||
|
block_info* bi = compiler_find_info(self, INFO_KIND_LOOP);
|
||||||
|
block_info_push(bi, prog->instrs.size, HINT_START);
|
||||||
|
program_add_instr(prog, OP_BR, NO_PARAM);
|
||||||
|
}
|
||||||
else if (root->type == NODE_INDEX)
|
else if (root->type == NODE_INDEX)
|
||||||
{
|
{
|
||||||
compile_children(self, root, prog);
|
compile_children(self, root, prog);
|
||||||
|
|
|
@ -85,7 +85,14 @@ exprs:
|
||||||
|
|
||||||
|
|
||||||
expr:
|
expr:
|
||||||
BREAK {
|
CONTINUE {
|
||||||
|
node* n = malloc(sizeof(node));
|
||||||
|
node_init(n, NODE_CONTINUE, "", line);
|
||||||
|
stack_push(n);
|
||||||
|
$$ = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
| BREAK {
|
||||||
node* n = malloc(sizeof(node));
|
node* n = malloc(sizeof(node));
|
||||||
node_init(n, NODE_BREAK, "", line);
|
node_init(n, NODE_BREAK, "", line);
|
||||||
stack_push(n);
|
stack_push(n);
|
||||||
|
|
|
@ -34,3 +34,22 @@ end
|
||||||
|
|
||||||
assert 17 == e
|
assert 17 == e
|
||||||
|
|
||||||
|
let! f = 0
|
||||||
|
let! g = 0
|
||||||
|
|
||||||
|
while f < 100
|
||||||
|
f = f + 1
|
||||||
|
|
||||||
|
if f % 2 == 0
|
||||||
|
continue
|
||||||
|
end
|
||||||
|
|
||||||
|
if f >= 50
|
||||||
|
break
|
||||||
|
end
|
||||||
|
|
||||||
|
g = g + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
assert 51 == f
|
||||||
|
assert 25 == g
|
||||||
|
|
Loading…
Reference in New Issue