@exercism/codemirror-lang-assembly 1.0.0 → 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.
Files changed (3) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/README.md +126 -129
  3. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 1.0.1
2
+
3
+ The README is restructured. This release is the first published from GitHub Actions, with npm provenance.
4
+
1
5
  ## 1.0.0
2
6
 
3
7
  This is Exercism's first release of the package, published as
package/README.md CHANGED
@@ -1,57 +1,76 @@
1
1
  # @exercism/codemirror-lang-assembly [![NPM version](https://img.shields.io/npm/v/@exercism/codemirror-lang-assembly.svg)](https://www.npmjs.org/package/@exercism/codemirror-lang-assembly)
2
2
 
3
- ## This fork
3
+ [ [**CHANGELOG**](CHANGELOG.md) ]
4
4
 
5
- This is Exercism's fork of
6
- [`@codincod/codemirror-lang-assembly`](https://codeberg.org/reeven/codemirror-lang-assembly)
7
- by CodinCod, released under the MIT license. Exercism uses it in the x86-64
8
- Assembly, ARM64 Assembly and MIPS Assembly editors on [exercism.org](https://exercism.org). Our changes are on
9
- the `main` branch, and are published as `@exercism/codemirror-lang-assembly`.
5
+ This package implements assembly language support for the
6
+ [CodeMirror](https://codemirror.net/) code editor, using a
7
+ [Lezer](https://lezer.codemirror.net/) grammar written for this package.
8
+ Exercism uses it in the x86-64 Assembly, ARM64 Assembly and MIPS Assembly
9
+ editors on [exercism.org](https://exercism.org).
10
10
 
11
- The shared grammar still reads every assembler. The fork adds dialects to it.
12
- A dialect gives the tokenizer one instruction set's registers and directives
13
- in place of the shared lists. The first dialect is `x86`, which reads NASM as
14
- written for x86-64:
11
+ It is not written for one assembler. It reads 8080, Z80, NASM, FASM, MASM, the
12
+ GNU assembler in both its syntaxes, 68000, ARM and AArch64, 6502, MIPS, RISC-V,
13
+ PDP-8 and the IBM 360 assemblers, because it is written for the shape all of
14
+ them share rather than the vocabulary none of them do.
15
15
 
16
- - `x` and `a` are names, because x86 has no registers with those names.
17
- - `.loop` is always a local label, and `loop .zero` is an instruction.
18
- - `mov qword [x], 1` is an instruction. The shared grammar also reads this
19
- correctly.
20
- - `%1` is a macro parameter (`MacroParameter`), and `%%done:` is a label.
21
- - `rep movsb` and `lock xadd` are one mnemonic each.
22
- - `db` after `times` or `at` is a directive.
16
+ CodeMirror 6 has never shipped assembly, and no Lezer grammar for it existed
17
+ anywhere before this one. What a CodeMirror 6 editor could offer until now was
18
+ the CodeMirror 5 stream mode for the GNU assembler, which knows AT&T syntax and
19
+ nothing else.
23
20
 
24
- The second dialect is `arm64`, which reads the GNU assembler as written for
25
- AArch64:
21
+ This code is released under an [MIT license](LICENSE).
26
22
 
27
- - The registers are `x0` to `x30`, `w0` to `w30`, `sp`, `xzr`, `lr`, the
28
- floating point and vector registers, and the SVE registers. A vector
29
- register keeps its arrangement, so `v0.16b` is one register. `a` and `x` are
30
- names.
31
- - Every directive starts with a dot, and `.loop` without a colon is a label.
32
- - `count .req x19` names `count`.
33
- - `lsl`, `uxtw` and the relocations in `:lo12:msg` are operand keywords.
34
- - A condition code such as `eq` is a keyword when it ends the line, as in
35
- `csel x0, x1, x2, eq`. Anywhere else it is a name, so `hi` can still be an
36
- alias in `ldr x0, [hi]`.
37
- - `1b` and `1f` refer to the numeric label `1:`.
23
+ ## Install
38
24
 
39
- The third dialect is `mips`, which reads MIPS32 as MARS assembles it. MARS
40
- is the simulator that runs the MIPS track's tests.
25
+ ```
26
+ npm install @exercism/codemirror-lang-assembly
27
+ ```
41
28
 
42
- - Every register has a `$` in front: `$t0`, `$a0`, `$zero`, `$31` and
43
- `$f12`. `$a0` is a register, never a hexadecimal number, and a word without
44
- a `$`, such as `sp`, is a name.
45
- - `#` always opens a comment, so `#note` with no space after it is one too.
46
- - `%count` is a macro parameter, as in `.macro incr(%count)`, and
47
- `.end_macro` closes the macro.
29
+ ## Usage
48
30
 
49
- In the shared grammar and every dialect, `#:lo12:msg`, `#~32` and a gas
50
- macro's `#\offset` are immediates, and `.copy_\name:` is one label.
31
+ ```javascript
32
+ import {EditorView, basicSetup} from "codemirror"
33
+ import {assembly} from "@exercism/codemirror-lang-assembly"
34
+
35
+ const view = new EditorView({
36
+ parent: document.body,
37
+ doc: ` global main
38
+ section .text
39
+ main:
40
+ push rbp
41
+ mov rbp, rsp
42
+ xor eax, eax
43
+ lea rdi, [fmt]
44
+ call printf@PLT ; say it
45
+ leave
46
+ ret
47
+
48
+ section .data
49
+ fmt db "Hello, World!", 10, 0
50
+ `,
51
+ extensions: [basicSetup, assembly()]
52
+ })
53
+ ```
54
+
55
+ Each Exercism track calls its own entry point:
56
+
57
+ ```javascript
58
+ import {EditorView, basicSetup} from "codemirror"
59
+ import {x86_64Assembly} from "@exercism/codemirror-lang-assembly"
60
+ // or {arm64Assembly} or {mipsAssembly}
61
+
62
+ new EditorView({
63
+ parent: document.body,
64
+ doc: `section .text\nglobal add\nadd:\n mov rax, rdi\n add rax, rsi\n ret\n`,
65
+ extensions: [basicSetup, x86_64Assembly()]
66
+ })
67
+ ```
68
+
69
+ ## Entry points and completion
51
70
 
52
71
  The package has four entry points:
53
72
 
54
- - `assembly()` is upstream's support for every assembler.
73
+ - `assembly()` is the support for every assembler, using the shared grammar.
55
74
  - `x86_64Assembly()` is the support for x86-64 NASM, as used on Exercism's
56
75
  x86-64 Assembly track. It offers:
57
76
  - Completion of the x86-64 mnemonics where a statement starts, and of NASM's
@@ -111,101 +130,48 @@ The grammar reads `;` as a comment in every dialect. The GNU assembler for
111
130
  AArch64 reads it as a statement separator, but none of the track's solutions
112
131
  use it that way.
113
132
 
114
- ### Adding another instruction set
115
-
116
- The line structure lives in `src/assembly.grammar` and `src/tokens.ts`, and
117
- knows no instruction set. Each instruction set has its own files, such as these
118
- for x86-64 (ARM64 and MIPS have the same three, named `arm64-*` and `mips-*`):
119
-
120
- - `src/x86-64-vocabulary.ts` lists the registers, directives and size keywords
121
- that the tokenizer reads, as a `Vocabulary`.
122
- - `src/x86-64-mnemonics.ts` lists the mnemonics offered by completion.
123
- - `src/x86-64.ts` builds the language, the completion and the snippets.
124
-
125
- To add another one, such as RISC-V:
126
-
127
- 1. Name a dialect in `@dialects` in the grammar, and declare its
128
- `Dialect_<name>` term in `src/parser.terms.d.ts`.
129
- 2. Write its vocabulary, and list it in `src/dialects.ts`. `src/vocabulary.ts`
130
- describes each field. The optional fields cover a register suffix such as
131
- ARM64's `.16b`, keywords that only count at the end of a line, gas's
132
- `1b` and `1f`, registers written with a `$`, `#` as a comment and
133
- `%name` macro parameters.
134
- 3. Build its entry point from `assemblyCompletionSource` (in `src/complete.ts`)
135
- and `assemblyLayout` (in `src/layout.ts`). Both take the instruction set's
136
- own words. For a GNU assembler dialect, pass `labels: "gas"` to both, and
137
- the comment markers to the layout as `lineComments`.
138
- 4. Export it from `src/index.ts`, and add a test file in `test/`.
139
-
140
- ## Install
141
-
142
- ```
143
- npm install @exercism/codemirror-lang-assembly
144
- ```
145
-
146
- Each Exercism track calls its own entry point:
147
-
148
- ```javascript
149
- import {EditorView, basicSetup} from "codemirror"
150
- import {x86_64Assembly} from "@exercism/codemirror-lang-assembly"
151
- // or {arm64Assembly} or {mipsAssembly}
152
-
153
- new EditorView({
154
- parent: document.body,
155
- doc: `section .text\nglobal add\nadd:\n mov rax, rdi\n add rax, rsi\n ret\n`,
156
- extensions: [basicSetup, x86_64Assembly()]
157
- })
158
- ```
159
-
160
- ## Upstream README
161
-
162
- [ [**CHANGELOG**](https://codeberg.org/reeven/codemirror-lang-assembly/src/branch/master/CHANGELOG.md) ]
163
-
164
- This package implements assembly language support for the
165
- [CodeMirror](https://codemirror.net/) code editor, using a
166
- [Lezer](https://lezer.codemirror.net/) grammar written for this package.
167
-
168
- It is not written for one assembler. It reads 8080, Z80, NASM, FASM, MASM, the
169
- GNU assembler in both its syntaxes, 68000, ARM and AArch64, 6502, MIPS, RISC-V,
170
- PDP-8 and the IBM 360 assemblers, because it is written for the shape all of
171
- them share rather than the vocabulary none of them do.
133
+ ## Dialects
172
134
 
173
- CodeMirror 6 has never shipped assembly, and no Lezer grammar for it existed
174
- anywhere before this one. What a CodeMirror 6 editor could offer until now was
175
- the CodeMirror 5 stream mode for the GNU assembler, which knows AT&T syntax and
176
- nothing else.
135
+ The shared grammar reads every assembler. The package also has dialects. A
136
+ dialect gives the tokenizer one instruction set's registers and directives
137
+ in place of the shared lists. The first dialect is `x86`, which reads NASM as
138
+ written for x86-64:
177
139
 
178
- Written in part for [CodinCod](https://codincod.com/), a competitive coding
179
- platform, where it colours the editor people solve puzzles in.
140
+ - `x` and `a` are names, because x86 has no registers with those names.
141
+ - `.loop` is always a local label, and `loop .zero` is an instruction.
142
+ - `mov qword [x], 1` is an instruction. The shared grammar also reads this
143
+ correctly.
144
+ - `%1` is a macro parameter (`MacroParameter`), and `%%done:` is a label.
145
+ - `rep movsb` and `lock xadd` are one mnemonic each.
146
+ - `db` after `times` or `at` is a directive.
180
147
 
181
- This code is released under an
182
- [MIT license](https://codeberg.org/reeven/codemirror-lang-assembly/src/branch/master/LICENSE).
148
+ The second dialect is `arm64`, which reads the GNU assembler as written for
149
+ AArch64:
183
150
 
184
- ## Usage
151
+ - The registers are `x0` to `x30`, `w0` to `w30`, `sp`, `xzr`, `lr`, the
152
+ floating point and vector registers, and the SVE registers. A vector
153
+ register keeps its arrangement, so `v0.16b` is one register. `a` and `x` are
154
+ names.
155
+ - Every directive starts with a dot, and `.loop` without a colon is a label.
156
+ - `count .req x19` names `count`.
157
+ - `lsl`, `uxtw` and the relocations in `:lo12:msg` are operand keywords.
158
+ - A condition code such as `eq` is a keyword when it ends the line, as in
159
+ `csel x0, x1, x2, eq`. Anywhere else it is a name, so `hi` can still be an
160
+ alias in `ldr x0, [hi]`.
161
+ - `1b` and `1f` refer to the numeric label `1:`.
185
162
 
186
- ```javascript
187
- import {EditorView, basicSetup} from "codemirror"
188
- import {assembly} from "@codincod/codemirror-lang-assembly"
163
+ The third dialect is `mips`, which reads MIPS32 as MARS assembles it. MARS
164
+ is the simulator that runs the MIPS track's tests.
189
165
 
190
- const view = new EditorView({
191
- parent: document.body,
192
- doc: ` global main
193
- section .text
194
- main:
195
- push rbp
196
- mov rbp, rsp
197
- xor eax, eax
198
- lea rdi, [fmt]
199
- call printf@PLT ; say it
200
- leave
201
- ret
166
+ - Every register has a `$` in front: `$t0`, `$a0`, `$zero`, `$31` and
167
+ `$f12`. `$a0` is a register, never a hexadecimal number, and a word without
168
+ a `$`, such as `sp`, is a name.
169
+ - `#` always opens a comment, so `#note` with no space after it is one too.
170
+ - `%count` is a macro parameter, as in `.macro incr(%count)`, and
171
+ `.end_macro` closes the macro.
202
172
 
203
- section .data
204
- fmt db "Hello, World!", 10, 0
205
- `,
206
- extensions: [basicSetup, assembly()]
207
- })
208
- ```
173
+ In the shared grammar and every dialect, `#:lo12:msg`, `#~32` and a gas
174
+ macro's `#\offset` are immediates, and `.copy_\name:` is one label.
209
175
 
210
176
  ## Coverage
211
177
 
@@ -324,6 +290,32 @@ x86-64 in gas syntax by assembling it, and
324
290
  grammar makes the same bet this one does: that the shape is worth more than the
325
291
  vocabulary.
326
292
 
293
+ ## Adding another instruction set
294
+
295
+ The line structure lives in `src/assembly.grammar` and `src/tokens.ts`, and
296
+ knows no instruction set. Each instruction set has its own files, such as these
297
+ for x86-64 (ARM64 and MIPS have the same three, named `arm64-*` and `mips-*`):
298
+
299
+ - `src/x86-64-vocabulary.ts` lists the registers, directives and size keywords
300
+ that the tokenizer reads, as a `Vocabulary`.
301
+ - `src/x86-64-mnemonics.ts` lists the mnemonics offered by completion.
302
+ - `src/x86-64.ts` builds the language, the completion and the snippets.
303
+
304
+ To add another one, such as RISC-V:
305
+
306
+ 1. Name a dialect in `@dialects` in the grammar, and declare its
307
+ `Dialect_<name>` term in `src/parser.terms.d.ts`.
308
+ 2. Write its vocabulary, and list it in `src/dialects.ts`. `src/vocabulary.ts`
309
+ describes each field. The optional fields cover a register suffix such as
310
+ ARM64's `.16b`, keywords that only count at the end of a line, gas's
311
+ `1b` and `1f`, registers written with a `$`, `#` as a comment and
312
+ `%name` macro parameters.
313
+ 3. Build its entry point from `assemblyCompletionSource` (in `src/complete.ts`)
314
+ and `assemblyLayout` (in `src/layout.ts`). Both take the instruction set's
315
+ own words. For a GNU assembler dialect, pass `labels: "gas"` to both, and
316
+ the comment markers to the layout as `lineComments`.
317
+ 4. Export it from `src/index.ts`, and add a test file in `test/`.
318
+
327
319
  ## Building and testing
328
320
 
329
321
  ```
@@ -331,3 +323,8 @@ npm install # installs the dependencies and builds the package into dist/
331
323
  npm run build # regenerates the parser, then rebuilds the package
332
324
  npm test # builds the package, then runs the tests
333
325
  ```
326
+
327
+ ## Contributing
328
+
329
+ Please read about how to [contribute to Exercism](https://exercism.org/docs/building).
330
+ Be sure to read the Exercism [Code of Conduct](https://exercism.org/docs/using/legal/code-of-conduct).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exercism/codemirror-lang-assembly",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Assembly language support for the CodeMirror code editor, with x86-64 NASM, ARM64 GNU assembler and MIPS MARS completion, as used on Exercism",
5
5
  "keywords": [
6
6
  "editor",
@@ -53,7 +53,7 @@
53
53
  "homepage": "https://github.com/exercism/codemirror-lang-assembly",
54
54
  "repository": {
55
55
  "type": "git",
56
- "url": "https://github.com/exercism/codemirror-lang-assembly"
56
+ "url": "git+https://github.com/exercism/codemirror-lang-assembly.git"
57
57
  },
58
58
  "bugs": {
59
59
  "url": "https://github.com/exercism/codemirror-lang-assembly/issues"