From 1b36deaabbb32f586fac2d1349ca5a97f1a71858 Mon Sep 17 00:00:00 2001 From: allexanderbergmns Date: Wed, 26 Aug 2026 13:35:56 +0200 Subject: [PATCH] Extension update for vasm --- README.MD | 6 +- extension/client/extension.js | 2 + extension/language-configuration-vasm.json | 5 + extension/package.json | 19 +++- .../syntaxes/vuurraaf-asm.tmLanguage.json | 98 +++++++++++++++++++ extension/test/fixtures/workspace/math.vasm | 29 ++++++ extension/test/suite/extension.test.js | 10 ++ 7 files changed, 166 insertions(+), 3 deletions(-) create mode 100644 extension/language-configuration-vasm.json create mode 100644 extension/syntaxes/vuurraaf-asm.tmLanguage.json create mode 100644 extension/test/fixtures/workspace/math.vasm diff --git a/README.MD b/README.MD index c5ebbe2..98700b4 100644 --- a/README.MD +++ b/README.MD @@ -487,8 +487,10 @@ contents (arrays rendered as `[1, 2, ...]`). (functions, structs, enums, constants, locals, and stdlib module functions), and hover (symbol kind + line). The `extension/` folder contains a VS Code client (`code --install-extension extension/` after `npm install` in -`extension/`) with syntax highlighting, or point any other LSP client at -`vr lsp`. +`extension/`) with syntax highlighting for `.vr` / `.vrmm` source and +`.vasm` assembly (labels, `.global` directives, and mnemonics; the +assembly language gets highlighting only — no language server), or point +any other LSP client at `vr lsp`. ## Releases diff --git a/extension/client/extension.js b/extension/client/extension.js index 4f96823..b6c5615 100644 --- a/extension/client/extension.js +++ b/extension/client/extension.js @@ -2,6 +2,8 @@ // // Spawns `vr lsp` (the toolchain's built-in language server) and wires up // diagnostics, go-to-definition, and hover for .vr / .vrmm files. +// .vasm files get their own language (vuurraaf-asm) with dedicated syntax +// highlighting but no language server, since the server compiles .vr source. // The toolchain binary defaults to `vr` on PATH; override it with the // `vuurraaf.toolchainPath` setting. diff --git a/extension/language-configuration-vasm.json b/extension/language-configuration-vasm.json new file mode 100644 index 0000000..24c0b6e --- /dev/null +++ b/extension/language-configuration-vasm.json @@ -0,0 +1,5 @@ +{ + "comments": { + "lineComment": ";" + } +} diff --git a/extension/package.json b/extension/package.json index b530f90..232c372 100644 --- a/extension/package.json +++ b/extension/package.json @@ -13,7 +13,8 @@ "Linters" ], "activationEvents": [ - "onLanguage:vuurraaf" + "onLanguage:vuurraaf", + "onLanguage:vuurraaf-asm" ], "main": "./client/extension.js", "contributes": { @@ -29,6 +30,17 @@ ".vrmm" ], "configuration": "./language-configuration.json" + }, + { + "id": "vuurraaf-asm", + "aliases": [ + "VuurRaaf Assembly", + "vasm" + ], + "extensions": [ + ".vasm" + ], + "configuration": "./language-configuration-vasm.json" } ], "grammars": [ @@ -36,6 +48,11 @@ "language": "vuurraaf", "scopeName": "source.vuurraaf", "path": "./syntaxes/vuurraaf.tmLanguage.json" + }, + { + "language": "vuurraaf-asm", + "scopeName": "source.vuurraaf-asm", + "path": "./syntaxes/vuurraaf-asm.tmLanguage.json" } ], "configuration": { diff --git a/extension/syntaxes/vuurraaf-asm.tmLanguage.json b/extension/syntaxes/vuurraaf-asm.tmLanguage.json new file mode 100644 index 0000000..e3dd5ae --- /dev/null +++ b/extension/syntaxes/vuurraaf-asm.tmLanguage.json @@ -0,0 +1,98 @@ +{ + "$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json", + "name": "VuurRaaf Assembly", + "scopeName": "source.vuurraaf-asm", + "patterns": [ + { + "include": "#comments" + }, + { + "include": "#directives" + }, + { + "include": "#labels" + }, + { + "include": "#mnemonics" + }, + { + "include": "#strings" + }, + { + "include": "#numbers" + }, + { + "include": "#operands" + } + ], + "repository": { + "comments": { + "patterns": [ + { + "name": "comment.line.semicolon.vuurraaf-asm", + "match": ";.*$" + } + ] + }, + "directives": { + "patterns": [ + { + "name": "keyword.other.directive.vuurraaf-asm", + "match": "^\\s*(\\.[a-zA-Z_][a-zA-Z0-9_]*)\\b" + } + ] + }, + "labels": { + "patterns": [ + { + "name": "meta.label.vuurraaf-asm", + "match": "^\\s*([a-zA-Z_][a-zA-Z0-9_]*)\\s*:\\s*$", + "captures": { + "1": { + "name": "entity.name.function.vuurraaf-asm" + } + } + } + ] + }, + "mnemonics": { + "patterns": [ + { + "name": "keyword.control.vuurraaf-asm", + "match": "\\b(halt|push_int|push_str|load|store|pop|dup|add|sub|mul|div|mod|neg|eq|ne|lt|le|gt|ge|and|or|not|jmp|jz|jnz|call|ret|retv|print|println|assert|enter|mkarray|aget|aset|alen|apush|mkstruct|sget|sset)\\b" + } + ] + }, + "strings": { + "patterns": [ + { + "name": "string.quoted.double.vuurraaf-asm", + "begin": "\"", + "end": "\"", + "patterns": [ + { + "name": "constant.character.escape.vuurraaf-asm", + "match": "\\\\\\(\\\\|n|t|r|\"|$)" + } + ] + } + ] + }, + "numbers": { + "patterns": [ + { + "name": "constant.numeric.vuurraaf-asm", + "match": "-?\\b\\d+\\b" + } + ] + }, + "operands": { + "patterns": [ + { + "name": "variable.other.reference.vuurraaf-asm", + "match": "\\b[a-zA-Z_][a-zA-Z0-9_]*\\b" + } + ] + } + } +} diff --git a/extension/test/fixtures/workspace/math.vasm b/extension/test/fixtures/workspace/math.vasm new file mode 100644 index 0000000..9d53c9a --- /dev/null +++ b/extension/test/fixtures/workspace/math.vasm @@ -0,0 +1,29 @@ +; math.vasm — raw bytecode, hand-written in VuurRaaf assembly. +; Assemble + link + run with: +; vr assemble examples/math.vasm +; vr link math.vobj -o math.vbin +; vr run math.vbin + +.global main + +main: + push_int 6 + push_int 7 + mul + println + push_str "computed 6 * 7 = 42" + println + push_int 40 + push_int 2 + call add 2 ; calls the exported `add` symbol below + println + halt + +; a callable function: takes two args, returns their sum +.global add +add: + enter 0 ; no extra locals (args were copied in by `call`) + load 0 + load 1 + add + retv diff --git a/extension/test/suite/extension.test.js b/extension/test/suite/extension.test.js index 47dfb27..32b9ec7 100644 --- a/extension/test/suite/extension.test.js +++ b/extension/test/suite/extension.test.js @@ -12,6 +12,9 @@ const vscode = require('vscode'); const DEMO_URI = vscode.Uri.file( path.join(__dirname, '..', 'fixtures', 'workspace', 'demo.vr') ); +const VASM_URI = vscode.Uri.file( + path.join(__dirname, '..', 'fixtures', 'workspace', 'math.vasm') +); async function openDemo() { const doc = await vscode.workspace.openTextDocument(DEMO_URI); @@ -37,6 +40,13 @@ suite('VuurRaaf extension', function () { test('vuurraaf language (grammar) is registered', async function () { const langs = await vscode.languages.getLanguages(); assert.ok(langs.includes('vuurraaf'), 'vuurraaf language id not registered'); + assert.ok(langs.includes('vuurraaf-asm'), 'vuurraaf-asm language id not registered'); + }); + + test('.vasm files get the vuurraaf-asm language id', async function () { + const doc = await vscode.workspace.openTextDocument(VASM_URI); + await vscode.window.showTextDocument(doc); + assert.strictEqual(doc.languageId, 'vuurraaf-asm', 'expected vuurraaf-asm, got ' + doc.languageId); }); test('language server publishes compiler diagnostics', async function () {