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 @@ -158,6 +158,7 @@ Enabled via `processors` config:
| V (Wasm) | `v-wasm`, `v`, `vlang`, `wasm.v`, `vsh` | V compiler in WASM |
| Janet (Wasm) | `janet-wasm`, `janet`, `wasm.janet` | Janet interpreter (WASM) |
| Io | `io`, `iolang` | Io VM (WASM) |
| Self | `self` | Self interpreter (TypeScript) |
| Elixir (Wasm) | `elixir-wasm`, `ex`, `exs`, `elixir`, `wasm.ex` | Elixir compiler in WASM |
| Erlang (Wasm) | `erlang-wasm`, `erl`, `erlang`, `wasm.erl` | Erlang runtime in WASM (AtomVM) |
| Tcl | `tcl` | Tcl interpreter |
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-130-blue)](https://livecodes.io/docs/languages/)
[![LiveCodes: languages](https://img.shields.io/badge/languages-131-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
115 changes: 115 additions & 0 deletions docs/docs/languages/self.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# Self

[Self](https://selflanguage.org/) is a prototype-based, dynamically typed, object-oriented programming
language. It grew out of Smalltalk and uses message passing, blocks and slots instead of classes.

In LiveCodes, Self runs in the browser on a TypeScript implementation of its interpreter, entirely
client-side. No server is involved.

## Usage

Demo:

import LiveCodes from '../../src/components/LiveCodes.tsx';

export const selfConfig = {
activeEditor: 'script',
script: {
language: 'self',
content: `'Hello, World!' printLine.\n\n1 to: 5 Do: [|:n| n printLine].`,
},
mode: 'simple',
editor: 'auto',
tools: {
status: 'full',
},
};

<LiveCodes config={selfConfig}></LiveCodes>

### Output

The program runs on the [result page](../features/result.mdx). Anything it writes with `print` or
`printLine` is captured and shown in the [console](../features/console.mdx). When the final
expression prints nothing, its value is shown as `=> value`, as in a Self REPL.

```self
'Hello, World!' printLine.
1 + 2.
```

### Standard I/O

The text passed as `livecodes.self.input` is available in the Self lobby as the `stdin` string slot.
It can be parsed with `asInteger` or `asFloat`:

```self
'Self' printLine.
(stdin asInteger + 1) printLine.
```

Set `livecodes.self.input` before the program runs, or pass the new input to
`livecodes.self.run(input)`.

### Communication with JavaScript

A few helper properties and methods are available in the browser global `livecodes.self` object:

- `livecodes.self.input`: the standard input passed to the program.
- `livecodes.self.loaded`: a promise that resolves when the interpreter has loaded and the program
has run once. It rejects if the runtime fails to load. Other helpers should be used after it
resolves.
- `livecodes.self.output`: the program's output.
- `livecodes.self.error`: the error message, if the program failed.
- `livecodes.self.exitCode`: the evaluation status (`0` ok, `1` Self parse or runtime error).
- `livecodes.self.run(input)`: runs the code again with new input, returning a promise that resolves
to `{ output, error, exitCode }`.

Example:

<LiveCodes template="self" params={{ activeEditor: 'markup' }} height="80vh"></LiveCodes>

## Language Info

### Name

`self`

### Aliases / Extensions

`self`

### Editor

`script`

## Compiler

A TypeScript port of the
[pinneyja/self-interpreter](https://github.com/pinneyja/self-interpreter), packaged by
[@live-codes/self](https://www.npmjs.com/package/@live-codes/self). The parser, object model,
primitive methods and core Self world run as JavaScript; no WebAssembly or Pyodide is needed.

### Version

`@live-codes/self` 0.1.0.

## Code Formatting

Not currently supported.

## Starter Template

https://livecodes.io/?template=self

## Limitations

This is an educational implementation of the core language, not the official Self VM. The Morphic
GUI, the process scheduler and snapshots are not included, and integers are JavaScript numbers.

## Links

- [Self official website](https://selflanguage.org/)
- [Self source code](https://github.com/russellallen/self)
- [pinneyja/self-interpreter](https://github.com/pinneyja/self-interpreter)
- [@live-codes/self on npm](https://www.npmjs.com/package/@live-codes/self)
1 change: 1 addition & 0 deletions docs/src/components/LanguageSliders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export default function Sliders() {
{ name: 'fennel', title: 'Fennel' },
{ name: 'julia', title: 'Julia' },
{ name: 'io', title: 'Io' },
{ name: 'self', title: 'Self' },
{ name: 'tcl', title: 'Tcl' },
{ name: 'ada-wasm', title: 'Ada (Wasm)' },
{ name: 'pascal', title: 'Pascal' },
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 @@ -42,6 +42,7 @@ const templates = [
{ name: 'nim-wasm', title: 'Nim (Wasm) Starter', thumbnail: 'nim.svg' },
{ name: 'janet-wasm', title: 'Janet (Wasm) Starter', thumbnail: 'janet.png' },
{ name: 'io', title: 'Io Starter', thumbnail: 'io.svg' },
{ name: 'self', title: 'Self Starter', thumbnail: 'self.svg' },
{ name: 'python', title: 'Python Starter', thumbnail: 'python.svg' },
{ name: 'python-wasm', title: 'Python (Wasm) Starter', thumbnail: 'python.svg' },
{ name: 'r', title: 'R Starter', thumbnail: 'r.svg' },
Expand Down
48 changes: 48 additions & 0 deletions e2e/specs/starter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,32 @@ test.describe('Starter Templates from UI', () => {
await expect(getResult().locator('text=You clicked')).toHaveText('You clicked 3 times.');
});

test('self Starter', async ({ page, getTestUrl }) => {
// the Self interpreter boots its core world on the first run
test.slow();

await page.goto(getTestUrl());

const { app, getResult, waitForResultUpdate } = await getLoadedApp(page);

await app.click('[aria-label="Project"]');
await app.click('text=New');
await app.click('text="Self Starter"');

await waitForEditorFocus(app);
await waitForResultUpdate();

// the button stays disabled until the interpreter has loaded and run once
await expect(getResult().locator('#counter-button')).toBeEnabled({ timeout: 120_000 });

await getResult().click('text=Click me');
await getResult().click('text=Click me');
await getResult().click('text=Click me');

await expect(getResult().locator('h1')).toHaveText('Hello, Self!');
await expect(getResult().locator('text=You clicked')).toHaveText('You clicked 3 times.');
});

test('haskell Starter', async ({ page, getTestUrl }) => {
test.slow();

Expand Down Expand Up @@ -1497,6 +1523,28 @@ test.describe('Starter Templates from URL', () => {
await expect(getResult().locator('text=You clicked')).toHaveText('You clicked 3 times.');
});

test('self Starter (in URL)', async ({ page, getTestUrl }) => {
// the Self interpreter boots its core world on the first run
test.slow();

await page.goto(getTestUrl({ template: 'self' }));

const { app, getResult, waitForResultUpdate } = await getLoadedApp(page);

await waitForEditorFocus(app);
await waitForResultUpdate();

// the button stays disabled until the interpreter has loaded and run once
await expect(getResult().locator('#counter-button')).toBeEnabled({ timeout: 120_000 });

await getResult().click('text=Click me');
await getResult().click('text=Click me');
await getResult().click('text=Click me');

await expect(getResult().locator('h1')).toHaveText('Hello, Self!');
await expect(getResult().locator('text=You clicked')).toHaveText('You clicked 3 times.');
});

test('haskell Starter (in URL)', async ({ page, getTestUrl }) => {
test.slow();

Expand Down
1 change: 1 addition & 0 deletions functions/vendors/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const starterTemplates = {
"odin-wasm": "Odin Starter",
"janet-wasm": "Janet (Wasm) Starter",
"io": "Io Starter",
"self": "Self Starter",
"python": "Python Starter",
"python-wasm": "Python (Wasm) Starter",
"r": "R Starter",
Expand Down
1 change: 1 addition & 0 deletions scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ const iifeBuild = () =>
'languages/nim/lang-nim-wasm-script.ts',
'languages/janet-wasm/lang-janet-wasm-script.ts',
'languages/io/lang-io-script.ts',
'languages/self/lang-self-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',
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 @@ -44,6 +44,7 @@
"odin-wasm": "Odin Starter",
"janet-wasm": "Janet (Wasm) Starter",
"io": "Io Starter",
"self": "Self Starter",
"python": "Python Starter",
"python-wasm": "Python (Wasm) Starter",
"r": "R 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 @@ -298,6 +298,7 @@ export const getCommandMenuActions = ({
'nim-wasm',
'janet-wasm',
'io',
'self',
'python',
'python-wasm',
'r',
Expand Down
27 changes: 27 additions & 0 deletions src/livecodes/assets/templates/self.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions src/livecodes/html/language-info.html
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,39 @@ <h3 data-i18n="language-info:io.name">Io</h3>
</li>
</ul>
</section>
<section data-lang="self">
<h3 data-i18n="language-info:self.name">Self</h3>
<div data-i18n="language-info:self.desc" data-i18n-prop="innerHTML">
The <a href="https://selflanguage.org/" target="_blank" rel="noopener">Self</a> prototype-based
programming language, run in the browser by a TypeScript implementation of its interpreter.
Programs print to the console.
</div>
<ul data-i18n="language-info:self.link" data-i18n-prop="innerHTML">
<li>
<a href="https://selflanguage.org/" target="_blank" rel="noopener">Self official website</a>
</li>
<li>
<a href="https://github.com/russellallen/self" target="_blank" rel="noopener"
>Self GitHub repo</a
>
</li>
<li>
<a href="https://www.npmjs.com/package/@live-codes/self" target="_blank" rel="noopener"
>@live-codes/self on npm</a
>
</li>
<li>
<a href="{{DOCS_BASE_URL}}languages/self" target="_blank" rel="noopener"
>LiveCodes Documentation</a
>
</li>
<li>
<a href="?template=self" class="button" target="_parent" data-template="self"
>Load starter template</a
>
</li>
</ul>
</section>
<section data-lang="janet-wasm">
<h3 data-i18n="language-info:janetWasm.name">Janet (Wasm)</h3>
<div data-i18n="language-info:janetWasm.desc" data-i18n-prop="innerHTML">
Expand Down
9 changes: 9 additions & 0 deletions src/livecodes/i18n/locales/ar/language-info.lokalise.json
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,15 @@
"scss.name": {
"translation": "SCSS"
},
"self.desc": {
"translation": "لغة البرمجة <tag-1>Self</tag-1> القائمة على النماذج الأولية، تُشغَّل في المتصفح بواسطة تطبيق TypeScript لمفسّرها. تطبع البرامج ناتجها في وحدة التحكم."
},
"self.link": {
"translation": "<tag-1> <tag-2>الموقع الرسمي لـ Self</tag-2> </tag-1> <tag-3> <tag-4>مستودع Self على GitHub</tag-4> </tag-3> <tag-5> <tag-6>@live-codes/self على npm</tag-6> </tag-5> <tag-7> <tag-8>وثائق LiveCodes</tag-8> </tag-7> <tag-9> <tag-10>تحميل قالب البدء</tag-10> </tag-9>"
},
"self.name": {
"translation": "Self"
},
"solid.desc": {
"translation": "مكتبة JavaScript تصريحية وفعالة ومرنة لبناء واجهات المستخدم."
},
Expand Down
5 changes: 5 additions & 0 deletions src/livecodes/i18n/locales/ar/language-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,11 @@ const languageInfo: I18nLangInfoTranslation = {
link: '<1> <2>الموقع الرسمي لـ Sass</2> </1> <3> <4>وثائق Sass</4> </3> <5> <6>بناء جملة SCSS</6> </5> <7> <8>تعلم X في Y دقيقة، حيث X=sass</8> </7>',
name: 'SCSS',
},
self: {
desc: 'لغة البرمجة <1>Self</1> القائمة على النماذج الأولية، تُشغَّل في المتصفح بواسطة تطبيق TypeScript لمفسّرها. تطبع البرامج ناتجها في وحدة التحكم.',
link: '<1> <2>الموقع الرسمي لـ Self</2> </1> <3> <4>مستودع Self على GitHub</4> </3> <5> <6>@live-codes/self على npm</6> </5> <7> <8>وثائق LiveCodes</8> </7> <9> <10>تحميل قالب البدء</10> </9>',
name: 'Self',
},
solid: {
desc: 'مكتبة JavaScript تصريحية وفعالة ومرنة لبناء واجهات المستخدم.',
link: '<1><2>الموقع الرسمي</2></1> <3><4>الوثائق</4></3> <5> <6>وثائق LiveCodes</6> </5> <7> <8>تحميل قالب البداية (TSX)</8> </7>',
Expand Down
3 changes: 3 additions & 0 deletions src/livecodes/i18n/locales/ar/translation.lokalise.json
Original file line number Diff line number Diff line change
Expand Up @@ -2178,6 +2178,9 @@
"templates.starter.scheme": {
"translation": "قالب Scheme"
},
"templates.starter.self": {
"translation": "قالب Self"
},
"templates.starter.shadcnui": {
"translation": "قالب shadcn/ui"
},
Expand Down
1 change: 1 addition & 0 deletions src/livecodes/i18n/locales/ar/translation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,7 @@ const translation: I18nTranslation = {
'rust-wasm': 'قالب Rust (Wasm)',
scala: 'قالب Scala',
scheme: 'قالب Scheme',
self: 'قالب Self',
shadcnui: 'قالب shadcn/ui',
solid: 'قالب Solid',
sql: 'قالب SQL',
Expand Down
9 changes: 9 additions & 0 deletions src/livecodes/i18n/locales/bn/language-info.lokalise.json
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,15 @@
"scss.name": {
"translation": "SCSS"
},
"self.desc": {
"translation": "<tag-1>Self</tag-1> প্রোটোটাইপ-ভিত্তিক প্রোগ্রামিং ভাষা, যা এর ইন্টারপ্রেটারের একটি TypeScript বাস্তবায়ন দ্বারা ব্রাউজারে চালিত হয়। প্রোগ্রামগুলি কনসোলে আউটপুট প্রিন্ট করে।"
},
"self.link": {
"translation": "<tag-1> <tag-2>Self অফিসিয়াল ওয়েবসাইট</tag-2> </tag-1> <tag-3> <tag-4>GitHub-এ Self রিপো</tag-4> </tag-3> <tag-5> <tag-6>npm-এ @live-codes/self</tag-6> </tag-5> <tag-7> <tag-8>লাইভকোড ডকুমেন্টেশন</tag-8> </tag-7> <tag-9> <tag-10>স্টার্টার টেমপ্লেট লোড করুন</tag-10> </tag-9>"
},
"self.name": {
"translation": "Self"
},
"solid.desc": {
"translation": "ব্যবহারকারী ইন্টারফেস তৈরির জন্য একটি ঘোষণামূলক, দক্ষ এবং নমনীয় JavaScript লাইব্রেরি।"
},
Expand Down
5 changes: 5 additions & 0 deletions src/livecodes/i18n/locales/bn/language-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,11 @@ const languageInfo: I18nLangInfoTranslation = {
link: '<1> <2>Sass অফিসিয়াল ওয়েবসাইট</2> </1> <3> <4>Sass ডকুমেন্টেশন</4> </3> <5> <6>SCSS সিনট্যাক্স</6> </5> <7> <8>Y মিনিটে X শিখুন, যেখানে X=sass</8> </7>',
name: 'SCSS',
},
self: {
desc: '<1>Self</1> প্রোটোটাইপ-ভিত্তিক প্রোগ্রামিং ভাষা, যা এর ইন্টারপ্রেটারের একটি TypeScript বাস্তবায়ন দ্বারা ব্রাউজারে চালিত হয়। প্রোগ্রামগুলি কনসোলে আউটপুট প্রিন্ট করে।',
link: '<1> <2>Self অফিসিয়াল ওয়েবসাইট</2> </1> <3> <4>GitHub-এ Self রিপো</4> </3> <5> <6>npm-এ @live-codes/self</6> </5> <7> <8>লাইভকোড ডকুমেন্টেশন</8> </7> <9> <10>স্টার্টার টেমপ্লেট লোড করুন</10> </9>',
name: 'Self',
},
solid: {
desc: 'ব্যবহারকারী ইন্টারফেস তৈরির জন্য একটি ঘোষণামূলক, দক্ষ এবং নমনীয় JavaScript লাইব্রেরি।',
link: '<1><2>অফিসিয়াল ওয়েবসাইট</2></1> <3><4>ডকুমেন্টেশন</4></3> <5> <6>LiveCodes ডকুমেন্টেশন</6> </5> <7> <8>স্টার্টার টেমপ্লেট লোড করুন (TSX)</8> </7>',
Expand Down
Loading
Loading