@exercism/codemirror-lang-assembly 0.0.0-stage → 1.0.1
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.
- package/CHANGELOG.md +60 -0
- package/LICENSE +21 -0
- package/README.md +329 -2
- package/dist/index.cjs +1938 -0
- package/dist/index.d.cts +595 -0
- package/dist/index.d.ts +595 -0
- package/dist/index.js +1914 -0
- package/package.json +62 -4
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,595 @@
|
|
|
1
|
+
import { LRParser } from '@lezer/lr';
|
|
2
|
+
|
|
3
|
+
declare const parser: LRParser
|
|
4
|
+
|
|
5
|
+
declare const assemblyLanguage = LRLanguage.define({
|
|
6
|
+
name: "assembly",
|
|
7
|
+
parser: parser.configure({
|
|
8
|
+
props: [
|
|
9
|
+
foldNodeProp.add({
|
|
10
|
+
Parens: foldInside,
|
|
11
|
+
Brackets: foldInside,
|
|
12
|
+
Braces: foldInside,
|
|
13
|
+
BlockComment: foldInside
|
|
14
|
+
}),
|
|
15
|
+
styleTags({
|
|
16
|
+
Mnemonic: t.keyword,
|
|
17
|
+
DirectiveName: t.meta,
|
|
18
|
+
MacroName: t.macroName,
|
|
19
|
+
Label: t.definition(t.labelName),
|
|
20
|
+
Register: t.special(t.variableName),
|
|
21
|
+
SizeKeyword: t.typeName,
|
|
22
|
+
Identifier: t.variableName,
|
|
23
|
+
Number: t.number,
|
|
24
|
+
"String RawString": t.string,
|
|
25
|
+
Char: t.character,
|
|
26
|
+
Here: t.atom,
|
|
27
|
+
MacroParameter: t.local(t.variableName),
|
|
28
|
+
ImmediatePrefix: t.operator,
|
|
29
|
+
// The Ctrl-Z a DOS assembler wrote at the end of a file, and
|
|
30
|
+
// whatever somebody left behind it.
|
|
31
|
+
EndMarker: t.comment,
|
|
32
|
+
"LineComment StatementComment": t.lineComment,
|
|
33
|
+
BlockComment: t.blockComment,
|
|
34
|
+
Continuation: t.escape,
|
|
35
|
+
"ArithOp Star Slash Percent": t.arithmeticOperator,
|
|
36
|
+
CompareOp: t.compareOperator,
|
|
37
|
+
AssignOp: t.definitionOperator,
|
|
38
|
+
Equals: t.operator,
|
|
39
|
+
",": t.separator,
|
|
40
|
+
": ? Bang": t.punctuation,
|
|
41
|
+
"( )": t.paren,
|
|
42
|
+
"[ ]": t.squareBracket,
|
|
43
|
+
"{ }": t.brace
|
|
44
|
+
})
|
|
45
|
+
]
|
|
46
|
+
}),
|
|
47
|
+
languageData: {
|
|
48
|
+
// Every assembler in the corpus this was measured against takes a
|
|
49
|
+
// semicolon, and the ones that take something else take it as well.
|
|
50
|
+
commentTokens: { line: ";" },
|
|
51
|
+
closeBrackets: { brackets: ["(", "[", "{", '"', "'"] }
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
/**
|
|
55
|
+
Autocompletion for the assembler's own vocabulary: the directives that
|
|
56
|
+
reserve storage and open sections, the GNU assembler's dot-prefixed set, the
|
|
57
|
+
widths an Intel-syntax operand can carry, and the registers of every
|
|
58
|
+
instruction set the grammar knows. Mnemonics are not proposed, because a
|
|
59
|
+
mnemonic belongs to a processor rather than to assembly.
|
|
60
|
+
*/
|
|
61
|
+
declare const assemblyCompletion = completeFromList([
|
|
62
|
+
...proposals(DIRECTIVES, "keyword"),
|
|
63
|
+
...proposals(DOT_DIRECTIVES, "keyword"),
|
|
64
|
+
...proposals(SIZE_KEYWORDS, "type"),
|
|
65
|
+
...proposals(REGISTERS, "variable")
|
|
66
|
+
]);
|
|
67
|
+
/**
|
|
68
|
+
Assembly language support, with completion for directives, operand widths
|
|
69
|
+
and registers.
|
|
70
|
+
*/
|
|
71
|
+
declare function assembly() {
|
|
72
|
+
return new LanguageSupport(assemblyLanguage, [
|
|
73
|
+
assemblyLanguage.data.of({ autocomplete: assemblyCompletion })
|
|
74
|
+
]);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* The names declared in the file. A label, an `equ` constant, a `%define`
|
|
79
|
+
* and a macro are global. A local label such as `.loop` belongs to the global
|
|
80
|
+
* label before it, as NASM reads it. A `%%end` label belongs to the macro it
|
|
81
|
+
* is written in. A field such as `.size` inside `struc item` is offered as
|
|
82
|
+
* `item.size`, and the structure also gives `item_size`.
|
|
83
|
+
*/
|
|
84
|
+
declare function declaredNames(tree, doc, style = "nasm") {
|
|
85
|
+
const cache = caches[style];
|
|
86
|
+
const cached = cache.get(tree);
|
|
87
|
+
if (cached)
|
|
88
|
+
return cached;
|
|
89
|
+
const names = [];
|
|
90
|
+
const end = doc.length;
|
|
91
|
+
let ownerFrom = 0;
|
|
92
|
+
let pendingLocals = [];
|
|
93
|
+
let macro = null;
|
|
94
|
+
let struc = null;
|
|
95
|
+
const closeOwner = (at) => {
|
|
96
|
+
for (const local of pendingLocals)
|
|
97
|
+
local.to = at;
|
|
98
|
+
pendingLocals = [];
|
|
99
|
+
};
|
|
100
|
+
for (let node = tree.topNode.firstChild; node; node = node.nextSibling) {
|
|
101
|
+
if (node.name == "Label") {
|
|
102
|
+
const name = text(doc, node).replace(/:+$/, "");
|
|
103
|
+
const next = node.nextSibling;
|
|
104
|
+
const nextWord = next && sameLine(doc, node, next) ? statementWord(doc, next) : "";
|
|
105
|
+
const type = CONSTANT.test(nextWord) || (next === null || next === void 0 ? void 0 : next.name) == "Assignment"
|
|
106
|
+
? "constant"
|
|
107
|
+
: DATA.test(nextWord) || ALIAS.test(nextWord) ? "variable" : null;
|
|
108
|
+
if (style == "gas") {
|
|
109
|
+
// gas labels are global, and a numeric one is kept as its digits for
|
|
110
|
+
// namesInScope to turn into `1b` or `1f`.
|
|
111
|
+
names.push({ name, type: type !== null && type !== void 0 ? type : (/^\d+$/.test(name) ? "label" : "function"), at: node.from, from: 0, to: end });
|
|
112
|
+
}
|
|
113
|
+
else if (struc && name.startsWith(".")) {
|
|
114
|
+
names.push({ name: struc + name, type: "constant", at: node.from, from: 0, to: end });
|
|
115
|
+
}
|
|
116
|
+
else if (name.startsWith("%%")) {
|
|
117
|
+
if (macro) {
|
|
118
|
+
const label = { name, type: "label", at: node.from, from: macro.from, to: end };
|
|
119
|
+
macro.labels.push(label);
|
|
120
|
+
names.push(label);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
else if (isLocalLabel(name)) {
|
|
124
|
+
const local = { name, type: type !== null && type !== void 0 ? type : "label", at: node.from, from: ownerFrom, to: end };
|
|
125
|
+
pendingLocals.push(local);
|
|
126
|
+
names.push(local);
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
if (!type) {
|
|
130
|
+
closeOwner(node.from);
|
|
131
|
+
ownerFrom = node.from;
|
|
132
|
+
}
|
|
133
|
+
names.push({ name, type: type !== null && type !== void 0 ? type : "function", at: node.from, from: 0, to: end });
|
|
134
|
+
}
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
if (node.name != "Preprocessor" && node.name != "Directive" && node.name != "Instruction")
|
|
138
|
+
continue;
|
|
139
|
+
const word = statementWord(doc, node);
|
|
140
|
+
const named = firstOperandWord(doc, node);
|
|
141
|
+
if (DEFINE.test(word) && named) {
|
|
142
|
+
names.push({ name: text(doc, named), type: "constant", at: named.from, from: 0, to: end });
|
|
143
|
+
}
|
|
144
|
+
else if (MACRO_OPEN.test(word) && named) {
|
|
145
|
+
names.push({ name: text(doc, named), type: "macro", at: named.from, from: 0, to: end });
|
|
146
|
+
macro = { from: node.from, labels: [], parameters: [] };
|
|
147
|
+
if (word == ".macro") {
|
|
148
|
+
for (const parameter of macroParameters(doc, node, named)) {
|
|
149
|
+
const name = { name: parameter, type: "variable", at: node.from, from: node.from, to: end, macroParameter: true };
|
|
150
|
+
macro.parameters.push(name);
|
|
151
|
+
names.push(name);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
else if (MACRO_CLOSE.test(word) && macro) {
|
|
156
|
+
for (const label of [...macro.labels, ...macro.parameters])
|
|
157
|
+
label.to = node.to;
|
|
158
|
+
macro = null;
|
|
159
|
+
}
|
|
160
|
+
else if (word == "struc" && named) {
|
|
161
|
+
struc = text(doc, named);
|
|
162
|
+
names.push({ name: struc, type: "type", at: named.from, from: 0, to: end });
|
|
163
|
+
names.push({ name: struc + "_size", type: "constant", at: named.from, from: 0, to: end });
|
|
164
|
+
}
|
|
165
|
+
else if (word == "endstruc") {
|
|
166
|
+
struc = null;
|
|
167
|
+
}
|
|
168
|
+
else if ((word == "extern" || word == "extrn" || word == ".extern") && node.getChild("Operands")) {
|
|
169
|
+
for (const operand of node.getChild("Operands").getChildren("Operand")) {
|
|
170
|
+
const first = operand.firstChild;
|
|
171
|
+
if ((first === null || first === void 0 ? void 0 : first.name) == "Identifier") {
|
|
172
|
+
names.push({ name: text(doc, first), type: "function", at: first.from, from: 0, to: end });
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
cache.set(tree, names);
|
|
178
|
+
return names;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* The names that can be used at `pos`, with the newest declaration of each.
|
|
182
|
+
* In the gas style, a numeric label `1:` is offered as `1b` below it and as
|
|
183
|
+
* `1f` above it.
|
|
184
|
+
*/
|
|
185
|
+
declare function namesInScope(tree, doc, pos, style = "nasm") {
|
|
186
|
+
const seen = new Map();
|
|
187
|
+
for (const declared of declaredNames(tree, doc, style)) {
|
|
188
|
+
if (pos < declared.from || pos > declared.to)
|
|
189
|
+
continue;
|
|
190
|
+
let name = declared;
|
|
191
|
+
if (style == "gas" && /^\d+$/.test(declared.name)) {
|
|
192
|
+
if (doc.lineAt(declared.at).number == doc.lineAt(pos).number)
|
|
193
|
+
continue;
|
|
194
|
+
name = Object.assign(Object.assign({}, declared), { name: declared.name + (declared.at < pos ? "b" : "f") });
|
|
195
|
+
}
|
|
196
|
+
if (!seen.has(name.name))
|
|
197
|
+
seen.set(name.name, name);
|
|
198
|
+
}
|
|
199
|
+
return [...seen.values()];
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* A completion source for one instruction set. Where a statement starts, it
|
|
204
|
+
* offers the mnemonics, directives, macros declared in the file and snippets.
|
|
205
|
+
* After `%` it offers the preprocessor words. In an operand it offers the
|
|
206
|
+
* registers, size keywords, and the labels and constants in scope. Local labels
|
|
207
|
+
* such as `.loop` are offered only after the global label they belong to.
|
|
208
|
+
* Nothing is offered in comments and strings, or where a new name is being
|
|
209
|
+
* written.
|
|
210
|
+
*/
|
|
211
|
+
declare function assemblyCompletionSource(vocabulary) {
|
|
212
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
213
|
+
const statement = [
|
|
214
|
+
...options(vocabulary.mnemonics, "keyword"),
|
|
215
|
+
...options(vocabulary.directives, "keyword"),
|
|
216
|
+
...((_a = vocabulary.snippets) !== null && _a !== void 0 ? _a : [])
|
|
217
|
+
];
|
|
218
|
+
const mnemonics = options(vocabulary.mnemonics, "keyword");
|
|
219
|
+
const preprocessor = options((_b = vocabulary.preprocessor) !== null && _b !== void 0 ? _b : [], "keyword");
|
|
220
|
+
const operand = [
|
|
221
|
+
...options(vocabulary.registers, "variable"),
|
|
222
|
+
...options((_c = vocabulary.sizeKeywords) !== null && _c !== void 0 ? _c : [], "type"),
|
|
223
|
+
...options((_d = vocabulary.operandDirectives) !== null && _d !== void 0 ? _d : [], "keyword")
|
|
224
|
+
];
|
|
225
|
+
const sections = options((_e = vocabulary.sections) !== null && _e !== void 0 ? _e : [], "namespace");
|
|
226
|
+
const relocations = options((_f = vocabulary.relocations) !== null && _f !== void 0 ? _f : [], "type");
|
|
227
|
+
const style = (_g = vocabulary.labels) !== null && _g !== void 0 ? _g : "nasm";
|
|
228
|
+
const prefixes = [...((_h = vocabulary.prefixes) !== null && _h !== void 0 ? _h : [])];
|
|
229
|
+
const afterPrefix = prefixes.length
|
|
230
|
+
? new RegExp(`^\\s*((%%|\\.)?[\\w$?@.]+:\\s*)*(${prefixes.join("|")})\\s+$`, "i")
|
|
231
|
+
: null;
|
|
232
|
+
return (context) => {
|
|
233
|
+
const { state, pos } = context;
|
|
234
|
+
const tree = syntaxTree(state);
|
|
235
|
+
const inner = tree.resolveInner(pos, -1);
|
|
236
|
+
for (let node = inner; node; node = node.parent) {
|
|
237
|
+
if (DONT_COMPLETE_IN.has(node.name))
|
|
238
|
+
return null;
|
|
239
|
+
}
|
|
240
|
+
const word = context.matchBefore(WORD);
|
|
241
|
+
if (!word || (word.from == word.to && !context.explicit))
|
|
242
|
+
return null;
|
|
243
|
+
const line = state.doc.lineAt(pos);
|
|
244
|
+
const before = line.text.slice(0, word.from - line.from);
|
|
245
|
+
if (NAMES_SOMETHING.test(before))
|
|
246
|
+
return null;
|
|
247
|
+
const result = (list) => ({
|
|
248
|
+
from: word.from,
|
|
249
|
+
options: list,
|
|
250
|
+
validFor: /^[%$.\w?@]*$/
|
|
251
|
+
});
|
|
252
|
+
if (/(^|\s)\.?(section|segment)\s+$/i.test(before))
|
|
253
|
+
return result(sections);
|
|
254
|
+
if (afterPrefix === null || afterPrefix === void 0 ? void 0 : afterPrefix.test(before))
|
|
255
|
+
return result(mnemonics);
|
|
256
|
+
if (relocations.length && /(^|[\s,#]):$/.test(before))
|
|
257
|
+
return result(relocations);
|
|
258
|
+
const names = namesInScope(tree, state.doc, pos, style);
|
|
259
|
+
const parameters = names
|
|
260
|
+
.filter((name) => name.macroParameter)
|
|
261
|
+
.map((name) => ({ label: name.name, type: name.type }));
|
|
262
|
+
// A gas macro writes its parameters as `\name`.
|
|
263
|
+
if (before.endsWith("\\"))
|
|
264
|
+
return result(parameters);
|
|
265
|
+
if (STATEMENT_START.test(before)) {
|
|
266
|
+
if (word.text.startsWith("%") && !word.text.startsWith("%%"))
|
|
267
|
+
return result(preprocessor);
|
|
268
|
+
const macros = names
|
|
269
|
+
.filter((name) => name.type == "macro")
|
|
270
|
+
.map((name) => ({ label: name.name, type: "function" }));
|
|
271
|
+
return result([...statement, ...macros]);
|
|
272
|
+
}
|
|
273
|
+
const declared = names
|
|
274
|
+
.filter((name) => name.type != "macro" && !name.macroParameter)
|
|
275
|
+
.map((name) => ({ label: name.name, type: name.type }));
|
|
276
|
+
// MARS writes a macro's parameters as `%name`.
|
|
277
|
+
if (word.text.startsWith("%") && parameters.some((name) => name.label.startsWith("%"))) {
|
|
278
|
+
return result(parameters.filter((name) => name.label.startsWith("%")));
|
|
279
|
+
}
|
|
280
|
+
// An immediate such as `#SIZE` can only be a number or a constant.
|
|
281
|
+
if (before.endsWith("#"))
|
|
282
|
+
return result(declared.filter((name) => name.type == "constant"));
|
|
283
|
+
return result([...operand, ...declared]);
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/** Folding and indentation for the blocks and labels of one assembler. */
|
|
288
|
+
declare function assemblyLayout(options) {
|
|
289
|
+
return [foldStatements(options), indentStatements(options)];
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
The assembly language with the `x86` dialect, which reads NASM as written
|
|
294
|
+
for x86-64.
|
|
295
|
+
*/
|
|
296
|
+
declare const x86_64AssemblyLanguage = assemblyLanguage.configure({ dialect: "x86" }, "x86-64-assembly");
|
|
297
|
+
/**
|
|
298
|
+
Snippets for the common shapes of an x86-64 NASM program.
|
|
299
|
+
*/
|
|
300
|
+
declare const snippets$2 = [
|
|
301
|
+
snip("section .text\nglobal ${name}\n${name}:\n\t${}\n\tret", {
|
|
302
|
+
label: "section .text",
|
|
303
|
+
detail: "with a global function",
|
|
304
|
+
type: "keyword"
|
|
305
|
+
}),
|
|
306
|
+
snip("section .data\n${name}: db ${\"text\"}, 0\n${name}_len: equ $ - ${name}", {
|
|
307
|
+
label: "section .data",
|
|
308
|
+
detail: "with a string",
|
|
309
|
+
type: "keyword"
|
|
310
|
+
}),
|
|
311
|
+
snip("section .bss\n${name}: resb ${64}", {
|
|
312
|
+
label: "section .bss",
|
|
313
|
+
detail: "with a buffer",
|
|
314
|
+
type: "keyword"
|
|
315
|
+
}),
|
|
316
|
+
snip("${name}:\n\tpush rbp\n\tmov rbp, rsp\n\t${}\n\tmov rsp, rbp\n\tpop rbp\n\tret", {
|
|
317
|
+
label: "function",
|
|
318
|
+
detail: "with prologue and epilogue",
|
|
319
|
+
type: "keyword"
|
|
320
|
+
}),
|
|
321
|
+
snip("\tmov rcx, ${count}\n.${loop}:\n\t${}\n\tdec rcx\n\tjnz .${loop}", {
|
|
322
|
+
label: "loop",
|
|
323
|
+
detail: "counting down rcx",
|
|
324
|
+
type: "keyword"
|
|
325
|
+
}),
|
|
326
|
+
snip("\tcmp ${rax}, ${0}\n\tj${e} .${label}", {
|
|
327
|
+
label: "cmp",
|
|
328
|
+
detail: "and jump",
|
|
329
|
+
type: "keyword"
|
|
330
|
+
}),
|
|
331
|
+
snip("%macro ${name} ${1}\n\t${}\n%endmacro", {
|
|
332
|
+
label: "%macro",
|
|
333
|
+
detail: "block",
|
|
334
|
+
type: "keyword"
|
|
335
|
+
}),
|
|
336
|
+
snip("struc ${name}\n\t.${field}: resq 1\nendstruc", {
|
|
337
|
+
label: "struc",
|
|
338
|
+
detail: "block",
|
|
339
|
+
type: "keyword"
|
|
340
|
+
})
|
|
341
|
+
];
|
|
342
|
+
/**
|
|
343
|
+
Completion for x86-64 NASM. Where a statement starts it offers the x86-64
|
|
344
|
+
mnemonics, NASM's directives, the macros declared in the file and the
|
|
345
|
+
snippets. In an operand it offers the registers, the size keywords and the
|
|
346
|
+
labels and constants declared in the file.
|
|
347
|
+
*/
|
|
348
|
+
declare const x86_64Completion = assemblyCompletionSource({
|
|
349
|
+
mnemonics: MNEMONICS,
|
|
350
|
+
directives: DIRECTIVES,
|
|
351
|
+
preprocessor: PREPROCESSOR,
|
|
352
|
+
registers: REGISTERS,
|
|
353
|
+
sizeKeywords: SIZE_KEYWORDS,
|
|
354
|
+
operandDirectives: [...DATA_DIRECTIVES, "times"],
|
|
355
|
+
sections: SECTIONS,
|
|
356
|
+
prefixes: PREFIXES,
|
|
357
|
+
snippets
|
|
358
|
+
});
|
|
359
|
+
/**
|
|
360
|
+
Folding and indentation for NASM's blocks, and for a function's body under
|
|
361
|
+
its label.
|
|
362
|
+
*/
|
|
363
|
+
declare const x86_64Layout = assemblyLayout({
|
|
364
|
+
blocks: [
|
|
365
|
+
{ open: /^%i?macro$/, close: /^%endmacro$/ },
|
|
366
|
+
{ open: /^%rep$/, close: /^%endrep$/ },
|
|
367
|
+
{ open: /^%if/, close: /^%endif$/ },
|
|
368
|
+
{ open: /^struc$/, close: /^endstruc$/ },
|
|
369
|
+
{ open: /^istruc$/, close: /^iend$/ }
|
|
370
|
+
],
|
|
371
|
+
sectionBreaks: /^(section|segment|global|extern|default|bits)$/
|
|
372
|
+
});
|
|
373
|
+
/**
|
|
374
|
+
x86-64 assembly support for NASM, as used on Exercism's x86-64 Assembly
|
|
375
|
+
track.
|
|
376
|
+
*/
|
|
377
|
+
declare function x86_64Assembly() {
|
|
378
|
+
return new LanguageSupport(x86_64AssemblyLanguage, [
|
|
379
|
+
x86_64AssemblyLanguage.data.of({
|
|
380
|
+
autocomplete: x86_64Completion,
|
|
381
|
+
// Typing the colon of a label or the end of a block moves it back to
|
|
382
|
+
// the margin of its block.
|
|
383
|
+
indentOnInput: /^\s*(%end\w*|%else|%elif\w*|endstruc|iend|(%%|\.)?[\w$?@.]+:)$/i
|
|
384
|
+
}),
|
|
385
|
+
x86_64Layout
|
|
386
|
+
]);
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
The assembly language with the `arm64` dialect, which reads the GNU
|
|
391
|
+
assembler as written for AArch64.
|
|
392
|
+
*/
|
|
393
|
+
declare const arm64AssemblyLanguage = assemblyLanguage.configure({ dialect: "arm64" }, "arm64-assembly");
|
|
394
|
+
/**
|
|
395
|
+
Snippets for the common shapes of an AArch64 program.
|
|
396
|
+
*/
|
|
397
|
+
declare const snippets$1 = [
|
|
398
|
+
snip(".text\n.globl ${name}\n${name}:\n\t${}\n\tret", {
|
|
399
|
+
label: ".text",
|
|
400
|
+
detail: "with a global function",
|
|
401
|
+
type: "keyword"
|
|
402
|
+
}),
|
|
403
|
+
snip(".data\n${name}: .asciz ${\"text\"}\n.equ ${name}_len, . - ${name}", {
|
|
404
|
+
label: ".data",
|
|
405
|
+
detail: "with a string",
|
|
406
|
+
type: "keyword"
|
|
407
|
+
}),
|
|
408
|
+
snip(".bss\n${name}: .skip ${64}", {
|
|
409
|
+
label: ".bss",
|
|
410
|
+
detail: "with a buffer",
|
|
411
|
+
type: "keyword"
|
|
412
|
+
}),
|
|
413
|
+
snip("${name}:\n\tstp x29, x30, [sp, #-16]!\n\tmov x29, sp\n\t${}\n\tldp x29, x30, [sp], #16\n\tret", {
|
|
414
|
+
label: "function",
|
|
415
|
+
detail: "with prologue and epilogue",
|
|
416
|
+
type: "keyword"
|
|
417
|
+
}),
|
|
418
|
+
snip("\tmov x9, #${count}\n1:\n\t${}\n\tsubs x9, x9, #1\n\tb.ne 1b", {
|
|
419
|
+
label: "loop",
|
|
420
|
+
detail: "counting down x9",
|
|
421
|
+
type: "keyword"
|
|
422
|
+
}),
|
|
423
|
+
snip("\tcmp ${x0}, #${0}\n\tb.${eq} ${label}", {
|
|
424
|
+
label: "cmp",
|
|
425
|
+
detail: "and branch",
|
|
426
|
+
type: "keyword"
|
|
427
|
+
}),
|
|
428
|
+
snip("\tcbz ${x0}, ${label}", {
|
|
429
|
+
label: "cbz",
|
|
430
|
+
detail: "branch if zero",
|
|
431
|
+
type: "keyword"
|
|
432
|
+
}),
|
|
433
|
+
snip("\tadrp ${x0}, ${label}\n\tadd ${x0}, ${x0}, :lo12:${label}", {
|
|
434
|
+
label: "adrp",
|
|
435
|
+
detail: "load an address",
|
|
436
|
+
type: "keyword"
|
|
437
|
+
}),
|
|
438
|
+
snip(".macro ${name} ${arg}\n\t${}\n.endm", {
|
|
439
|
+
label: ".macro",
|
|
440
|
+
detail: "block",
|
|
441
|
+
type: "keyword"
|
|
442
|
+
})
|
|
443
|
+
];
|
|
444
|
+
/**
|
|
445
|
+
Completion for AArch64 in GNU assembler syntax. Where a statement starts it
|
|
446
|
+
offers the AArch64 mnemonics, the GNU assembler's directives, the macros
|
|
447
|
+
declared in the file and the snippets. In an operand it offers the
|
|
448
|
+
registers, shifts, condition codes, and the labels, `.equ` constants and
|
|
449
|
+
`.req` aliases declared in the file. A numeric label `1:` is offered as `1b`
|
|
450
|
+
below it and `1f` above it.
|
|
451
|
+
*/
|
|
452
|
+
declare const arm64Completion = assemblyCompletionSource({
|
|
453
|
+
mnemonics: MNEMONICS,
|
|
454
|
+
directives: DIRECTIVES,
|
|
455
|
+
registers: REGISTERS,
|
|
456
|
+
sizeKeywords: [...SHIFTS, ...CONDITIONS],
|
|
457
|
+
sections: SECTIONS,
|
|
458
|
+
relocations: RELOCATIONS,
|
|
459
|
+
snippets,
|
|
460
|
+
labels: "gas"
|
|
461
|
+
});
|
|
462
|
+
/**
|
|
463
|
+
Folding and indentation for the GNU assembler's blocks, and for a
|
|
464
|
+
function's body under its label.
|
|
465
|
+
*/
|
|
466
|
+
declare const arm64Layout = assemblyLayout({
|
|
467
|
+
blocks: [
|
|
468
|
+
{ open: /^\.macro$/, close: /^\.endm$/ },
|
|
469
|
+
{ open: /^\.(rept|irpc?)$/, close: /^\.endr$/ },
|
|
470
|
+
{ open: /^\.if/, close: /^\.endif$/ }
|
|
471
|
+
],
|
|
472
|
+
sectionBreaks: /^\.(section|text|data|bss|pushsection|popsection|globl|global|extern|type|size|equ|set)$/,
|
|
473
|
+
labels: "gas",
|
|
474
|
+
lineComments: ["//", "/*", ";"]
|
|
475
|
+
});
|
|
476
|
+
/**
|
|
477
|
+
AArch64 assembly support for the GNU assembler, as used on Exercism's
|
|
478
|
+
ARM64 Assembly track.
|
|
479
|
+
*/
|
|
480
|
+
declare function arm64Assembly() {
|
|
481
|
+
return new LanguageSupport(arm64AssemblyLanguage, [
|
|
482
|
+
arm64AssemblyLanguage.data.of({
|
|
483
|
+
autocomplete: arm64Completion,
|
|
484
|
+
commentTokens: { line: "//", block: { open: "/*", close: "*/" } },
|
|
485
|
+
// Typing the colon of a label or the end of a block moves it back to
|
|
486
|
+
// the margin of its block.
|
|
487
|
+
indentOnInput: /^\s*(\.endm|\.endr|\.endif|[\w$.\\@]+:)$/i
|
|
488
|
+
}),
|
|
489
|
+
arm64Layout
|
|
490
|
+
]);
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
The assembly language with the `mips` dialect, which reads MIPS32 as the
|
|
495
|
+
MARS simulator assembles it.
|
|
496
|
+
*/
|
|
497
|
+
declare const mipsAssemblyLanguage = assemblyLanguage.configure({ dialect: "mips" }, "mips-assembly");
|
|
498
|
+
/**
|
|
499
|
+
Snippets for the common shapes of a MIPS program.
|
|
500
|
+
*/
|
|
501
|
+
declare const snippets = [
|
|
502
|
+
snip(".text\n.globl ${name}\n${name}:\n\t${}\n\tjr $ra", {
|
|
503
|
+
label: ".text",
|
|
504
|
+
detail: "with a global function",
|
|
505
|
+
type: "keyword"
|
|
506
|
+
}),
|
|
507
|
+
snip(".data\n${name}: .asciiz ${\"text\"}", {
|
|
508
|
+
label: ".data",
|
|
509
|
+
detail: "with a string",
|
|
510
|
+
type: "keyword"
|
|
511
|
+
}),
|
|
512
|
+
snip("${name}:\n\taddi $sp, $sp, -8\n\tsw $ra, 4($sp)\n\tsw $s0, 0($sp)\n\t${}\n" +
|
|
513
|
+
"\tlw $s0, 0($sp)\n\tlw $ra, 4($sp)\n\taddi $sp, $sp, 8\n\tjr $ra", {
|
|
514
|
+
label: "function",
|
|
515
|
+
detail: "with a stack frame",
|
|
516
|
+
type: "keyword"
|
|
517
|
+
}),
|
|
518
|
+
snip("\tli $t0, 0\n${loop}:\n\tbge $t0, ${count}, ${done}\n\t${}\n\taddi $t0, $t0, 1\n\tj ${loop}\n${done}:", {
|
|
519
|
+
label: "loop",
|
|
520
|
+
detail: "counting up $t0",
|
|
521
|
+
type: "keyword"
|
|
522
|
+
}),
|
|
523
|
+
snip("\tbne ${$t0}, ${$t1}, ${else}\n\t${}\n\tj ${done}\n${else}:\n\t\n${done}:", {
|
|
524
|
+
label: "if",
|
|
525
|
+
detail: "branch on equal and else",
|
|
526
|
+
type: "keyword"
|
|
527
|
+
}),
|
|
528
|
+
snip("\tli $v0, 4\n\tla $a0, ${msg}\n\tsyscall", {
|
|
529
|
+
label: "print_string",
|
|
530
|
+
detail: "syscall 4",
|
|
531
|
+
type: "keyword"
|
|
532
|
+
}),
|
|
533
|
+
snip("\tli $v0, 1\n\tmove $a0, ${$t0}\n\tsyscall", {
|
|
534
|
+
label: "print_int",
|
|
535
|
+
detail: "syscall 1",
|
|
536
|
+
type: "keyword"
|
|
537
|
+
}),
|
|
538
|
+
snip("\tli $v0, 5\n\tsyscall\n\tmove ${$t0}, $v0", {
|
|
539
|
+
label: "read_int",
|
|
540
|
+
detail: "syscall 5",
|
|
541
|
+
type: "keyword"
|
|
542
|
+
}),
|
|
543
|
+
snip("\tli $v0, 10\n\tsyscall", {
|
|
544
|
+
label: "exit",
|
|
545
|
+
detail: "syscall 10",
|
|
546
|
+
type: "keyword"
|
|
547
|
+
}),
|
|
548
|
+
snip(".macro ${name}(%${arg})\n\t${}\n.end_macro", {
|
|
549
|
+
label: ".macro",
|
|
550
|
+
detail: "block",
|
|
551
|
+
type: "keyword"
|
|
552
|
+
})
|
|
553
|
+
];
|
|
554
|
+
/**
|
|
555
|
+
Completion for MIPS32 as MARS assembles it. Where a statement starts it
|
|
556
|
+
offers the instructions and pseudo-instructions, the directives, the
|
|
557
|
+
macros declared in the file and the snippets. In an operand it offers the
|
|
558
|
+
registers, and the labels and `.eqv` constants declared in the file. After
|
|
559
|
+
`%` inside a macro, it offers the macro's parameters.
|
|
560
|
+
*/
|
|
561
|
+
declare const mipsCompletion = assemblyCompletionSource({
|
|
562
|
+
mnemonics: MNEMONICS,
|
|
563
|
+
directives: DIRECTIVES,
|
|
564
|
+
registers: WRITTEN_REGISTERS,
|
|
565
|
+
snippets,
|
|
566
|
+
labels: "gas"
|
|
567
|
+
});
|
|
568
|
+
/**
|
|
569
|
+
Folding and indentation for MARS macros, and for a function's body under
|
|
570
|
+
its label.
|
|
571
|
+
*/
|
|
572
|
+
declare const mipsLayout = assemblyLayout({
|
|
573
|
+
blocks: [{ open: /^\.macro$/, close: /^\.end_macro$/ }],
|
|
574
|
+
sectionBreaks: /^\.(text|data|ktext|kdata|globl|extern|eqv|include)$/,
|
|
575
|
+
labels: "gas",
|
|
576
|
+
lineComments: ["#"]
|
|
577
|
+
});
|
|
578
|
+
/**
|
|
579
|
+
MIPS32 assembly support for MARS, as used on Exercism's MIPS Assembly
|
|
580
|
+
track.
|
|
581
|
+
*/
|
|
582
|
+
declare function mipsAssembly() {
|
|
583
|
+
return new LanguageSupport(mipsAssemblyLanguage, [
|
|
584
|
+
mipsAssemblyLanguage.data.of({
|
|
585
|
+
autocomplete: mipsCompletion,
|
|
586
|
+
commentTokens: { line: "#" },
|
|
587
|
+
// Typing the colon of a label or the end of a macro moves it back to the
|
|
588
|
+
// margin of its block.
|
|
589
|
+
indentOnInput: /^\s*(\.end_macro|[\w$.]+:)$/i
|
|
590
|
+
}),
|
|
591
|
+
mipsLayout
|
|
592
|
+
]);
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
export { arm64Assembly, arm64AssemblyLanguage, arm64Completion, arm64Layout, snippets$1 as arm64Snippets, assembly, assemblyCompletion, assemblyCompletionSource, assemblyLanguage, assemblyLayout, declaredNames, mipsAssembly, mipsAssemblyLanguage, mipsCompletion, mipsLayout, snippets as mipsSnippets, namesInScope, parser, x86_64Assembly, x86_64AssemblyLanguage, x86_64Completion, x86_64Layout, snippets$2 as x86_64Snippets };
|