Skip to content
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

New version of systemTime that returns an Int representing microseconds #2418

Merged
merged 10 commits into from
Sep 25, 2021
1 change: 1 addition & 0 deletions parser-typechecker/src/Unison/Builtin.hs
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@ ioBuiltins =
, ("IO.putBytes.impl.v3", handle --> bytes --> iof unit)
, ("IO.getLine.impl.v1", handle --> iof text)
, ("IO.systemTime.impl.v3", unit --> iof nat)
, ("IO.systemTime2.impl.v1", unit --> iof int)
alvaroc1 marked this conversation as resolved.
Show resolved Hide resolved
, ("IO.getTempDirectory.impl.v3", unit --> iof text)
, ("IO.createTempDirectory.impl.v3", text --> iof text)
, ("IO.getCurrentDirectory.impl.v3", unit --> iof text)
Expand Down
25 changes: 24 additions & 1 deletion parser-typechecker/src/Unison/Runtime/Builtin.hs
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,19 @@ outIoFailNat stack1 stack2 stack3 fail nat result =
$ TCon eitherReference 1 [nat])
]

outIoFailInt :: forall v. Var v => v -> v -> v -> v -> v -> v -> ANormal v
outIoFailInt stack1 stack2 stack3 fail int result =
TMatch result . MatchSum $ mapFromList
[ (0, ([BX, BX],)
. TAbss [stack1, stack2]
. TLetD fail BX (TCon Ty.failureRef 0 [stack1, stack2])
$ TCon eitherReference 0 [fail])
, (1, ([UN],)
. TAbs stack3
. TLetD int BX (TCon Ty.intRef 0 [stack3])
$ TCon eitherReference 1 [int])
]

alvaroc1 marked this conversation as resolved.
Show resolved Hide resolved
outIoFailBox :: forall v. Var v => v -> v -> v -> v -> ANormal v
outIoFailBox stack1 stack2 fail result =
TMatch result . MatchSum $ mapFromList
Expand Down Expand Up @@ -1076,6 +1089,12 @@ unitToEFNat = inUnit unit result
$ outIoFailNat stack1 stack2 stack3 fail nat result
where (unit, stack1, stack2, stack3, fail, nat, result) = fresh7

-- () -> Either Failure Int
unitToEFInt :: ForeignOp
unitToEFInt = inUnit unit result
$ outIoFailInt stack1 stack2 stack3 fail int result
where (unit, stack1, stack2, stack3, fail, int, result) = fresh7

-- () -> Either Failure a
unitToEFBox :: ForeignOp
unitToEFBox = inUnit unit result
Expand Down Expand Up @@ -1547,8 +1566,12 @@ declareForeigns = do
$ \(h,n) -> Bytes.fromArray <$> hGet h n

declareForeign "IO.putBytes.impl.v3" boxBoxToEF0 . mkForeignIOF $ \(h,bs) -> hPut h (Bytes.toArray bs)

declareForeign "IO.systemTime.impl.v3" unitToEFNat
$ mkForeignIOF $ \() -> getPOSIXTime
$ mkForeignIOF $ \() -> getPOSIXTime

declareForeign "IO.systemTime2.impl.v1" unitToEFInt
$ mkForeignIOF $ \() -> fmap (1e6 *) getPOSIXTime

declareForeign "IO.getTempDirectory.impl.v3" unitToEFBox
$ mkForeignIOF $ \() -> getTemporaryDirectory
Expand Down