diff --git a/.github/labeler.yml b/.github/labeler.yml index b8907c051..2ed3caf05 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -111,6 +111,9 @@ lang-solidity: lang-swift: - lib/compilers/swift.js - etc/config/swift.*.properties +lang-toit: + - lib/compilers/toit.ts + - etc/config/toit.*.properties lang-typescript: - lib/compilers/typescript.js - etc/config/typescript.*.properties diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index b2baa5ec5..1d57d93d4 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -95,6 +95,7 @@ From oldest to newest contributor, we would like to thank: - [Julian Hammer](https://github.com/cod3monk) - [Peter Schussheim](https://github.com/peterschussheim) - [Robert Cohn](https://github.com/rscohn2) +- [Serzhan Nasredin](https://github.com/snxx-lppxx) - [Jeremy Overesch](https://github.com/jovere) - [Arseniy Zaostrovnykh](https://github.com/necto) - [Julien Marrec](https://github.com/jmarrec) diff --git a/etc/config/toit.amazon.properties b/etc/config/toit.amazon.properties new file mode 100644 index 000000000..ec7681192 --- /dev/null +++ b/etc/config/toit.amazon.properties @@ -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 diff --git a/etc/config/toit.defaults.properties b/etc/config/toit.defaults.properties new file mode 100644 index 000000000..123dc1751 --- /dev/null +++ b/etc/config/toit.defaults.properties @@ -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 diff --git a/examples/toit/default.toit b/examples/toit/default.toit new file mode 100644 index 000000000..9b74d5d82 --- /dev/null +++ b/examples/toit/default.toit @@ -0,0 +1,2 @@ +square num/int: + return num * num diff --git a/lib/compilers/argument-parsers.js b/lib/compilers/argument-parsers.js index 98641f47a..bec330b87 100644 --- a/lib/compilers/argument-parsers.js +++ b/lib/compilers/argument-parsers.js @@ -354,3 +354,10 @@ export class TurboCParser extends BaseParser { return compiler; } } + +export class ToitParser extends BaseParser { + static async parse(compiler) { + await ToitParser.getOptions(compiler, '-help'); + return compiler; + } +} diff --git a/lib/compilers/toit.ts b/lib/compilers/toit.ts new file mode 100644 index 000000000..999bff727 --- /dev/null +++ b/lib/compilers/toit.ts @@ -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; + } +} diff --git a/lib/languages.ts b/lib/languages.ts index aec29b021..cb03dab4e 100644 --- a/lib/languages.ts +++ b/lib/languages.ts @@ -403,6 +403,16 @@ const definitions: Record = { formatter: null, previewFilter: null, }, + toit: { + name: 'Toit', + monaco: 'toit', + extensions: ['.toit'], + alias: [], + logoUrl: 'toit.svg', + logoUrlDark: null, + formatter: null, + previewFilter: null, + }, typescript: { name: 'TypeScript Native', monaco: 'typescript', diff --git a/static/modes/toit-mode.ts b/static/modes/toit-mode.ts new file mode 100644 index 000000000..3261436d9 --- /dev/null +++ b/static/modes/toit-mode.ts @@ -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: /[=> + + + +