diff --git a/.github/labeler.yml b/.github/labeler.yml index 81afdde62..402714960 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -171,6 +171,9 @@ lang-solidity: lang-swift: - lib/compilers/swift.js - etc/config/swift.*.properties +lang-snowball: + - lib/compilers/snowball.ts + - etc/config/snowball.*.properties lang-toit: - lib/compilers/toit.ts - etc/config/toit.*.properties diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index b72985862..0cbb52c80 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -131,3 +131,4 @@ From oldest to newest contributor, we would like to thank: - [Johel Ernesto Guerrero Peña](https://github.com/JohelEGP) - [Ali](https://github.com/aliaegik) - [Vlad Serebrennikov](https://github.com/endilll) +- [Mauro Baladés](https://github.com/mauro-balades) diff --git a/etc/config/snowball.amazon.properties b/etc/config/snowball.amazon.properties new file mode 100644 index 000000000..58aa04db6 --- /dev/null +++ b/etc/config/snowball.amazon.properties @@ -0,0 +1,26 @@ + +compilers=&snowball +objdumper=/opt/compiler-explorer/gcc-11.1.0/bin/objdump +defaultCompiler=snowball07 +supportsExecute=true + +# TODO: +demangler=c++filt +supportsDemangler=false + +#buildenvsetup=ceconan +#buildenvsetup.host=https://conan.compiler-explorer.com + +group.snowball.compilers=snowball07 +group.snowball.compilerType=snowball +group.snowball.isSemVer=true +group.snowball.baseName=snowball +group.snowball.licenseLink=https://github.com/snowball-lang/snowball/blob/dev/LICENSE +group.snowball.licenseName=The MIT License (MIT) +group.snowball.licensePreamble=Copyright (c) 2022 mauro-balades +group.snowball.supportsBinary=true +group.snowball.supportsBinaryObject=true + +# \_0_/ +compiler.snowball07.exe=/opt/compiler-explorer/snowball-0.0.7/bin/snowball +compiler.snowball07.semver=0.0.7 diff --git a/etc/config/snowball.default.properties b/etc/config/snowball.default.properties new file mode 100644 index 000000000..f202a08b4 --- /dev/null +++ b/etc/config/snowball.default.properties @@ -0,0 +1,29 @@ + +compilers=&snowball +supportsBinary=true +objdumper=objdump +stubRe=\bmain\b +stubText=pub fn main() i32 {/*stub provided by Compiler Explorer*/} +versionFlag=--version +supportsBinaryObject=true +supportsExecute=true +supportsDemangler=false + +group.snowball.compilers=snowball07 +group.snowball.compilerType=snowball +group.snowball.isSemVer=true +group.snowball.baseName=snowball +group.snowball.licenseLink=https://github.com/snowball-lang/snowball/blob/dev/LICENSE +group.snowball.licenseName=The MIT License (MIT) +group.snowball.licensePreamble=Copyright (c) 2022 mauro-balades +group.snowball.supportsBinary=true +group.snowball.supportsBinaryObject=true + +################################# +################################# +# Installed libs (See c++.amazon.properties for a scheme of libs group) +libs= + +compiler.snowball07.exe=/opt/compiler-explorer/snowball-0.0.7/bin/snowball +compiler.snowball07.semver=0.0.7 +compiler.snowball07.name=snowball 0.0.7 diff --git a/examples/snowball/default.sn b/examples/snowball/default.sn new file mode 100644 index 000000000..fc3d208d0 --- /dev/null +++ b/examples/snowball/default.sn @@ -0,0 +1,15 @@ +// Snowball compiler (MIT) /l、 +// https://github.com/snowball-lang/snowball (゚、 。7 +// ⠀ l、゙~ヽ +// Simple example for the lang じし(_,)ノ +// Docs: https://snowball-lang.gitbook.io/docs/ + +// Import the core library. +// This is required for the println function. +use Core::System; + +// The main function is the entry point of the program. +// It is called when the program is started. +pub fn main() i32 { + System::println("Hello, world!"); +} diff --git a/examples/snowball/fib.sn b/examples/snowball/fib.sn new file mode 100644 index 000000000..ef5fbaad4 --- /dev/null +++ b/examples/snowball/fib.sn @@ -0,0 +1,24 @@ +// Snowball compiler (MIT) /l、 +// https://github.com/snowball-lang/snowball (゚、 。7 +// ⠀ l、゙~ヽ +// Fibonacci example for the lang じし(_,)ノ +// Docs: https://snowball-lang.gitbook.io/docs/ + +// Import the core library. +// This is required for the println function. +use Core::System; + +// Define a static function that calculates the nth Fibonacci number. +// This is a recursive function. +static fn [[inline]] fib(n: i64) i64 { + if n <= 1 { + return n + } + + return fib(n-1) + fib(n-2) +} + +// Define the main function. +pub fn main() i32 { + System::println(fib(47 as i64)) +} diff --git a/examples/snowball/vectors.sn b/examples/snowball/vectors.sn new file mode 100644 index 000000000..1866abaf4 --- /dev/null +++ b/examples/snowball/vectors.sn @@ -0,0 +1,16 @@ +// Snowball compiler (MIT) /l、 +// https://github.com/snowball-lang/snowball (゚、 。7 +// ⠀ l、゙~ヽ +// Vectors example for the lang じし(_,)ノ +// Docs: https://snowball-lang.gitbook.io/docs/ + +use Core::System; + +pub fn main() i32 { + let vec = new Vector{}; + let str = String::from("Hello, world!"); + vec.push(str); + + System::println(vec[0]); + System::println(vec.size()); +} diff --git a/lib/cfg/cfg.ts b/lib/cfg/cfg.ts index f1d33128e..c57c18775 100644 --- a/lib/cfg/cfg.ts +++ b/lib/cfg/cfg.ts @@ -40,7 +40,8 @@ function isLLVMBased({compilerType, version}: CompilerInfo) { version.includes('rustc') || compilerType === 'swift' || compilerType === 'zig' || - compilerType === 'ispc' + compilerType === 'ispc' || + compilerType === 'snowball' ); } diff --git a/lib/compilers/_all.ts b/lib/compilers/_all.ts index a66343ecd..770d27c02 100644 --- a/lib/compilers/_all.ts +++ b/lib/compilers/_all.ts @@ -78,6 +78,7 @@ export {MovfuscatorCompiler} from './movfuscator.js'; export {MLIRCompiler} from './mlir.js'; export {GM2Compiler} from './gm2.js'; export {MrustcCompiler} from './mrustc.js'; +export {SnowballCompiler} from './snowball.js'; export {NasmCompiler} from './nasm.js'; export {NimCompiler} from './nim.js'; export {NvccCompiler} from './nvcc.js'; diff --git a/lib/compilers/snowball.ts b/lib/compilers/snowball.ts new file mode 100644 index 000000000..613e69276 --- /dev/null +++ b/lib/compilers/snowball.ts @@ -0,0 +1,95 @@ +// Copyright (c) 2023, Compiler Explorer Authors +// 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 type {PreliminaryCompilerInfo} from '../../types/compiler.interfaces.js'; +import type {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces.js'; +import {unwrap} from '../assert.js'; +import {BaseCompiler} from '../base-compiler.js'; + +export class SnowballCompiler extends BaseCompiler { + linker: string; + + static get key() { + return 'snowball'; + } + + constructor(info: PreliminaryCompilerInfo, env) { + super(info, env); + this.compiler.supportsIntel = false; + this.compiler.supportsIrView = true; + this.compiler.supportsLLVMOptPipelineView = true; + this.compiler.supportsCfg = true; + + this.compiler.irArg = ['--emit', 'llvm-ir']; + this.linker = this.compilerProps('linker'); + } + + override getSharedLibraryPathsAsArguments(libraries, libDownloadPath) { + return []; + } + + override getSharedLibraryLinks(libraries: any[]): string[] { + return []; + } + + override orderArguments( + options: string[], + inputFilename: string, + libIncludes: string[], + libOptions: string[], + libPaths: string[], + libLinks: string[], + userOptions: string[], + staticLibLinks: string[], + ) { + return options.concat(userOptions, libIncludes, libOptions, libPaths, libLinks, staticLibLinks, [ + '-f', + this.filename(inputFilename), + ]); + } + + override optionsForFilter(filters: ParseFiltersAndOutputOptions, outputFilename: string, userOptions?: string[]) { + let options = ['build', '--silent', '-o', this.filename(outputFilename)]; + + const userRequestedEmit = _.any(unwrap(userOptions), opt => opt.includes('--emit')); + if (filters.binary) { + options = options.concat(['--emit', 'exec']); + } else if (filters.binaryObject) { + options = options.concat(['--emit', 'lib']); + } else { + if (!userRequestedEmit) { + options = options.concat('--emit', 'asm'); + } + // TODO: + // if (filters.intel) options = options.concat('--llvm-args', '--x86-asm-syntax=intel'); + } + return options; + } + + override isCfgCompiler(/*compilerVersion*/) { + return true; + } +} diff --git a/lib/languages.ts b/lib/languages.ts index 4553f1642..c85419fa8 100644 --- a/lib/languages.ts +++ b/lib/languages.ts @@ -582,6 +582,17 @@ const definitions: Record = { previewFilter: null, monacoDisassembly: null, }, + snowball: { + name: 'Snowball', + monaco: 'rust', + extensions: ['.sn'], + alias: [], + logoUrl: 'snowball.svg', + logoUrlDark: null, + formatter: null, + previewFilter: null, + monacoDisassembly: null, + }, scala: { name: 'Scala', monaco: 'scala', diff --git a/types/languages.interfaces.ts b/types/languages.interfaces.ts index 8da043097..acdef9b88 100644 --- a/types/languages.interfaces.ts +++ b/types/languages.interfaces.ts @@ -37,6 +37,7 @@ export type LanguageKey = | 'cobol' | 'cpp_for_opencl' | 'cppx' + | 'snowball' | 'cppx_blue' | 'cppx_gold' | 'cpp2_cppfront' diff --git a/views/resources/logos/snowball.svg b/views/resources/logos/snowball.svg new file mode 100644 index 000000000..a4abb266b --- /dev/null +++ b/views/resources/logos/snowball.svg @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + +