Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 4 additions & 22 deletions plutus-benchmark/uplc-evaluator/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import PlutusCore.Quote (runQuoteT)
import PlutusPrelude (void)
import System.Directory
import System.Exit (exitFailure)
import System.FilePath (takeBaseName, takeExtension, (</>))
import System.FilePath (takeBaseName, takeExtension, takeFileName, (</>))
import System.IO (BufferMode (LineBuffering), hPutStrLn, hSetBuffering, stderr)
import System.Mem (performGC, performMinorGC)
import UntypedPlutusCore qualified as UPLC
Expand Down Expand Up @@ -136,22 +136,9 @@ parseJobId filename =
else baseName
in UUID.fromString jobIdStr

{-| Check if file is a valid UPLC program file.
Supports two extensions:
- @.uplc.txt@ - Textual UPLC syntax (currently supported)
- @.uplc.flat@ - Flat-encoded binary UPLC (future: requires different parsing path)

TODO [Flat Encoding Support]:
Flat-encoded UPLC files (.uplc.flat) require binary deserialization rather than
text parsing. Flat is a bit-oriented format that's ~35% smaller than CBOR.
Implementation would require:
1. Detect flat vs text format (by extension or magic bytes)
2. Use "Flat" package with UPLC.UnrestrictedProgram decoder
3. Skip the "(program" prefix validation for binary files
Currently, flat files fail with syntax_error (expected MVP behavior). -}
-- | Check if file is a valid UPLC program file (textual @.uplc.txt@ format only).
isUplcFile :: FilePath -> Bool
isUplcFile path =
".uplc.txt" `isSuffixOf` path || ".uplc.flat" `isSuffixOf` path
isUplcFile path = ".uplc.txt" `isSuffixOf` path

{-| Parse a UPLC program from textual syntax.
Returns either a descriptive error message or the parsed program with unit annotations. -}
Expand Down Expand Up @@ -320,9 +307,6 @@ processProgram Config {..} inputPath = do
hPutStrLn stderr $ "Processing job: " ++ UUID.toString jobId

-- Read the file content as Text
-- TODO [Flat Encoding Support]: For .uplc.flat files, read as ByteString
-- and use binary deserialization instead of text parsing.
-- See Note [Flat Encoding Support] at isUplcFile.
readResult <- try @SomeException $ TIO.readFile inputPath

case readResult of
Expand Down Expand Up @@ -483,9 +467,7 @@ evaluationLoop config@Config {..} processedFiles = do
-- Continue loop
evaluationLoop config newProcessed

-- | Utility function to extract filename from path
takeFileName :: FilePath -> FilePath
takeFileName = reverse . takeWhile (/= '/') . reverse


-- | Main entry point
main :: IO ()
Expand Down