-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
194 additions
and
28 deletions.
There are no files selected for viewing
This file contains 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 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,5 @@ | ||
import { runWorker } from "../application/run-worker.js"; | ||
import Worker from "./run/worker.js?worker"; | ||
|
||
export const run = async (source: string): Promise<Uint8Array<ArrayBuffer>> => | ||
runWorker(() => new Worker(), source); |
This file contains 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,8 @@ | ||
import init, { run } from "@raviqqe/stak"; | ||
import { handleWorkerMessage } from "../handle-worker-message"; | ||
|
||
const heapSize: number = 2 ** 20; | ||
|
||
handleWorkerMessage(init, (input: string) => | ||
run(input, new Uint8Array(), heapSize), | ||
); |
This file contains 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 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,10 @@ | ||
--- | ||
import { DemoForm } from "./CompilerDemo/DemoForm.jsx"; | ||
import { DemoIo } from "./CompilerDemo/DemoIo.jsx"; | ||
import Demo from "./Demo.astro"; | ||
--- | ||
|
||
<Demo> | ||
<DemoForm client:visible /> | ||
<DemoIo client:visible /> | ||
</Demo> |
File renamed without changes.
14 changes: 7 additions & 7 deletions
14
doc/src/components/DemoForm.tsx → doc/src/components/CompilerDemo/DemoForm.tsx
This file contains 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 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
12 changes: 6 additions & 6 deletions
12
doc/src/components/DemoIo.tsx → doc/src/components/CompilerDemo/DemoIo.tsx
This file contains 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 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 |
---|---|---|
@@ -1,10 +1,8 @@ | ||
--- | ||
import classNames from "classnames"; | ||
import styles from "./Demo.module.css"; | ||
import { DemoForm } from "./DemoForm.jsx"; | ||
import { DemoIo } from "./DemoIo.jsx"; | ||
--- | ||
|
||
<div class={styles.container}> | ||
<DemoForm client:visible /> | ||
<DemoIo client:visible /> | ||
<div class={classNames(styles.root, "not-content")}> | ||
<slot /> | ||
</div> |
This file contains 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 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,10 @@ | ||
--- | ||
import Demo from "./Demo.astro"; | ||
import { DemoForm } from "./InterpreterDemo/DemoForm.jsx"; | ||
import { DemoOutput } from "./InterpreterDemo/DemoOutput.jsx"; | ||
--- | ||
|
||
<Demo> | ||
<DemoForm client:visible /> | ||
<DemoOutput client:visible /> | ||
</Demo> |
This file contains 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,13 @@ | ||
.root { | ||
display: flex; | ||
flex-direction: column; | ||
min-height: 24rem; | ||
|
||
> * { | ||
flex: 1; | ||
} | ||
} | ||
|
||
.textArea { | ||
flex: 1; | ||
} |
This file contains 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,25 @@ | ||
import { useStore } from "@nanostores/solid"; | ||
import type { JSX } from "solid-js"; | ||
import * as store from "../../stores/interpreter-demo.js"; | ||
import { Field } from "../Field.jsx"; | ||
import { Label } from "../Label.jsx"; | ||
import { TextArea } from "../TextArea.jsx"; | ||
import styles from "./DemoForm.module.css"; | ||
|
||
export const DemoForm = (): JSX.Element => { | ||
const source = useStore(store.source); | ||
|
||
return ( | ||
<form class={styles.root}> | ||
<Field> | ||
<Label for="source">Program</Label> | ||
<TextArea | ||
class={styles.textArea} | ||
id="source" | ||
onChange={(source) => store.source.set(source)} | ||
value={source()} | ||
/> | ||
</Field> | ||
</form> | ||
); | ||
}; |
This file contains 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,18 @@ | ||
.root { | ||
display: flex; | ||
flex-direction: column; | ||
|
||
> * { | ||
flex: 1; | ||
} | ||
} | ||
|
||
.output { | ||
composes: textArea from "../../system.module.css"; | ||
flex: 1; | ||
margin: 0; | ||
|
||
> pre { | ||
margin: 0; | ||
} | ||
} |
This file contains 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,24 @@ | ||
import { useStore } from "@nanostores/solid"; | ||
import type { JSX } from "solid-js"; | ||
import * as store from "../../stores/interpreter-demo.js"; | ||
import { ErrorMessage } from "../ErrorMessage.js"; | ||
import { Field } from "../Field.jsx"; | ||
import { Label } from "../Label.jsx"; | ||
import styles from "./DemoOutput.module.css"; | ||
|
||
export const DemoOutput = (): JSX.Element => { | ||
const output = useStore(store.output); | ||
const error = useStore(store.error); | ||
|
||
return ( | ||
<div class={styles.root}> | ||
<Field> | ||
<Label for="output">Output</Label> | ||
<pre class={styles.output} id="output"> | ||
{output()} | ||
</pre> | ||
{error() && <ErrorMessage>{error()?.message}</ErrorMessage>} | ||
</Field> | ||
</div> | ||
); | ||
}; |
This file contains 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 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 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,10 @@ | ||
--- | ||
title: Interpreter demo | ||
description: Stak Scheme interpreter demo running on web browsers. | ||
--- | ||
|
||
import InterpreterDemo from "../../components/InterpreterDemo.astro"; | ||
|
||
Stak Scheme can run on many platforms including web browsers. The following is the demo of Stak Scheme built in WASM running on a web page. | ||
|
||
<InterpreterDemo /> |
This file contains 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
File renamed without changes.
This file contains 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,35 @@ | ||
import { atom, computed, task } from "nanostores"; | ||
import { run as runProgram } from "../application/run.js"; | ||
|
||
export const source = atom( | ||
` | ||
(import (scheme base) (scheme write)) | ||
(define (fibonacci x) | ||
(if (<= x 1) | ||
1 | ||
(+ (fibonacci (- x 1)) (fibonacci (- x 2))))) | ||
(display "Answer: ") | ||
(write (fibonacci 10)) | ||
(newline) | ||
`.trim(), | ||
); | ||
|
||
const run = computed(source, (source) => | ||
task(async () => { | ||
try { | ||
return await runProgram(source); | ||
} catch (error) { | ||
return error as Error; | ||
} | ||
}), | ||
); | ||
|
||
export const output = computed(run, (output) => | ||
output instanceof Error ? null : new TextDecoder().decode(output), | ||
); | ||
|
||
export const error = computed(run, (error) => | ||
error instanceof Error ? error : null, | ||
); |
This file contains 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