Moved name labels to the statement production.
This commit is contained in:
parent
649e01b7c5
commit
2ce9882cad
3 changed files with 30 additions and 21 deletions
|
@ -28,23 +28,29 @@ namespace arookas {
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class sunLoop : sunNode {
|
abstract class sunLoop : sunNode {
|
||||||
public bool IsNamed { get { return NameLabel != null; } }
|
|
||||||
public sunNameLabel NameLabel { get { return this[0] as sunNameLabel; } }
|
|
||||||
|
|
||||||
protected sunLoop(sunSourceLocation location)
|
protected sunLoop(sunSourceLocation location)
|
||||||
: base(location) { }
|
: base(location) { }
|
||||||
|
|
||||||
|
public void PushLoop(sunContext context) {
|
||||||
|
var name = context.PopNameLabel();
|
||||||
|
if (name == null) {
|
||||||
|
context.Loops.Push();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
context.Loops.Push(name.Label.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class sunWhile : sunLoop
|
class sunWhile : sunLoop {
|
||||||
{
|
public sunExpression Condition { get { return this[0] as sunExpression; } }
|
||||||
public sunExpression Condition { get { return this[Count - 2] as sunExpression; } }
|
public sunNode Body { get { return this[1]; } }
|
||||||
public sunNode Body { get { return this[Count - 1]; } }
|
|
||||||
|
|
||||||
public sunWhile(sunSourceLocation location)
|
public sunWhile(sunSourceLocation location)
|
||||||
: base(location) { }
|
: base(location) { }
|
||||||
|
|
||||||
public override void Compile(sunContext context) {
|
public override void Compile(sunContext context) {
|
||||||
context.Loops.Push(IsNamed ? NameLabel.Label.Value : null);
|
PushLoop(context);
|
||||||
var bodyPrologue = context.Text.OpenPoint();
|
var bodyPrologue = context.Text.OpenPoint();
|
||||||
var continuePoint = context.Text.OpenPoint();
|
var continuePoint = context.Text.OpenPoint();
|
||||||
Condition.Compile(context);
|
Condition.Compile(context);
|
||||||
|
@ -57,16 +63,15 @@ namespace arookas {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class sunDo : sunLoop
|
class sunDo : sunLoop {
|
||||||
{
|
public sunNode Body { get { return this[0]; } }
|
||||||
public sunNode Body { get { return this[Count - 2]; } }
|
public sunExpression Condition { get { return this[1] as sunExpression; } }
|
||||||
public sunExpression Condition { get { return this[Count - 1] as sunExpression; } }
|
|
||||||
|
|
||||||
public sunDo(sunSourceLocation location)
|
public sunDo(sunSourceLocation location)
|
||||||
: base(location) { }
|
: base(location) { }
|
||||||
|
|
||||||
public override void Compile(sunContext context) {
|
public override void Compile(sunContext context) {
|
||||||
context.Loops.Push(IsNamed ? NameLabel.Label.Value : null);
|
PushLoop(context);
|
||||||
var bodyPrologue = context.Text.OpenPoint();
|
var bodyPrologue = context.Text.OpenPoint();
|
||||||
Body.Compile(context);
|
Body.Compile(context);
|
||||||
var continuePoint = context.Text.OpenPoint();
|
var continuePoint = context.Text.OpenPoint();
|
||||||
|
@ -89,8 +94,8 @@ namespace arookas {
|
||||||
: base(location) { }
|
: base(location) { }
|
||||||
|
|
||||||
public override void Compile(sunContext context) {
|
public override void Compile(sunContext context) {
|
||||||
context.Scopes.Push(context.Scopes.Top.Type);
|
context.Scopes.Push();
|
||||||
context.Loops.Push(IsNamed ? NameLabel.Label.Value : null);
|
PushLoop(context);
|
||||||
TryCompile(Declaration, context);
|
TryCompile(Declaration, context);
|
||||||
var bodyPrologue = context.Text.OpenPoint();
|
var bodyPrologue = context.Text.OpenPoint();
|
||||||
TryCompile(Condition, context);
|
TryCompile(Condition, context);
|
||||||
|
|
|
@ -35,5 +35,9 @@
|
||||||
|
|
||||||
public sunNameLabel(sunSourceLocation location)
|
public sunNameLabel(sunSourceLocation location)
|
||||||
: base(location) { }
|
: base(location) { }
|
||||||
|
|
||||||
|
public override void Compile(sunContext context) {
|
||||||
|
context.PushNameLabel(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -123,9 +123,9 @@ root_statement =
|
||||||
statement =
|
statement =
|
||||||
compound_statement SEMICOLON |
|
compound_statement SEMICOLON |
|
||||||
if_statement |
|
if_statement |
|
||||||
while_statement |
|
[name_label] while_statement |
|
||||||
do_statement SEMICOLON |
|
[name_label] do_statement SEMICOLON |
|
||||||
for_statement |
|
[name_label] for_statement |
|
||||||
return_statement SEMICOLON |
|
return_statement SEMICOLON |
|
||||||
break_statement SEMICOLON |
|
break_statement SEMICOLON |
|
||||||
continue_statement SEMICOLON |
|
continue_statement SEMICOLON |
|
||||||
|
@ -219,9 +219,9 @@ builtin_declaration = BUILTIN IDENTIFIER parameter_list;
|
||||||
|
|
||||||
// flow control
|
// flow control
|
||||||
if_statement = IF expression statement [ELSE statement];
|
if_statement = IF expression statement [ELSE statement];
|
||||||
while_statement = [name_label] WHILE expression statement;
|
while_statement = WHILE expression statement;
|
||||||
do_statement = [name_label] DO statement WHILE expression;
|
do_statement = DO statement WHILE expression;
|
||||||
for_statement = [name_label] FOR L_PAREN [for_declaration] SEMICOLON [for_condition] SEMICOLON [for_iteration] R_PAREN statement;
|
for_statement = FOR L_PAREN [for_declaration] SEMICOLON [for_condition] SEMICOLON [for_iteration] R_PAREN statement;
|
||||||
for_declaration = compound_statement;
|
for_declaration = compound_statement;
|
||||||
for_condition = expression;
|
for_condition = expression;
|
||||||
for_iteration = compound_statement;
|
for_iteration = compound_statement;
|
||||||
|
|
Loading…
Reference in a new issue