From 98f74c22d93d0c259aa92ad075a3fbfe33b6a295 Mon Sep 17 00:00:00 2001 From: thedavidmeister Date: Fri, 16 Aug 2024 11:01:50 +0400 Subject: [PATCH] wip on float --- .../RainterpreterParserNPE2.pointers.sol | 6 +++--- src/lib/op/LibAllStandardOpsNP.sol | 2 +- .../parse/literal/LibParseLiteralDecimal.sol | 17 +++++++++++++++++ 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/generated/RainterpreterParserNPE2.pointers.sol b/src/generated/RainterpreterParserNPE2.pointers.sol index 35f5e4fd0..2b1cd23a9 100644 --- a/src/generated/RainterpreterParserNPE2.pointers.sol +++ b/src/generated/RainterpreterParserNPE2.pointers.sol @@ -9,7 +9,7 @@ pragma solidity =0.8.25; /// @dev Hash of the known bytecode. -bytes32 constant BYTECODE_HASH = bytes32(0x9dc8d07f99b6134659f649d06710097ca77214e78f1cb5ccef5ae0a063dc77e2); +bytes32 constant BYTECODE_HASH = bytes32(0x11aba6006d98ab79c4372ab4f0d673880a1efc51f9c1f901f06e706029c052d7); /// @dev The parse meta that is used to lookup word definitions. /// The structure of the parse meta is: @@ -38,11 +38,11 @@ uint8 constant PARSE_META_BUILD_DEPTH = 2; /// These positional indexes all map to the same indexes looked up in the parse /// meta. bytes constant OPERAND_HANDLER_FUNCTION_POINTERS = - hex"173517351735179a181318131813179a179a173517351735181318131813181318131813"; + hex"13ef13ef13ef145414cd14cd14cd1454145413ef13ef13ef14cd14cd14cd14cd14cd14cd"; /// @dev Every two bytes is a function pointer for a literal parser. /// Literal dispatches are determined by the first byte(s) of the literal /// rather than a full word lookup, and are done with simple conditional /// jumps as the possibilities are limited compared to the number of words we /// have. -bytes constant LITERAL_PARSER_FUNCTION_POINTERS = hex"0dab1073147a1554"; +bytes constant LITERAL_PARSER_FUNCTION_POINTERS = hex"0dab1073112411fe"; diff --git a/src/lib/op/LibAllStandardOpsNP.sol b/src/lib/op/LibAllStandardOpsNP.sol index b35775d62..8921de70f 100644 --- a/src/lib/op/LibAllStandardOpsNP.sol +++ b/src/lib/op/LibAllStandardOpsNP.sol @@ -329,7 +329,7 @@ library LibAllStandardOpsNP { memory pointersFixed = [ lengthPointer, LibParseLiteralHex.parseHex, - LibParseLiteralDecimal.parseDecimal, + LibParseLiteralDecimal.parseDecimalFloatPacked, LibParseLiteralString.parseString, LibParseLiteralSubParseable.parseSubParseable ]; diff --git a/src/lib/parse/literal/LibParseLiteralDecimal.sol b/src/lib/parse/literal/LibParseLiteralDecimal.sol index 6825ae69d..5b7634580 100644 --- a/src/lib/parse/literal/LibParseLiteralDecimal.sol +++ b/src/lib/parse/literal/LibParseLiteralDecimal.sol @@ -18,6 +18,7 @@ import { } from "../LibParseCMask.sol"; import {LibParseError} from "../LibParseError.sol"; import {LibParse} from "../LibParse.sol"; +import {LibDecimalFloatImplementation, LibDecimalFloat} from "rain.math.float/src/lib/LibDecimalFloat.sol"; /// @dev The default is 18 decimal places for a fractional number. uint256 constant DECIMAL_SCALE = 18; @@ -115,6 +116,22 @@ library LibParseLiteralDecimal { } } + function parseDecimalFloatPacked(ParseState memory state, uint256 start, uint256 end) + internal + pure + returns (uint256 cursor, uint256 packedFloat) + { + int256 signedCoefficient; + int256 exponent; + (cursor, signedCoefficient, exponent) = parseDecimalFloat(state, start, end); + (int256 normalizedSignedCoefficient, int256 normalizedExponent) = + LibDecimalFloatImplementation.normalize(signedCoefficient, exponent); + if (!LibDecimalFloat.eq(normalizedSignedCoefficient, normalizedExponent, signedCoefficient, exponent)) { + revert DecimalLiteralPrecisionLoss(state.parseErrorOffset(start)); + } + packedFloat = LibDecimalFloat.pack(normalizedSignedCoefficient, normalizedExponent); + } + function parseDecimalFloat(ParseState memory state, uint256 start, uint256 end) internal pure