Repository navigation
add Crystal language support #1064
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e145148
feat(Compilers): add Crystal language support
hatemhosny c0f1c24
fixes
hatemhosny 24e4671
docs: add Crystal (Wasm) to storybook stories and skill language refe…
pullfrog[bot] 4d320c5
feat(i18n): add Crystal, Dart and Flutter translations for all locales
pullfrog[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| # Crystal (Wasm) | ||
|
|
||
| [Crystal](https://crystal-lang.org/) is a statically typed, compiled language with a Ruby-like syntax. | ||
|
|
||
| In LiveCodes, Crystal is compiled and run entirely in the browser by Crystal's compiler, compiled to WebAssembly. Nothing runs on a server. | ||
|
|
||
| ## Usage | ||
|
|
||
| Demo: | ||
|
|
||
| import LiveCodes from '../../src/components/LiveCodes.tsx'; | ||
|
|
||
| export const crystalConfig = { | ||
| mode: 'simple', | ||
| activeEditor: 'script', | ||
| script: { | ||
| language: 'crystal-wasm', | ||
| content: `begin | ||
| raise "boom" | ||
| rescue ex : Exception | ||
| puts "caught: #{ex.message}" | ||
| end\n | ||
| name = gets | ||
| puts "hello #{name}" | ||
| `, | ||
| }, | ||
| tools: { status: 'full' }, | ||
| }; | ||
|
|
||
| <LiveCodes config={crystalConfig}></LiveCodes> | ||
|
|
||
| The first run downloads about 22 MB of compressed compiler, linker and standard library, and compiles them; later runs reuse them. | ||
|
|
||
|
|
||
| ### Communication with JavaScript | ||
|
|
||
| The Crystal code is compiled and run in a web worker. The following helpers are available in the browser global `livecodes.crystalWasm` object: | ||
|
|
||
| - `livecodes.crystalWasm.input`: The standard input passed to the program. | ||
| - `livecodes.crystalWasm.loaded`: A promise that resolves when the compiler is loaded and the program has run once. | ||
| - `livecodes.crystalWasm.output`: The program's output. | ||
| - `livecodes.crystalWasm.error`: The compiler diagnostics, if the code failed to compile. | ||
| - `livecodes.crystalWasm.exitCode`: The program's exit code. | ||
| - `livecodes.crystalWasm.run`: A function that compiles and runs the code with new input. It takes a string as input and returns a promise that resolves with an object containing `output`, `error` and `exitCode`. | ||
|
|
||
| Example: | ||
|
|
||
| <LiveCodes template="crystal-wasm" params={{ activeEditor: 'markup' }} height="80vh"></LiveCodes> | ||
|
|
||
| ## Language Info | ||
|
|
||
| ### Name | ||
|
|
||
| `crystal-wasm` | ||
|
|
||
| ### Aliases and Extensions | ||
|
|
||
| `cr`, `crystal` | ||
|
|
||
| ### Editor | ||
|
|
||
| `script` | ||
|
|
||
| ## Compiler | ||
|
|
||
| Crystal's compiler, compiled to WebAssembly. | ||
|
|
||
| ### Version | ||
|
|
||
| Crystal 1.17.0, linked against LLVM 20.1.8 with the WASI sysroot from wasi-sdk 33. | ||
|
|
||
| ## Custom Settings | ||
|
|
||
| [Custom settings](../advanced/custom-settings.mdx) added to the property `crystal-wasm` are passed as a JSON object to the `compiler` during compile. Please check the [documentation](../advanced/custom-settings.mdx) for full reference. | ||
|
|
||
| Please note that custom settings should be valid JSON (i.e. functions are not allowed). | ||
|
|
||
| **Example:** | ||
|
|
||
| ```json title="Custom Settings" | ||
| { | ||
| "crystal-wasm": {} | ||
| } | ||
| ``` | ||
|
|
||
| `args` is passed to the program as its command-line arguments, and `compileArgs` is added to the `crystal build` command line. | ||
|
|
||
| **Example:** | ||
|
|
||
| ```json title="Custom Settings" | ||
| { | ||
| "crystal-wasm": { | ||
| "args": ["--flag", "value"], | ||
| "compileArgs": ["-Dpreview_mt"] | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## Live Reload | ||
|
|
||
| By default, new code changes are sent to the result page for re-evaluation without a full page reload, avoiding the need to reinitialize the Crystal environment. This behavior can be disabled by adding the code comment `# __livecodes_reload__` to the Crystal code, which forces a full page reload. | ||
|
|
||
| This comment can be added in the `hiddenContent` property of the editor for embedded playgrounds. | ||
|
|
||
| ## Limitations | ||
|
|
||
| {/* - Crystal 1.17.0 only: the wasm target does not build on newer releases. */} | ||
| - Memory is never reclaimed — `wasm32` selects Crystal's no-GC allocator — so a long-running program will grow. | ||
| - No threads, sockets or subprocesses: WASI preview 1 has none, and a program is given an empty filesystem. | ||
|
|
||
| ## Example Usage | ||
|
|
||
| ```ruby | ||
| puts "hello from Crystal, compiled in your browser" | ||
|
|
||
| 1.upto(5) do |n| | ||
| puts "#{n} squared is #{n * n}" | ||
| end | ||
| ``` | ||
|
|
||
| ## Starter Template | ||
|
|
||
| https://livecodes.io/?template=crystal-wasm | ||
|
|
||
| ## Links | ||
|
|
||
| - [Crystal official website](https://crystal-lang.org/) | ||
| - [Crystal language reference](https://crystal-lang.org/reference/) | ||
| - [Standard library API](https://crystal-lang.org/api/) | ||
| - [Learn X in Y minutes, where X=Crystal](https://learnxinyminutes.com/crystal/) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.