Basic

Compiling to a module

The same code can become a binary for one machine or a module for any machine. The module is a different deliverable, and the difference is what the host is allowed to do with it.

What you will see

Two lines. The convention is agreed, not enforced, which is why it is written.

About 1 min of reading

Try It

Read the exports of a module

1

Write the export list

printf 'run\nreset\nalloc\n' > /tmp/x.txt; wc -l < /tmp/x.txt

Before you run it, say out loud what it will print. Then open the answer.

What it prints
3. Three names is the contract, and the contract is a file.
2

Check the host uses them

printf 'run\nreset\n' > /tmp/h.txt; comm -23 /tmp/x.txt /tmp/h.txt

Before you run it, say out loud what it will print. Then open the answer.

What it prints
alloc. An export nobody imports is dead weight in the binary.
3

Write the convention for types

printf 'boundary=integers only\nstrings=offset+length\n' > /tmp/b.txt; cat /tmp/b.txt

Before you run it, say out loud what it will print. Then open the answer.

What it prints
Two lines. The convention is agreed, not enforced, which is why it is written.

Data Flow

Source to a host contract
1 The source is compiled to a target
↓
2 The module exports a list of names
↓
3 The host imports the names it needs
↓
4 Both sides are checked against the list
Why this works
Why the export list is written down

The host is written by someone else. A contract that is only in the compiler output is a contract that will drift.

The cost of the boundary

Crossing the boundary copies. The cost is per crossing, which is why crossings are batched.

Examples

The target is a contract

A module exports names and imports names. The host is written against that list, and the list is the contract.

Why the module is small

There is no operating system inside it. The module asks the host for anything it needs beyond memory.

The boundary is where types stop

Across the boundary there are integers. Everything else is a convention both sides agree to.

Words this lesson uses

Each one is defined here on this site. Open the entry for the full definition and the other words it points at.

← Cancellation loses work
Previous Lesson
Cancellation loses work
Next Lesson
One flat memory, two owners
One flat memory, two owners →