No matching definitions.

tur/capability

stdlib/capability.tur

capability-passing typeclasses for controlled side-effect injection.

Since: Phase 16

defn

FileSystem-type

(FileSystem-type)

return NULL; declares the FileSystem struct typedef for inline C blocks.

Since: Phase 16

defn

make-FileSystem

(make-FileSystem [read_fn write_fn delete_fn list_fn])

construct a FileSystem capability from four function pointers.

read_fn(path buf buf_len out_len) -> int
write_fn(path data data_len) -> int
delete_fn(path) -> int
list_fn(path entries max_entries out_count) -> int

A heap-allocated FileSystem capability pointer; free with FileSystem-free.

(def fs (make-FileSystem my-read my-write my-delete my-list))

Since: Phase 16

defn

FileSystem-free

(FileSystem-free [fs])

free a FileSystem capability allocated by make-FileSystem.

fsFileSystem pointer from make-FileSystem

Since: Phase 16

defn

Logger-type

(Logger-type)

return NULL; declares the Logger struct typedef for inline C blocks.

Since: Phase 16

defn

make-Logger

(make-Logger [debug_fn info_fn warn_fn error_fn])

construct a Logger capability from four function pointers (debug/info/warn/error).

debug_fn(msg: cstr) -> void
info_fn(msg: cstr) -> void
warn_fn(msg: cstr) -> void
error_fn(msg: cstr) -> void

A heap-allocated Logger capability pointer; free with Logger-free.

Since: Phase 16

defn

Logger-free

(Logger-free [log])

free a Logger capability allocated by make-Logger.

logLogger pointer from make-Logger

Since: Phase 16

defn

Random-type

(Random-type)

return NULL; declares the Random struct typedef for inline C blocks.

Since: Phase 16

defn

make-Random

(make-Random [next_int_fn next_float_fn])

construct a Random capability from two function pointers.

next_int_fn(min max) -> int; returns integer in [min, max]
next_float_fn() -> int; returns value in [0, 10000) representing a float

A heap-allocated Random capability pointer; free with Random-free.

Since: Phase 16

defn

Random-free

(Random-free [rng])

free a Random capability allocated by make-Random.

rngRandom pointer from make-Random

Since: Phase 16

defn

Time-type

(Time-type)

return NULL; declares the Time struct typedef for inline C blocks.

Since: Phase 16

defn

make-Time

(make-Time [now_fn sleep_fn])

construct a Time capability from two function pointers.

now_fn() -> int; returns current time in milliseconds since epoch
sleep_fn(ms: int) -> void; sleeps for ms milliseconds

A heap-allocated Time capability pointer; free with Time-free.

Since: Phase 16

defn

Time-free

(Time-free [t])

free a Time capability allocated by make-Time.

tTime pointer from make-Time

Since: Phase 16

defmacro

with-capability

(with-capability [binding cap_expr body])

bind cap_expr to binding and evaluate body with that capability in scope.

bindingname to bind the capability to
cap_exprexpression producing the capability
bodyexpression to evaluate with binding in scope
(with-capability [fs (make-FileSystem ...)] (fs-read fs "data.txt"))

Since: Phase 16

defn

default-capability

(default-capability [type_name])

return the default implementation for a capability type (currently always nil).

type_namesymbolic name of the capability type (unused in v1)

Since: Phase 16

defn

fs-read

(fs-read [fs path buf buf_len])

call read_file on a FileSystem capability.

fsFileSystem capability pointer
pathfile path to read
bufoutput buffer pointer
buf_lensize of buf in bytes

0 on success, non-zero on error (as returned by the underlying read_file fn).

Since: Phase 16

defn

fs-write

(fs-write [fs path data data_len])

call write_file on a FileSystem capability.

fsFileSystem capability pointer
pathfile path to write
datadata buffer pointer
data_lennumber of bytes to write

0 on success, non-zero on error.

Since: Phase 16

defn

fs-delete

(fs-delete [fs path])

call delete on a FileSystem capability.

fsFileSystem capability pointer
pathpath of the file to delete

0 on success, non-zero on error.

Since: Phase 16

defn

fs-list

(fs-list [fs path entries max_entries])

call list on a FileSystem capability.

fsFileSystem capability pointer
pathdirectory path to list
entriesoutput buffer for entry name pointers
max_entriescapacity of entries buffer

Number of entries found, or negative on error.

Since: Phase 16

defn

log-debug

(log-debug [log msg])

emit a debug-level log message via a Logger capability.

logLogger capability pointer
msgmessage string to log

Since: Phase 16

defn

log-info

(log-info [log msg])

emit an info-level log message via a Logger capability.

logLogger capability pointer
msgmessage string to log

Since: Phase 16

defn

log-warn

(log-warn [log msg])

emit a warning-level log message via a Logger capability.

logLogger capability pointer
msgmessage string to log

Since: Phase 16

defn

log-error

(log-error [log msg])

emit an error-level log message via a Logger capability.

logLogger capability pointer
msgmessage string to log

Since: Phase 16

defn

rng-next-int

(rng-next-int [rng min max])

return a random integer in [min, max] from a Random capability.

rngRandom capability pointer
mininclusive lower bound
maxinclusive upper bound

A random integer in [min, max].

Since: Phase 16

defn

rng-next-float

(rng-next-float [rng])

return a random pseudo-float in [0, 10000) from a Random capability.

rngRandom capability pointer

Integer in [0, 10000); divide by 10000.0 to get a float in [0.0, 1.0).

Since: Phase 16

defn

time-now

(time-now [t])

return the current time in milliseconds since epoch from a Time capability.

tTime capability pointer

Current time as an integer (milliseconds since epoch).

Since: Phase 16

defn

time-sleep

(time-sleep [t ms])

sleep for ms milliseconds via a Time capability.

tTime capability pointer
msduration in milliseconds

Since: Phase 16