Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
dolio committed Dec 14, 2023
1 parent 19ff30a commit 49a7d17
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 53 deletions.
15 changes: 8 additions & 7 deletions parser-typechecker/src/Unison/Runtime/Decompile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
{-# LANGUAGE ViewPatterns #-}

module Unison.Runtime.Decompile
( decompile
, DecompResult
, DecompError (..)
, renderDecompError
) where
( decompile,
DecompResult,
DecompError (..),
renderDecompError,
)
where

import Data.Set (singleton)
import Prelude hiding (lines)
import Unison.ABT (substs)
import Unison.Codebase.Runtime (Error)
import Unison.ConstructorReference (GConstructorReference (..))
Expand Down Expand Up @@ -65,10 +65,11 @@ import Unison.Type
typeLinkRef,
)
import Unison.Util.Bytes qualified as By
import Unison.Util.Pretty (lit, indentN, lines, wrap, syntaxToColor)
import Unison.Util.Pretty (indentN, lines, lit, syntaxToColor, wrap)
import Unison.Util.Text qualified as Text
import Unison.Var (Var)
import Unsafe.Coerce -- for Int -> Double
import Prelude hiding (lines)

con :: (Var v) => Reference -> Word64 -> Term v ()
con rf ct = constructor () (ConstructorReference rf $ fromIntegral ct)
Expand Down
59 changes: 30 additions & 29 deletions parser-typechecker/src/Unison/Runtime/Interface.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ import Data.Bytes.Get (MonadGet)
import Data.Bytes.Put (MonadPut, putWord32be, runPutL, runPutS)
import Data.Bytes.Serial
import Data.Foldable
import Data.List qualified as L
import Data.IORef
import Data.List qualified as L
import Data.Map.Strict qualified as Map
import Data.Sequence qualified as Seq (fromList)
import Data.Set as Set
Expand All @@ -45,11 +45,11 @@ import Data.Set as Set
import Data.Set qualified as Set
import Data.Text (isPrefixOf, unpack)
import System.Process
( proc,
( CreateProcess (..),
StdStream (..),
proc,
waitForProcess,
withCreateProcess,
CreateProcess(..),
StdStream(..)
)
import Unison.Builtin.Decls qualified as RF
import Unison.Codebase.CodeLookup (CodeLookup (..))
Expand All @@ -72,7 +72,7 @@ import Unison.Runtime.ANF.Rehash as ANF (rehashGroups)
import Unison.Runtime.ANF.Serialize as ANF
( getGroup,
putGroup,
serializeValue
serializeValue,
)
import Unison.Runtime.Builtin
import Unison.Runtime.Decompile
Expand Down Expand Up @@ -412,25 +412,25 @@ loadDeps cl ppe ctx tyrs tmrs = do
out@(_, rgrp) <- loadCode cl ppe ctx tmrs
out <$ cacheAdd0 tyAdd rgrp (expandSandbox sand rgrp) cc

compileValue :: Reference -> [(Reference, SuperGroup Symbol)] -> Value
compileValue :: Reference -> [(Reference, SuperGroup Symbol)] -> Value
compileValue base =
flip pair (rf base) . ANF.BLit . List . Seq.fromList . fmap cpair
where
rf = ANF.BLit . TmLink . RF.Ref
cons x y = Data RF.pairRef 0 [] [x, y]
tt = Data RF.unitRef 0 [] []
code sg = ANF.BLit (Code sg)
pair x y = cons x (cons y tt)
cpair (r, sg) = pair (rf r) (code sg)
rf = ANF.BLit . TmLink . RF.Ref
cons x y = Data RF.pairRef 0 [] [x, y]
tt = Data RF.unitRef 0 [] []
code sg = ANF.BLit (Code sg)
pair x y = cons x (cons y tt)
cpair (r, sg) = pair (rf r) (code sg)

decompileCtx ::
EnumMap Word64 Reference -> EvalCtx -> Closure -> DecompResult Symbol
decompileCtx crs ctx = decompile ib $ backReferenceTm crs fr ir dt
where
ib = intermedToBase ctx
fr = floatRemap ctx
ir = intermedRemap ctx
dt = decompTm ctx
ib = intermedToBase ctx
fr = floatRemap ctx
ir = intermedRemap ctx
dt = decompTm ctx

nativeEval ::
IORef EvalCtx ->
Expand Down Expand Up @@ -648,12 +648,12 @@ backReferenceTm ws frs irs dcm c i = do
Map.lookup i bs

schemeProc :: [String] -> CreateProcess
schemeProc args = (proc "native-compiler/bin/runner" args)
{ std_in = CreatePipe
, std_out = Inherit
, std_err = Inherit
}

schemeProc args =
(proc "native-compiler/bin/runner" args)
{ std_in = CreatePipe,
std_out = Inherit,
std_err = Inherit
}

-- Note: this currently does not support yielding values; instead it
-- just produces a result appropriate for unitary `run` commands. The
Expand All @@ -678,21 +678,22 @@ nativeEvalInContext _ ctx codes base = do
let bytes = serializeValue . compileValue base $ codes

decodeResult (Left msg) = pure . Left $ fromString msg
decodeResult (Right val) = reifyValue cc val >>= \case
Left _ -> pure . Left $ "missing references from result"
Right cl -> case decompileCtx crs ctx cl of
(errs, dv) -> pure $ Right (listErrors errs, dv)
decodeResult (Right val) =
reifyValue cc val >>= \case
Left _ -> pure . Left $ "missing references from result"
Right cl -> case decompileCtx crs ctx cl of
(errs, dv) -> pure $ Right (listErrors errs, dv)

callout (Just pin) _ _ ph = do
BS.hPut pin . runPutS . putWord32be . fromIntegral $ BS.length bytes
BS.hPut pin bytes
UnliftIO.hClose pin
let unit = Data RF.unitRef 0 [] []
sunit = Data RF.pairRef 0 [] [unit,unit]
sunit = Data RF.pairRef 0 [] [unit, unit]
waitForProcess ph
decodeResult $ Right sunit
-- TODO: actualy receive output from subprocess
-- decodeResult . deserializeValue =<< BS.hGetContents pout
-- TODO: actualy receive output from subprocess
-- decodeResult . deserializeValue =<< BS.hGetContents pout
callout _ _ _ _ =
pure . Left $ "withCreateProcess didn't provide handles"
withCreateProcess (schemeProc []) callout
Expand Down
23 changes: 13 additions & 10 deletions unison-cli/src/Unison/Codebase/Editor/HandleInput.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2444,8 +2444,8 @@ getSchemeStaticLibDir =
liftIO $
getXdgDirectory XdgData ("unisonlanguage" </> "scheme-libs")

doGenerateSchemeBoot
:: Bool -> Maybe PPE.PrettyPrintEnv -> Maybe String -> Cli ()
doGenerateSchemeBoot ::
Bool -> Maybe PPE.PrettyPrintEnv -> Maybe String -> Cli ()
doGenerateSchemeBoot force mppe mdir = do
ppe <- maybe basicPPE pure mppe
dir <- maybe getSchemeGenLibDir pure mdir
Expand Down Expand Up @@ -2585,21 +2585,24 @@ doExecute native main args = do
#lastRunResult .= Just (Term.amap (\() -> External) mainRes, mainResType, unisonFile)
Cli.respond (RunResult ppe mainRes)
where
bonk (_, (_ann, watchKind, _id, _term0, term1, _isCacheHit)) =
(watchKind, term1)
bonk (_, (_ann, watchKind, _id, _term0, term1, _isCacheHit)) =
(watchKind, term1)

doCompile :: Bool -> String -> HQ.HashQualified Name -> Cli ()
doCompile native output main = do
Cli.Env {codebase, runtime, nativeRuntime} <- ask
let theRuntime | native = nativeRuntime
| otherwise = runtime
let theRuntime
| native = nativeRuntime
| otherwise = runtime
(ref, ppe) <- resolveMainRef main
let codeLookup = () <$ Codebase.toCodeLookup codebase
outf | native = output
| otherwise = output <> ".uc"
outf
| native = output
| otherwise = output <> ".uc"
whenJustM
(liftIO $
Runtime.compileTo theRuntime codeLookup ppe ref outf)
( liftIO $
Runtime.compileTo theRuntime codeLookup ppe ref outf
)
(Cli.returnEarly . EvaluationFailure)

doRunAsScheme :: String -> [String] -> Cli ()
Expand Down
18 changes: 11 additions & 7 deletions unison-cli/src/Unison/CommandLine/InputPatterns.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2495,13 +2495,17 @@ createAuthor =
[]
I.Visible
[(Required, noCompletionsArg), (Required, noCompletionsArg)]
( makeExample createAuthor ["alicecoder", "\"Alice McGee\""] <> " "
<> P.wrap (" creates "
<> backtick "alicecoder"
<> "values in"
<> backtick "metadata.authors"
<> "and"
<> backtick (P.group ("metadata.copyrightHolders" <> "."))))
( makeExample createAuthor ["alicecoder", "\"Alice McGee\""]
<> " "
<> P.wrap
( " creates "
<> backtick "alicecoder"
<> "values in"
<> backtick "metadata.authors"
<> "and"
<> backtick (P.group ("metadata.copyrightHolders" <> "."))
)
)
( \case
symbolStr : authorStr@(_ : _) -> first fromString $ do
symbol <- Path.definitionNameSegment symbolStr
Expand Down

0 comments on commit 49a7d17

Please sign in to comment.