modus
Menu
On this page

The entry imports

A demonstration of the loader: a module with imports, and the replacement of an import. The design: Module contract: Replacement of an import.

The module agenda imports the module calendar. calendar has a fault: the year 2000 has 365 days. calendar_fixed has the correction and the same description; calendar_changed has another description. This process loads agenda in its own memory with the loader of the system, with no replacement and with each replacement, and shows what the loader answers. It also imports calendar itself: the root service gave it the replacements of the machine when it started it.

What it is for. It shows that a module is named by the hash of its code, and that the principal can give another module where a module imports one, with a check: a replacement with the same description is accepted, and one with another description is a load error that names the export and its difference. It also shows that the import of a module is a direct call through an import slot, with its cost measured, and that two processes that import one module share one copy of its code.

What a reader sees. Start it from the start menu, or with start("imports") in the console. The window has one row for each case: the load of agenda with no replacement (the year 2000 has 365 days), with calendar_fixed (366 days), and with calendar_changed (refused at the check). The log gets imports: ok, <count> cases, then the measures: a call through an import slot, the bind of agenda, and the pages of the shared code.

The cases also cover a missing import (lonely), a cycle (agenda in place of calendar), a type that differs (number against fibonacci), the unload of a module with its imports, and one copy of the code of calendar for two loads.

The module record of its starter. The root service wrote the module record of this process. The process tries to remove it, to replace it with the hash of agenda, to unmap its first segment and to map memory at its base: the kernel refuses each change with No_Right and the error kind Starter_Module. A module that the process loads itself has a record of the writer process.

The replacements of the machine apply to its own import of calendar: after replace("calendar", "calendar_fixed") in the console, a new start of imports finds 29 days in February 2000 in its last row, and says that the root service gave calendar_fixed.

Its grants: Image, to load the modules of the boot image, and Inspect, to read its module records and to measure with the cycle counter.

See: The writer of a module record in the repository

imports module with an entry

Hash
dce58fb00b1bed910d8ab94a7ec72bafcbd4354325257a6daa1e5863882b5e90
Size
328927 bytes
Exports
0
Imports
1
Imported by
0
License
MIT

A demonstration of the loader: a module with imports, and the replacement of an import

FactValue
KindModules with an entry
Sourcesrc/modules/demonstrations/imports
Boot imageyes: in the boot image, 328927 bytes in this build
Build settingsnone: the defaults of the source
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.

imports calendar

Exports

ExportWhat it does
entry()runs each load case once with the loader of the system, calls agenda and calendar through their import slots, measures the calls and the bind, writes the lines on the log, then keeps the window open until the process is stopped

entry

entry()

entry runs each load case once with the loader of the system, calls agenda and calendar through their import slots, measures the calls and the bind, writes the lines on the log, then keeps the window open until the process is stopped. 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/imports/main.odin:345

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
GrantsIt loads modules of the boot image, and measures with the cycle counter.
Other terms of its start grant setnone
Budget that it asks for
  • working memory pages 1162
  • pages of its threads 110
  • pages of the pictures of its window 4438
  • pages of the module and its imports from the files of the build
  • processes 3
  • threads 3
Itself and two processes that import calendar: 808 pages. And the glyph memory of the copy of the text rendering of the drawing module, which draws its text: 354 pages (display.TEXT_MEMORY_PAGES). 808 + 354 = 1162.

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).