jukebox
All repositories: gitoria
7.4 KB
// The View's READERS — realm-neutral: the same code reads values on the server and (compiled to JS) in the// browser; the browser's bundle carries this file and nothing server-only (viewserver.hl). It reads a TREE, the// syntax of a View member reflected into plain hybrids by the server (see// server.hl `tree()`), against an INSTANCE whose members supply the values.//// Tree node shapes:// { k = 'el' tag key path = [ keys… ] site attrs = [ { name text } | { name member } ] children = [ … ] }// `site` is `file:line:col` of the literal — the id its class is minted under// `tag` is what the DOM gets (a custom key kebab-cased), `key` the source key// { k = 'text' text }// { k = 'member' name } an ordered entry naming a member of the class — a SITE// { k = 'field' name path } `p.title`: a path off a member or a `for` row variable// { k = 'for' row list body } `for (row of list) { … }`, body rendered per entry// { k = 'if' cond then other } `if (cond) { … } else { … }`// { k = 'on' event } a DOM event the owning literal handles (its inline `on`)// { k = 'component' cls key path bindings ons } `Child { count = count on done(v) { … } }`:// a composed component — its own mount renders here// { k = 'other' tag } a construct this round does not render yet (if / for / on)//// `ctx` rides through every call: `ctx.slot` is the HTML a shell's `slot` member// stands for (null when rendering a page alone), `ctx.kids` the child mounts of// the instance being rendered, keyed by the component node's path joined with// '/'. A component node renders ITS mount: its own instance, its own kids.// the language has no escapes: a newline and a tab are written as themselvesstatic newline = ""static tab = " "// a component node's key in a mount's `kids`: its path, '/'-joined (a list has no// join in the language; the walk is written out)kidKey(&path) {let out = ''for (p of path) { out = out + '/' + p }return out}// THE KEY OF ONE ROW — the record's id, then @id (hl:mpackdb documents), and by// the row's index where the row is not a record or carries neither key (a list of strings// is one: demo-blog's paragraphs). ONE rule, called by everything that has to tell// one row from the next: the server's HTML walk below, the mount key of a row's// children (WebFramework `mountKids`), and the browser's keyed region (client.hl).// Two rows with the SAME id are two rows to the language and one key to this rule;// the browser's region gives the second one a key of its own, the server does not.rowKey(&entry, i) {if (entry != null) {t = hlTypeName(&entry)if (t == 'Hybrid' || t == 'Instance') {if (entry.id != null) { return '' + entry.id }if (entry.@id != null) { return '' + entry.@id }}}return '' + i}// THE KEYS OF A LIST, in order: rowKey of each row, and where one id stands twice the second and later// rows get ':' + their index (#119). The browser's region (client listKeys) keys a list the same way, so a// child of the second row of one id is its own mount on the server too, not the first row's.listKeys(&entries) {let out = []let seen = {}let ri = 0for (entry of entries) {let k = rowKey(&entry, ri)if (seen[k] != null) { k = k + ':' + ri }seen[k] = trueout.push(k)ri = ri + 1}return out}// A LITERAL'S VALUE, TYPED — COMPONENTS.md §12, "typed, not stringified". `hlSyntax`// hands a literal back as its source text and its KIND, and a reference binding carries// the value rather than the text: `Level2 { n = 1 }` gives the child a Number, so `n * 97`// is arithmetic and not "operator '*' does not apply to String and Number" (measured// 2026-09-14, demo-nested wall 3). An attribute and a text child keep the text, because// HTML is text; only what crosses into a member of another class is typed.literalValue(kind, text) {if (kind == 'number') { return toNumber(text) }if (kind == 'boolean') { return text == 'true' }if (kind == 'null_literal') { return null }return text}// THE VALUE A REFERENCE BINDING CARRIES when it is a literal or a folded static — the// one place the two are read, so the server's mount and the browser's do it alike. A// static is folded to its VALUE and carried as one ('folded'), never printed and parsed// back; a literal carries its source text and its kind, which is all the syntax has.refValue(b) {if (b.kind == 'folded') { return b.value }if (b.kind != null) { return literalValue(b.kind, b.text) }return b.text}// THE VALUE a read names: a `for` row variable in scope wins over a member of the// same name (nesting is scope); a field path walks into it.value(&node, &page, &rows) {if (node.k == 'text') { return refValue(node) }if (node.k == 'expr') { return evalExpr(&node.x, &page, &rows) }// READ IN PLACE: `v = rows[node.name]` copied the whole row value (a block with all its spans) and each// `v = v[f]` step copied the rest again, per read, per mount; a path of up to three steps is one indexed readlet name = node.namelet inRow = rows[name] != nullif (node.k == 'field') {let path = node.pathlet n = path.lengthif (n == 1) {if (inRow) { return rows[name] == null ? null : rows[name][path[0]] }return page[name] == null ? null : page[name][path[0]]}if (n == 2) {if (inRow) { return rows[name][path[0]] == null ? null : rows[name][path[0]][path[1]] }return page[name][path[0]] == null ? null : page[name][path[0]][path[1]]}}let v = nullif (inRow) { v = rows[name] } else { v = page[name] }if (node.k == 'field') {for (f of node.path) {if (v == null) { return null }v = v[f]}}return v}// A VIEW EXPRESSION (`p { "x" + n }`, `a - b`, `n > 3 ? 'big' : 'small'`) is evaluated by// the LANGUAGE'S OWN OPERATORS: this walk only picks the operator the author wrote and// applies it, so what `+` gives null and a string, what `==` says of two types, what `&&`// returns — all of it is the runtime's answer, on the server (the interpreter or a// binary) and in the browser (the client target), and hl:web has no rule of its own.// The leaves are reads (`value`) and literals. `&&`, `||` and `?:` evaluate what they// pick only, as the language does.evalExpr(&x, &page, &rows) {if (x.k == 'bin') {let l = evalExpr(&x.l, &page, &rows)let op = x.opif (op == 'logical_and') { return l && evalExpr(&x.r, &page, &rows) }if (op == 'logical_or') { return l || evalExpr(&x.r, &page, &rows) }let r = evalExpr(&x.r, &page, &rows)if (op == 'add') { return l + r }if (op == 'subtract') { return l - r }if (op == 'multiply') { return l * r }if (op == 'divide') { return l / r }if (op == 'modulo') { return l % r }if (op == 'equal') { return l == r }if (op == 'not_equal') { return l != r }if (op == 'less_than') { return l < r }if (op == 'greater_than') { return l > r }if (op == 'less_equal') { return l <= r }if (op == 'greater_equal') { return l >= r }if (op == 'bit_and') { return l & r }if (op == 'bit_or') { return l | r }if (op == 'bit_xor') { return l ^ r }if (op == 'shift_left') { return l << r }return l >> r}if (x.k == 'un') {let o = evalExpr(&x.x, &page, &rows)if (x.op == 'logical_not') { return !o }if (x.op == 'negate') { return -o }return ~o}if (x.k == 'cond') { return evalExpr(&x.c, &page, &rows) ? evalExpr(&x.a, &page, &rows) : evalExpr(&x.b, &page, &rows) }return value(&x, &page, &rows)}
Branches
Latest commits
- 10f8a8c8Merge branch 'code-order' into mainJukebox
- 204fc828Merge branch 'day72' into mainJukebox
- 95f5faae|||PR jukebox#7 Drop needless let declarationsmre
- 33072bb5|||PR Record day72 gates and Chrome proofmre
- 95f2cd73|||PR Use typed parent methods for screen playback and local server facesmre
- 6422a020Sync media-player at 51c3818mre
- b582ba1cVendor complete Hybriel day72 plugin setmre
- 02dccbc9Merge branch 'records-1119' into mainJukebox
- a39e1c23|||PR Records: missions 013-015, reconnect fix livemre
- fc7db075Merge branch 'reconnect-retry' into mainJukebox
- ac6f4c6fL2: plain declaration for a in pickedNextmre
- 2f335086Review round 2: only an explicit queue pick drops pend (not the automatic advance); jb23 records every source changemre
- 3eb6695fReview fixes: action generation, queue pick clears pend, Previous/Next retry the decided request, typed handlersmre
- 7a53c0c2|||PR A tap lost to a dead socket plays after reconnect (mission 015)mre
- 1f0cd77bMerge branch 'records-day41' into mainJukebox
- 67be229f|||PR Records: day41 live (PR #4), mission 012, statusmre
- 0bb027daconductor: caramboleyo is the user, not owner/creatorApollo
- 04f5d9d5Merge branch 'day41' into mainJukebox
- 8ed6da45|||PR README: media-player pin df9e7dfmre
- d5d45fc3|||PR media-player df9e7df (repeat-one fix), sync pin and SOURCEmre