From ba7326eecbae5f090ba5cdb27e35b5fbe76626a3 Mon Sep 17 00:00:00 2001 From: Ben Taylor Date: Sun, 11 Dec 2022 09:11:17 +1100 Subject: [PATCH] WIP Trealla implementation --- packages/host/src/index.ts | 3 +++ packages/host/src/types.ts | 13 +++++++++++-- packages/runtime/src/provider.ts | 13 ++++++++++++- packages/website/src/components/form.ts | 1 + packages/website/src/examples.ts | 9 +++++++++ packages/website/src/pages/docs.ts | 8 ++++++++ 6 files changed, 44 insertions(+), 3 deletions(-) diff --git a/packages/host/src/index.ts b/packages/host/src/index.ts index 9b006456..c17d07b2 100644 --- a/packages/host/src/index.ts +++ b/packages/host/src/index.ts @@ -56,6 +56,9 @@ export function runtimeToSyntax(runtime: string | undefined | null): Syntax { if (runtime == "ruby") { return "ruby"; } + if (runtime == "trealla") { + return "prolog"; + } return undefined; } diff --git a/packages/host/src/types.ts b/packages/host/src/types.ts index aa33f9b5..ff476ed3 100644 --- a/packages/host/src/types.ts +++ b/packages/host/src/types.ts @@ -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; diff --git a/packages/runtime/src/provider.ts b/packages/runtime/src/provider.ts index c91d7bcb..03d9689e 100644 --- a/packages/runtime/src/provider.ts +++ b/packages/runtime/src/provider.ts @@ -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: [ @@ -110,7 +116,12 @@ export class RunnoProvider implements RuntimeMethods { return Promise.resolve(this.editor.program); } - interactiveRunCode(runtime: Runtime, code: string): Promise { + async interactiveRunCode(runtime: Runtime, code: string): Promise { + 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 }, }); diff --git a/packages/website/src/components/form.ts b/packages/website/src/components/form.ts index c0daf4a5..b2acb60a 100644 --- a/packages/website/src/components/form.ts +++ b/packages/website/src/components/form.ts @@ -117,6 +117,7 @@ export class WebsiteForm extends TailwindElement { + diff --git a/packages/website/src/examples.ts b/packages/website/src/examples.ts index aa0f8080..0cb6089d 100644 --- a/packages/website/src/examples.ts +++ b/packages/website/src/examples.ts @@ -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; @@ -84,5 +89,9 @@ export function exampleForRuntime(name: Runtime): string { return ruby; } + if (name == "trealla") { + return trealla; + } + return ""; } diff --git a/packages/website/src/pages/docs.ts b/packages/website/src/pages/docs.ts index 6072c3bb..405fbbd8 100644 --- a/packages/website/src/pages/docs.ts +++ b/packages/website/src/pages/docs.ts @@ -538,6 +538,14 @@ Cross-Origin-Embedder-Policy: require-corp clangpp - Compiles and runs C++ code using the same llvm fork. +
  • + trealla - Runs Prolog using the + Trealla implementation. +