modus
Menu
On this page

The entry life

The source src/modules/demonstrations/life built with the setting DRAWING_THROUGH_MODULE=true. The text after this paragraph is the comment of that source.

A demonstration: Conway's Game of Life.

pointer, left button: draw cells    space: pause    r: random    c: clear

This process is also a service: another process reads and changes the cells with isolated calls, while the game runs.

What it is for. It shows a process that is at once a window and a service: its exports change the state that its window draws, while the window runs. A caller reaches them through a connection that the root service grants; it sees the cells only through the exports, never the memory of the process.

What a reader sees. Start it from the start menu, or with start("life") in the console. A board of 96 by 64 cells, filled at random, takes one step each 80 ms. The input draws cells with the left button; Space pauses; r fills the board at random; c clears it. The log gets life: ok after the first frame.

Its grant: Serve, its exports. It needs no other.

Its exports: population, empty and glider.

connect("life")
life.empty()
life.glider(10, 10)
life.population()

The board wraps at its edges: a cell at the right edge has neighbours at the left edge.

life module with an entry

Hash
716f239c97d02ab9203f1cdeddf14aa3034e115f5fc21baa1d38499a07d7cebd
Size
162944 bytes
Exports
3
Imports
1
Imported by
0
License
MIT

A demonstration: Conway's Game of Life

FactValue
KindModules with an entry
Sourcesrc/modules/demonstrations/life
Boot imageyes: in the boot image, 162944 bytes in this build
Build settings
  • DRAWING_THROUGH_MODULE=true
Imports
Imported bynone

Neighbours

What it imports, at its left, and what imports it, at its right: the part of the module graph that touches it.

life drawing

Exports

ExportWhat it does
population() -> Integergives the count of live cells
empty()removes all the cells
glider(column: Integer, row: Integer) -> Integeradds a glider: five cells that move down and right
entry()opens the window, fills the board at random, and runs the game until the process is stopped

population

population() -> 

population gives the count of live cells.

It counts the cells of the board that the window shows now. The result is from 0 to 6144 (96 by 64). It has no parameter and no error.

Parameters
none
Result
Source
src/modules/demonstrations/life/main.odin:82

empty

empty()

empty removes all the cells.

The window shows the empty board at its next frame. The game goes on: an empty board stays empty until a cell is added.

Parameters
none
Result
none
Source
src/modules/demonstrations/life/main.odin:97

glider

glider(column: , row: ) -> 

glider adds a glider: five cells that move down and right.

Parameters: column and row, the top left corner of the 3 by 3 box of the glider, from 0. A value past the board wraps: column modulo 96, row modulo 64.

It adds cells and removes none. The result is 1. It fails with -1 and an error record: Too_Small when column or row is negative; the record names the argument, and no cell changes.

Parameters
  • column:
  • row:
Result
When it fails
a negative result, and the error record
Source
src/modules/demonstrations/life/main.odin:112

entry

entry()

entry opens the window, fills the board at random, and runs the game until the process is stopped.

The loop: it runs the calls of its exports, takes the keys and the pointer of the window, takes one step when the time of the next step came and the game is not paused, and draws the board when a cell changed. It then waits for an event, a call, or the next step (with no end while paused). With no window, it stops with Failed.

Form
The entry of the module: one parameter, an address, fixed by the contract.
Source
src/modules/demonstrations/life/main.odin:167

Read from the source of the module, as the build reads it to describe the exports (tools/modustool/build/describe.odin).

What the root service gives it

WhatValueAs the root service says
GrantsA service: the console calls its exports through a connection.
Other terms of its start grant setnone
Budget that it asks for
  • working memory pages 1748
  • pages of its threads 72
  • pages of the pictures of its window 1200
  • pages of the module and its imports from the files of the build
  • processes the least
  • threads the least
The least budget of 2048 pages, in which it ran before it stated its window, less that window at the scale 1 (300 pages): its module, its stack, its grids and its glyph memory. The tool counts the window at the largest scale. See: Module contract: The budget that a module asks for

The start grant set is read from start_grant_sets in src/modules/system/root/start_grant_sets.odin. The stated budget is read from the constant MODULE_BUDGET of the source of the module (its line); the build adds the counted parts and writes the sum in the module (tools/modustool/build/budget_count.odin); the root service accepts it up to the largest budget of a process, and adds the limits of processor time and of log records (src/modules/system/root/budgets.odin).

Integer wire form

A wire form of the module contract: one word of a call. A signed integer of 64 bits, in a register.

Error_Record record of a module

A record of the module life: 56 bytes, aligned on 8 bytes, 0 bytes of padding.

  • kindi6408 bytes
  • uniti6488 bytes
  • operationi64168 bytes
  • argumenti64248 bytes
  • valuei64328 bytes
  • limiti64408 bytes
  • foundi64488 bytes