This commit is contained in:
Patrick Quist
2022-06-24 22:07:40 +02:00
committed by GitHub
parent 3bc192287d
commit 5452166ae1
11 changed files with 287 additions and 1 deletions

3
.github/labeler.yml vendored
View File

@@ -111,6 +111,9 @@ lang-solidity:
lang-swift: lang-swift:
- lib/compilers/swift.js - lib/compilers/swift.js
- etc/config/swift.*.properties - etc/config/swift.*.properties
lang-toit:
- lib/compilers/toit.ts
- etc/config/toit.*.properties
lang-typescript: lang-typescript:
- lib/compilers/typescript.js - lib/compilers/typescript.js
- etc/config/typescript.*.properties - etc/config/typescript.*.properties

View File

@@ -95,6 +95,7 @@ From oldest to newest contributor, we would like to thank:
- [Julian Hammer](https://github.com/cod3monk) - [Julian Hammer](https://github.com/cod3monk)
- [Peter Schussheim](https://github.com/peterschussheim) - [Peter Schussheim](https://github.com/peterschussheim)
- [Robert Cohn](https://github.com/rscohn2) - [Robert Cohn](https://github.com/rscohn2)
- [Serzhan Nasredin](https://github.com/snxx-lppxx)
- [Jeremy Overesch](https://github.com/jovere) - [Jeremy Overesch](https://github.com/jovere)
- [Arseniy Zaostrovnykh](https://github.com/necto) - [Arseniy Zaostrovnykh](https://github.com/necto)
- [Julien Marrec](https://github.com/jmarrec) - [Julien Marrec](https://github.com/jmarrec)

View File

@@ -0,0 +1,10 @@
compilers=&toit
defaultCompiler=toit1614
group.toit.compilers=toit1614
group.toit.isSemVer=true
group.toit.baseName=Toit
group.toit.compilerType=toit
compiler.toit1614.semver=1.6.14
compiler.toit1614.exe=/opt/compiler-explorer/toit-1.6.14/bin/toit.run

View File

@@ -0,0 +1,9 @@
compilers=/usr/bin/toit
supportsBinary=false
supportsExecute=true
interpreted=true
compilerType=toit
versionFlag=version
disasmScript=
group.toit.intelAsm=-mllvm -x86-asm-syntax=intel

View File

@@ -0,0 +1,2 @@
square num/int:
return num * num

View File

@@ -354,3 +354,10 @@ export class TurboCParser extends BaseParser {
return compiler; return compiler;
} }
} }
export class ToitParser extends BaseParser {
static async parse(compiler) {
await ToitParser.getOptions(compiler, '-help');
return compiler;
}
}

60
lib/compilers/toit.ts Normal file
View File

@@ -0,0 +1,60 @@
// Copyright (c) 2022, Serzhan Nasredin
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
import _ from 'underscore';
import {ParseFilters} from '../../types/features/filters.interfaces';
import {BaseCompiler} from '../base-compiler';
import {ToitParser} from './argument-parsers';
export class ToitCompiler extends BaseCompiler {
static get key() {
return 'toit';
}
constructor(info, env) {
super(info, env);
this.compiler.supportsIntel = true;
}
cacheDir(outputFilename: string) {
return outputFilename + '.cache';
}
override optionsForFilter(filters: ParseFilters, outputFilename, userOptions?): string[] {
if (!filters.binary) return ['execute', outputFilename];
return [];
}
override getSharedLibraryPathsAsArguments(libraries: object[], libDownloadPath: string) {
return [];
}
override getArgumentParser() {
return ToitParser;
}
override isCfgCompiler() {
return true;
}
}

View File

@@ -403,6 +403,16 @@ const definitions: Record<LanguageKey, LanguageDefinition> = {
formatter: null, formatter: null,
previewFilter: null, previewFilter: null,
}, },
toit: {
name: 'Toit',
monaco: 'toit',
extensions: ['.toit'],
alias: [],
logoUrl: 'toit.svg',
logoUrlDark: null,
formatter: null,
previewFilter: null,
},
typescript: { typescript: {
name: 'TypeScript Native', name: 'TypeScript Native',
monaco: 'typescript', monaco: 'typescript',

165
static/modes/toit-mode.ts Normal file
View File

@@ -0,0 +1,165 @@
// Copyright (c) 2022, Serzhan Nasredin
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
'use strict';
const monaco = require('monaco-editor');
function configuration() {
/* Toit Language Configuration: */
return {
comment: [[/\/\*/, 'comment'], [/\*\//, 'comment', '@pop'], [{lineComment: /\/\//}]],
brackets: [
['{', '}', 'delimiter.curly'],
['[', ']', 'delimiter.square'],
['#[', ']', 'delimiter.square'],
['(', ')', 'delimiter.parenthesis'],
['<', '>', 'delimiter.angle'],
],
writespace: [[/[ \t\r\n]+/, 'write']],
string: [
[/@escapes/, 'string.escape'],
[/"/, 'string', '@pop'],
],
tripleQuoteString: [[/"""/, 'string', '@pop']],
rawString: [[/"/, 'string', '@pop']],
character: [
[/@charEscapes/, 'string.escape'],
[/'/, 'string', '@pop'],
],
};
}
function definition() {
/* Toit Language Definition: */
return {
keywords: [
'import',
'export',
'as',
'show',
'class',
'extends',
'for',
'while',
'if',
'else',
'break',
'continue',
'static',
'assert',
'abstract',
'try',
'finally',
'return',
],
builtintypes: ['bool', 'int', 'string', 'float'],
wordOperators: ['and', 'or', 'not'],
operators: [
'=',
'+',
'-',
'*',
'/',
'^',
'<',
'>',
'%',
'?',
'|',
'&',
'~',
'++',
'--',
'+=',
'-=',
'*=',
'/=',
'%=',
'|=',
'^=',
'&=',
'!=',
'==',
':=',
'<<',
'>>',
'<=',
'>=',
'::=',
'>>>',
'<<=',
'>>=',
'>>>=',
],
/* We include these common regular expressions */
symbols: /[=><!~?:&|+\-*/^%]+/,
escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
/* The main tokenizer for our languages */
tokenizer: {
root: [
/* Identify type declarations (also functions): */
[
/[a-z_$][\w$]*/,
{
cases: {
'@builtintypes': 'keyword',
'@keywords': 'keyword',
'@wordOperators': 'keyword',
},
},
],
{include: '@writespace'},
[/([:|[[{(]\.|\.[\]})]|[[\]{}()])/, '@brackets'],
[
/@symbols/,
{
cases: {
'@operators': 'operator',
'@default': '',
},
},
],
],
},
};
}
const def = definition();
monaco.languages.register({id: 'toit'});
monaco.languages.setMonarchTokensProvider('toit', def);
monaco.languages.setLanguageConfiguration('toit', configuration());
export = def;

View File

@@ -62,7 +62,8 @@ export type LanguageKey =
| 'vb' | 'vb'
| 'dart' | 'dart'
| 'typescript' | 'typescript'
| 'solidity'; | 'solidity'
| 'toit';
export interface Language { export interface Language {
/** Id of language. Added programmatically based on CELanguages key */ /** Id of language. Added programmatically based on CELanguages key */

View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 441.85 290.69">
<path fill-rule="evenodd" transform="translate(-29.07 -104.65)"
d="M29.52,117.06a16.16,16.16,0,0,1,16-12.4,16.24,16.24,0,0,1,4,.44l169.24,
40.5h0c1,.24,2,.5,2.95.78a115.92,115.92,0,0,0,56.62,0c1-.28,2-.54,2.95-.78h0l169.24-40.5a16.21,
16.21,0,1,1,8,31.41L289.06,177l-2.09.56a29.38,29.38,0,0,
0-20.8,28.06v20.67a50.63,50.63,0,0,0,8.13,
27.52l64.41,99.51a21.48,
21.48,0,0,0,33.73,2.94l70.48-75.73a16.16,16.16,0,0,1,23.68,22L396.12,
378.2a53.84,53.84,0,0,1-84.56-7.39L253,280.31a3.55,3.55,0,0,0-6,0l-58.58,90.5a53.84,
53.84,0,0,1-84.56,7.39L33.4,302.47a16.16,16.16,0,0,1,23.68-22l70.48,75.73a21.48,
21.48,0,0,0,
33.73-2.94l64.41-99.51a50.63,50.63,0,
0,0,8.13-27.52V205.57A29.37,
29.37,0,0,0,213,177.51l-2.09-.56L41.49,136.51A16.14,16.14,0,0,1,29.52,117.06Z"
/>
</svg>

After

Width:  |  Height:  |  Size: 1.1 KiB