Repository navigation
Annotations
An annotation attaches named, validated metadata to a label or constant. The instruction set configuration declares which annotations exist and what their arguments mean; assembly source opts in with the #annotate directive. Annotations emit no bytes and never change the assembled image.
Other features read annotations:
- Output formats defined by the configuration, such as an export file that lists the annotated symbols.
- The built-in
-t symbolsJSON format, which outputs all symbols, will include every symbol's annotations if they have any. - The built-in
listingnamespace, which shapes-t listingoutput (see Thelistingnamespace).
A namespace can also accept verbatim blocks: text in the source that is not assembled, which an output format copies into its file.
Annotations require BespokeASM 0.9.0 or later.
#annotate xmin kind=addr name=AddW
add_w:
...
RTS
#annotate xmin kind=var type=int
pa: .2byte 0
#annotate listing heading="Parameter block"
#annotate xmin kind=var type=char count=16
buf: .zero 16
#annotate xmin kind=const type=int
LIMIT = 100The form is:
#annotate <namespace> <argument> <argument> ... ; optional comment
-
<namespace>names an annotation the configuration declares, or the framework'slistingnamespace. A namespace the configuration does not declare is an error, never silently ignored. - Each argument is
key=value. A boolean argument can also be written as a barekey, which meanskey=true; writekey=falseto set it to false. A boolean argument that is left out is unset. The assembler treats an unset boolean as false, but output formats may not: seedefaultunder Arguments. - A value is a word (
int,var), a numeric literal in any syntax the assembler accepts (16,0x10,$10,b10000), or a double-quoted string (heading="Lookup tables"). Quote a value that contains spaces. Inside quotes,\nstarts a new line,\tis a tab, and\"and\\are a quote and a backslash. Values are literals, not expressions. The one exception is an argument that the configuration declares with typesymbol: its value names a label or constant, which is resolved after assembly. - Quoted strings written next to each other are one value:
"ab" "cd"is"abcd".
An #annotate line that ends in \ continues on the next line. Together with joined strings, this splits a long value over several lines:
#annotate xmin kind=addr name=SumTo description= \
"SumTo\n" \
" Sums the integers from 1 to pa.\n" \
" Returns the result in pr."
sumto:- The
\must be the line's last character, outside quotes. A line with a;comment does not continue, so only the last line of the directive can have a comment. - A blank line or the end of the file after the
\is an error. Errors about the directive report its first line. - The directive is one line for conditional compilation, and the annotation applies to the definition after its last line.
-t listingshows each line as written. - Besides
#annotate, only data directives and embedded strings continue (see Data Directives). A\at the end of any other line keeps its meaning.
- An annotation applies to the next line that defines a label (
name:) or a constant (name = expr,name EQU expr). It must be directly above that definition. Only further#annotatelines, for other namespaces, may sit between them. A blank line, a comment line, an#includeor any other line in between is an error. - A symbol can carry several annotations, one per namespace. A second annotation in the same namespace on the same symbol is an error.
- The configuration can limit a namespace to labels or constants, and to symbol scopes (global, file
_name, local.name). -
#annotateobeys conditional compilation (#if,#ifdef) like any other line. An annotation inside a false branch does nothing. - Annotations in
#included files work the same way. An annotation at the end of a file, with no definition after it, is an error.
annotate, verbatim and endverbatim are reserved words in every instruction set, so they cannot be used as label or constant names.
The configuration can check each annotation against the symbol it annotates. A failed check is an error.
A label's data run is the data directives (.byte, .2byte, .4byte, .zero, .fill, .cstr and so on) that start on the label's line or on the line after it and continue without a break. Blank and comment lines do not end the run. Anything else does: another label, an instruction, or a directive that is not data.
A data_size constraint requires the run to be an exact number of words. Sizes are counted in words, the instruction set's addressable unit (general.word_size); on an 8-bit machine a word is a byte.
BespokeASM has no built-in data types. Names like int and char are values of an argument that the configuration declares, and the configuration says how many words each one needs. The examples in this section use the xmin annotation from the Minimal 64x4 configuration (shown in full under Declaring annotations in the configuration). Its type argument sizes char as 1 word, int as 2 and long as 4:
#annotate xmin kind=var type=int
pa: .2byte 0 ; OK: an int is 2 words
#annotate xmin kind=var type=int
pb: .byte 0 ; error: 'pb' is annotated as type=int, which needs 2 words, but 1 word of data follows itA configuration can also let the data set an array's count, so the source does not repeat it. In xmin, the array argument and the str type do this:
#annotate xmin kind=var type=int array
primes: .2byte 2, 3, 5, 7 ; exported as an int array of 4
#annotate xmin kind=var type=str
banner: .cstr "Hello" ; a string: exported as a char array of 5, without the terminatorWith array, the count is the data's size divided by one element's size; the data must hold at least one element and a whole number of them. With a type the configuration marks as terminated (str here), the data must also end with the instruction set's string terminator (general.cstr_terminator), and the count leaves it out. Which arguments do this is up to the configuration; see data_size.
An annotation that sets no size, such as kind=addr for a routine's entry point, puts no requirement on what follows the label.
A constant owns no memory, so a value_range constraint checks its value instead. The configuration sets the ranges too; xmin gives char the range 0 to 255:
#annotate xmin kind=const type=char
LIMIT = 1000 ; error: 'LIMIT' value 1000 is outside 0 to 255, the range of type=charxmin also accepts kind=addr on a constant that holds an address, such as an I/O register, with the range 0 to 65535. It is exported in hex (int kPort := 0xfec0), which xmin reads as a 16-bit int.
Every instruction set has the framework's listing namespace. It shapes the -t listing output and the listing output-format generator, and every other format ignores it. Bytes are assembled the same either way.
| Argument | Effect in the listing |
|---|---|
heading="..." |
Prints a heading, underlined, above the symbol. |
page_break |
Starts a new page: a form feed, then the file and column headers again, with the file marked (continued). |
collapse |
Shows the first row of the symbol's data, then one row with the address of the first word not shown and a count of the rest (... 194 more bytes). For large tables and .zero fills. |
hide |
Leaves the symbol's lines out of the listing: its #annotate lines and every line up to the next label of any scope. On a constant, only its own line. |
start:
RTS
#annotate listing page_break heading="Lookup tables" collapse
sine_table:
.byte 0, 3, 6, 9, 12, 16, 19, 22, 25, 28, 31, 34, 37, 40, 43, 46
.byte 49, 51, 54, 57, 60, 63, 65, 68, 71, 73, 76, 78, 81, 83, 85, 88Lookup tables
-------------
4 | 0001 | | #annotate listing page_break heading="Lookup tables" collapse |
5 | 0001 | | sine_table: |
6 | 0001 | 00 03 06 09 0c 10 | .byte 0, 3, 6, 9, 12, 16, 19, 22, 25, 28, 31, 34, 37, 40, 43, 46 |
| 0007 | | ... 26 more bytes |
Details:
- A heading and a page break go above the symbol's first
#annotateline, so the annotations stay with their symbol. -
collapseon a label with no data, or on a constant, has no effect and is a warning (an error with-W). - A hidden symbol prints no heading or page break. Hidden lines do not widen the listing's columns.
A verbatim block carries text that is not assembled, for an output format to copy into its file. For example, an xmin script file can hold the xmin functions that call the assembled routines:
#annotate xmin kind=addr name=SumTo
sumto:
...
RTS
#verbatim xmin
def AddTo(char value):
pa = value
call SumTo
return pr
#endverbatim-
#verbatim <namespace>starts a block and#endverbatimends it, each on a line of its own, optionally with a comment. The namespace must be one the configuration lets accept blocks (seeverbatimunder Namespace keys). -
A block can name a part the namespace declares, which an output format places separately. In the Minimal 64x4 configuration,
#verbatim xmin headerblocks go at the top of the xmin file, and blocks with no part go after the declarations:#verbatim xmin header # SumLib for Extended Min #endverbatim
-
The lines between are text: they are not preprocessed (a
#line is text), emit no bytes, and are kept exactly as written, including indentation and;. -
A block can appear anywhere a line of code can, any number of times, in any file. A block inside a false
#ifbranch is skipped. -
A block is not part of a symbol: it cannot sit between an
#annotateline and its definition, and#annotate listing hidedoes not hide it. -
-t listingshows a block's lines, and-t symbolslists every block underverbatim, with its part.
A top-level annotations section declares each namespace. This is the xmin annotation from the Minimal 64x4 configuration:
annotations:
xmin:
documentation:
description: Exports a label or constant to an [Extended Min (xmin)](https://github.com/michaelkamprath/extended-min) script.
verbatim:
documentation:
description: xmin source, written after the exported symbols in the xmin file.
parts:
header:
documentation:
description: xmin comment lines written at the top of the xmin file.
applies_to: [label, constant]
scopes: [global]
arguments:
kind:
type: enum
values:
addr:
documentation:
description: an address, as an int constant, for `call AddW`: a label's address or a constant's value
var:
documentation:
description: a variable bound to the label's data (`int pa @ 0x0113`)
const:
documentation:
description: the constant's value, as an xmin constant
required: true
documentation:
description: What the export declares in the xmin script.
type:
type: enum
values: [char, int, long, str]
required_when: { kind: [var, const] }
count:
type: integer
min: 1
allowed_when: { kind: [var], type: [char, int, long] }
array:
type: boolean
allowed_when: { kind: [var], type: [char, int, long] }
name:
type: string
pattern: '^[A-Za-z][A-Za-z0-9]{0,12}$'
data_size:
when: { kind: [var] }
words: { type: { char: 1, int: 2, long: 4, str: 1 }, times: count, infer_times: array }
terminated_when: { type: [str] }
value_range:
- when: { kind: [const] }
range: { type: { char: [0, 255], int: [-32768, 32767], long: [-2147483648, 2147483647], str: null } }
- when: { kind: [addr] }
range: [0, 65535]A namespace may not be named listing. A configuration that declares annotations should set general.min_version to 0.9.0 or later.
| Key | Meaning |
|---|---|
documentation.description |
Shown in the generated ISA documentation and in editor hover text. |
documentation.examples |
Usage examples, as instructions have: a list of code blocks, each with an optional title and description. Shown in the generated ISA documentation and in editor hover text. |
applies_to |
label, constant, or both. Default: both. |
scopes |
The symbol scopes allowed: global, file, local. Default: all. The scope comes from the name's prefix (. local, _ file, otherwise global). |
arguments |
The arguments, by name. |
data_size |
Optional constraint on a label's data run. |
value_range |
Optional constraint on a constant's value. |
verbatim |
Optional: the namespace accepts #verbatim blocks. A mapping with two optional keys: documentation.description, shown in the generated ISA documentation and hover text, and parts, the parts a block may name, each a mapping with an optional documentation.description. verbatim: {} opts in with neither. |
| Key | Meaning |
|---|---|
type |
enum, integer, string, boolean or symbol. A symbol value names a label or constant; consumers see its resolved value (an address for a label). |
values |
For enum: the allowed values, as a list, or as a mapping that documents each value: addr: { documentation: { description: ... } }. A value with nothing to document maps to nothing (addr:). |
min, max
|
For integer: the inclusive bounds. |
pattern |
For string: a regular expression the whole value must match. |
required |
The argument must be given. |
required_when |
The argument must be given when other enum arguments have these values, as { kind: [var, const] }. Several keys must all hold. |
allowed_when |
The argument may be given only when other enum arguments have these values. |
default |
The value used when the argument is absent. Without a default, an absent argument is unset: output formats see an empty value and -t symbols omits it. To have formats see false for an absent boolean, give it default: false. A default is not applied when the argument's allowed_when condition does not hold. |
documentation |
description: what the argument means. It appears in the generated ISA documentation and in editor hover text. |
data_size sets the exact number of words a label's data run must hold, from the annotation's arguments.
-
when: the condition under which the constraint applies, on enum arguments. -
words: either a fixed number (words: 2), or a table selected by one enum argument (words: { type: { char: 1, int: 2 } }). In the table form:-
timesnames an integer argument that multiplies the selected size (count). Absent, it counts as 1. -
infer_timesnames a boolean argument. When it is true, the data sets thetimesargument instead: the run's size divided by the selected size. The count argument may then not be given too.
-
-
terminated_when: a condition on enum arguments. When it holds, the data also setstimes, but its last element must be the instruction set's string terminator, and the count leaves it out. The data must hold at least one element before the terminator. - A table entry of
nullmeans the value is not allowed where the rule applies.
The count that the data sets is recorded with the annotation's arguments, so output formats and -t symbols see it like a written one.
value_range sets the inclusive range a constant's value must lie in: either fixed (range: [0, 255]) or a table selected by one enum argument. A null entry means that value is not allowed for a constant, so kind=const type=str above is an error.
value_range can also be a list of rules, each with its own when, as in the example. The first rule whose when holds applies; a constant that no rule applies to is not checked.
| Problem | Message |
|---|---|
| A namespace the configuration does not declare | this instruction set does not define annotation 'xmn'; defined annotations: listing, xmin |
| An unknown argument | annotation 'xmin': unknown argument 'knd'; did you mean 'kind'? |
| A bad value | annotation 'xmin': argument 'type' must be one of char, int, long, str |
| A missing required argument | annotation 'xmin': argument 'type' is required when kind is one of var, const |
| An argument not allowed here | annotation 'xmin': 'count' is only allowed when kind is var and type is one of char, int, long |
| Not directly above a definition | #annotate must be directly above a label or constant definition, but line 12 is a blank line |
| The same namespace twice | symbol 'pa' already has an annotation in the 'xmin' namespace |
| A symbol kind or scope not allowed | annotation 'xmin' is not allowed on local label '.loop'; it applies only to global symbols |
| The wrong amount of data | 'pa' is annotated as type=int, which needs 2 words, but 1 word of data follows it |
| Data that cannot set a count | 'odd' is annotated as type=int array, which needs a whole number of 2-word elements, but 3 words of data follow it |
| A terminated type without its terminator | 'msg' is annotated as type=str, which needs its data to end with a 0 terminator, but it ends with 0x42 |
| A constant out of range | 'LIMIT' value 1000 is outside 0 to 255, the range of type=char |
| A value the table does not allow | annotation 'xmin': type=str is not allowed when kind is const |
A symbol argument that names nothing |
annotation 'linked': 'len' names unknown symbol 'buf_len' |
A \ with nothing after it |
#annotate ends with \ but line 14 is blank |
| A block's namespace does not accept blocks | annotation 'xmn' does not accept #verbatim blocks; namespaces that do: xmin |
| A block's part is not one the namespace declares | annotation 'xmin' has no #verbatim part 'headr'; its parts are: header |
| A block with no end | #verbatim block started on line 12 has no #endverbatim |
#endverbatim with no block |
#endverbatim without a #verbatim block |
Warning: collapse with no data |
'#annotate listing collapse' on 'helper' has no effect: no data follows it |
Configuration problems, such as an unknown argument type or a when that names a missing argument, are reported when the configuration loads, by key path (for example annotations.xmin.data_size.words.times must name an integer argument of this annotation).