futhark
Safe HaskellNone
LanguageGHC2021

Language.Futhark.Interpreter.IO

Description

IO operations exposed through the interpreter.

Synopsis

Documentation

data IOOp Source #

The IO operation to perform. The idea of splitting it out into a type like this is to enforce some kind of auditing.

Constructors

LoadBytes FilePath 
LoadImg FilePath 
LoadAudio FilePath 
LoadValue ValueType FilePath

Load a value of this type.

SaveValue FilePath ValueType (Value m)

Write a value of this type to this file.

safeIO :: IOOp -> Bool Source #

Is this IO operation something that we allow in untrusted code, namely script input. This is not a completely firm security boundary, as even safe IO operations allow reading of arbitrary files, but the idea is to make it possible to benchmark untrusted Futhark programs (assuming you also use --safe, of course).

data IOIntrinsic (m :: Type -> Type) Source #

An IO intrinsic, which determines its operation from the type at which it is instantiated and its arguments, of which the first is always a file name. The file name is fetched in full before the intrinsic sees it, but any other argument is passed as-is, and so may contain references to values residing on a server.

Constructors

IOUnary (m ValueType -> Value m -> m IOOp) 
IOBinary (m ValueType -> Value m -> Value m -> m IOOp) 

determineIO :: forall (m :: Type -> Type). Monad m => Text -> Maybe (IOIntrinsic m) Source #

Determine which IO operation this is.

If you want to add a new one, then remember to also add it as an intrinsic in the type checker, and probably also to the prelude.

doIOOp :: forall (m :: Type -> Type). Maybe Server -> IOOp -> IO (Either Text (Value m)) Source #

Run an IO operation. Arrays are put on the server, if one is given.

ioRelativeTo :: FilePath -> IOOp -> IOOp Source #

Resolve relative file paths in the operation relative to the given directory, rather than the current working directory.