From 68f4fbe9b32cc96d31f7205a3a6122114a8f85b5 Mon Sep 17 00:00:00 2001 From: Dustin Swan Date: Thu, 12 Feb 2026 22:05:15 -0700 Subject: [PATCH] bugs --- src/cg/05-palette.cg | 7 +------ src/cg/06-inspector.cg | 45 ++++++++++++++++-------------------------- src/cg/10-os.cg | 18 +++++++++++------ src/compiler.ts | 1 + src/runtime-js.ts | 14 ++++++++++--- 5 files changed, 42 insertions(+), 43 deletions(-) diff --git a/src/cg/05-palette.cg b/src/cg/05-palette.cg index 5f55adb..ab02ce8 100644 --- a/src/cg/05-palette.cg +++ b/src/cg/05-palette.cg @@ -68,11 +68,6 @@ palette = config \ } }; - # local onSelect, calls passed in config.onSelect - onSelect = text \ text - | "" \ config.onSelect paletteState.query - | _ \ config.onSelect text; - ui.stateful { key = "palette", focusable = False, @@ -85,7 +80,7 @@ palette = config \ | Key { printable = True } \ { state = state.{ focusedIndex = 0 }, emit = [] } | Key { key = "ArrowUp" } \ { state = state.{ focusedIndex = max 0 (state.focusedIndex - 1) }, emit = [] } | Key { key = "ArrowDown" } \ { state = state.{ focusedIndex = min (len results - 1) (state.focusedIndex + 1) }, emit = [] } - | Key { key = "Enter" } \ { state = state, emit = [onSelect (unwrapOr "" (nth state.focusedIndex results))] } + | Key { key = "Enter" } \ { state = state, emit = [config.onSelect (unwrapOr "" (nth state.focusedIndex results))] } | _ \ { state = state, emit = [] }, view = state \ diff --git a/src/cg/06-inspector.cg b/src/cg/06-inspector.cg index 30f3757..48141c3 100644 --- a/src/cg/06-inspector.cg +++ b/src/cg/06-inspector.cg @@ -12,32 +12,21 @@ inspector = config \ contentWidth = windowWidth - (dialogPadding * 2); contentHeight = windowHeight - (dialogPadding * 2); - ui.positioned { - x = (config.viewport.width - windowWidth) / 2, - y = (config.viewport.height - windowHeight) / 2, - - child = ui.stack { - children = [ - # background - ui.rect { w = windowWidth, h = windowHeight, color = "#063351", radius = 0, strokeWidth = 1, strokeColor = "#1A5F80" }, - ui.column { - gap = 0, - children = mapWithIndex (line i \ - textInput { - key = "palette-query" & (str i), - initialValue = line, - initialFocus = i == 0, - color = "white", - backgroundColor = "rgba(0,0,0,0.0)", - w = contentWidth, - h = textInputHeight, - # onChange = text \ batch [config.state.query := text, config.state.focusedIndex := 0], - onChange = text \ batch [], - onKeyDown = key \ key - | _ \ noOp - } - ) sourceLines - } - ] - } + ui.column { + gap = 0, + children = mapWithIndex (line i \ + textInput { + key = "palette-query" & (show i), + initialValue = line, + initialFocus = i == 0, + color = "white", + backgroundColor = "rgba(0,0,0,0.0)", + w = contentWidth, + h = textInputHeight, + # onChange = text \ batch [config.state.query := text, config.state.focusedIndex := 0], + onChange = text \ batch [], + onKeyDown = key \ key + | _ \ noOp + } + ) sourceLines }; diff --git a/src/cg/10-os.cg b/src/cg/10-os.cg index f3c9ab5..1eb05a2 100644 --- a/src/cg/10-os.cg +++ b/src/cg/10-os.cg @@ -11,6 +11,8 @@ osState = { nextId = 0 }; +openPalette = _ \ osState.palette.visible := not (osState.palette.visible); + windowWidth = window \ window.fullWidth | True \ viewport.width | False \ window.width; @@ -77,9 +79,9 @@ focusWindow = index \ onSelect = input \ result = eval input; result - | Value v \ openWindow input (ui.text { content = show v, color = "white" }) - | Defined name \ noOp - | Err msg \ openWindow "Error" (ui.text { content = msg, color = "red" }); + | Value v \ openWindow input (_ \ ui.text { content = show v, color = "white" }) + | Defined name \ openWindow name (_ \ inspector { name = name }) + | Err msg \ openWindow "Error" (_ \ ui.text { content = msg, color = "red" }); renderWindow = window isActive \ titleBarHeight = 30; @@ -127,7 +129,7 @@ renderWindow = window isActive \ child = ui.clip { w = (windowWidth window), h = viewport.height - titleBarHeight, - child = window.content + child = window.content 0 } } ] @@ -158,6 +160,10 @@ renderWindows = _ \ } }; +search = q \ + storeRes = storeSearch q; + [...storeRes, q]; + os = ui.stateful { key = "os", autoFocus = True, @@ -166,7 +172,7 @@ os = ui.stateful { update = state event \ event | Key { key = "p", meta = True } \ - { state = state, emit = [osState.palette.visible := not (osState.palette.visible)] } + { state = state, emit = [openPalette] } | Key { key = "ArrowLeft", meta = True } \ ( newIndex = max 0 (osState.wm.focusedIndex - 1); @@ -193,7 +199,7 @@ os = ui.stateful { # keep palette at the end so it's on top osState.palette.visible | True \ palette { - search = storeSearch, + search = search, onSelect = onSelect, viewport = viewport, } diff --git a/src/compiler.ts b/src/compiler.ts index 7ed3107..4fbe5b2 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -29,6 +29,7 @@ export function compile(ast: AST, useStore = true, bound = new Set(), to const newBound = new Set([...bound, ...ast.params]); const params = ast.params.map(sanitizeName).join(') => ('); const id = astIdCounter++; + astRegistry.set(id, ast); return `Object.assign((${params}) => ${compile(ast.body, useStore, newBound, topLevel)}, { _astId: (${id}) })`; } diff --git a/src/runtime-js.ts b/src/runtime-js.ts index 925d5b9..45077d7 100644 --- a/src/runtime-js.ts +++ b/src/runtime-js.ts @@ -259,11 +259,19 @@ function valueToAst(value: any): AST { // Functions if (typeof value === 'function') { - if (value._astId !== undefined) { - return astRegistry.get(value._astId)!; + if (value._astId === undefined) { + throw new Error('Cannot persist native functions'); } + const ast = astRegistry.get(value._astId)!; - throw new Error('Cannot serialize function without _astId'); + if (!ast) { + console.error('Registry size:', astRegistry.size, 'Looking for:', value._astId, + 'Function:', value.toString().slice(0, 200)); + + throw new Error(`AST registry miss for _astId ${value._astId}`); + } + + return ast; } throw new Error(`Cannot convert to AST: ${typeof value}`);