This repository was archived by the owner on Apr 8, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 63
Beta release fixes and feature. #149
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -51,6 +51,10 @@ abstract class Code implements Spec { | |
abstract class Block implements Built<Block, BlockBuilder>, Code, Spec { | ||
factory Block([void updates(BlockBuilder b)]) = _$Block; | ||
|
||
factory Block.of(Iterable<Code> statements) { | ||
return new Block((b) => b..statements.addAll(statements)); | ||
} | ||
|
||
Block._(); | ||
|
||
@override | ||
|
@@ -111,7 +115,33 @@ abstract class CodeEmitter implements CodeVisitor<StringSink> { | |
} | ||
} | ||
|
||
/// Represents a simple, literal [code] block to be inserted as-is. | ||
/// Represents a code block that requires lazy visiting. | ||
class LazyCode implements Code { | ||
final Spec Function(SpecVisitor) generate; | ||
|
||
const LazyCode._(this.generate); | ||
|
||
@override | ||
R accept<R>(CodeVisitor<R> visitor, [R context]) { | ||
return generate(visitor).accept(visitor, context); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto. |
||
} | ||
} | ||
|
||
/// Returns a generic [Code] that is lazily generated when visited. | ||
Code lazyCode(Code Function() generate) => new _LazyCode(generate); | ||
|
||
class _LazyCode implements Code { | ||
final Code Function() generate; | ||
|
||
const _LazyCode(this.generate); | ||
|
||
@override | ||
R accept<R>(CodeVisitor<R> visitor, [R context]) { | ||
return generate().accept(visitor, context); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto. |
||
} | ||
} | ||
|
||
/// Represents a simple, literal code block to be inserted as-is. | ||
class StaticCode implements Code { | ||
final String code; | ||
|
||
|
@@ -126,9 +156,9 @@ class StaticCode implements Code { | |
String toString() => code; | ||
} | ||
|
||
/// Represents a [code] block that may require scoping. | ||
/// Represents a code block that may require scoping. | ||
class ScopedCode implements Code { | ||
final String Function(Allocate allocate) code; | ||
final String Function(Allocate) code; | ||
|
||
const ScopedCode._(this.code); | ||
|
||
|
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This not only generates lazily, but also generates every time it's visited. Is it intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. We could cache it, but we wouldn't know if the function is stateless or not.