Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ Enabled via `processors` config:
| C (Wasm) | `c-wasm`, `cwasm`, `wasm.c`, `c` | Clang WASM |
| C++ | `cpp`, | JSCPP interpreter |
| C++ (Wasm) | `cpp-wasm`, `clang`, `wasm.cpp` | Clang WASM |
| Crystal (Wasm) | `crystal-wasm`, `cr`, `crystal` | Crystal -> WASM (Clang/LLVM + WASI) |
| Objective-C | `objc-wasm`, `objc`, `wasm.m` | Clang WASM |
| Objective-C++ | `objcpp-wasm`, `objcpp`, `wasm.mm` | Clang WASM |
| COBOL (Wasm) | `cobol-wasm`, `cobol`, `cob`, `cbl`, `cpy`, `gnucobol`, `wasm.cobol` | GnuCOBOL (COBOL -> WASM) |
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ A [feature-rich](https://livecodes.io/docs/features/), open-source, **client-sid
[![LiveCodes: npm version](https://img.shields.io/npm/v/livecodes)](https://www.npmjs.com/package/livecodes)
[![LiveCodes: npm downloads](https://img.shields.io/npm/dm/livecodes)](https://www.npmjs.com/package/livecodes)
[![LiveCodes: jsdelivr downloads](https://data.jsdelivr.com/v1/package/npm/livecodes/badge?style=rounded)](https://www.jsdelivr.com/package/npm/livecodes)
[![LiveCodes: languages](https://img.shields.io/badge/languages-121-blue)](https://livecodes.io/docs/languages/)
[![LiveCodes: languages](https://img.shields.io/badge/languages-122-blue)](https://livecodes.io/docs/languages/)
[![LiveCodes: docs](https://img.shields.io/badge/Documentation-575757?logo=gitbook&logoColor=white)](https://livecodes.io/docs/)
[![LiveCodes: llms.txt](https://img.shields.io/badge/llms.txt-575757?logo=googledocs&logoColor=white)](https://livecodes.io/docs/llms.txt)
[![LiveCodes: llms-full.txt](https://img.shields.io/badge/llms--full.txt-575757?logo=googledocs&logoColor=white)](https://livecodes.io/docs/llms-full.txt)
Expand Down
130 changes: 130 additions & 0 deletions docs/docs/languages/crystal-wasm.mdx
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/)
1 change: 1 addition & 0 deletions docs/src/components/LanguageSliders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export default function Sliders() {
{ name: 'cobol-wasm', title: 'COBOL (Wasm)' },
{ name: 'fortran', title: 'Fortran' },
{ name: 'd-wasm', title: 'D (Wasm)' },
{ name: 'crystal-wasm', title: 'Crystal (Wasm)' },
{ name: 'dart', title: 'Dart' },
{ name: 'flutter', title: 'Flutter' },
{ name: 'v-wasm', title: 'V (Wasm)' },
Expand Down
1 change: 1 addition & 0 deletions docs/src/components/TemplateList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const templates = [
{ name: 'cobol-wasm', title: 'COBOL Starter', thumbnail: 'cobol.svg' },
{ name: 'fortran-wasm', title: 'Fortran Starter', thumbnail: 'fortran.svg' },
{ name: 'd-wasm', title: 'D Starter', thumbnail: 'd.svg' },
{ name: 'crystal-wasm', title: 'Crystal Starter', thumbnail: 'crystal.svg' },
{ name: 'v-wasm', title: 'V Starter', thumbnail: 'v.svg' },
{ name: 'cpp-wasm', title: 'C++ (Wasm) Starter', thumbnail: 'cpp.svg' },
{ name: 'objc-wasm', title: 'Objective-C (Wasm) Starter', thumbnail: 'objective-c.svg' },
Expand Down
1 change: 1 addition & 0 deletions functions/vendors/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const starterTemplates = {
"ocaml": "Ocaml Starter",
"nim": "Nim Starter",
"nim-wasm": "Nim (Wasm) Starter",
"crystal-wasm": "Crystal Starter",
"janet-wasm": "Janet (Wasm) Starter",
"python": "Python Starter",
"python-wasm": "Python (Wasm) Starter",
Expand Down
1 change: 1 addition & 0 deletions scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ const iifeBuild = () =>
'languages/janet-wasm/lang-janet-wasm-script.ts',
'languages/fortran-wasm/lang-fortran-wasm-script.ts',
'languages/d-wasm/lang-d-wasm-script.ts',
'languages/crystal/lang-crystal-wasm-script.ts',
'languages/cobol-wasm/lang-cobol-wasm-script.ts',
'languages/v-wasm/lang-v-wasm-script.ts',
'languages/go-wasm/lang-go-wasm-script.ts',
Expand Down
1 change: 1 addition & 0 deletions server/php/inc/starter-templates.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"ocaml": "Ocaml Starter",
"nim": "Nim Starter",
"nim-wasm": "Nim (Wasm) Starter",
"crystal-wasm": "Crystal Starter",
"janet-wasm": "Janet (Wasm) Starter",
"python": "Python Starter",
"python-wasm": "Python (Wasm) Starter",
Expand Down
1 change: 1 addition & 0 deletions src/livecodes/UI/command-menu-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ export const getCommandMenuActions = ({
'cobol-wasm',
'fortran-wasm',
'd-wasm',
'crystal-wasm',
'v-wasm',
'rust-wasm',
'swift-wasm',
Expand Down
3 changes: 3 additions & 0 deletions src/livecodes/assets/templates/crystal.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions src/livecodes/html/language-info.html
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,45 @@ <h3 data-i18n="language-info:cppWasm.name">C++ (Wasm)</h3>
</li>
</ul>
</section>
<section data-lang="crystal-wasm">
Comment thread
pullfrog[bot] marked this conversation as resolved.
<h3 data-i18n="language-info:crystal-wasm.name">Crystal (Wasm)</h3>
<div data-i18n="language-info:crystal-wasm.desc" data-i18n-prop="innerHTML">
Crystal's own compiler, compiled to WebAssembly — with LLVM's linker and the WASI sysroot it
links against — running entirely in the browser.
</div>
<ul data-i18n="language-info:crystal-wasm.link" data-i18n-prop="innerHTML">
<li>
<a href="https://crystal-lang.org/" target="_blank" rel="noopener"
>Crystal official website</a
>
</li>
<li>
<a href="https://crystal-lang.org/reference/" target="_blank" rel="noopener"
>Crystal language reference</a
>
</li>
<li>
<a href="https://crystal-lang.org/api/" target="_blank" rel="noopener"
>Standard library API</a
>
</li>
<li>
<a href="https://learnxinyminutes.com/docs/crystal/" target="_blank" rel="noopener"
>Learn X in Y minutes, where X=Crystal</a
>
</li>
<li>
<a href="{{DOCS_BASE_URL}}languages/crystal-wasm" target="_blank" rel="noopener"
>LiveCodes Documentation</a
>
</li>
<li>
<a href="?template=crystal-wasm" class="button" target="_parent" data-template="crystal-wasm"
>Load starter template</a
>
</li>
</ul>
</section>
<section data-lang="csharp-wasm">
<h3 data-i18n="language-info:csharpWasm.name">C# (Wasm)</h3>
<div data-i18n="language-info:csharpWasm.desc" data-i18n-prop="innerHTML">
Expand Down
27 changes: 27 additions & 0 deletions src/livecodes/i18n/locales/ar/language-info.lokalise.json
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,15 @@
"cppWasm.name": {
"translation": "C++ (Wasm)"
},
"crystal-wasm.desc": {
"translation": "مترجم Crystal الخاص، المُجمَّع إلى WebAssembly — مع رابط LLVM ونظام WASI sysroot الذي يرتبط به — يعمل بالكامل داخل المتصفح."
},
"crystal-wasm.link": {
"translation": "<tag-1> <tag-2>الموقع الرسمي لـ Crystal</tag-2> </tag-1> <tag-3> <tag-4>مرجع لغة Crystal</tag-4> </tag-3> <tag-5> <tag-6>واجهة برمجة المكتبة القياسية</tag-6> </tag-5> <tag-7> <tag-8>تعلم X في Y دقيقة، حيث X = Crystal</tag-8> </tag-7> <tag-9> <tag-10>وثائق LiveCodes</tag-10> </tag-9> <tag-11> <tag-12>تحميل قالب البدء</tag-12> </tag-11>"
},
"crystal-wasm.name": {
"translation": "Crystal (Wasm)"
},
"csharpWasm.desc": {
"translation": "مترجم C# الذي يعمل على WebAssembly، باستخدام <tag-1>Blazor</tag-1>"
},
Expand All @@ -201,6 +210,15 @@
"d-wasm.name": {
"translation": "D (Wasm)"
},
"dart.desc": {
"translation": "يتم تجميع Dart إلى JavaScript بواسطة سلسلة أدوات Dart من جهة العميل (DDC) — نفسها التي تشغّل DartPad — وتعمل بالكامل داخل المتصفح. ثم تعمل الحزمة المُجمَّعة في صفحة النتيجة. لا يشارك أي خادم."
},
"dart.link": {
"translation": "<tag-1> <tag-2>الموقع الرسمي لـ Dart</tag-2> </tag-1> <tag-3> <tag-4>وثائق Dart</tag-4> </tag-3> <tag-5> <tag-6>DartPad</tag-6> </tag-5> <tag-7> <tag-8>وثائق LiveCodes</tag-8> </tag-7> <tag-9> <tag-10>تحميل قالب البدء</tag-10> </tag-9>"
},
"dart.name": {
"translation": "Dart"
},
"diagrams.desc1": {
"translation": "(تجريبي)"
},
Expand Down Expand Up @@ -279,6 +297,15 @@
"flow.name": {
"translation": "Flow"
},
"flutter.desc": {
"translation": "يتم تجميع Flutter إلى JavaScript باستخدام سلسلة الأدوات من جهة العميل نفسها التي يستخدمها Dart، ثم يتم تشغيل محرك Flutter في صفحة النتيجة، حيث يُعرض التطبيق. لا يشارك أي خادم."
},
"flutter.link": {
"translation": "<tag-1> <tag-2>الموقع الرسمي لـ Flutter</tag-2> </tag-1> <tag-3> <tag-4>وثائق Flutter</tag-4> </tag-3> <tag-5> <tag-6>مقدمة إلى الودجات</tag-6> </tag-5> <tag-7> <tag-8>وثائق LiveCodes</tag-8> </tag-7> <tag-9> <tag-10>تحميل قالب البدء</tag-10> </tag-9>"
},
"flutter.name": {
"translation": "Flutter"
},
"fortran-wasm.desc": {
"translation": "يتم تجميع Fortran الحديثة إلى WebAssembly بواسطة <tag-1>LFortran</tag-1>، وتعمل بالكامل داخل المتصفح."
},
Expand Down
15 changes: 15 additions & 0 deletions src/livecodes/i18n/locales/ar/language-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ const languageInfo: I18nLangInfoTranslation = {
link: '<1> <2>مؤسسة C++ القياسية</2> </1> <3> <4>الموقع الرسمي لـ Clang</4> </3> <5> <6>تعلم X في Y دقائق، حيث X=C++</6> </5> <7> <8>وثائق LiveCodes</8> </7> <9> <10>تحميل القالب الأولي</10> </9>',
name: 'C++ (Wasm)',
},
'crystal-wasm': {
desc: 'مترجم Crystal الخاص، المُجمَّع إلى WebAssembly — مع رابط LLVM ونظام WASI sysroot الذي يرتبط به — يعمل بالكامل داخل المتصفح.',
link: '<1> <2>الموقع الرسمي لـ Crystal</2> </1> <3> <4>مرجع لغة Crystal</4> </3> <5> <6>واجهة برمجة المكتبة القياسية</6> </5> <7> <8>تعلم X في Y دقيقة، حيث X = Crystal</8> </7> <9> <10>وثائق LiveCodes</10> </9> <11> <12>تحميل قالب البدء</12> </11>',
name: 'Crystal (Wasm)',
},
csharpWasm: {
desc: 'مترجم C# الذي يعمل على WebAssembly، باستخدام <1>Blazor</1>',
link: '<1> <2>وثائق لغة C#</2> </1> <3> <4> تعلم X في دقائق Y، حيث X = C#</4> </3> <5> <6> وثائق LiveCodes</6> </5> <7> <8> تحميل قالب البدء</8> </7>',
Expand All @@ -116,6 +121,11 @@ const languageInfo: I18nLangInfoTranslation = {
link: '<1> <2>الموقع الرسمي لـ D</2> </1> <3> <4>مواصفات لغة D</4> </3> <5> <6>جولة في لغة D</6> </5> <7> <8>تعلم X في Y دقيقة، حيث X = D</8> </7> <9> <10>وثائق LiveCodes</10> </9> <11> <12>تحميل قالب البدء</12> </11>',
name: 'D (Wasm)',
},
dart: {
desc: 'يتم تجميع Dart إلى JavaScript بواسطة سلسلة أدوات Dart من جهة العميل (DDC) — نفسها التي تشغّل DartPad — وتعمل بالكامل داخل المتصفح. ثم تعمل الحزمة المُجمَّعة في صفحة النتيجة. لا يشارك أي خادم.',
link: '<1> <2>الموقع الرسمي لـ Dart</2> </1> <3> <4>وثائق Dart</4> </3> <5> <6>DartPad</6> </5> <7> <8>وثائق LiveCodes</8> </7> <9> <10>تحميل قالب البدء</10> </9>',
name: 'Dart',
},
diagrams: {
desc1: '(تجريبي)',
desc2: 'رسومات بيانية كبرمجة. يدعم:',
Expand Down Expand Up @@ -159,6 +169,11 @@ const languageInfo: I18nLangInfoTranslation = {
link: '<1> <2>الموقع الرسمي لفلو</2> </1> <3> <4>وثائق فلو</4> </3>',
name: 'Flow',
},
flutter: {
desc: 'يتم تجميع Flutter إلى JavaScript باستخدام سلسلة الأدوات من جهة العميل نفسها التي يستخدمها Dart، ثم يتم تشغيل محرك Flutter في صفحة النتيجة، حيث يُعرض التطبيق. لا يشارك أي خادم.',
link: '<1> <2>الموقع الرسمي لـ Flutter</2> </1> <3> <4>وثائق Flutter</4> </3> <5> <6>مقدمة إلى الودجات</6> </5> <7> <8>وثائق LiveCodes</8> </7> <9> <10>تحميل قالب البدء</10> </9>',
name: 'Flutter',
},
'fortran-wasm': {
desc: 'يتم تجميع Fortran الحديثة إلى WebAssembly بواسطة <1>LFortran</1>، وتعمل بالكامل داخل المتصفح.',
link: '<1> <2>تعلم Fortran</2> </1> <3> <4>الموقع الرسمي لـ LFortran</4> </3> <5> <6>موقع لغة Fortran</6> </5> <7> <8>تعلم X في Y دقيقة، حيث X = Fortran</8> </7> <9> <10>وثائق LiveCodes</10> </9> <11> <12>تحميل قالب البدء</12> </11>',
Expand Down
9 changes: 9 additions & 0 deletions src/livecodes/i18n/locales/ar/translation.lokalise.json
Original file line number Diff line number Diff line change
Expand Up @@ -1968,6 +1968,9 @@
"templates.starter.cpp-wasm": {
"translation": "قالب C++ (Wasm)"
},
"templates.starter.crystal-wasm": {
"translation": "قالب Crystal"
},
"templates.starter.csharp-wasm": {
"translation": "قالب C# (Wasm)"
},
Expand All @@ -1980,6 +1983,9 @@
"templates.starter.daisyui": {
"translation": "قالب daisyUI"
},
"templates.starter.dart": {
"translation": "قالب Dart"
},
"templates.starter.diagrams": {
"translation": "قالب الرسوم البيانية"
},
Expand All @@ -1992,6 +1998,9 @@
"templates.starter.fennel": {
"translation": "قالب Fennel"
},
"templates.starter.flutter": {
"translation": "قالب Flutter"
},
"templates.starter.fortran-wasm": {
"translation": "قالب Fortran"
},
Expand Down
3 changes: 3 additions & 0 deletions src/livecodes/i18n/locales/ar/translation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -995,14 +995,17 @@ const translation: I18nTranslation = {
commonlisp: 'قالب Common Lisp',
cpp: 'قالب C++',
'cpp-wasm': 'قالب C++ (Wasm)',
'crystal-wasm': 'قالب Crystal',
'csharp-wasm': 'قالب C# (Wasm)',
'd-wasm': 'قالب D',
d3: 'قالب D3',
daisyui: 'قالب daisyUI',
dart: 'قالب Dart',
diagrams: 'قالب الرسوم البيانية',
elm: 'قالب Elm',
fanak: 'قالب Fanak',
fennel: 'قالب Fennel',
flutter: 'قالب Flutter',
'fortran-wasm': 'قالب Fortran',
fsharp: 'قالب F#',
'fsharp-wasm': 'قالب F# (Wasm)',
Expand Down
Loading
Loading