mac support, and vscode language!
parent
d47e0ee781
commit
6f78719809
Binary file not shown.
14
disco.disco
14
disco.disco
|
|
@ -1,14 +1,2 @@
|
|||
|
||||
|
||||
link log
|
||||
const test = "Hello"
|
||||
const test2 ="Hello2"
|
||||
const test3 = 'Hello'
|
||||
const a="5"
|
||||
log(test)
|
||||
log("World")
|
||||
log("Hello\n \"Wor(l)d\"\n\\o/")
|
||||
|
||||
|
||||
|
||||
|
||||
log("Hello World")
|
||||
BIN
disco_test
BIN
disco_test
Binary file not shown.
|
|
@ -1,28 +1,15 @@
|
|||
global _main
|
||||
section .data
|
||||
VVQDDBDZ db 72,101,108,108,111,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
|
||||
UMRRSQMF db 72,101,108,108,111,32,87,111,114,108,100,0
|
||||
section .text
|
||||
global _start
|
||||
_start:
|
||||
_main:
|
||||
push rbp
|
||||
mov rbp, rsp
|
||||
push VVQDDBDZ
|
||||
push EWXBIBSR
|
||||
push PJQDTHUC
|
||||
push ECIATSPU
|
||||
mov rdi, [rbp - 8]
|
||||
call _log
|
||||
mov rdi, GTZCFAMK
|
||||
call _log
|
||||
mov rdi, YDHYSXWS
|
||||
mov rdi, UMRRSQMF
|
||||
call _log
|
||||
mov rsp, rbp
|
||||
pop rbp
|
||||
mov rax, 60
|
||||
mov rax, 0x02000001
|
||||
mov rdi, 0
|
||||
syscall
|
||||
_log:
|
||||
|
|
@ -37,12 +24,12 @@ _log_loop:
|
|||
jmp _log_loop
|
||||
_log_loop_end:
|
||||
mov rdx, rbx
|
||||
mov rax, 1
|
||||
mov rax, 0x02000004
|
||||
mov rdi, 1
|
||||
pop rsi
|
||||
syscall
|
||||
push 10
|
||||
mov rax, 1
|
||||
mov rax, 0x02000004
|
||||
mov rdi, 1
|
||||
mov rsi, rsp
|
||||
mov rdx, 1
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
asm: `\
|
||||
push rdi
|
||||
|
|
@ -25,3 +51,4 @@ _log_loop_end:
|
|||
pop rdi
|
||||
ret`
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,8 @@
|
|||
"scripts": {
|
||||
"build": "nasm -f elf64 disco.asm -o disco.o && ld disco.o -o disco",
|
||||
"start": "./disco",
|
||||
"dev": "yarn build && yarn start"
|
||||
"dev": "yarn build && yarn start",
|
||||
"code": "code . --extensionDevelopmentPath=$(pwd)/support/vscode/disco-language-support"
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/node": "^17.0.21",
|
||||
|
|
|
|||
|
|
@ -21,6 +21,13 @@ const statements = [];
|
|||
const localVariables = new Map();
|
||||
|
||||
const sections = {
|
||||
preamble() {
|
||||
if(process.platform === 'darwin') {
|
||||
return ' global _main\n';
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
},
|
||||
data() {
|
||||
const convert = ([name, xs]) => name + ' db ' + xs.join(',')
|
||||
return 'section .data\n '
|
||||
|
|
@ -29,12 +36,19 @@ const sections = {
|
|||
.join('\n ')
|
||||
},
|
||||
text() {
|
||||
if(process.platform === 'darwin') {
|
||||
return 'section .text\n_main:\n push rbp\n mov rbp, rsp\n '
|
||||
+ statements.join('\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')
|
||||
} 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')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function zip(a, b) {
|
||||
const len = Math.min(a.length, b.length);
|
||||
|
|
@ -123,5 +137,5 @@ export function compile(tree) {
|
|||
for(const item of tree.value) {
|
||||
compileStatement(item);
|
||||
}
|
||||
return sections.data() + '\n' + sections.text();
|
||||
return sections.preamble() + sections.data() + '\n' + sections.text();
|
||||
}
|
||||
28
src/disco.ts
28
src/disco.ts
|
|
@ -41,11 +41,35 @@ try {
|
|||
|
||||
console.log();
|
||||
console.log('=== nasm ===');
|
||||
require('child_process').execSync('nasm -f elf64 disco_test.asm -o disco_test.o', { stdio: 'inherit' });
|
||||
nasm();
|
||||
console.log('=== ld ===');
|
||||
require('child_process').execSync('ld disco_test.o -o disco_test', { stdio: 'inherit' });
|
||||
ld();
|
||||
console.log('=== execute ===');
|
||||
require('child_process').execSync('./disco_test', { stdio: 'inherit' });
|
||||
} catch (e) {
|
||||
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' });
|
||||
}
|
||||
}
|
||||
|
|
@ -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}"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
.vscode/**
|
||||
.vscode-test/**
|
||||
.gitignore
|
||||
vsc-extension-quickstart.md
|
||||
|
|
@ -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
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
# Disco Language Supprt
|
||||
|
||||
its literally just syntax highlighting.
|
||||
|
|
@ -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": [
|
||||
["{", "}"],
|
||||
["[", "]"],
|
||||
["(", ")"],
|
||||
["\"", "\""],
|
||||
["'", "'"]
|
||||
]
|
||||
}
|
||||
|
|
@ -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"
|
||||
}]
|
||||
}
|
||||
}
|
||||
|
|
@ -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"
|
||||
}
|
||||
|
|
@ -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.
|
||||
Loading…
Reference in New Issue