-
Notifications
You must be signed in to change notification settings - Fork 39
Add hexadecimal literals for 'Byte' #1170
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
Changes from all commits
fd3674f
72d3949
332f2f6
1b1f6d3
5e50fd3
57dacd9
7c29244
29e26d6
794c6ea
2e5688d
5ad1246
8348f32
7b6b722
941d360
0eb96bf
b9b0203
dddc5c1
a946db2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,13 +2,15 @@ package effekt | |
| package machine | ||
|
|
||
| import effekt.context.Context | ||
| import effekt.core.substitutions.{ Substitution, substitute } | ||
| import effekt.core.{ Block, DeclarationContext, Toplevel, Id, given } | ||
| import effekt.symbols.{ Symbol, TermSymbol } | ||
| import effekt.core.substitutions.{Substitution, substitute} | ||
| import effekt.core.{Block, DeclarationContext, Id, Toplevel, given} | ||
| import effekt.symbols.{Symbol, TermSymbol} | ||
| import effekt.symbols.builtins.TState | ||
| import effekt.util.messages.ErrorReporter | ||
| import effekt.util.Trampoline | ||
| import effekt.symbols.ErrorMessageInterpolator | ||
| import effekt.util.UByte | ||
|
|
||
| import scala.annotation.tailrec | ||
|
|
||
|
|
||
|
|
@@ -460,10 +462,12 @@ object Transformer { | |
| LiteralInt(unboxed, value, Coerce(variable, unboxed, k(variable))) | ||
| } | ||
|
|
||
| case core.Literal(value: Int, core.Type.TByte) => | ||
| case core.Literal(value: Byte, core.Type.TByte) => | ||
| shift { k => | ||
| val unboxed = Variable(freshName("byte"), Type.Byte()) | ||
| LiteralByte(unboxed, value, Coerce(variable, unboxed, k(variable))) | ||
| val b = UByte.unsafeFromByte(value) | ||
| // TODO: Literal bytes could now also be just byte-sized in Machine (= use 'UByte'; they are byte-sized in LLVM anyway). | ||
| LiteralByte(unboxed, b.toInt, Coerce(variable, unboxed, k(variable))) | ||
|
Comment on lines
+468
to
+470
Collaborator
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. I would prefer
Contributor
Author
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. The biggest issue I have with |
||
| } | ||
|
|
||
| case core.Literal(v: Double, core.Type.TDouble) => | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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 might be a bit confusing, but we can't match on a
UByteas it's opaque, so we have to match on aByte, just to zero-cost convert it to aByte, just to print thehexStringconsistently.... I really don't know how to do this better without either wrapping it in a custom type and dealing with the overhead, or pulling a newtype library :/
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.
It's ok. You could have
toHexStringoperate directly onByteand usetoUnsignedInteverywhere.