Skip to main content

Module host_words

Module host_words 

Source
Expand description

The words of the program’s environment, imported from the “host” module and called like C functions: sleep_ms(ms) pauses, random() is a float in [0, 1), random_below(n) an int in 0..n, clock() the milliseconds since the Unix epoch. A program that defines a word of the same name keeps its own. warp adds the words that need its compiler, the network or threads (host.rs); these need nothing. signal_poll() and signal_listen(kind, id, argument) serve the handlers of system signals (system_signals.rs).

Constants§

BASIC_HOST_WORDS
The words link_host_words provides
BATTERY
CHARGING
CLICK_PRESSED
Whether a click over the paint window is left to read (1, then it is the click read) or none (0), each click read once, and that click’s place: natively on click {…} (lowering/signals/system_signals.rs); not values a program names
CLICK_X
CLICK_Y
CLIPBOARD
clipboard: the clipboard’s text, read only when the program reads it (host.rs clipboard_text)
CLIPBOARD_COUNT
How often the clipboard changed since the machine started (macOS NSPasteboard changeCount): on clipboard change
CLIPBOARD_TEXT
CLOCK
CLOCK_WEEKDAYS
The clock argument’s weekdays count in ten-thousands: (signal_listen 2 0 1271290) is 21:30 (1290) every day (127)
DARK_MODE
DISPLAY_DPI
display.dpi: the screen’s device pixels per inch, which turn px into lengths (decision dimensions-units)
DISPLAY_HEIGHT
DISPLAY_WIDTH
ESCAPE_KEPT
Read once as a program naming the Escape key starts (key == ESC): Escape over the paint window is then its key, else it ends the run (card escape-window, src/graphics/paint_window.rs); not a value a program names
EXIT
exit(code) ends the run, not the process (P121, system_signals.rs ExitRequest)
EXIT_HANDLER
The exported handler of on exit {…}, run once as the run ends (system_signals.rs run_exit_handler)
FETCH_HANDLER_PREFIX
on·fetch·0: the handler run when the reply of the first users := fetch url arrived (src/web/fetches.rs)
FILE_HANDLER_PREFIX
on·file·0: the handler of the first on file "x" change {…}
FOREIGN_CALL
foreign_call(runtime, module, member, call, arguments): a module of another runtime (foreign.rs), Nodes in and out
GPU_COMPUTE
gpu_compute(shader, numbers, workgroups): a WGSL compute shader run over the numbers on the GPU (WebGPU in the browser, web/playground/host-gpu.js), the numbers it left (card web-apis, notes/web_framework.md “web-apis: WebGPU”)
GPU_COMPUTE_LINEAR
gpu_compute(shader, xs, workgroups) of a linear xs = float[n]: the shader runs over the cells of the block in linear memory, read and written in place without building a list (card gpu-vectors, notes/gpu.md); gives the block back
GPU_DRAWING
Whether use draw draws on the GPU (src/graphics/gpu_canvas.rs): natively in a window, or as WARP_DRAW says; never on a page
GPU_MAP_LINEAR
ys = xs.map(x => …) @gpu of a linear float array (src/lowering/foreign/gpu_maps.rs): the WGSL kernel run over xs’s cells, written into ys’s; gives 1, or 0 without an adapter (said once), when the CPU maps them instead
GPU_PAINTS
Whether a shader can paint here (1) or not (0): paint(f, w, h) of a warp function reads it before painting f’s fragment shader, else paints f on the CPU (card paint-function, src/lowering/foreign/gpu_maps/kernels.rs); not a value a program names
GPU_REDUCE_LINEAR
s = sum(xs.map(x => …) @gpu), min, max (src/lowering/foreign/gpu_maps.rs): the kernel leaves one partial result per workgroup, written into a block the program combines; 1, or 0 without an adapter, as gpu_map_linear
GPU_RENDER
gpu_render(shader, width, height): a WGSL fragment shader main run over every pixel, the pixels paint shows (0xFFRRGGBB row by row; card g_YqWY, notes/web_framework.md “web-apis: WebGPU”)
HANDLER_PREFIX
What every exported handler name starts with
HELD_KEY
The name of the key held now (“a”, “ArrowUp”, “” for none), as on key names presses (card held-key): the word a program reads, made from KEY_CODE_HELD, the held key’s code (0: none), which it does not name
HOST_LIBRARY
INTERRUPT_HANDLER
The exported handler of on interrupt {…} (src/lowering/signals/event_signals.rs)
KEY_CODE_HELD
KEY_DOWN
Whether a key is held now, over the paint window or the page (card keyboard-state): on key hears each press
KEY_HELD
key_held(code): whether that key is held now, among others (card allow-diagonals: held_key == LEFT while UP is held too); code 0 whether none is
KEY_PRESSED
The next key pressed over the paint window, its code (0: none left), each press read once: natively on key {…} (lowering/signals/system_signals.rs); not a value a program names
LISTEN_CLOCK
LISTEN_EVERY
LISTEN_FRAME
LOCAL_OFFSET
local_offset(ms): seconds east of UTC in the environment’s time zone (TZ) at that instant: an instant’s wall clock
MOUSE_DOWN
MOUSE_WHEEL
The wheel turned over the paint window or the page’s canvas since the start, in steps (notches): up (away from you) adds, down takes away; a trackpad’s scroll counts PIXELS_PER_WHEEL_STEP pixels a step (card shader-wheel)
MOUSE_X
The pointer over the page’s canvas, in canvas pixels, and whether a button is down (card drawing-frames)
MOUSE_Y
NOTIFY
notify "text": a desktop notification (system_values.rs notify; the playground: the browser’s Notification)
ONLINE
PAGE_PATH
The path of the page shown (“/users/7”), which picks its route (lowering/web/routes.rs); “/” natively
PIXELS_PER_WHEEL_STEP
RANDOM
RANDOM_BELOW
RANDOM_SEED
random_seed(n): random and random_below give the same numbers after the same seed (natively and in the browser)
SET_SYSTEM_VALUE
set_system_value(name, value): writes one, window.width = 800 resizes the paint window (system_values.rs write)
SHARED_HANDLER
The checks of the listeners on shared values (P106), polled at every check point (lowering/signals/signal_values.rs)
SIGNAL_LISTEN
signal_listen(kind, id, argument): starts the timer on·every·id, on every 5 seconds {…} (LISTEN_EVERY, ms), on frame {…} (LISTEN_FRAME, ms; every frame of the paint window while it shows, without a window once), on every monday at 9:00 {…} and at 9:00 {…} (LISTEN_CLOCK, weekdays · CLOCK_WEEKDAYS + minute of day, the weekdays a mask with bit 0 Sunday … bit 6 Saturday, 0 once at the next such local time)
SIGNAL_POLL
SIGNAL_WATCH
SLEEP
sleep(seconds), the prelude word; it calls sleep_ms(milliseconds), the host word that pauses
SLEEP_MS
SYSTEM_VALUE
system_value(name): the machine’s battery percent, charging, online, dark mode (system_values.rs)
SYSTEM_VALUES
The system values, and whether each is a yes/no value
TEXT_COVERAGE
text_coverage(words, size): the words set in a sans-serif font size pixels high (card paint-text, lib/draw.warp label): [width, height, then how much each pixel is covered, 0 to 255, row by row]; the browser’s canvas 2D fillText in the playground, a system font through ab_glyph natively (src/graphics/text_raster.rs)
TIMER_HANDLER_PREFIX
on·every·0: the handler of the first on every … {…}
TIME_OF_DAY
The local time of day in milliseconds since midnight, what the word time is compared with a duration (src/numbers/units.rs)
VIEW_HEIGHT
VIEW_WIDTH
the size a picture gets: the playground’s output pane, natively the paint window’s first size (system_values.rs)
WINDOW_HEIGHT
WINDOW_OPEN
Whether a window shows the pictures: natively the paint window until it closes (no before the first paint and headless), on a page its canvas, always; while window_open { … } is a drawing loop that ends with its window
WINDOW_WIDTH
window.width/height (card make-width): the paint window’s inner size in points (the playground: the paintings’ frame in CSS pixels), writable; display.width/height the screen’s, read only (lowering/words/module_properties.rs)

Functions§

link_host_words
Link sleep, random, random_below and clock, for a store of any state