flan/test/programs/dev-break.flan
Joseph Ferano 831cab9fb2 Review follow-ups: x86 parity, ArithError, and three refusal bugs
Five fixes off the independent review, plus the author's u8 ruling.

x86 parity: the bad-index block always ran x86 (it is flan dev's
default) and now says so with an explicit --x86; the condition render
gets an assertion under the x86 backend too, beside the LLVM one, and
a user error is pinned as carrying no site on both.

ArithError's layout is now pinned: {i32 op; i64 lhs, rhs} in C against
the prelude's defstruct, read field by field through the break loop's
render, driven from the editor through a divide under a restart-case.
That also covers condition and site on LLVM.

Three refusals that were wrong: trap_site tested the prefix "err"
and so ate any site whose path began with those letters; source_line
let Sys_error from input_line escape and take the whole break reply
with it, leaking the handle; and a condition with no fields was
reported as a name no struct has. The daemon now sends its own field
count and the buffer tells the two empties apart.

Nits taken: an over-long site is dropped rather than silently
truncated into a plausible one; the caret pads with the source line's
own tabs; the headline says when it has cut the field list;
flan-cnr-layout is live again as the single spelling of that request
rather than dead beside an inlined copy.

And the ruling: a u8 renders as 97 (\a) where a person is inspecting
and stays 97 where the program is printing.
2026-09-20 22:55:11 +07:00

45 lines
1.5 KiB
Plaintext

;;;; A program that stops, for driving the break loop from an editor.
;;;;
;;;; It errors on its first frame, with nothing having handled the condition,
;;;; so [flan dev] meets a program that is already stopped — which is the state
;;;; an editor has to cope with, and the one that is hardest to arrange on
;;;; purpose later. Two restarts are on offer and they return different values,
;;;; so the transcript says which one was chosen.
;;;;
;;;; After resuming it keeps polling, because the claim worth testing is that
;;;; everything else still works on either side of a break.
(import agent "vendor:agent")
(defstruct Missing [id i32])
(defn fetch [n i32] i32
(restart-case
(do (error (Missing {.id n})) 0)
(use-placeholder [] -1)
(retry [] 7)))
(defvar ticks i64)
(defn step [] i64
(set ticks (+ ticks 1))
ticks)
;;; A division under a restart-case, called from the editor rather than from
;;; main. It is here for the *other* condition the runtime builds by hand:
;;; ArithError's three fields are a C struct in flan_rt.c and a defstruct in
;;; the prelude, and the break loop's render now reads them field by field,
;;; padding and all. A layout that drifted would show the op in `lhs'.
;;; The operands are parameters so nothing constant-folds the division away.
(defn divide [a i64 b i64] i64
(restart-case
(/ a b)
(use-zero [] 0)))
(defn main [] i32
(agent/start "/tmp/flan-dev-break-fallback.sock")
(print (fetch 1)) (println "")
(dotimes [i 4000]
(agent/wait 5)
(set ticks (step)))
0)