From a667e46f60e06ab0481f83bcb62b4e1dce32fb99 Mon Sep 17 00:00:00 2001 From: Patrick Date: Thu, 31 Oct 2024 09:05:35 +0000 Subject: [PATCH 1/7] Remove $ get/set syntax Fixes #50 Remove `$` get/set syntax from Insitux. * Remove `$` syntax handling from `getExe` and `exeOp` functions in `src/index.ts`. * Remove `$` syntax handling from `set`, `get`, and `exe` functions in `src/web.ts`. * Remove mention of `$` get/set syntax from `README.md`. * Remove tests related to `$` syntax in `src/test.ts`. * Bump version to 24.10.30 in `package.json` and `package-lock.json`. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/phunanon/Insitux/issues/50?shareId=XXXX-XXXX-XXXX-XXXX). --- README.md | 22 ---------------------- package-lock.json | 15 ++++++++++++--- package.json | 2 +- src/index.ts | 28 +--------------------------- src/test.ts | 5 ----- src/web.ts | 20 -------------------- 6 files changed, 14 insertions(+), 78 deletions(-) diff --git a/README.md b/README.md index 62c117e..4180867 100644 --- a/README.md +++ b/README.md @@ -113,18 +113,6 @@ set-timeout set-interval ## Coding in Insitux -Like any programming language it is written down as _code_. Insitux takes your -code and follows it like complex instructions. -You and the Insitux app talk to each other in these ways: - -| what | direction of data | example | -| ------ | ------------------------ | ----------------------------- | -| code | goes into the app | `(+ 2 2)` | -| return | comes out of the app | `4` | -| set | writes data | `($day.cycle_speed 100)` | -| get | reads data | `$day.cycle_speed` | -| exe | data goes both in an out | `(util.fire [0 0 0] [0 1 0])` | - ### Writing the code Most code is written as _expressions_ like `(+ 2 2)`. As you can see, values are @@ -1138,16 +1126,6 @@ It can also be used as an identity function (i.e. `val`). - Parameters take precedence over lets, vars, and functions. -- Insitux implementations are advised to support this behaviour: - -```clj -($test.ing 123) → 123 -$test.ing → 123 -(ing "$test") → 123 -(ing "$test" 456) → 456 -$test.ing → 456 -``` - ### Functions **Named functions** diff --git a/package-lock.json b/package-lock.json index f47a871..5205648 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "insitux", - "version": "24.10.21", + "version": "24.10.30", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "insitux", - "version": "23.10.29", + "version": "24.10.30", "license": "MIT", "dependencies": { "prompt-sync": "^4.2.0" @@ -2789,7 +2789,10 @@ "version": "2.2.0", "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz", "integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==", - "dev": true + "dev": true, + "engines": { + "node": ">=6" + } }, "path-exists": { "version": "4.0.0", @@ -2966,6 +2969,9 @@ "integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==", "requires": { "ansi-regex": "^4.1.0" + }, + "engines": { + "node": ">=6" } }, "supports-color": { @@ -3053,6 +3059,9 @@ "requires": { "glob-to-regexp": "^0.4.1", "graceful-fs": "^4.1.2" + }, + "engines": { + "node": ">=10.13.0" } }, "webpack": { diff --git a/package.json b/package.json index d8ae807..27b68a4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "insitux", - "version": "24.10.21", + "version": "24.10.30", "description": "Extensible scripting language written in portable TypeScript.", "main": "dist/invoker.js", "types": "dist/invoker.d.ts", diff --git a/src/index.ts b/src/index.ts index 666e43d..f280142 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,4 @@ -export const insituxVersion = 241021; +export const insituxVersion = 241030; import { asBoo } from "./checks"; import { arityCheck, keyOpErr, numOpErr, typeCheck, typeErr } from "./checks"; import { isLetter, isDigit, isSpace, isPunc } from "./checks"; @@ -1417,22 +1417,6 @@ function getExe( if (name in ctx.env.vars) { return getExe(ctx, ctx.env.vars[name], errCtx); } - if (starts(name, "$")) { - return (params: Val[]) => { - if (!len(params)) { - _throw(monoArityError(op.t, errCtx)); - } - if (!ctx.set) { - const m = `"set" feature not implemented on this platform`; - return _throw([{ e: "External", m, errCtx }]); - } - const err = ctx.set(substr(name, 1), params[0]); - if (err) { - _throw([{ e: "External", m: err, errCtx }]); - } - return params[0]; - }; - } return (params: Val[]) => { if (!ctx.exe) { const m = `operation "${name}" does not exist"`; @@ -1648,16 +1632,6 @@ function exeFunc( stack.push(ctx.env.vars[name]); } else if (name in ctx.env.funcs) { stack.push(_fun(name)); - } else if (starts(name, "$")) { - if (!ctx.get) { - const m = `"get" feature not implemented on this platform`; - return _throw([{ e: "External", m, errCtx }]); - } - const valAndErr = ctx.get(substr(name, 1)); - if ("err" in valAndErr) { - return _throw([{ e: "External", m: valAndErr.err, errCtx }]); - } - stack.push(valAndErr); } else { _throw([{ e: "Reference", m: `"${name}" did not exist`, errCtx }]); } diff --git a/src/test.ts b/src/test.ts index 3fb75d5..241b9e6 100644 --- a/src/test.ts +++ b/src/test.ts @@ -501,11 +501,6 @@ const tests: { out: `{"1" 4, "2" 4}`, }, //Test environment functions - { - name: "set get", - code: `[($globals.time_offset 5.5) $globals.time_offset]`, - out: `[5.5 5.5]`, - }, { name: "exe", code: `(test.function 123)`, out: `123\nnull` }, //Syntax errors { name: "Empty parens", code: `()`, err: ["Parse"] }, diff --git a/src/web.ts b/src/web.ts index 73c958c..021b39b 100644 --- a/src/web.ts +++ b/src/web.ts @@ -3,25 +3,7 @@ import { Ctx, defaultCtx, ExternalFunctions, Val, ValOrErr } from "./types"; import { num, str, val2str, _nul, _str, _num, _boo } from "./val"; import { jsToIx } from "./val-translate"; -let state = new Map(); - -const get = (key: string): ValOrErr => - state.has(key) ? state.get(key)! : _nul(); -const set = (key: string, val: Val) => { - state.set(key, val); - localStorage.setItem("insitux-state", JSON.stringify([...state.entries()])); - return undefined; -}; - function exe(name: string, args: Val[]): ValOrErr { - if (args.length && args[0].t == "str" && args[0].v.startsWith("$")) { - if (args.length === 1) { - return get(`${args[0].v.substring(1)}.${name}`); - } else { - set(`${args[0].v.substring(1)}.${name}`, args[1]); - return args[1]; - } - } return { err: `operation ${name} does not exist` }; } @@ -253,8 +235,6 @@ const loadScript = async (scriptEl: HTMLScriptElement) => { }; window.onload = async () => { - const savedState = localStorage.getItem("insitux-state"); - state = new Map(savedState ? JSON.parse(savedState) : []); const scripts = Array.from(document.querySelectorAll("script")).filter( el => el.type === "text/insitux", ); From 34e6d5b12399f19396d47745ea2670fe5e5a6c71 Mon Sep 17 00:00:00 2001 From: Patrick Date: Thu, 31 Oct 2024 09:13:09 +0000 Subject: [PATCH 2/7] * **src/types.ts** - Remove any get/set API --- README.md | 22 ---------------------- package-lock.json | 15 ++++++++++++--- package.json | 2 +- src/index.ts | 28 +--------------------------- src/test.ts | 5 ----- src/types.ts | 5 ----- src/web.ts | 20 -------------------- 7 files changed, 14 insertions(+), 83 deletions(-) diff --git a/README.md b/README.md index 62c117e..4180867 100644 --- a/README.md +++ b/README.md @@ -113,18 +113,6 @@ set-timeout set-interval ## Coding in Insitux -Like any programming language it is written down as _code_. Insitux takes your -code and follows it like complex instructions. -You and the Insitux app talk to each other in these ways: - -| what | direction of data | example | -| ------ | ------------------------ | ----------------------------- | -| code | goes into the app | `(+ 2 2)` | -| return | comes out of the app | `4` | -| set | writes data | `($day.cycle_speed 100)` | -| get | reads data | `$day.cycle_speed` | -| exe | data goes both in an out | `(util.fire [0 0 0] [0 1 0])` | - ### Writing the code Most code is written as _expressions_ like `(+ 2 2)`. As you can see, values are @@ -1138,16 +1126,6 @@ It can also be used as an identity function (i.e. `val`). - Parameters take precedence over lets, vars, and functions. -- Insitux implementations are advised to support this behaviour: - -```clj -($test.ing 123) → 123 -$test.ing → 123 -(ing "$test") → 123 -(ing "$test" 456) → 456 -$test.ing → 456 -``` - ### Functions **Named functions** diff --git a/package-lock.json b/package-lock.json index f47a871..5205648 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "insitux", - "version": "24.10.21", + "version": "24.10.30", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "insitux", - "version": "23.10.29", + "version": "24.10.30", "license": "MIT", "dependencies": { "prompt-sync": "^4.2.0" @@ -2789,7 +2789,10 @@ "version": "2.2.0", "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz", "integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==", - "dev": true + "dev": true, + "engines": { + "node": ">=6" + } }, "path-exists": { "version": "4.0.0", @@ -2966,6 +2969,9 @@ "integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==", "requires": { "ansi-regex": "^4.1.0" + }, + "engines": { + "node": ">=6" } }, "supports-color": { @@ -3053,6 +3059,9 @@ "requires": { "glob-to-regexp": "^0.4.1", "graceful-fs": "^4.1.2" + }, + "engines": { + "node": ">=10.13.0" } }, "webpack": { diff --git a/package.json b/package.json index d8ae807..27b68a4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "insitux", - "version": "24.10.21", + "version": "24.10.30", "description": "Extensible scripting language written in portable TypeScript.", "main": "dist/invoker.js", "types": "dist/invoker.d.ts", diff --git a/src/index.ts b/src/index.ts index 666e43d..f280142 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,4 @@ -export const insituxVersion = 241021; +export const insituxVersion = 241030; import { asBoo } from "./checks"; import { arityCheck, keyOpErr, numOpErr, typeCheck, typeErr } from "./checks"; import { isLetter, isDigit, isSpace, isPunc } from "./checks"; @@ -1417,22 +1417,6 @@ function getExe( if (name in ctx.env.vars) { return getExe(ctx, ctx.env.vars[name], errCtx); } - if (starts(name, "$")) { - return (params: Val[]) => { - if (!len(params)) { - _throw(monoArityError(op.t, errCtx)); - } - if (!ctx.set) { - const m = `"set" feature not implemented on this platform`; - return _throw([{ e: "External", m, errCtx }]); - } - const err = ctx.set(substr(name, 1), params[0]); - if (err) { - _throw([{ e: "External", m: err, errCtx }]); - } - return params[0]; - }; - } return (params: Val[]) => { if (!ctx.exe) { const m = `operation "${name}" does not exist"`; @@ -1648,16 +1632,6 @@ function exeFunc( stack.push(ctx.env.vars[name]); } else if (name in ctx.env.funcs) { stack.push(_fun(name)); - } else if (starts(name, "$")) { - if (!ctx.get) { - const m = `"get" feature not implemented on this platform`; - return _throw([{ e: "External", m, errCtx }]); - } - const valAndErr = ctx.get(substr(name, 1)); - if ("err" in valAndErr) { - return _throw([{ e: "External", m: valAndErr.err, errCtx }]); - } - stack.push(valAndErr); } else { _throw([{ e: "Reference", m: `"${name}" did not exist`, errCtx }]); } diff --git a/src/test.ts b/src/test.ts index 3fb75d5..241b9e6 100644 --- a/src/test.ts +++ b/src/test.ts @@ -501,11 +501,6 @@ const tests: { out: `{"1" 4, "2" 4}`, }, //Test environment functions - { - name: "set get", - code: `[($globals.time_offset 5.5) $globals.time_offset]`, - out: `[5.5 5.5]`, - }, { name: "exe", code: `(test.function 123)`, out: `123\nnull` }, //Syntax errors { name: "Empty parens", code: `()`, err: ["Parse"] }, diff --git a/src/types.ts b/src/types.ts index c002beb..dcfb38a 100644 --- a/src/types.ts +++ b/src/types.ts @@ -41,11 +41,6 @@ export type Env = { /** A context supplied with an Insitux invocation to provide its environment. */ export type Ctx = { - /** Called to set an external variable, returning nothing or an error. */ - set?: (key: string, val: Val) => undefined | string; - /** Called to retrieve an external variable, - * returning the value or an error. */ - get?: (key: string) => ValOrErr; /** Called to print data out of Insitux. */ print: (str: string, withNewline: boolean) => void; /** Extra function definitions to make available within this invocation */ diff --git a/src/web.ts b/src/web.ts index 73c958c..021b39b 100644 --- a/src/web.ts +++ b/src/web.ts @@ -3,25 +3,7 @@ import { Ctx, defaultCtx, ExternalFunctions, Val, ValOrErr } from "./types"; import { num, str, val2str, _nul, _str, _num, _boo } from "./val"; import { jsToIx } from "./val-translate"; -let state = new Map(); - -const get = (key: string): ValOrErr => - state.has(key) ? state.get(key)! : _nul(); -const set = (key: string, val: Val) => { - state.set(key, val); - localStorage.setItem("insitux-state", JSON.stringify([...state.entries()])); - return undefined; -}; - function exe(name: string, args: Val[]): ValOrErr { - if (args.length && args[0].t == "str" && args[0].v.startsWith("$")) { - if (args.length === 1) { - return get(`${args[0].v.substring(1)}.${name}`); - } else { - set(`${args[0].v.substring(1)}.${name}`, args[1]); - return args[1]; - } - } return { err: `operation ${name} does not exist` }; } @@ -253,8 +235,6 @@ const loadScript = async (scriptEl: HTMLScriptElement) => { }; window.onload = async () => { - const savedState = localStorage.getItem("insitux-state"); - state = new Map(savedState ? JSON.parse(savedState) : []); const scripts = Array.from(document.querySelectorAll("script")).filter( el => el.type === "text/insitux", ); From c2fa7ae41b6dc1487d615add1e0c489fba4c9ea6 Mon Sep 17 00:00:00 2001 From: Patrick Date: Thu, 31 Oct 2024 09:17:26 +0000 Subject: [PATCH 3/7] * **src/test.ts** - Remove tests related to `$` - Remove getters/setters --- src/test.ts | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/src/test.ts b/src/test.ts index 241b9e6..504aff7 100644 --- a/src/test.ts +++ b/src/test.ts @@ -1,19 +1,7 @@ import { concat, round, getTimeMs, len, padEnd, trim } from "./poly-fills"; import { Ctx, Env, Val, ValOrErr, InvokeResult } from "./types"; -type State = { dict: Map; output: string }; - -function get(state: State, key: string): ValOrErr { - if (!state.dict.has(key)) { - return { err: `"${key}" not found.` }; - } - return state.dict.get(key)!; -} - -function set(state: State, key: string, val: Val): string | undefined { - state.dict.set(key, val); - return undefined; -} +type State = { output: string }; function exe(state: State, name: string, args: Val[]): ValOrErr { const nullVal: Val = { t: "null", v: undefined }; @@ -564,16 +552,11 @@ export function doTests( }[] = []; for (let t = 0; t < len(tests); ++t) { const { name, code, err, out } = tests[t]; - const state: State = { - dict: new Map(), - output: "", - }; + const state: State = { output: "" }; const env: Env = { funcs: {}, vars: {}, mocks: {} }; const startTime = getTimeMs(); const valOrErrs = invoke( { - get: (key: string) => get(state, key), - set: (key: string, val: Val) => set(state, key, val), print: (str, withNewLine) => { state.output += str + (withNewLine ? "\n" : ""); }, From 5d5a12706f6594530cf120eceda8b6203276ccc6 Mon Sep 17 00:00:00 2001 From: Patrick Date: Thu, 31 Oct 2024 09:23:13 +0000 Subject: [PATCH 4/7] Finish off what Copilot was too dumb to do --- src/test.ts | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/src/test.ts b/src/test.ts index 241b9e6..504aff7 100644 --- a/src/test.ts +++ b/src/test.ts @@ -1,19 +1,7 @@ import { concat, round, getTimeMs, len, padEnd, trim } from "./poly-fills"; import { Ctx, Env, Val, ValOrErr, InvokeResult } from "./types"; -type State = { dict: Map; output: string }; - -function get(state: State, key: string): ValOrErr { - if (!state.dict.has(key)) { - return { err: `"${key}" not found.` }; - } - return state.dict.get(key)!; -} - -function set(state: State, key: string, val: Val): string | undefined { - state.dict.set(key, val); - return undefined; -} +type State = { output: string }; function exe(state: State, name: string, args: Val[]): ValOrErr { const nullVal: Val = { t: "null", v: undefined }; @@ -564,16 +552,11 @@ export function doTests( }[] = []; for (let t = 0; t < len(tests); ++t) { const { name, code, err, out } = tests[t]; - const state: State = { - dict: new Map(), - output: "", - }; + const state: State = { output: "" }; const env: Env = { funcs: {}, vars: {}, mocks: {} }; const startTime = getTimeMs(); const valOrErrs = invoke( { - get: (key: string) => get(state, key), - set: (key: string, val: Val) => set(state, key, val), print: (str, withNewLine) => { state.output += str + (withNewLine ? "\n" : ""); }, From 3df5cb3aee15a02a1f2a6fd415456f97fdb15503 Mon Sep 17 00:00:00 2001 From: Patrick Date: Thu, 31 Oct 2024 09:29:56 +0000 Subject: [PATCH 5/7] Even more clean-up, actually trying to compile it in a Codespace How civilised --- src/repl.ts | 29 ----------------------------- src/web.ts | 2 -- 2 files changed, 31 deletions(-) diff --git a/src/repl.ts b/src/repl.ts index dda1c4a..b5cd448 100644 --- a/src/repl.ts +++ b/src/repl.ts @@ -348,42 +348,13 @@ function makeFunctions( //#endregion //#region Context -const env = new Map(); - -function get(key: string): ValOrErr { - return env.has(key) ? env.get(key)! : { err: `key ${key} not found` }; -} - -function set(key: string, val: Val) { - env.set(key, val); - return undefined; -} - const ctx: Ctx = { ...defaultCtx, - get, - set, functions: {}, print(str, withNewLine) { process.stdout.write(`\x1b[32m${str}\x1b[0m${withNewLine ? "\n" : ""}`); }, - exe, }; - -function exe(name: string, args: Val[]): ValOrErr { - if (args.length) { - const a = args[0]; - if (a.t === "str" && a.v.startsWith("$")) { - if (args.length === 1) { - return get(`${a.v.substring(1)}.${name}`); - } else { - set(`${a.v.substring(1)}.${name}`, args[1]); - return args[1]; - } - } - } - return { err: `operation "${name}" does not exist` }; -} //#endregion //#region REPL IO diff --git a/src/web.ts b/src/web.ts index 021b39b..003e5ee 100644 --- a/src/web.ts +++ b/src/web.ts @@ -221,8 +221,6 @@ const functions: ExternalFunctions = { const ctx: Ctx = { ...defaultCtx, exe, - get, - set, print: str => console.log(str), functions, }; From 01e6e8b3abb53c7a4d1a9e9aa0e6f4b57506cde4 Mon Sep 17 00:00:00 2001 From: Patrick Date: Thu, 31 Oct 2024 09:56:19 +0000 Subject: [PATCH 6/7] Ensure we're still able to use local storage in web by updating web-example.html --- integrations/web-example.html | 8 ++++++-- src/web.ts | 5 ----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/integrations/web-example.html b/integrations/web-example.html index 15aec0d..9b84371 100644 --- a/integrations/web-example.html +++ b/integrations/web-example.html @@ -4,9 +4,13 @@ Example - + diff --git a/src/web.ts b/src/web.ts index 003e5ee..83ffe84 100644 --- a/src/web.ts +++ b/src/web.ts @@ -3,10 +3,6 @@ import { Ctx, defaultCtx, ExternalFunctions, Val, ValOrErr } from "./types"; import { num, str, val2str, _nul, _str, _num, _boo } from "./val"; import { jsToIx } from "./val-translate"; -function exe(name: string, args: Val[]): ValOrErr { - return { err: `operation ${name} does not exist` }; -} - const invokeFunction = (ctx: Ctx, name: string, args: Val[]) => { alertErrors(functionInvoker(ctx, name, args, false)); }; @@ -220,7 +216,6 @@ const functions: ExternalFunctions = { const ctx: Ctx = { ...defaultCtx, - exe, print: str => console.log(str), functions, }; From 5ee0870373bc4daed4e4b60641bd1fb4921289cc Mon Sep 17 00:00:00 2001 From: Patrick Date: Thu, 7 Nov 2024 10:24:30 +0000 Subject: [PATCH 7/7] Update web-example.html remove a space --- integrations/web-example.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integrations/web-example.html b/integrations/web-example.html index 9b84371..3c73458 100644 --- a/integrations/web-example.html +++ b/integrations/web-example.html @@ -8,7 +8,7 @@