Skip to content
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

Draft Trealla/Prolog Implementation #215

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 3 additions & 0 deletions packages/host/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ export function runtimeToSyntax(runtime: string | undefined | null): Syntax {
if (runtime == "ruby") {
return "ruby";
}
if (runtime == "trealla") {
return "prolog";
}
return undefined;
}

Expand Down
13 changes: 11 additions & 2 deletions packages/host/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,17 @@ export type Runtime =
| "sqlite"
| "clang"
| "clangpp"
| "ruby";
export type Syntax = "python" | "js" | "sql" | "cpp" | "ruby" | undefined;
| "ruby"
| "trealla";

export type Syntax =
| "python"
| "js"
| "sql"
| "cpp"
| "ruby"
| "prolog"
| undefined;

export type CommandResult = {
stdin: string;
Expand Down
13 changes: 12 additions & 1 deletion packages/runtime/src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ function commandsForRuntime(name: string, entryPath: string): RuntimeCommands {
return { run: `cat ${entryPath} | sqlite` };
}

if (name === "trealla") {
return {
run: `tpl --library / --trace -g main,halt -f ${entryPath}`,
};
}

if (name === "clang") {
return {
prepare: [
Expand Down Expand Up @@ -110,7 +116,12 @@ export class RunnoProvider implements RuntimeMethods {
return Promise.resolve(this.editor.program);
}

interactiveRunCode(runtime: Runtime, code: string): Promise<RunResult> {
async interactiveRunCode(runtime: Runtime, code: string): Promise<RunResult> {
if (runtime === "trealla") {
return await this.interactiveRunFS(runtime, "program.pl", {
"program.pl": { name: "program.pl", content: code },
});
}
return this.interactiveRunFS(runtime, "program", {
program: { name: "program", content: code },
});
Expand Down
1 change: 1 addition & 0 deletions packages/website/src/components/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export class WebsiteForm extends TailwindElement {
<option value="sqlite">SQL (SQLite)</option>
<option value="clang">C (clang)</option>
<option value="clangpp">C++ (clang)</option>
<option value="trealla">Prolog (Trealla)</option>
</select>
</label>

Expand Down
9 changes: 9 additions & 0 deletions packages/website/src/examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ SELECT "Hello, World!";
SELECT "G'day, welcome to Runno.";
`.trimStart();

const trealla = `
main :-
write('hello world').
`.trimStart();

export function exampleForRuntime(name: Runtime): string {
if (name == "sqlite") {
return sqlite;
Expand All @@ -84,5 +89,9 @@ export function exampleForRuntime(name: Runtime): string {
return ruby;
}

if (name == "trealla") {
return trealla;
}

return "";
}
8 changes: 8 additions & 0 deletions packages/website/src/pages/docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,14 @@ Cross-Origin-Embedder-Policy: require-corp</code></pre>
<code>clangpp</code> - Compiles and runs C++ code using the same
llvm fork.
</li>
<li>
<code>trealla</code> - Runs Prolog using the
<a
target="_blank"
href="https://github.com/trealla-prolog/trealla"
>Trealla implementation</a
>.
</li>
</ul>

<p>
Expand Down