modus
Menu
On this page

The entry tally

A count that its callers add to. This module shows that one file has each role: the system has no difference between a command line program, a library and a dynamic library.

The same file, with the same hash, is used in four ways:

start("tally")     a process, with a window that shows the count
connect("tally")   a service: the calls go to the process that runs
load("tally")      a library: the calls are direct, in the memory of the caller
isolate("tally")   a sandboxed process: the calls go through a ring

The data of a module belongs to the process that runs it. The four uses give three counts: the process and the service have one count, the caller that loads the module has its own, and the sandboxed process has its own.

An export needs nothing from the entry: it reads and writes the data of the module only. That is the one rule for a module that has each role.

Grants, as the root service gives them: Serve, so that connect("tally") reaches the process that runs. load and isolate need no grant of tally: the console maps the file from the boot image.

What a reader sees, as a process: the count, the number of adds, the last 8 notes with the newest first, and the callers and the calls. The key Space adds 1, with the note "a key of the process". The log has "tally: ok" when the window opens.

Example, in the console:

load("tally")
add(2, "two")       the count of the console: 2
connect("tally")
tally.add(5, "five")  the count of the process: 5

The design:.

See: Module contract: Static is dynamic

tally module with an entry

Hash
67a9d56e149e6f328069d924f9d7cc491d2b3cca11c229b18f859eaa1c3ab51b
Size
268223 bytes
Exports
5
Imports
0
Imported by
0
License
MIT

A count that its callers add to

FactValue
KindModules with an entry
Sourcesrc/modules/demonstrations/tally
Boot imageyes: in the boot image, 268223 bytes in this build
Build settingsnone: the defaults of the source
Importsnone
Imported bynone

Neighbours

It imports no module, and no module imports it. The module graph shows it with the other modules that have no edge.

Exports

ExportWhat it does
add(amount: Integer, note: Text) -> Integeradds an amount to the count, with a note that says why
total() -> Integergives the count
adds() -> Integergives the number of calls of add after the start, or after the last reset
last() -> Textgives the note of the last add
reset() -> Integerputs the count at 0 and removes the notes
entry()The entry of tally: it runs only when tally is a process (start or connect), never after load

add

add(amount: , note: ) -> 

add adds an amount to the count, with a note that says why.

The count and the notes are data of the module, in the process that runs it: the four ways of tally give three counts. The module keeps the last 8 notes.

  • amount: the amount, positive or negative.
  • note: why, 36 bytes at most.

The result is the new count, never negative. It fails with -1 and an error record, and the count does not change:

  • Too_Long: the note has more than 36 bytes;
  • Too_Small: the amount takes the count below 0; the record holds the least amount that is allowed;
  • Bad_Value: the count passes the largest integer.

Example: tally.add(-3, "a refund").

Parameters
  • amount:
  • note:
Result
When it fails
a negative result, and the error record
Source
src/modules/demonstrations/tally/main.odin:79

total

total() -> 

total gives the count.

The count of the process that runs the module: after load("tally") it is the count of the caller itself. It never fails.

Parameters
none
Result
Source
src/modules/demonstrations/tally/main.odin:105

adds

adds() -> 

adds gives the number of calls of add after the start, or after the last reset.

A refused add does not count. A test compares it with the calls that it made: a call over a ring that ran two times shows here.

Parameters
none
Result
Source
src/modules/demonstrations/tally/main.odin:114

last

last() -> 

last gives the note of the last add. The text is empty before the first add.

The result is the length of the note, 36 at most; a text shorter than the note gets its first bytes.

Parameters
none
Result
Source
src/modules/demonstrations/tally/main.odin:122

reset

reset() -> 

reset puts the count at 0 and removes the notes. The result is the count before.

It also sets the count of adds to 0. It never fails.

Parameters
none
Result
Source
src/modules/demonstrations/tally/main.odin:137

entry

entry()

The entry of tally: it runs only when tally is a process (start or connect), never after load. It opens the service and the window, then runs the calls and the key Space in one loop until the principal closes the window.

With no window it stops with Failed. It writes "tally: ok". Each turn draws the window, waits for an event or a call, runs the calls, then the keys: Space is one add of 1.

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

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 1880
  • pages of its threads 72
  • pages of the pictures of its window 669
  • 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 (168 pages): its module, its stack, its tables 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.

Text wire form

A wire form of the module contract: one word of a call. The address of a slice record {address, count} of UTF-8 bytes.

Error_Record record of a module

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

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