mac support, and vscode language!

canary
Bronwen 2022-03-13 23:15:17 -04:00
parent d47e0ee781
commit 6f78719809
16 changed files with 267 additions and 41 deletions

BIN
.vscode/extensions/disco.vsix vendored 100644

Binary file not shown.

View File

@ -1,14 +1,2 @@
link log link log
const test = "Hello" log("Hello World")
const test2 ="Hello2"
const test3 = 'Hello'
const a="5"
log(test)
log("World")
log("Hello\n \"Wor(l)d\"\n\\o/")

Binary file not shown.

View File

@ -1,28 +1,15 @@
global _main
section .data section .data
VVQDDBDZ db 72,101,108,108,111,0 UMRRSQMF db 72,101,108,108,111,32,87,111,114,108,100,0
EWXBIBSR db 72,101,108,108,111,50,0
PJQDTHUC db 72,101,108,108,111,0
ECIATSPU db 53,0
GTZCFAMK db 87,111,114,108,100,0
YDHYSXWS db 72,101,108,108,111,10,32,34,87,111,114,40,108,41,100,34,10,92,111,47,0
section .text section .text
global _start _main:
_start:
push rbp push rbp
mov rbp, rsp mov rbp, rsp
push VVQDDBDZ mov rdi, UMRRSQMF
push EWXBIBSR
push PJQDTHUC
push ECIATSPU
mov rdi, [rbp - 8]
call _log
mov rdi, GTZCFAMK
call _log
mov rdi, YDHYSXWS
call _log call _log
mov rsp, rbp mov rsp, rbp
pop rbp pop rbp
mov rax, 60 mov rax, 0x02000001
mov rdi, 0 mov rdi, 0
syscall syscall
_log: _log:
@ -37,12 +24,12 @@ _log_loop:
jmp _log_loop jmp _log_loop
_log_loop_end: _log_loop_end:
mov rdx, rbx mov rdx, rbx
mov rax, 1 mov rax, 0x02000004
mov rdi, 1 mov rdi, 1
pop rsi pop rsi
syscall syscall
push 10 push 10
mov rax, 1 mov rax, 0x02000004
mov rdi, 1 mov rdi, 1
mov rsi, rsp mov rsi, rsp
mov rdx, 1 mov rdx, 1

View File

@ -1,4 +1,30 @@
module.exports = { module.exports = process.platform === 'darwin' ? {
asmName: '_log',
asm: `\
push rdi
mov rbx, 0
_log_loop:
mov cl, [rdi]
cmp cl, 0
je _log_loop_end
inc rdi
inc rbx
jmp _log_loop
_log_loop_end:
mov rdx, rbx
mov rax, 0x02000004
mov rdi, 1
pop rsi
syscall
push 10
mov rax, 0x02000004
mov rdi, 1
mov rsi, rsp
mov rdx, 1
syscall
pop rdi
ret`
} : {
asmName: '_log', asmName: '_log',
asm: `\ asm: `\
push rdi push rdi
@ -24,4 +50,5 @@ _log_loop_end:
syscall syscall
pop rdi pop rdi
ret` ret`
} }

View File

@ -6,7 +6,8 @@
"scripts": { "scripts": {
"build": "nasm -f elf64 disco.asm -o disco.o && ld disco.o -o disco", "build": "nasm -f elf64 disco.asm -o disco.o && ld disco.o -o disco",
"start": "./disco", "start": "./disco",
"dev": "yarn build && yarn start" "dev": "yarn build && yarn start",
"code": "code . --extensionDevelopmentPath=$(pwd)/support/vscode/disco-language-support"
}, },
"dependencies": { "dependencies": {
"@types/node": "^17.0.21", "@types/node": "^17.0.21",

View File

@ -21,6 +21,13 @@ const statements = [];
const localVariables = new Map(); const localVariables = new Map();
const sections = { const sections = {
preamble() {
if(process.platform === 'darwin') {
return ' global _main\n';
} else {
return '';
}
},
data() { data() {
const convert = ([name, xs]) => name + ' db ' + xs.join(',') const convert = ([name, xs]) => name + ' db ' + xs.join(',')
return 'section .data\n ' return 'section .data\n '
@ -29,10 +36,17 @@ const sections = {
.join('\n ') .join('\n ')
}, },
text() { text() {
return 'section .text\n global _start\n_start:\n push rbp\n mov rbp, rsp\n ' if(process.platform === 'darwin') {
return 'section .text\n_main:\n push rbp\n mov rbp, rsp\n '
+ statements.join('\n ') + statements.join('\n ')
+ '\n mov rsp, rbp\n pop rbp\n mov rax, 60\n mov rdi, 0\n syscall\n' + '\n mov rsp, rbp\n pop rbp\n mov rax, 0x02000001\n mov rdi, 0\n syscall\n'
+ [...linkedLibraries.values()].map(({asmName, asm}) => asmName + ':\n' + asm).join('\n') + [...linkedLibraries.values()].map(({asmName, asm}) => asmName + ':\n' + asm).join('\n')
} else {
return 'section .text\n global _start\n_start:\n push rbp\n mov rbp, rsp\n '
+ statements.join('\n ')
+ '\n mov rsp, rbp\n pop rbp\n mov rax, 60\n mov rdi, 0\n syscall\n'
+ [...linkedLibraries.values()].map(({asmName, asm}) => asmName + ':\n' + asm).join('\n')
}
} }
} }
@ -123,5 +137,5 @@ export function compile(tree) {
for(const item of tree.value) { for(const item of tree.value) {
compileStatement(item); compileStatement(item);
} }
return sections.data() + '\n' + sections.text(); return sections.preamble() + sections.data() + '\n' + sections.text();
} }

View File

@ -41,11 +41,35 @@ try {
console.log(); console.log();
console.log('=== nasm ==='); console.log('=== nasm ===');
require('child_process').execSync('nasm -f elf64 disco_test.asm -o disco_test.o', { stdio: 'inherit' }); nasm();
console.log('=== ld ==='); console.log('=== ld ===');
require('child_process').execSync('ld disco_test.o -o disco_test', { stdio: 'inherit' }); ld();
console.log('=== execute ==='); console.log('=== execute ===');
require('child_process').execSync('./disco_test', { stdio: 'inherit' }); require('child_process').execSync('./disco_test', { stdio: 'inherit' });
} catch (e) { } catch (e) {
process.exit(1); process.exit(1);
} }
function nasm() {
if(process.platform === 'darwin') {
require('child_process').execSync('nasm -f macho64 disco_test.asm -o disco_test.o', { stdio: 'inherit' });
} else {
require('child_process').execSync('nasm -f elf64 disco_test.asm -o disco_test.o', { stdio: 'inherit' });
}
}
function ld() {
if(process.platform === 'darwin') {
require('child_process').execSync([
'ld', 'disco_test.o',
'-o', 'disco_test',
'-macosx_version_min', '11.0',
'-L', '/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib',
'-lSystem'
].join(' '), {
stdio: 'inherit'
});
} else {
require('child_process').execSync('ld disco_test.o -o disco_test', { stdio: 'inherit' });
}
}

View File

@ -0,0 +1,17 @@
// A launch configuration that launches the extension inside a new window
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
{
"version": "0.2.0",
"configurations": [
{
"name": "Extension",
"type": "extensionHost",
"request": "launch",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
]
}
]
}

View File

@ -0,0 +1,4 @@
.vscode/**
.vscode-test/**
.gitignore
vsc-extension-quickstart.md

View File

@ -0,0 +1,9 @@
# Change Log
All notable changes to the "disco-language-support" extension will be documented in this file.
Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.
## [Unreleased]
- Initial release

View File

@ -0,0 +1,3 @@
# Disco Language Supprt
its literally just syntax highlighting.

View File

@ -0,0 +1,30 @@
{
"comments": {
// symbol used for single line comment. Remove this entry if your language does not support line comments
"lineComment": "//",
// symbols used for start and end a block comment. Remove this entry if your language does not support block comments
"blockComment": [ "/*", "*/" ]
},
// symbols used as brackets
"brackets": [
["{", "}"],
["[", "]"],
["(", ")"]
],
// symbols that are auto closed when typing
"autoClosingPairs": [
["{", "}"],
["[", "]"],
["(", ")"],
["\"", "\""],
["'", "'"]
],
// symbols that can be used to surround a selection
"surroundingPairs": [
["{", "}"],
["[", "]"],
["(", ")"],
["\"", "\""],
["'", "'"]
]
}

View File

@ -0,0 +1,25 @@
{
"name": "disco-language-support",
"displayName": "Disco Language Support",
"description": "",
"version": "0.0.1",
"engines": {
"vscode": "^1.65.0"
},
"categories": [
"Programming Languages"
],
"contributes": {
"languages": [{
"id": "disco",
"aliases": ["Disco", "disco"],
"extensions": [".disco"],
"configuration": "./language-configuration.json"
}],
"grammars": [{
"language": "disco",
"scopeName": "source.disco",
"path": "./syntaxes/disco.tmLanguage.json"
}]
}
}

View File

@ -0,0 +1,68 @@
{
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
"name": "Disco",
"patterns": [
{ "include": "#Keywords" },
{ "include": "#DoubleQuoteString" },
{ "include": "#SingleQuoteString" },
{ "include": "#Identifier" },
{ "include": "#SingleLineComment" }
],
"repository": {
"Keywords": {
"patterns": [{
"name": "keyword.control.disco",
"match": "\\b(link|const)\\b"
}]
},
"Identifier": {
"patterns": [{
"name": "variable.other.constant.disco",
"match": "[A-Za-z][A-Za-z0-9]*"
}]
},
"SingleLineComment": {
"name": "comment.line.double-slash.disco",
"begin": "(^[ \\t]+)?(?=//)",
"end": "(?=$)",
"beginCaptures": {
"1": {
"name": "punctuation.whitespace.comment.leading.js"
}
},
"patterns": [
{
"name": "comment.line.double-slash.js",
"begin": "//",
"beginCaptures": {
"0": {
"name": "punctuation.definition.comment.js"
}
},
"end": "(?=$)"
}
]
},
"DoubleQuoteString": {
"name": "string.quoted.double.disco",
"begin": "\"",
"end": "\"",
"patterns": [
{ "include": "#EscapeCharacter" }
]
},
"SingleQuoteString": {
"name": "string.quoted.single.disco",
"begin": "'",
"end": "'",
"patterns": [
{ "include": "#EscapeCharacter" }
]
},
"EscapeCharacter": {
"name": "constant.character.escape.disco",
"match": "\\\\."
}
},
"scopeName": "source.disco"
}

View File

@ -0,0 +1,29 @@
# Welcome to your VS Code Extension
## What's in the folder
* This folder contains all of the files necessary for your extension.
* `package.json` - this is the manifest file in which you declare your language support and define the location of the grammar file that has been copied into your extension.
* `syntaxes/disco.tmLanguage.json` - this is the Text mate grammar file that is used for tokenization.
* `language-configuration.json` - this is the language configuration, defining the tokens that are used for comments and brackets.
## Get up and running straight away
* Make sure the language configuration settings in `language-configuration.json` are accurate.
* Press `F5` to open a new window with your extension loaded.
* Create a new file with a file name suffix matching your language.
* Verify that syntax highlighting works and that the language configuration settings are working.
## Make changes
* You can relaunch the extension from the debug toolbar after making changes to the files listed above.
* You can also reload (`Ctrl+R` or `Cmd+R` on Mac) the VS Code window with your extension to load your changes.
## Add more language features
* To add features such as intellisense, hovers and validators check out the VS Code extenders documentation at https://code.visualstudio.com/docs
## Install your extension
* To start using your extension with Visual Studio Code copy it into the `<user home>/.vscode/extensions` folder and restart Code.
* To share your extension with the world, read on https://code.visualstudio.com/docs about publishing an extension.