@andrivet/z80-assembler 1.1.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16,19 +16,29 @@
16
16
  * License: GPLv3
17
17
  * Copyrights: Copyright (C) 2023 Sebastien Andrivet
18
18
  */
19
- import { bytes } from '../types/Types';
19
+ import { Address, bytes } from '../types/Types';
20
20
  import { ByteValue, Expression, PosInfo, WordValue } from "../grammar/z80";
21
21
  /**
22
- * A function taking no argument and returning a number (if it is known) or null (if it is unknown).
22
+ * A function returning a number (if it is known) or null (if it is unknown).
23
23
  * Une function qui ne prend pas d'argument et qui retourne un nombre (s'il est connu) ou null (s'il est inconnu).
24
24
  */
25
- export type EvalFunc = () => number | null;
25
+ export type EvalFunc = (pc: Address, mustExist: boolean) => number | null;
26
26
  /**
27
27
  * An abstract element generated by the parser.
28
28
  * Un élément abstrait générà par l'analyseur.
29
29
  */
30
30
  export interface AstBase {
31
+ /**
32
+ * The number of bytes that will be generated by this element.
33
+ * Le nombre d'octets générés par cet élément.
34
+ */
31
35
  get size(): number;
36
+ /**
37
+ * Generate actual bytes.
38
+ * Génération des octets
39
+ * @param instructionAddress Address of the next byte to generate,
40
+ * Adresse du prochain octet à générer.
41
+ */
32
42
  generate(instructionAddress: number): bytes;
33
43
  }
34
44
  /**
@@ -91,7 +101,7 @@ type UnaryOperation = (a: number) => number;
91
101
  * @param op Operation to be applied to the left and right side.
92
102
  * L'opération à appliquer aux opérandes
93
103
  */
94
- export declare function binaryOperation<Operation extends BinaryOperation, Inner extends Evaluable, Left extends InnerExpression<Inner>, Right extends Evaluable>(left: Left | undefined, right: Right, op: Operation): EvalFunc;
104
+ export declare function binaryOperation<Operation extends BinaryOperation, Inner extends Evaluable, Left extends InnerExpression<Inner>, Right extends Evaluable>(left: Left | null, right: Right, op: Operation): EvalFunc;
95
105
  /**
96
106
  * A map of strings versus binary operations. For example: '*' => operatorMul
97
107
  */
@@ -120,7 +130,7 @@ interface InnerOp<E extends Evaluable> extends InnerExpression<E> {
120
130
  * @param map Map the operations to be applied to the left and right side.
121
131
  * Une correspondance pour les opérations à appliquer aux opérandes.
122
132
  */
123
- export declare function binaryOperations<Inner extends Evaluable, Left extends InnerOp<Inner>, Right extends Evaluable>(left: Left, right: Right, map: BinaryOperationsMap): EvalFunc;
133
+ export declare function binaryOperations<Inner extends Evaluable, Left extends InnerOp<Inner>, Right extends Evaluable>(left: Left | null, right: Right, map: BinaryOperationsMap): EvalFunc;
124
134
  /**
125
135
  * A Unary operation.
126
136
  * @param e The argument.
@@ -167,15 +177,20 @@ export declare function value16LE(pos: PosInfo, e: Expression): AstElement;
167
177
  */
168
178
  export declare function value8(pos: PosInfo, e: Expression): AstElement;
169
179
  /**
170
- * Returns an AST element that represents an 8-bit signed value.
171
- * Retourne un élément de l'AST qui représente une valeur 8 bits signée.
172
- * @param pos The position of the element in the source.
173
- * La position de l'élément dans le code source.
174
- * @param s The sign of the value.
175
- * @param e The 8-bit signed value
176
- * La valeur 8-bit signée.
180
+ * Returns an AST element that represents an 8-bit signed offset for IX or IY.
181
+ * Retourne un élément de l'AST qui représente un décalage 8 bits signé pour IX ou IY.
182
+ * @offset The offset for IX or IY with:
183
+ * pos The position of the element in the source.
184
+ * La position de l'élément dans le code source.
185
+ * s The sign of the value.
186
+ * e The 8-bit signed décalage
187
+ * Le décalage 8-bit signée.
177
188
  */
178
- export declare function svalue8(pos: PosInfo, s: string, e: Expression): AstElement;
189
+ export declare function index(offset: {
190
+ pos: PosInfo;
191
+ s: string;
192
+ d: Expression;
193
+ } | null): AstElement;
179
194
  /**
180
195
  * Returns an AST element that represents an offset for a JR (jump relative) opcode.
181
196
  * Retourne un élément de l'AST qui représente un décalage pour un saut relatif JR.
@@ -243,4 +258,6 @@ export declare function dataWords(_: PosInfo, data0: WordValue, data: InnerWord[
243
258
  * La valeur utilisée pour initialiser le bloc.
244
259
  */
245
260
  export declare function dataBlock(pos0: PosInfo, length: Expression, pos1: PosInfo | undefined, value: Expression | undefined): AstElement;
261
+ export declare function labelValue(pos: PosInfo, name: string): (pc: Address, mustExist: boolean) => number | null;
262
+ export declare function value(nn: number): (pc: Address, mustExist: boolean) => number;
246
263
  export {};
@@ -45,7 +45,7 @@ declare const parseData: ParseDate;
45
45
  * @param filename Filename for the binary.
46
46
  * Nom de fichier pour le binaire.
47
47
  * @param sld Filename for the SLD.
48
- * Nom de fihcier pour le SLD.
48
+ * Nom de fichier pour le SLD.
49
49
  */
50
50
  declare function setOutputName(filename: string, sld?: string): void;
51
51
  /**
@@ -26,7 +26,7 @@ interface Chunk {
26
26
  }
27
27
  /**
28
28
  * Format bytes to display them.
29
- * Formatte des octets pour les afficher.
29
+ * Formate des octets pour les afficher.
30
30
  * @param bytes An array of bytes.
31
31
  * Un tableau d'octets.
32
32
  * @param perLine Number of bytes per line.
@@ -17,39 +17,55 @@
17
17
  * Copyrights: Copyright (C) 2023 Sebastien Andrivet
18
18
  */
19
19
  import { Expression, PosInfo } from "../grammar/z80";
20
+ import { Address, Position } from '../types/Types';
20
21
  /**
21
22
  * Reset the labels.
23
+ * Supprime toutes les étiquettes.
22
24
  */
23
25
  declare function resetLabels(): void;
26
+ declare function resetLabelsRecursion(): void;
24
27
  /**
25
28
  * Add a label.
29
+ * Ajoute une étiquette.
26
30
  * @param pos The position of the label in the source code.
31
+ * La position de l'étiquette dans le code source.
27
32
  * @param name The name of the label.
28
- * @param value The value of the label (if known) or null (if unknown)
33
+ * Le nom de l'étiquette.
34
+ * @param value The value of the label (if known) or null (if unknown).
35
+ * La valeur de l'étiquette (si connue) ou null (si inconnue).
29
36
  */
30
- declare function addLabel(pos: PosInfo, name: string, value: number | null): void;
37
+ declare function addLabel(pos: Position, name: string, value: number | null): void;
31
38
  /**
32
39
  * Add a label and its associated expression.
40
+ * Ajoute une étiquette et son expression associée.
33
41
  * @param _ The position of the label in the source code.
42
+ * La position de l'étiquette dans le code source.
34
43
  * @param name The name of the label.
44
+ * Le nom de l'étiquette.
35
45
  * @param expression The expression that gives that value of the label.
46
+ * L'expression qui donne la valeur de l'étiquette.
36
47
  */
37
48
  declare function addLabelExpression(_: PosInfo, name: string, expression: Expression): void;
38
49
  /**
39
50
  * Get the value associated with a label.
51
+ * Obtient la valeur associée avec une étiquette.
52
+ * @param pc: Current program counter (PC).
40
53
  * @param name The name of the label.
41
- * @param setUsed Set the used flag or not.
54
+ * Le nom de l'étiquette.
55
+ * @param pos Where this label is used.
56
+ * @param setUsed If set, mark the label as used.
57
+ * @param mustExist If set, the value of the label has to be known (not null).
42
58
  * @return The value associated with a label or null if it is unknown.
59
+ * La valeur associée avec l'étiquette ou null si elle est inconnue.
43
60
  */
44
- declare function getLabelValue(name: string, setUsed?: boolean): number | null;
61
+ declare function getLabelValue(pc: Address, name: string, pos: Position, setUsed: boolean, mustExist: boolean): number | null;
45
62
  /**
46
63
  * Is a label used in the program or only declared?
64
+ * Est-ce qu'une étiquette a été utilisée ou seulement déclarée ?
47
65
  * @param name The name of the label.
48
- * @return true if the label is used, false if it is unused or undeclared.
66
+ * Le nom de l'étiquette.
67
+ * @return true if the label is used, false otherwise.
68
+ * true si l'étiquette a été utilisée, false sinon.
49
69
  */
50
70
  declare function isLabelUsed(name: string): boolean | undefined;
51
- /**
52
- * Get the list of labels with an unknown value.
53
- */
54
- declare function getUnknownLabels(): string[];
55
- export { resetLabels, addLabel, addLabelExpression, getLabelValue, isLabelUsed, getUnknownLabels };
71
+ export { resetLabels, resetLabelsRecursion, addLabel, addLabelExpression, getLabelValue, isLabelUsed };
@@ -19,59 +19,87 @@
19
19
  import { byte } from "../types/Types";
20
20
  /**
21
21
  * Compute the binary representation of the r argument.
22
- * @param r The argument of the opcode
22
+ * Calcule la représentation binaire de l'argument r.
23
+ * @param r The argument of the opcode.
24
+ * L'argument du code assembleur.
23
25
  * @param offset The number of bits to shift to the left.
26
+ * Le nombre de bits à décaler vers la gauche.
24
27
  */
25
28
  export declare function r_bits(r: string, offset?: number): byte;
26
29
  /**
27
30
  * Compute the binary representation of the dd argument.
28
- * @param dd The argument of the opcode
31
+ * Calcule la représentation binaire de l'argument dd.
32
+ * @param dd The argument of the opcode.
33
+ * L'argument du code assembleur.
29
34
  * @param offset The number of bits to shift to the left.
35
+ * Le nombre de bits à décaler vers la gauche.
30
36
  */
31
37
  export declare function dd_bits(dd: string, offset?: number): byte;
32
38
  /**
33
39
  * Compute the binary representation of the qq argument.
34
- * @param qq The argument of the opcode
40
+ * Calcule la représentation binaire de l'argument qq.
41
+ * @param qq The argument of the opcode.
42
+ * L'argument du code assembleur.
35
43
  * @param offset The number of bits to shift to the left.
44
+ * Le nombre de bits à décaler vers la gauche.
36
45
  */
37
46
  export declare function qq_bits(qq: string, offset?: number): byte;
38
47
  /**
39
48
  * Compute the binary representation of the ss argument.
40
- * @param ss The argument of the opcode
49
+ * Calcule la représentation binaire de l'argument ss.
50
+ * @param ss The argument of the opcode.
51
+ * L'argument du code assembleur.
41
52
  * @param offset The number of bits to shift to the left.
53
+ * Le nombre de bits à décaler vers la gauche.
42
54
  */
43
55
  export declare function ss_bits(ss: string, offset?: number): byte;
44
56
  /**
45
57
  * Compute the binary representation of the pp argument.
46
- * @param pp The argument of the opcode
58
+ * Calcule la représentation binaire de l'argument pp.
59
+ * @param pp The argument of the opcode.
60
+ * L'argument du code assembleur.
47
61
  * @param offset The number of bits to shift to the left.
62
+ * Le nombre de bits à décaler vers la gauche.
48
63
  */
49
64
  export declare function pp_bits(pp: string, offset?: number): byte;
50
65
  /**
51
66
  * Compute the binary representation of the rr argument.
52
- * @param rr The argument of the opcode
67
+ * Calcule la représentation binaire de l'argument rr.
68
+ * @param rr The argument of the opcode.
69
+ * L'argument du code assembleur.
53
70
  * @param offset The number of bits to shift to the left.
71
+ * Le nombre de bits à décaler vers la gauche.
54
72
  */
55
73
  export declare function rr_bits(rr: string, offset?: number): byte;
56
74
  /**
57
75
  * Compute the binary representation of the cc argument.
58
- * @param cc The argument of the opcode
76
+ * Calcule la représentation binaire de l'argument cc.
77
+ * @param cc The argument of the opcode.
78
+ * L'argument du code assembleur.
59
79
  * @param offset The number of bits to shift to the left.
80
+ * Le nombre de bits à décaler vers la gauche.
60
81
  */
61
82
  export declare function cc_bits(cc: string, offset?: number): byte;
62
83
  /**
63
84
  * Compute the binary representation of the jj argument.
64
- * @param jj The argument of the opcode
85
+ * Calcule la représentation binaire de l'argument jj.
86
+ * @param jj The argument of the opcode.
87
+ * L'argument du code assembleur.
65
88
  */
66
89
  export declare function jj_bits(jj?: string): byte;
67
90
  /**
68
91
  * Compute the binary representation of the p argument.
69
- * @param p The argument of the opcode
92
+ * Calcule la représentation binaire de l'argument p.
93
+ * @param p The argument of the opcode.
94
+ * L'argument du code assembleur.
70
95
  * @param offset The number of bits to shift to the left.
96
+ * Le nombre de bits à décaler vers la gauche.
71
97
  */
72
98
  export declare function p_bits(p: number, offset?: number): byte;
73
99
  /**
74
100
  * Compute the binary representation of the mode argument.
75
- * @param mode The argument of the opcode
101
+ * Calcule la représentation binaire de l'argument mode.
102
+ * @param mode The argument of the opcode.
103
+ * L'argument du code assembleur.
76
104
  */
77
105
  export declare function imode(mode: string): byte;
@@ -19,39 +19,59 @@
19
19
  import { PosInfo } from "./z80";
20
20
  /**
21
21
  * Parse a number.
22
+ * Analyse un nombre.
22
23
  * @param pos Position of the number in the source code.
24
+ * Position du nombre dans le code source.
23
25
  * @param str The characters of the number.
26
+ * Les caractères du nombre.
24
27
  * @param base The base of the number.
28
+ * La base du nombre.
25
29
  * @param nbBytes The number of bytes to represent this number (1 or 2)
30
+ * Le nombre d'octets pour représenter ce nombre (1 ou 2)
26
31
  */
27
32
  export declare function parseNumber(pos: PosInfo, str: string, base: number, nbBytes: number): number;
28
33
  /**
29
34
  * Parse a simple escape, i.e. a backslash followed by a character.
35
+ * Analyse un échappement simple, c.-à-d. une barre oblique inversée suivie d'un caractère.
30
36
  * @param pos Position of the character in the source code.
37
+ * Position du caractère dans le code source.
31
38
  * @param c The character after the backslash.
39
+ * Le caractère après la barre oblique inversée.
32
40
  */
33
41
  export declare function parseSimpleEscape(pos: PosInfo, c: string): number[];
34
42
  /**
35
43
  * Parse an octal value.
44
+ * Analyse une valeur octale.
36
45
  * @param pos Position of the value in the source code.
46
+ * Position de la valeur dans le code source.
37
47
  * @param value The characters representing the value.
48
+ * Les caractères représentant la valeur.
38
49
  */
39
50
  export declare function parseOctalEscape(pos: PosInfo, value: string): number[];
40
51
  /**
41
52
  * Parse a hexadecimal value.
53
+ * Analyse une valeur hexadécimale.
42
54
  * @param pos Position of the value in the source code.
55
+ * Position de la valeur dans le code source.
43
56
  * @param value The characters representing the value.
57
+ * Les caractères représentant la valeur.
44
58
  */
45
59
  export declare function parseHexadecimalEscape(pos: PosInfo, value: string): number[];
46
60
  /**
47
61
  * Parse a ZX81 character written in ASCII.
62
+ * Analyse un caractère ZX81 écrit en ASCII.
48
63
  * @param pos Position of the character in the source code.
64
+ * Position du caractère dans le code source.
49
65
  * @param c The ASCII character.
66
+ * Le caractère ASCII.
50
67
  */
51
- export declare function parseZX81Char(pos: PosInfo, c: string): number;
68
+ export declare function parseZX81Char(pos: PosInfo, c: string): [number];
52
69
  /**
53
70
  * Parse a ZX81 string written in ASCII.
71
+ * Analyse un chaine ZX81 écrit en ASCII.
54
72
  * @param pos Position of the string in the source code.
73
+ * Position de la chaine dans le code source.
55
74
  * @param str The ASCII string.
75
+ * La chaine ASCII.
56
76
  */
57
77
  export declare function parseZX81String(pos: PosInfo, str: string): number[];