-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b753fa0
commit 96ecba4
Showing
22 changed files
with
292 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import 'package:dart_eval/src/eval/compiler/context.dart'; | ||
|
||
class CompilerLabel { | ||
final int offset; | ||
final int Function(CompilerContext ctx) cleanup; | ||
final String? name; | ||
final LabelType type; | ||
|
||
const CompilerLabel(this.type, this.offset, this.cleanup, {this.name}); | ||
} | ||
|
||
class SimpleCompilerLabel implements CompilerLabel { | ||
get offset => -1; | ||
final String? name; | ||
get type => LabelType.block; | ||
|
||
const SimpleCompilerLabel({this.name}); | ||
|
||
get cleanup => (CompilerContext ctx) { | ||
ctx.endAllocScopeQuiet(); | ||
return -1; | ||
}; | ||
} | ||
|
||
enum LabelType { loop, branch, block } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import 'package:analyzer/dart/ast/ast.dart'; | ||
import 'package:dart_eval/src/eval/compiler/context.dart'; | ||
import 'package:dart_eval/src/eval/compiler/errors.dart'; | ||
import 'package:dart_eval/src/eval/compiler/model/label.dart'; | ||
import 'package:dart_eval/src/eval/compiler/statement/statement.dart'; | ||
|
||
StatementInfo compileBreakStatement(BreakStatement s, CompilerContext ctx) { | ||
if (s.label != null) { | ||
throw CompileError('Break labels are not currently supported', s); | ||
} | ||
|
||
final currentState = ctx.saveState(); | ||
|
||
final index = | ||
ctx.labels.lastIndexWhere((label) => label.type == LabelType.loop); | ||
|
||
if (index == -1) { | ||
throw CompileError('Cannot use \'break\' outside of a loop context', s); | ||
} | ||
|
||
for (var i = ctx.labels.length - 1; i > index; i--) { | ||
ctx.labels[i].cleanup(ctx); | ||
} | ||
final label = ctx.labels[index]; | ||
final offset = label.cleanup(ctx); | ||
if (!ctx.labelReferences.containsKey(label)) { | ||
ctx.labelReferences[label] = {}; | ||
} | ||
ctx.labelReferences[label]!.add(offset); | ||
ctx.restoreState(currentState); | ||
return StatementInfo(-1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.