-
Notifications
You must be signed in to change notification settings - Fork 27
Adopt JacoDB native TypeScript frontend in USVM #344
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
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
b78115d
Adopt JacoDB native TypeScript frontend
CaelmBleidd 27ad246
[TS] Map literal types to base sorts
CaelmBleidd 6132231
[TS] Advance execution through NOP statements
CaelmBleidd 35f1f9c
[TS] Implement increment and decrement expressions
CaelmBleidd 05cecb4
[TS] Canonicalize array memory descriptors
CaelmBleidd e9ce7bf
[TS] Bind lexical environments to closures
CaelmBleidd 3d62679
[TS] Resolve Number pointer calls
CaelmBleidd 31062ae
[TS] Initialize native module fields
CaelmBleidd cb56e5b
[TS] Concatenate concrete string operands
CaelmBleidd 1cf4476
[TS] Preserve nominal instanceof alternatives
CaelmBleidd 1d49d64
[TS] Check type guesser fixed point
CaelmBleidd 593b2bb
[TS] Execute overload implementations
CaelmBleidd d677b3d
[TS] Support Number without arguments
CaelmBleidd b5e0d09
[TS] Canonicalize static overload groups before forking
CaelmBleidd 6d1436a
[TS] Format concrete numbers in string concatenation
CaelmBleidd 3454b8b
[TS] Clean up native frontend fix style
CaelmBleidd 92d7c8f
[CI] Pin ArkAnalyzer Node types
CaelmBleidd c0f9a5b
[TS] Pin published native frontend artifact
CaelmBleidd 62c1d94
[TS] Pin the hardened frontend artifact
CaelmBleidd 55ee546
[TS] Pin the merged native frontend artifact
CaelmBleidd 912de52
[TS] Address native frontend review feedback
CaelmBleidd 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
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
85 changes: 85 additions & 0 deletions
85
usvm-ts/src/main/kotlin/org/usvm/machine/expr/EcmaScriptNumberToString.kt
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 |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| package org.usvm.machine.expr | ||
|
|
||
| import java.math.BigDecimal | ||
| import java.math.BigInteger | ||
| import java.math.MathContext | ||
| import java.math.RoundingMode | ||
| import kotlin.math.absoluteValue | ||
|
|
||
| private const val MAX_SIGNIFICANT_DIGITS = 17 | ||
| private const val MAX_PLAIN_DECIMAL_POINT = 21 | ||
| private const val MIN_PLAIN_DECIMAL_POINT = -5 | ||
| private const val ROUNDING_NEIGHBORHOOD = 2 | ||
|
|
||
| /** Formats a concrete IEEE-754 value according to ECMAScript Number::toString. */ | ||
| internal fun Double.toEcmaScriptString(): String = when { | ||
| isNaN() -> { | ||
| "NaN" | ||
| } | ||
|
|
||
| this == Double.POSITIVE_INFINITY -> { | ||
| "Infinity" | ||
| } | ||
|
|
||
| this == Double.NEGATIVE_INFINITY -> { | ||
| "-Infinity" | ||
| } | ||
|
|
||
| this == 0.0 -> { | ||
| "0" | ||
| } | ||
|
|
||
| else -> { | ||
| val negative = this < 0.0 | ||
| val decimal = absoluteValue.shortestRoundTripDecimal().stripTrailingZeros() | ||
| val digits = decimal.unscaledValue().abs().toString() | ||
| val decimalPoint = digits.length - decimal.scale() | ||
| val unsigned = when { | ||
| decimalPoint in 1..MAX_PLAIN_DECIMAL_POINT -> { | ||
| if (decimalPoint >= digits.length) { | ||
| digits + "0".repeat(decimalPoint - digits.length) | ||
| } else { | ||
| digits.substring(0, decimalPoint) + "." + digits.substring(decimalPoint) | ||
| } | ||
| } | ||
|
|
||
| decimalPoint in MIN_PLAIN_DECIMAL_POINT..0 -> { | ||
| "0." + "0".repeat(-decimalPoint) + digits | ||
| } | ||
|
|
||
| else -> { | ||
| val mantissa = if (digits.length == 1) { | ||
| digits | ||
| } else { | ||
| digits.substring(0, 1) + "." + digits.substring(1) | ||
| } | ||
| val exponent = decimalPoint - 1 | ||
| mantissa + "e" + (if (exponent >= 0) "+" else "") + exponent | ||
| } | ||
| } | ||
| if (negative) "-$unsigned" else unsigned | ||
| } | ||
| } | ||
|
|
||
| private fun Double.shortestRoundTripDecimal(): BigDecimal { | ||
| // This constructor intentionally retains the exact binary value. At the first | ||
| // precision that round-trips, ECMAScript selects the closest decimal (ties to even). | ||
| val exact = BigDecimal(this) | ||
| for (precision in 1..MAX_SIGNIFICANT_DIGITS) { | ||
| val rounded = exact.round(MathContext(precision, RoundingMode.HALF_EVEN)) | ||
| val unit = rounded.ulp() | ||
| val candidates = (-ROUNDING_NEIGHBORHOOD..ROUNDING_NEIGHBORHOOD) | ||
| .asSequence() | ||
| .map { offset -> rounded + unit * offset.toBigDecimal() } | ||
| .filter { candidate -> candidate.signum() > 0 && candidate.toDouble() == this } | ||
| .toList() | ||
| if (candidates.isNotEmpty()) { | ||
| return candidates.minWith( | ||
| compareBy<BigDecimal> { candidate -> candidate.subtract(exact).abs() } | ||
| .thenBy { candidate -> candidate.unscaledValue().abs().and(BigInteger.ONE).toInt() } | ||
| .thenBy { candidate -> candidate }, | ||
| ) | ||
| } | ||
| } | ||
| error("Could not format finite double: $this") | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.