132 lines
8.0 KiB
Markdown
132 lines
8.0 KiB
Markdown
# Let's discuss
|
|
|
|
Open questions, raised and deliberately not answered yet. Nothing here is a decision or a task. Each entry is the
|
|
question as asked, plus what is already known in this repo that bears on it — so the investigation starts from what
|
|
exists rather than from scratch.
|
|
|
|
Settled decisions live in `NEXT.md`. Reasons for what already exists live in `BUILT.md`.
|
|
|
|
---
|
|
|
|
## 1. What is `i` supposed to inspect in the stack section?
|
|
|
|
Raised as a question about intent, and it deserves one, because the current answer may be wrong rather than merely
|
|
undocumented.
|
|
|
|
`i` on a local passes that local's **name** to the inspector, which evaluates it as an expression inside the running
|
|
program. That is correct for the innermost frame, where the name is in scope. **It is not obviously correct for any
|
|
other frame** — evaluating `y` while looking at frame 3 evaluates `y` wherever the evaluator stands, not in frame 3.
|
|
It may resolve to a global, to a different binding, or fail.
|
|
|
|
The locals *listing* does not have this problem: it renders from the frame's own slot addresses. So the display is
|
|
frame-accurate and the inspector may not be. Options: root the inspector at the slot's address the way the listing is
|
|
rooted; refuse `i` outside the innermost frame; or make the inspector frame-aware. Worth settling before anyone relies
|
|
on it.
|
|
|
|
## 2. Annotating the IR and the disassembly with the source
|
|
|
|
The compiler should interleave the originating Flan expression into both the emitted LLVM IR and the disassembly
|
|
listing.
|
|
|
|
What already exists: `emit.ml` writes `.ll` as text, so a comment costs nothing and cannot break anything. Every typed IR
|
|
node carries a `Loc.t`. DWARF is emitted under `--debug`, with a line table naming the `.flan` file, and the disassembly
|
|
listing already rebases addresses and annotates cells, calls and branch targets. So both halves have the information
|
|
already; what is missing is the interleaving.
|
|
|
|
The IR half is nearly free. The disassembly half is more interesting and more valuable — it is what would let you see
|
|
what one line of Flan actually costs, including the indirection cell a dev build puts on every cross-function call.
|
|
|
|
## 3. `def`, `defvar`, `defconst`
|
|
|
|
There is no `def`. There is `defvar` (mutable global) and `defconst` (compile-time constant, folded).
|
|
|
|
The proposal: a `def` that is mutable, where `defvar` only rewrites the value if the variable is *new* — Common Lisp's
|
|
actual `defvar` semantics, where re-evaluating a `defvar` deliberately does not clobber a value you have been building up
|
|
at runtime. That distinction matters much more here than in most languages, because `C-c C-k` on a whole buffer
|
|
re-evaluates every top-level form against a *running* program, and today that resets state you may have spent a session
|
|
accumulating.
|
|
|
|
`defconst` under redefinition is the unclear one, as noted — it is folded into its use sites, so changing one is closer to
|
|
a recompile than to an assignment.
|
|
|
|
## 4. Structural typing, row polymorphism, anonymous structs
|
|
|
|
Worth noting before this is scoped: `types.ml` already does **structural equality** on resolved types, and a Flan struct
|
|
is exactly its C layout with no header or tag word. So the representation is already structural; what is nominal is the
|
|
*checking*, not the data.
|
|
|
|
The questions this opens: whether a function can take "any struct with an `x` and a `y`"; whether anonymous structs get a
|
|
spelling; how this interacts with the FFI, where the shim generates a C typedef per named struct; and how it interacts
|
|
with the planned managed classes, which are explicitly the *opposite* direction — identity and metadata rather than plain
|
|
layout.
|
|
|
|
## 5. A performant JS transpiler
|
|
|
|
Asked as a feasibility question. Bear in mind the web target already exists and ships real machine code via wasm, so this
|
|
is not the only route to a browser and the case for it needs stating: smaller artifacts, no wasm toolchain, debuggability
|
|
in browser devtools, or something else.
|
|
|
|
The hard parts are the ones the wasm target got for free from clang: the memory model (Flan is pointers and explicit
|
|
layout; JS is not), the FFI, and the fact that the whole raylib layer is C. A JS backend that cannot run raylib is a
|
|
different product from the one that can.
|
|
|
|
## 6. C interop as seamless as Zig's
|
|
|
|
Today: `declare-c` names one C function per line, and the compiler generates the wrapper, the typedefs and the flattened
|
|
declaration. 175 of them for raylib. **No header is ever read, deliberately** — which means nothing can check that a
|
|
declaration matches the real signature, and that is written down as trusted rather than guaranteed.
|
|
|
|
The proposal is to read the header, prefix a namespace, and get `rl/InitWindow` for free — plus possibly automatic
|
|
kebab-casing to `rl/init-window`.
|
|
|
|
This is a large change in kind, not just in size: it means a C parser or a libclang dependency in the build, and it
|
|
trades an explicit, checkable list for an implicit surface. Worth weighing against what `declare-c` already buys, which
|
|
is that a binding is one line and the wrapper is generated. The auto-kebab-case question is separable and much smaller —
|
|
and note the FFI currently keeps C's own spelling on purpose, so the mapping would need to be reversible.
|
|
|
|
## 7. Where `defclass` stands
|
|
|
|
Specified in `plan.org` and **deliberately not started** — its own last line says nothing happens until ordinary
|
|
`struct`, `Handle` and reload semantics work. Those have largely landed since that was written, so the gate may be closer
|
|
than the document assumes.
|
|
|
|
What it is meant to add: identity, runtime shape metadata, an implementation-defined representation, generic-function
|
|
dispatch, and live schema change with an explicit migration at a frame boundary — which is the answer to the one thing
|
|
redefinition still cannot do, changing a struct's layout while instances exist.
|
|
|
|
Three findings from an earlier review, recorded in `NEXT.md` and not yet in `plan.org`:
|
|
|
|
- **A generic function is a cell.** Adding a method from a later module is the same problem indirection cells already
|
|
solve, so the expensive half is built and tested.
|
|
- **The pool is not one storage option among three.** `migrate-instances` has to enumerate live instances, which a pool
|
|
behind a generational `Handle` gives by construction and the other two options do not.
|
|
- **Every layout version must stay resolvable** for as long as any instance holds it — the same rule as "nothing is ever
|
|
`dlclose`d".
|
|
|
|
Also open and related: whether a *condition* can be a class, which decides whether handler matching has one path or two.
|
|
`NEXT.md` records the argument; decision 4 there took the cheaper parent-link route for now and explicitly left real
|
|
inheritance possible later.
|
|
|
|
## 8. Watching variables
|
|
|
|
Raised while designing item 1, and deliberately separated from it.
|
|
|
|
Item 1 shows globals *per frame*, chosen by what the code in that frame references. That is the right default and it
|
|
cannot cover the case where the thing you care about is not named by the frame you are standing in — stopped deep in a
|
|
helper, still wanting to see the grid.
|
|
|
|
So: a way to say "always show me this", surviving a resume and the next break.
|
|
|
|
Questions it opens:
|
|
|
|
- **What can be watched.** A global is easy — it has a name and an address that does not move. A *local* is harder: it
|
|
belongs to a frame that is gone as soon as you resume, so "watch `y`" either means a different `y` every time or means
|
|
nothing. A watched expression — `(at velocity 40 12)` — is the most useful and the most expensive, since it has to be
|
|
compiled and run in the program each time, which is what `eval-expr` already does.
|
|
- **Where the list lives.** Per project, per session, or in the file. A watch list that vanishes when Emacs restarts is
|
|
one you stop using; one in the repo is one you accidentally commit.
|
|
- **When it updates.** Only on entering a break is cheap and probably enough. Live-updating while the program runs is a
|
|
different feature — closer to a HUD than a debugger — and worth not conflating.
|
|
- **Whether it belongs in the break buffer at all**, or in its own window that is useful while the program is *running*,
|
|
which is arguably where a game developer wants it.
|