From bc2d65e668a93f96545c1abddc38875a9e4d7a74 Mon Sep 17 00:00:00 2001 From: Peter Date: Mon, 10 Oct 2022 18:53:05 +0200 Subject: [PATCH] start universal entrypoint stuff --- editor/package-lock.json | 22 + editor/package.json | 1 + editor/public/saved.json | 952 +++++++--------------- editor/rollup.config.js | 143 ++-- editor/src/main.js | 1 + editor/src/other.js | 19 + eyg/src/eyg/analysis.gleam | 4 + eyg/src/eyg/ast/encode.gleam | 5 +- eyg/src/eyg/entry.gleam | 46 ++ eyg/src/eyg/interpreter/effectful.gleam | 16 + eyg/src/eyg/interpreter/interpreter.gleam | 4 +- 11 files changed, 510 insertions(+), 703 deletions(-) create mode 100644 editor/src/other.js create mode 100644 eyg/src/eyg/entry.gleam diff --git a/editor/package-lock.json b/editor/package-lock.json index a18bf4384..15d60113b 100644 --- a/editor/package-lock.json +++ b/editor/package-lock.json @@ -12,6 +12,7 @@ }, "devDependencies": { "@rollup/plugin-commonjs": "^17.0.0", + "@rollup/plugin-json": "^4.1.0", "@rollup/plugin-node-resolve": "^11.0.0", "rollup": "^2.3.4", "rollup-plugin-css-only": "^3.1.0", @@ -82,6 +83,18 @@ "rollup": "^2.30.0" } }, + "node_modules/@rollup/plugin-json": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/@rollup/plugin-json/-/plugin-json-4.1.0.tgz", + "integrity": "sha512-yfLbTdNS6amI/2OpmbiBoW12vngr5NW2jCJVZSBEz+H5KfUJZ2M7sDjk0U6GOOdCWFVScShte29o9NezJ53TPw==", + "dev": true, + "dependencies": { + "@rollup/pluginutils": "^3.0.8" + }, + "peerDependencies": { + "rollup": "^1.20.0 || ^2.0.0" + } + }, "node_modules/@rollup/plugin-node-resolve": { "version": "11.2.1", "resolved": "https://registry.npmjs.org/@rollup/plugin-node-resolve/-/plugin-node-resolve-11.2.1.tgz", @@ -1087,6 +1100,15 @@ "resolve": "^1.17.0" } }, + "@rollup/plugin-json": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/@rollup/plugin-json/-/plugin-json-4.1.0.tgz", + "integrity": "sha512-yfLbTdNS6amI/2OpmbiBoW12vngr5NW2jCJVZSBEz+H5KfUJZ2M7sDjk0U6GOOdCWFVScShte29o9NezJ53TPw==", + "dev": true, + "requires": { + "@rollup/pluginutils": "^3.0.8" + } + }, "@rollup/plugin-node-resolve": { "version": "11.2.1", "resolved": "https://registry.npmjs.org/@rollup/plugin-node-resolve/-/plugin-node-resolve-11.2.1.tgz", diff --git a/editor/package.json b/editor/package.json index 07400ffc7..2ba40ccbd 100644 --- a/editor/package.json +++ b/editor/package.json @@ -9,6 +9,7 @@ }, "devDependencies": { "@rollup/plugin-commonjs": "^17.0.0", + "@rollup/plugin-json": "^4.1.0", "@rollup/plugin-node-resolve": "^11.0.0", "rollup": "^2.3.4", "rollup-plugin-css-only": "^3.1.0", diff --git a/editor/public/saved.json b/editor/public/saved.json index 901588894..ffa20a566 100644 --- a/editor/public/saved.json +++ b/editor/public/saved.json @@ -2698,17 +2698,12 @@ "value": { "node": "Function", "pattern": { - "node": "Tuple", - "elements": [ - { - "node": "Bind", - "label": "" - } - ] + "node": "Variable", + "label": "state" }, "body": { - "node": "Binary", - "value": "hello" + "node": "Variable", + "label": "state" } }, "then": { @@ -2921,13 +2916,8 @@ "label": "new" }, "value": { - "node": "Tuple", - "elements": [ - { - "node": "Variable", - "label": "old" - } - ] + "node": "Variable", + "label": "old" }, "then": { "node": "Call", @@ -2943,572 +2933,157 @@ } }, "then": { - "node": "Record", - "fields": [ - { - "node": "Field", - "key": "init", - "value": { - "node": "Call", - "function": { - "node": "Variable", - "label": "run" - }, - "with": { - "node": "Tuple", - "elements": [ - { - "node": "Binary", - "value": "" - } - ] - } - } - }, - { - "node": "Field", - "key": "release", - "value": { - "node": "Variable", - "label": "release" - } - } - ] - } - } - } - }, - "then": { - "node": "Let", - "pattern": { - "node": "Variable", - "label": "reload" - }, - "value": { - "node": "Function", - "pattern": { - "node": "Tuple", - "elements": [] - }, - "body": { - "node": "Let", - "pattern": { - "node": "Variable", - "label": "release" - }, - "value": { - "node": "Function", + "node": "Let", "pattern": { "node": "Variable", - "label": "old" + "label": "init" }, - "body": { - "node": "Let", - "pattern": { - "node": "Tuple", - "elements": [] - }, - "value": { - "node": "Variable", - "label": "old" - }, - "then": { - "node": "Let", - "pattern": { - "node": "Variable", - "label": "new" - }, - "value": { - "node": "Tuple", - "elements": [ - { - "node": "Variable", - "label": "old" - } - ] - }, - "then": { - "node": "Let", - "pattern": { - "node": "Variable", - "label": "run" - }, + "value": { + "node": "Record", + "fields": [ + { + "node": "Field", + "key": "page", "value": { - "node": "Function", - "pattern": { - "node": "Variable", - "label": "state" - }, - "body": { - "node": "Function", - "pattern": { - "node": "Variable", - "label": "interrupt" - }, - "body": { - "node": "Case", - "value": { - "node": "Variable", - "label": "interrupt" - }, - "branches": [ - { - "node": "Branch", - "name": "Click", - "pattern": { - "node": "Variable", - "label": "target" - }, - "then": { - "node": "Let", - "pattern": { - "node": "Variable", - "label": "" - }, - "value": { - "node": "Call", - "function": { - "node": "Variable", - "label": "equal" - }, - "with": { - "node": "Tuple", - "elements": [ - { - "node": "Binary", - "value": "" - }, - { - "node": "Variable", - "label": "target" - } - ] - } - }, - "then": { - "node": "Record", - "fields": [ - { - "node": "Field", - "key": "page", - "value": { - "node": "Binary", - "value": "render" - } - }, - { - "node": "Field", - "key": "interrupt", - "value": { - "node": "Call", - "function": { - "node": "Variable", - "label": "run" - }, - "with": { - "node": "Variable", - "label": "state" - } - } - } - ] - } - } - }, - { - "node": "Branch", - "name": "Code", - "pattern": { - "node": "Variable", - "label": "source" - }, - "then": { - "node": "Case", - "value": { - "node": "Call", - "function": { - "node": "Provider", - "config": "", - "generator": "Loader" - }, - "with": { - "node": "Variable", - "label": "source" - } - }, - "branches": [ - { - "node": "Branch", - "name": "Error", - "pattern": { - "node": "Variable", - "label": "" - }, - "then": { - "node": "Hole" - } - }, - { - "node": "Branch", - "name": "OK", - "pattern": { - "node": "Variable", - "label": "release" - }, - "then": { - "node": "Call", - "function": { - "node": "Variable", - "label": "release" - }, - "with": { - "node": "Variable", - "label": "state" - } - } - } - ] - } - } - ] - } - } - }, - "then": { "node": "Call", "function": { "node": "Variable", - "label": "run" + "label": "render" }, "with": { - "node": "Variable", - "label": "new" + "node": "Binary", + "value": "initial state" } } - } - } - } - }, - "then": { - "node": "Let", - "pattern": { - "node": "Variable", - "label": "run" - }, - "value": { - "node": "Function", - "pattern": { - "node": "Variable", - "label": "state" - }, - "body": { - "node": "Function", - "pattern": { - "node": "Variable", - "label": "interupt" }, - "body": { - "node": "Case", + { + "node": "Field", + "key": "interrupt", "value": { - "node": "Variable", - "label": "interupt" - }, - "branches": [ - { - "node": "Branch", - "name": "Click", - "pattern": { - "node": "Variable", - "label": "target" - }, - "then": { - "node": "Let", - "pattern": { - "node": "Variable", - "label": "" - }, - "value": { - "node": "Call", - "function": { - "node": "Variable", - "label": "equal" - }, - "with": { - "node": "Tuple", - "elements": [ - { - "node": "Binary", - "value": "" - }, - { - "node": "Variable", - "label": "target" - } - ] - } - }, - "then": { - "node": "Record", - "fields": [ - { - "node": "Field", - "key": "page", - "value": { - "node": "Binary", - "value": "render" - } - }, - { - "node": "Field", - "key": "interrupt", - "value": { - "node": "Call", - "function": { - "node": "Variable", - "label": "run" - }, - "with": { - "node": "Variable", - "label": "state" - } - } - } - ] - } - } + "node": "Call", + "function": { + "node": "Variable", + "label": "run" }, - { - "node": "Branch", - "name": "Code", - "pattern": { - "node": "Variable", - "label": "source" - }, - "then": { - "node": "Case", - "value": { - "node": "Call", - "function": { - "node": "Provider", - "config": "", - "generator": "Loader" - }, - "with": { - "node": "Variable", - "label": "source" - } - }, - "branches": [ - { - "node": "Branch", - "name": "Error", - "pattern": { - "node": "Variable", - "label": "" - }, - "then": { - "node": "Record", - "fields": [ - { - "node": "Field", - "key": "page", - "value": { - "node": "Binary", - "value": "render" - } - }, - { - "node": "Field", - "key": "interrupt", - "value": { - "node": "Call", - "function": { - "node": "Variable", - "label": "run" - }, - "with": { - "node": "Variable", - "label": "state" - } - } - } - ] - } - }, - { - "node": "Branch", - "name": "OK", - "pattern": { - "node": "Variable", - "label": "release" - }, - "then": { - "node": "Call", - "function": { - "node": "Variable", - "label": "release" - }, - "with": { - "node": "Variable", - "label": "state" - } - } - } - ] - } + "with": { + "node": "Binary", + "value": "initial state" } - ] + } } - } + ] }, "then": { - "node": "Let", - "pattern": { - "node": "Variable", - "label": "handle" - }, - "value": { - "node": "Function", - "pattern": { - "node": "Tuple", - "elements": [ - { - "node": "Bind", - "label": "interrupt" - }, - { - "node": "Bind", - "label": "state" - } - ] - }, - "body": { - "node": "Let", - "pattern": { - "node": "Variable", - "label": "" - }, + "node": "Record", + "fields": [ + { + "node": "Field", + "key": "init", "value": { - "node": "Case", - "value": { - "node": "Hole" - }, - "branches": [ - { - "node": "Branch", - "name": "Update", - "pattern": { - "node": "Variable", - "label": "source" - }, - "then": { - "node": "Hole" - } - } - ] - }, - "then": { - "node": "Let", - "pattern": { - "node": "Variable", - "label": "" - }, - "value": { - "node": "Tuple", - "elements": [] - }, - "then": { - "node": "Variable", - "label": "state" - } + "node": "Variable", + "label": "init" } - } - }, - "then": { - "node": "Let", - "pattern": { - "node": "Variable", - "label": "update" }, - "value": { - "node": "Function", - "pattern": { + { + "node": "Field", + "key": "release", + "value": { "node": "Variable", - "label": "state" - }, - "body": { - "node": "Let", - "pattern": { - "node": "Variable", - "label": "page" - }, - "value": { - "node": "Binary", - "value": "render" - }, - "then": { - "node": "Record", - "fields": [ - { - "node": "Field", - "key": "interrupt", - "value": { - "node": "Function", - "pattern": { - "node": "Variable", - "label": "i" - }, - "body": { - "node": "Call", - "function": { - "node": "Variable", - "label": "update" - }, - "with": { - "node": "Call", - "function": { - "node": "Variable", - "label": "handle" - }, - "with": { - "node": "Tuple", - "elements": [ - { - "node": "Variable", - "label": "i" - }, - { - "node": "Variable", - "label": "state" - } - ] - } - } - } - } - } - ] - } + "label": "release" } + } + ] + } + } + } + } + }, + "then": { + "node": "Let", + "pattern": { + "node": "Variable", + "label": "web" + }, + "value": { + "node": "Function", + "pattern": { + "node": "Variable", + "label": "req" + }, + "body": { + "node": "Case", + "value": { + "node": "Call", + "function": { + "node": "Variable", + "label": "equal" + }, + "with": { + "node": "Tuple", + "elements": [ + { + "node": "Binary", + "value": "/code" }, - "then": { - "node": "Call", - "function": { + { + "node": "Access", + "value": { "node": "Variable", - "label": "update" + "label": "req" }, - "with": { - "node": "Binary", - "value": "0" - } + "key": "path" } + ] + } + }, + "branches": [ + { + "node": "Branch", + "name": "False", + "pattern": { + "node": "Tuple", + "elements": [] + }, + "then": { + "node": "Binary", + "value": "" + } + }, + { + "node": "Branch", + "name": "True", + "pattern": { + "node": "Tuple", + "elements": [] + }, + "then": { + "node": "Binary", + "value": "TODO encode" } } - } + ] } }, "then": { - "node": "Hole" + "node": "Record", + "fields": [ + { + "node": "Field", + "key": "counter", + "value": { + "node": "Variable", + "label": "counter" + } + }, + { + "node": "Field", + "key": "web", + "value": { + "node": "Variable", + "label": "web" + } + } + ] } } } @@ -4459,11 +4034,15 @@ "elements": [ { "node": "Binary", - "value": "localhost:5003" + "value": "localhost:5004" }, { - "node": "Variable", - "label": "counter" + "node": "Access", + "value": { + "node": "Variable", + "label": "reload" + }, + "key": "web" } ] }, @@ -4491,7 +4070,7 @@ "elements": [ { "node": "Binary", - "value": "counter.web.petersaxton.uk" + "value": "localhost:5003" }, { "node": "Variable", @@ -4523,11 +4102,11 @@ "elements": [ { "node": "Binary", - "value": "localhost:5002" + "value": "counter.web.petersaxton.uk" }, { "node": "Variable", - "label": "cluster" + "label": "counter" } ] }, @@ -4555,7 +4134,7 @@ "elements": [ { "node": "Binary", - "value": "cluster.web.petersaxton.uk" + "value": "localhost:5002" }, { "node": "Variable", @@ -4587,11 +4166,11 @@ "elements": [ { "node": "Binary", - "value": "localhost:5001" + "value": "cluster.web.petersaxton.uk" }, { "node": "Variable", - "label": "dashboard" + "label": "cluster" } ] }, @@ -4619,7 +4198,7 @@ "elements": [ { "node": "Binary", - "value": "dashboard.web.petersaxton.uk" + "value": "localhost:5001" }, { "node": "Variable", @@ -4638,92 +4217,125 @@ "node": "Let", "pattern": { "node": "Variable", - "label": "route" + "label": "routes" }, "value": { - "node": "Call", - "function": { - "node": "Access", - "value": { - "node": "Access", - "value": { - "node": "Variable", - "label": "lib" - }, - "key": "list" - }, - "key": "key_find" - }, - "with": { + "node": "Tagged", + "tag": "Cons", + "value": { "node": "Tuple", "elements": [ { - "node": "Variable", - "label": "routes" + "node": "Tuple", + "elements": [ + { + "node": "Binary", + "value": "dashboard.web.petersaxton.uk" + }, + { + "node": "Variable", + "label": "dashboard" + } + ] }, { - "node": "Access", - "value": { - "node": "Variable", - "label": "request" - }, - "key": "origin" + "node": "Variable", + "label": "routes" } ] } }, "then": { - "node": "Case", - "value": { + "node": "Let", + "pattern": { "node": "Variable", "label": "route" }, - "branches": [ - { - "node": "Branch", - "name": "Error", - "pattern": { - "node": "Tuple", - "elements": [] - }, - "then": { + "value": { + "node": "Call", + "function": { + "node": "Access", + "value": { "node": "Access", "value": { "node": "Variable", - "label": "request" + "label": "lib" }, - "key": "origin" - } + "key": "list" + }, + "key": "key_find" }, - { - "node": "Branch", - "name": "Ok", - "pattern": { - "node": "Tuple", - "elements": [ - { - "node": "Bind", - "label": "" + "with": { + "node": "Tuple", + "elements": [ + { + "node": "Variable", + "label": "routes" + }, + { + "node": "Access", + "value": { + "node": "Variable", + "label": "request" }, - { - "node": "Bind", - "label": "page" - } - ] + "key": "origin" + } + ] + } + }, + "then": { + "node": "Case", + "value": { + "node": "Variable", + "label": "route" + }, + "branches": [ + { + "node": "Branch", + "name": "Error", + "pattern": { + "node": "Tuple", + "elements": [] + }, + "then": { + "node": "Access", + "value": { + "node": "Variable", + "label": "request" + }, + "key": "origin" + } }, - "then": { - "node": "Call", - "function": { - "node": "Variable", - "label": "page" + { + "node": "Branch", + "name": "Ok", + "pattern": { + "node": "Tuple", + "elements": [ + { + "node": "Bind", + "label": "" + }, + { + "node": "Bind", + "label": "page" + } + ] }, - "with": { - "node": "Variable", - "label": "request" + "then": { + "node": "Call", + "function": { + "node": "Variable", + "label": "page" + }, + "with": { + "node": "Variable", + "label": "request" + } } } - } - ] + ] + } } } } @@ -4735,25 +4347,89 @@ } }, "then": { - "node": "Record", - "fields": [ - { - "node": "Field", - "key": "proxy", - "value": { - "node": "Variable", - "label": "web" + "node": "Let", + "pattern": { + "node": "Variable", + "label": "counter_init" + }, + "value": { + "node": "Tuple", + "elements": [ + { + "node": "Access", + "value": { + "node": "Access", + "value": { + "node": "Access", + "value": { + "node": "Variable", + "label": "reload" + }, + "key": "counter" + }, + "key": "init" + }, + "key": "page" + }, + { + "node": "Access", + "value": { + "node": "Access", + "value": { + "node": "Access", + "value": { + "node": "Variable", + "label": "reload" + }, + "key": "counter" + }, + "key": "init" + }, + "key": "interrupt" } - }, - { - "node": "Field", - "key": "web", - "value": { - "node": "Variable", - "label": "web" + ] + }, + "then": { + "node": "Record", + "fields": [ + { + "node": "Field", + "key": "proxy", + "value": { + "node": "Variable", + "label": "web" + } + }, + { + "node": "Field", + "key": "web", + "value": { + "node": "Variable", + "label": "web" + } + }, + { + "node": "Field", + "key": "counter_init", + "value": { + "node": "Variable", + "label": "counter_init" + } + }, + { + "node": "Field", + "key": "counter", + "value": { + "node": "Access", + "value": { + "node": "Variable", + "label": "reload" + }, + "key": "counter" + } } - } - ] + ] + } } } } diff --git a/editor/rollup.config.js b/editor/rollup.config.js index e8965ec8d..4fd6acd31 100644 --- a/editor/rollup.config.js +++ b/editor/rollup.config.js @@ -1,76 +1,93 @@ -import svelte from 'rollup-plugin-svelte'; -import commonjs from '@rollup/plugin-commonjs'; -import resolve from '@rollup/plugin-node-resolve'; -import livereload from 'rollup-plugin-livereload'; -import { terser } from 'rollup-plugin-terser'; -import css from 'rollup-plugin-css-only'; +import svelte from "rollup-plugin-svelte"; +import commonjs from "@rollup/plugin-commonjs"; +import resolve from "@rollup/plugin-node-resolve"; +import livereload from "rollup-plugin-livereload"; +import { terser } from "rollup-plugin-terser"; +import css from "rollup-plugin-css-only"; +import json from "@rollup/plugin-json"; const production = !process.env.ROLLUP_WATCH; function serve() { - let server; + let server; - function toExit() { - if (server) server.kill(0); - } + function toExit() { + if (server) server.kill(0); + } - return { - writeBundle() { - if (server) return; - server = require('child_process').spawn('npm', ['run', 'start', '--', '--dev'], { - stdio: ['ignore', 'inherit', 'inherit'], - shell: true - }); + return { + writeBundle() { + if (server) return; + server = require("child_process").spawn( + "npm", + ["run", "start", "--", "--dev"], + { + stdio: ["ignore", "inherit", "inherit"], + shell: true, + } + ); - process.on('SIGTERM', toExit); - process.on('exit', toExit); - } - }; + process.on("SIGTERM", toExit); + process.on("exit", toExit); + }, + }; } -export default { - input: 'src/main.js', - output: { - sourcemap: true, - format: 'iife', - name: 'app', - file: 'public/build/bundle.js' - }, - plugins: [ - svelte({ - compilerOptions: { - // enable run-time checks when not in production - dev: !production - } - }), - // we'll extract any component CSS out into - // a separate file - better for performance - css({ output: 'bundle.css' }), +export default [ + { + input: "src/other.js", + output: { + sourcemap: true, + format: "iife", + name: "app", + file: "public/build/other.js", + }, + plugins: [json()], + }, + { + input: "src/main.js", + output: { + sourcemap: true, + format: "iife", + name: "app", + file: "public/build/bundle.js", + }, + plugins: [ + svelte({ + compilerOptions: { + // enable run-time checks when not in production + dev: !production, + }, + }), + // we'll extract any component CSS out into + // a separate file - better for performance + css({ output: "bundle.css" }), - // If you have external dependencies installed from - // npm, you'll most likely need these plugins. In - // some cases you'll need additional configuration - - // consult the documentation for details: - // https://github.com/rollup/plugins/tree/master/packages/commonjs - resolve({ - browser: true, - dedupe: ['svelte'] - }), - commonjs(), + // If you have external dependencies installed from + // npm, you'll most likely need these plugins. In + // some cases you'll need additional configuration - + // consult the documentation for details: + // https://github.com/rollup/plugins/tree/master/packages/commonjs + resolve({ + browser: true, + dedupe: ["svelte"], + }), + commonjs(), - // In dev mode, call `npm run start` once - // the bundle has been generated - !production && serve(), + // In dev mode, call `npm run start` once + // the bundle has been generated + !production && serve(), - // Watch the `public` directory and refresh the - // browser on changes when not in production - !production && livereload('public'), + // Watch the `public` directory and refresh the + // browser on changes when not in production + !production && livereload("public"), - // If we're building for production (npm run build - // instead of npm run dev), minify - production && terser() - ], - watch: { - clearScreen: false - } -}; + // If we're building for production (npm run build + // instead of npm run dev), minify + production && terser(), + ], + watch: { + clearScreen: false, + }, + }, +]; diff --git a/editor/src/main.js b/editor/src/main.js index fdc47ab57..e382ae50f 100644 --- a/editor/src/main.js +++ b/editor/src/main.js @@ -1,4 +1,5 @@ // import { main } from "../../eyg/build/dev/javascript/eyg/dist/eyg/workspace/main"; +// TODO remove deploy import { deploy } from "../../eyg/build/dev/javascript/eyg/dist/eyg/workspace/ui.mjs"; import * as Spreasheet from "../../eyg/build/dev/javascript/eyg/dist/spreadsheet/main.mjs"; diff --git a/editor/src/other.js b/editor/src/other.js new file mode 100644 index 000000000..af24cd3a3 --- /dev/null +++ b/editor/src/other.js @@ -0,0 +1,19 @@ +import * as Entry from "../../eyg/build/dev/javascript/eyg/dist/eyg/entry.mjs"; +import * as Encode from "../../eyg/build/dev/javascript/eyg/dist/eyg/ast/encode.mjs"; + +// Roll up adds a default object that breaks matchings +import data from "../public/saved.json"; +// This is not generic has because we have the server or maybe not. this is the arbitrary script pull +// let target = new URL(document.currentScript.src).hash.slice(1); +// console.log(target, Analysis); + +(async function name() { + const source = Encode.from_json(data); + const initial = Entry.interpret_client(source, "counter"); + console.log(initial); + const { default: next } = await import("../public/saved.json"); + console.log(Encode.from_json(data)); +})(); + +// Started doing this because the code gen was troublesome, also in code gen we will nee to pull in the loader +// here we have can use the already existing gleam .run diff --git a/eyg/src/eyg/analysis.gleam b/eyg/src/eyg/analysis.gleam index d267fb7d7..b1fe51926 100644 --- a/eyg/src/eyg/analysis.gleam +++ b/eyg/src/eyg/analysis.gleam @@ -16,6 +16,10 @@ pub fn infer(untyped, type_, variables) { typer.infer(untyped, type_, t.empty, state) } +pub fn infer_unbound(untyped) { + infer(untyped, t.Unbound(-1), []) +} + pub fn infer_effectful(untyped, type_, effects, variables) { let checker = typer.init() let scope = typer.root_scope(variables) diff --git a/eyg/src/eyg/ast/encode.gleam b/eyg/src/eyg/ast/encode.gleam index 7172175e7..9dfa2dfb3 100644 --- a/eyg/src/eyg/ast/encode.gleam +++ b/eyg/src/eyg/ast/encode.gleam @@ -164,6 +164,9 @@ external fn from_array(value: JSON) -> List(JSON) = pub fn from_json(json: JSON) { assert Ok(#(node, rest)) = list.key_pop(entries(json), "node") + + // TODO need to load out properly + // TODO make this robust no asserts or assumption of order use key pop // find node and order rest case assert_string(node) { "Binary" -> { @@ -203,8 +206,8 @@ pub fn from_json(json: JSON) { let [#("label", label)] = rest ast.variable(assert_string(label)) } - "Let" -> { + let [#("pattern", pattern), #("value", value), #("then", then)] = rest let pattern = pattern_from_json(pattern) let value = from_json(value) diff --git a/eyg/src/eyg/entry.gleam b/eyg/src/eyg/entry.gleam new file mode 100644 index 000000000..1a3532bf5 --- /dev/null +++ b/eyg/src/eyg/entry.gleam @@ -0,0 +1,46 @@ +import gleam/io +import gleam/string +import eyg/ast/encode +import eyg/ast/expression as e +import eyg/interpreter/effectful +// TODO need an effectful version that allows us to access stuff here +import eyg/interpreter/tail_call +import gleam/javascript/array +import eyg/interpreter/interpreter as r +import eyg/analysis +import eyg/typer +import eyg/typer/monotype as t +import eyg/editor/editor + +fn update(page, interrupt, display, on_click) { + + io.debug(page) + display(page) + + } + + +fn b(args) { + Ok(r.Binary("done")) + } +// uses default builtin that need moving out of effectful +// has an entry point key should eventually be a hash +// maybe rename interpret standard +// builtin is always the same but env things are passed in +// All the runtime stuff is in gleam terms +// TODO are there any gleam helpers to turn tuples into things +pub fn interpret_client(source, key, display, on_click) { + io.debug("hooo") + let init = e.access(e.access(source, key), "init") + io.debug(init) + let #(typed, typer) = analysis.infer(init, t.Unbound(-1), []) + io.debug("---- typed") + let #(xtyped, typer) = typer.expand_providers(typed, typer, []) +// assert Ok(term) = effectful.eval(editor.untype(xtyped)) +// io.debug(term) + |> io.debug +// effectful.eval_call(r.BuiltinFn(b), term, effectful.real_log) +// |> io.debug +// // TODO make an AST the requires rendering +// term +} \ No newline at end of file diff --git a/eyg/src/eyg/interpreter/effectful.gleam b/eyg/src/eyg/interpreter/effectful.gleam index 87a302b4b..9d70e5a65 100644 --- a/eyg/src/eyg/interpreter/effectful.gleam +++ b/eyg/src/eyg/interpreter/effectful.gleam @@ -81,7 +81,22 @@ fn term_serialize(term) { "({ on_click: (f) => { document.onclick = () => f() }, display: (value) => document.body.innerHTML = value, + // TODO does with work can we have outside poller + on_code: (f) => { document.oncode = f } });", +// This didn't work because of rendering captured variables for a fn within some scope. +// We need a whole review of rendering or use interpreter +// "(({init}) => { +// console.log(init, 'initial state') +// const update = ({page, interrupt}) => { +// document.body.innerHTML = page +// document.onclick = () => update(interrupt({Click: 'key'})) +// document.oncode = (code) => update(interrupt({Code: code})) +// TODO this needs the codegen part of loader +// } +// update(init) +// // TODO set interval +// })" ) let page = string.concat([""]) @@ -89,6 +104,7 @@ fn term_serialize(term) { Ok(r.Binary(page)) } + fn env() { map.new() |> map.insert("do", r.BuiltinFn(do)) diff --git a/eyg/src/eyg/interpreter/interpreter.gleam b/eyg/src/eyg/interpreter/interpreter.gleam index 70bda68d1..28dadb2ef 100644 --- a/eyg/src/eyg/interpreter/interpreter.gleam +++ b/eyg/src/eyg/interpreter/interpreter.gleam @@ -64,6 +64,7 @@ pub fn render_var(assignment) { #("equal", _) -> "let equal = ([a, b]) => a == b;" // TODO remove duplication of this builtincode // can i import * as builtin from /gleam/version + // TODO builtin needs to include render #("builtin", _) -> "let builtin = {append: ([a, b]) => a + b}" // TODO have a standard builtin to lookup table #("send", BuiltinFn(_)) -> @@ -117,7 +118,8 @@ pub fn render_object(object) { string.concat(["{", tag, ":", render_object(value), "}"]) // Builtins should never be included, I need to check variables used in a previous step // Function(_,_,_,_) -> todo("this needs compile again but I need a way to do this without another type check") - Function(pattern, body, _, _) -> { + Function(pattern, body, captured, _) -> { + // TODO this needs to render captured to be useful let #(typed, typer) = analysis.infer(e.function(pattern, body), t.Unbound(-1), []) let #(typed, typer) = typer.expand_providers(typed, typer, []) javascript.render_to_string(typed, typer)