Skip to content

Commit

Permalink
start universal entrypoint stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
CrowdHailer committed Oct 10, 2022
1 parent b4e297e commit bc2d65e
Show file tree
Hide file tree
Showing 11 changed files with 510 additions and 703 deletions.
22 changes: 22 additions & 0 deletions editor/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
952 changes: 314 additions & 638 deletions editor/public/saved.json

Large diffs are not rendered by default.

143 changes: 80 additions & 63 deletions editor/rollup.config.js
Original file line number Diff line number Diff line change
@@ -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,
},
},
];
1 change: 1 addition & 0 deletions editor/src/main.js
Original file line number Diff line number Diff line change
@@ -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";

Expand Down
19 changes: 19 additions & 0 deletions editor/src/other.js
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions eyg/src/eyg/analysis.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion eyg/src/eyg/ast/encode.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -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" -> {
Expand Down Expand Up @@ -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)
Expand Down
46 changes: 46 additions & 0 deletions eyg/src/eyg/entry.gleam
Original file line number Diff line number Diff line change
@@ -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
}
16 changes: 16 additions & 0 deletions eyg/src/eyg/interpreter/effectful.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,30 @@ 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(["<head></head><body></body><script>", program, "</script>"])
// assert r.Function() = term
Ok(r.Binary(page))
}


fn env() {
map.new()
|> map.insert("do", r.BuiltinFn(do))
Expand Down
4 changes: 3 additions & 1 deletion eyg/src/eyg/interpreter/interpreter.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -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(_)) ->
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit bc2d65e

Please sign in to comment.