[Template fetch failed for http://spivey.oriel.ox.ac.uk/corner/Template:Sitenotice?action=render: HTTP 404]
Keiko assembly language: Difference between revisions
(→Files) |
No edit summary |
||
Line 1: | Line 1: | ||
==Syntax== | ==Syntax== | ||
This section gives the syntax of Keiko assembly language programs in the form that is accepted by the bytecode assembler/linker @oblink@. The style of syntax description is similar to that used in the Kernighan & Ritchie book on C: a syntactic category is followed by a sequence of alternatives, each on a separate line. A subscript {{opt}} indicates that a construct is optional. | |||
===Lexical conventions== | |||
* Each element on its own line (''nl'' used below to denote a line boundary) | |||
* Blank lines and lines beginning @#@ are ignored | |||
* Identifiers can be any sequence of non-blank characters, including e.g. @Files.Read@. | |||
===Files=== | ===Files=== | ||
A Keiko file contains a heading that gives the name of the module and lists (in @IMPORT@ directives) other modules that it depends upon. A compiler that outputs Keiko code can generate a checksum for the public interface of a module and embed this checksum in each other module that uses it, and the assembler/linker will then check across all modules in a program that the checksums are consistent. Unused checksums can be replaced by 0. The module header also contains a count of source lines in the module that is used to allocate counters for line-count profiling; this too can be replaced by 0 of profiling is not going to be used on the program. | |||
''file'': | ''file'': | ||
''heading'' ''body''{{opt}} | ''heading'' ''body''{{opt}} | ||
heading: | ''heading'': | ||
module- | ''module-directive'' ''imports''{{opt}} ''endhdr-directive'' | ||
module- | ''module-directive'': | ||
MODULE ident checksum linecnt | MODULE ''ident'' ''checksum'' ''linecnt'' ''nl'' | ||
imports: | ''imports'': | ||
import- | ''import-directive'' | ||
import- | ''import-directive'' ''imports'' | ||
import- | ''import-directive'': | ||
IMPORT ident checksum | IMPORT ''ident'' ''checksum'' ''nl'' | ||
endhdr- | ''endhdr-directive'': | ||
ENDHDR | ENDHDR ''nl'' | ||
The body of a module constists of multi-line procedures interspersed with other single-line directives that (among other things) allocate global storage. | |||
body: | body: | ||
Line 38: | Line 49: | ||
GLOVAR | GLOVAR | ||
PRIMDEF | PRIMDEF | ||
* a @DEFINE@ directive defines a label at the current location in the data segment. That location is the address of any following data item created with another directive such as @WORD@, @FLOAT@ or @STRING@. | |||
===Procedures=== | ===Procedures=== | ||
Each procedure has a heading that gives its name and some other information. This is followed by a sequence of mingled Keiko machine instructions and pseudo-operations. The pseudo-operations typically assemble into an entry in the procedure's constant pool, together with an instruction that loads the constant onto the stack. | |||
procedure: | procedure: | ||
proc-directive | proc-directive body{{opt}} end-directive | ||
proc-directive: | proc-directive: | ||
PROC ident 0 0 0 | PROC ident 0 0 0 | ||
body: | |||
element | |||
element body | |||
end-directive: | end-directive: | ||
END | END | ||
LABEL | element: | ||
CONST | pseudo-operation | ||
GLOBAL | instruction | ||
FCONST | |||
DCONST | ==Pseudo-operations== | ||
QCONST | |||
STKMAP | LABEL | ||
LINE | CONST | ||
GLOBAL | |||
FCONST | |||
DCONST | |||
QCONST | |||
STKMAP | |||
LINE |
Revision as of 21:39, 11 May 2022
Syntax
This section gives the syntax of Keiko assembly language programs in the form that is accepted by the bytecode assembler/linker oblink
. The style of syntax description is similar to that used in the Kernighan & Ritchie book on C: a syntactic category is followed by a sequence of alternatives, each on a separate line. A subscript opt indicates that a construct is optional.
=Lexical conventions
- Each element on its own line (nl used below to denote a line boundary)
- Blank lines and lines beginning
#
are ignored - Identifiers can be any sequence of non-blank characters, including e.g.
Files.Read
.
Files
A Keiko file contains a heading that gives the name of the module and lists (in IMPORT
directives) other modules that it depends upon. A compiler that outputs Keiko code can generate a checksum for the public interface of a module and embed this checksum in each other module that uses it, and the assembler/linker will then check across all modules in a program that the checksums are consistent. Unused checksums can be replaced by 0. The module header also contains a count of source lines in the module that is used to allocate counters for line-count profiling; this too can be replaced by 0 of profiling is not going to be used on the program.
file: heading bodyopt
heading: module-directive importsopt endhdr-directive
module-directive: MODULE ident checksum linecnt nl
imports: import-directive import-directive imports
import-directive: IMPORT ident checksum nl
endhdr-directive: ENDHDR nl
The body of a module constists of multi-line procedures interspersed with other single-line directives that (among other things) allocate global storage.
body: phrase phrase body
phrase: directive procedure
Directives
directive: DEFINE WORD LONG FLOAT DOUBLE STRING GLOVAR PRIMDEF
- a
DEFINE
directive defines a label at the current location in the data segment. That location is the address of any following data item created with another directive such asWORD
,FLOAT
orSTRING
.
Procedures
Each procedure has a heading that gives its name and some other information. This is followed by a sequence of mingled Keiko machine instructions and pseudo-operations. The pseudo-operations typically assemble into an entry in the procedure's constant pool, together with an instruction that loads the constant onto the stack.
procedure: proc-directive bodyopt end-directive
proc-directive: PROC ident 0 0 0
body: element element body
end-directive: END
element: pseudo-operation instruction
Pseudo-operations
LABEL CONST GLOBAL FCONST DCONST QCONST STKMAP LINE