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 @@ -561,6 +561,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.systemTimeMicroseconds.v1", unit --> iof int)
, ("IO.getTempDirectory.impl.v3", unit --> iof text)
, ("IO.createTempDirectory.impl.v3", text --> iof text)
, ("IO.getCurrentDirectory.impl.v3", unit --> iof text)
Expand Down
12 changes: 11 additions & 1 deletion parser-typechecker/src/Unison/Runtime/Builtin.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,12 @@ unitToEFNat = inUnit unit result
$ outIoFailNat stack1 stack2 stack3 fail nat result
where (unit, stack1, stack2, stack3, fail, nat, result) = fresh7

-- () -> Int
unitToInt :: ForeignOp
unitToInt = inUnit unit result
$ TCon Ty.intRef 0 [result]
where (unit, result) = fresh2

-- () -> Either Failure a
unitToEFBox :: ForeignOp
unitToEFBox = inUnit unit result
Expand Down Expand Up @@ -1562,8 +1568,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.systemTimeMicroseconds.v1" unitToInt
$ mkForeignIOF $ \() -> fmap (1e6 *) getPOSIXTime

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