docs: add section about units to the pascal programming guide
This commit is contained in:
parent
11814cd24f
commit
d17c4c41fd
2 changed files with 80 additions and 1 deletions
|
|
@ -235,6 +235,85 @@ In Wirth Pascal, labels must be numbers. Other Pascal dialects also allow normal
|
|||
|
||||
Tridora-Pascal only allows identifiers as labels.
|
||||
|
||||
## Units
|
||||
Units are the method to create libraries in Tridora-Pascal, that is, codes module that can
|
||||
be reused in other programs.
|
||||
|
||||
Tridora-Pascal follows the unit syntax that has been established in UCSD-Pascal and is also
|
||||
used in Turbo Pascal.
|
||||
|
||||
Units are imported with the *USES* keyword, right after the *PROGRAM* statement.
|
||||
Multiple units can be imported by separating the unit names with commas.
|
||||
|
||||
There are some differences: In Tridora-Pascal, the unit file does not contain the interface
|
||||
section, only the implementation section. The interface section is instead placed into a
|
||||
separate file with the extension *.inc*, without any *UNIT* or *INTERFACE* keywords.
|
||||
|
||||
This file will be included by the compiler and should contain
|
||||
procedure or function declarations (as *EXTERNAL*). It can also contain *TYPE*,
|
||||
*CONST* and *VAR* statements.
|
||||
|
||||
All Pascal symbols of the unit are imported into the main program. There
|
||||
is no separate namespace for units.
|
||||
|
||||
### Using an Existing Unit
|
||||
An existing unit is imported with the *USES* statement that must be placed
|
||||
immediately after the *PROGRAM* statement.
|
||||
|
||||
The compiler will look for an include file with the unit name and an *.inc* extension.
|
||||
It will also
|
||||
tell the assembler to include an assembly language file for each
|
||||
unit. The filename must be the unit name plus an *.s* extension.
|
||||
|
||||
Since there is no linker in Tridora-Pascal, all imported units will be
|
||||
assembled together with the main program.
|
||||
|
||||
The compiler looks for unit *.inc* and *.s* files in the current volume or
|
||||
in the *SYSTEM* volume.
|
||||
|
||||
### Compiling a Unit
|
||||
A unit implementation file should start with a *UNIT* statement instead of a *PROGRAM*
|
||||
statement.
|
||||
|
||||
It should be compiled, not assembled.
|
||||
|
||||
When building a program that uses units, the assembler will include an assembly language
|
||||
file for each unit.
|
||||
|
||||
It is possible to write units in assembly language. This is done by
|
||||
directly providing the *.s* file and creating an *.inc* file with
|
||||
the *EXTERNAL* declarations matching the assembly language
|
||||
file.
|
||||
#### Example
|
||||
```pascal
|
||||
(* UnitExamples.pas *)
|
||||
program UnitExample;
|
||||
uses hello;
|
||||
|
||||
begin
|
||||
sayHello('unit');
|
||||
end.
|
||||
```
|
||||
|
||||
#### Example Unit Implementation File
|
||||
```pascal
|
||||
(* hello.pas *)
|
||||
unit hello;
|
||||
|
||||
implementation
|
||||
|
||||
procedure sayHello(s:string);
|
||||
begin
|
||||
writeln('hello, ', s);
|
||||
end;
|
||||
|
||||
end.
|
||||
```
|
||||
#### Example Unit Include File
|
||||
```pascal
|
||||
(* hello.inc *)
|
||||
procedure sayHello(s:string); external;
|
||||
```
|
||||
## Compiler Directives
|
||||
|
||||
Tridora-Pascal understands a small number of compiler directives which are introduced as usual with a comment and a dollar-sign. Both comment styles can be used.
|
||||
|
|
|
|||
|
|
@ -822,7 +822,7 @@ PUTPIXEL_4BPP:
|
|||
SHL 2 ; * 16
|
||||
DUP
|
||||
SHL 2; * 64
|
||||
ADD ; x*16 + x*64
|
||||
ADD ; y*16 + y*64
|
||||
|
||||
ADD ; add results together for vmem addr
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue