-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
13 changed files
with
199 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
"A `let` expression, that is, | ||
the keyword ‘`let`’, followed by a [[list of values|letValues]] | ||
and an [[expression]] that can involve these values. | ||
Examples: | ||
let (dist = sqrt(x^2 + y^2)) [x / dist, y / dist] | ||
let (c = other.a, d = other.b) Complex(a*c - b*d, a*d + b*c)" | ||
shared class LetExpression(letValues, expression) | ||
extends Expression() { | ||
|
||
"The values that the `let` expression introduces." | ||
shared LetValueList letValues; | ||
"The expression." | ||
shared Expression expression; | ||
|
||
shared actual [LetValueList, Expression] children = [letValues, expression]; | ||
|
||
shared actual Result transform<out Result>(Transformer<Result> transformer) | ||
=> transformer.transformLetExpression(this); | ||
|
||
shared actual Boolean equals(Object that) { | ||
if (is LetExpression that) { | ||
return letValues == that.letValues && expression == that.expression; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
shared actual Integer hash | ||
=> 31 * (letValues.hash + 31 * expression.hash); | ||
|
||
shared LetExpression copy(LetValueList letValues = this.letValues, Expression expression = this.expression) { | ||
value ret = LetExpression(letValues, expression); | ||
copyExtraInfoTo(ret); | ||
return ret; | ||
} | ||
} |
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,34 @@ | ||
"A list of `let` values, enclosed in parentheses. | ||
Examples: | ||
(dist = sqrt(x^2 + y^2)) | ||
(c = other.a, d = other.b)" | ||
shared class LetValueList(letValues) | ||
extends ExpressionIsh() { | ||
|
||
"The individual values." | ||
shared [SpecifiedVariable+] letValues; | ||
|
||
shared actual [SpecifiedVariable+] children = letValues; | ||
|
||
shared actual Result transform<out Result>(Transformer<Result> transformer) | ||
=> transformer.transformLetValueList(this); | ||
|
||
shared actual Boolean equals(Object that) { | ||
if (is LetValueList that) { | ||
return letValues == that.letValues; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
shared actual Integer hash | ||
=> 31 * letValues.hash; | ||
|
||
shared LetValueList copy([SpecifiedVariable+] letValues = this.letValues) { | ||
value ret = LetValueList(letValues); | ||
copyExtraInfoTo(ret); | ||
return ret; | ||
} | ||
} |
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,52 @@ | ||
import ceylon.ast.core { | ||
LetExpression, | ||
LetValueList, | ||
SpecifiedVariable, | ||
Type, | ||
ValueModifier | ||
} | ||
import com.redhat.ceylon.compiler.typechecker.tree { | ||
Tree { | ||
JLetExpression=LetExpression, | ||
JStaticType=StaticType, | ||
JValueModifier=ValueModifier | ||
} | ||
} | ||
import ceylon.interop.java { | ||
CeylonIterable | ||
} | ||
|
||
"Converts a RedHat AST [[LetExpression|JLetExpression]] to a `ceylon.ast` [[LetExpression]]." | ||
shared LetExpression letExpressionToCeylon(JLetExpression letExpression) { | ||
value letClause = letExpression.letClause; | ||
value letValues = CeylonIterable(letClause.variables).collect((jVariable) { | ||
assert (exists jSpecifierExpression = jVariable.specifierExpression); | ||
Type|ValueModifier? type; | ||
assert (is JStaticType|JValueModifier jType = jVariable.type); | ||
switch (jType) | ||
case (is JStaticType) { type = typeToCeylon(jType); } | ||
case (is JValueModifier) { | ||
if (jType.mainToken exists) { | ||
type = valueModifierToCeylon(jType); | ||
} else { | ||
// synthetic ValueModifier | ||
type = null; | ||
} | ||
} | ||
return SpecifiedVariable(lIdentifierToCeylon(jVariable.identifier), specifierToCeylon(jSpecifierExpression), type); | ||
}); | ||
"Must have at least one `let` value" | ||
assert (nonempty letValues); | ||
return LetExpression(LetValueList(letValues), expressionToCeylon(letClause.expression)); | ||
} | ||
|
||
"Compiles the given [[code]] for a Let Expression | ||
into a [[LetExpression]] using the Ceylon compiler | ||
(more specifically, the rule for a `let`)." | ||
shared LetExpression? compileLetExpression(String code) { | ||
if (exists jLet = createParser(code).\ilet()) { | ||
return letExpressionToCeylon(jLet); | ||
} else { | ||
return null; | ||
} | ||
} |
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