Fixing too much. also, the OS is actually spawning and managing windows

This commit is contained in:
Dustin Swan 2026-02-12 16:13:00 -07:00
parent 62f6e202b0
commit db4abfa450
No known key found for this signature in database
GPG key ID: 30D46587E2100467
5 changed files with 168 additions and 130 deletions

View file

@ -1,6 +1,6 @@
import { tokenize } from './lexer'
import { Parser } from './parser'
import { compile, recompile, definitions, freeVars, dependencies, dependents } from './compiler'
import { compile, recompile, definitions, freeVars, dependencies, dependents, astRegistry } from './compiler'
import { prettyPrint } from './ast'
import type { AST } from './ast'
import { measure } from './ui';
@ -61,7 +61,21 @@ export const _rt = {
? { _tag: 'Some', _0: xs[i] }
: { _tag: 'None' },
len: (xs: any[] | string) => xs.length,
str: (x: any) => String(x),
// str: (x: any) => String(x),
show: (value: any): string => {
if (value === null || value === undefined) return "None";
if (typeof value === 'string') return value;
if (typeof value === 'number') return String(value);
if (typeof value === 'boolean') return value ? "True" : "False";
if (value._tag) return value._0 !== undefined ? `${value._tag} ${_rt.show(value._0)}` : value._tag;
if (Array.isArray(value)) return `[${value.map(_rt.show).join(", ")}]`;
if (typeof value === 'function') return "<function>";
if (typeof value === 'object') {
const entries = Object.entries(value).map(([k, v]) => `${k} = ${_rt.show(v)}`);
return `{ ${entries.join(", ")} }`;
}
return String(value);
},
chars: (s: string) => s.split(''),
join: (delim: string) => (xs: string[]) => xs.join(delim),
split: (delim: string) => (xs: string) => xs.split(delim),
@ -183,7 +197,7 @@ export function loadDefinitions() {
try {
const saved = JSON.parse(data);
for (const [name, source] of Object.entries(saved)) {
for (const [_, source] of Object.entries(saved)) {
const tokens = tokenize(source as string);
const parser = new Parser(tokens, source as string);
const defs = parser.parse();
@ -245,11 +259,11 @@ function valueToAst(value: any): AST {
// Functions
if (typeof value === 'function') {
if (value._ast) {
return value._ast;
if (value._astId !== undefined) {
return astRegistry.get(value._astId)!;
}
throw new Error('Cannot serialize function without _ast');
throw new Error('Cannot serialize function without _astId');
}
throw new Error(`Cannot convert to AST: ${typeof value}`);