Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

break in loop control #230

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/generator/writers/writeFunction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ export function writeStatement(
}
}
return;
} else if (f.kind === "statement_break") {
ctx.append(`break ;`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FunC does not support break at the moment, unfortunately

return;
} else if (f.kind === "statement_let") {
// Contract/struct case
const t = resolveTypeRef(ctx.ctx, f.type);
Expand Down
11 changes: 10 additions & 1 deletion src/grammar/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,13 @@ export type ASTStatementRepeat = {
ref: ASTRef;
};

export type ASTStatementBreak = {
kind: "statement_break";
id: number;
ref: ASTRef;
};

//
//
// Unions
//
Expand All @@ -486,7 +493,8 @@ export type ASTStatement =
| ASTCondition
| ASTStatementWhile
| ASTStatementUntil
| ASTStatementRepeat;
| ASTStatementRepeat
| ASTStatementBreak;
export type ASTNode =
| ASTExpression
| ASTStruct
Expand All @@ -513,6 +521,7 @@ export type ASTNode =
| ASTStatementWhile
| ASTStatementUntil
| ASTStatementRepeat
| ASTStatementBreak
| ASTReceive
| ASTLvalueRef
| ASTString
Expand Down
6 changes: 5 additions & 1 deletion src/grammar/grammar.ohm
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,12 @@ Tact {
| StatementWhile
| StatementRepeat
| StatementUntil
| StatementBreak
StatementBlock = "{" Statement* "}"
StatementLet = let id ":" Type "=" Expression ";"
StatementReturn = return Expression ";" --withExpression
| return ";" --withoutExpression
| return ";" --withoutExpression
StatementBreak = break ";"
StatementExpression = Expression ";"
StatementAssign = LValue "=" Expression ";"
StatementAugmentedAssign = StatementAugmentedAssignAdd
Expand Down Expand Up @@ -234,6 +236,7 @@ Tact {
keyword = fun
| let
| return
| break
| extend
| native
| public
Expand All @@ -260,6 +263,7 @@ Tact {
let = "let" ~idPart
fun = "fun" ~idPart
return = "return" ~idPart
break = "break" ~idPart
extend = "extend" ~idPart
native = "native" ~idPart
public = "public" ~idPart
Expand Down
2 changes: 2 additions & 0 deletions src/grammar/grammar.ohm-bundle.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export interface TactActionDict<T> extends ActionDict<T> {
StatementReturn_withExpression?: (this: NonterminalNode, arg0: NonterminalNode, arg1: NonterminalNode, arg2: TerminalNode) => T;
StatementReturn_withoutExpression?: (this: NonterminalNode, arg0: NonterminalNode, arg1: TerminalNode) => T;
StatementReturn?: (this: NonterminalNode, arg0: NonterminalNode) => T;
StatementBreak?: (this: NonterminalNode, arg0: NonterminalNode, arg1: TerminalNode) => T;
StatementExpression?: (this: NonterminalNode, arg0: NonterminalNode, arg1: TerminalNode) => T;
StatementAssign?: (this: NonterminalNode, arg0: NonterminalNode, arg1: TerminalNode, arg2: NonterminalNode, arg3: TerminalNode) => T;
StatementAugmentedAssign?: (this: NonterminalNode, arg0: NonterminalNode) => T;
Expand Down Expand Up @@ -181,6 +182,7 @@ export interface TactActionDict<T> extends ActionDict<T> {
let?: (this: NonterminalNode, arg0: TerminalNode) => T;
fun?: (this: NonterminalNode, arg0: TerminalNode) => T;
return?: (this: NonterminalNode, arg0: TerminalNode) => T;
break?: (this: NonterminalNode, arg0: TerminalNode) => T;
extend?: (this: NonterminalNode, arg0: TerminalNode) => T;
native?: (this: NonterminalNode, arg0: TerminalNode) => T;
public?: (this: NonterminalNode, arg0: TerminalNode) => T;
Expand Down
2 changes: 1 addition & 1 deletion src/grammar/grammar.ohm-bundle.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions src/grammar/grammar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,12 @@ semantics.addOperation<ASTNode>("resolve_statement", {
ref: createRef(this),
});
},
StatementBreak(_arg0, _arg1) {
return createNode({
kind: "statement_break",
ref: createRef(this),
});
},
StatementExpression(arg0, _arg1) {
return createNode({
kind: "statement_expression",
Expand Down
Loading