gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit4d1a4cf44d1a4cf4log: #25 numbersmre4d1a4cf4/plugins/web/compile.hl

59.2 KB

  1. // plugins/web/compile.hl — THE FRAMEWORK COMPILES EACH COMPONENT.
  2. //
  3. // Mission 313 (the creator, 15 Sep 14:30: "clientside interpreter + table against
  4. // component code per component, no tables needed"). The old hl:web ships ONE generic client
  5. // that walks a tree the seed carries: it pairs elements with nodes, asks a table which
  6. // members each element shows, asks `view.value` what each bound spot holds, and does it
  7. // again on every paint. hl:web ships the ANSWERS instead — this file writes each
  8. // component's own code, once, where the old hl:web would have walked.
  9. //
  10. // WHAT IS EMITTED, per component, beside the class `hlJs` compiled:
  11. //
  12. // v(c,m,o,host,i,rows,rk,fill,cr,opt) the component's View, unrolled: one
  13. // statement per element, per handler, per
  14. // bound spot. `cr` false CLAIMS the server's
  15. // DOM (take host.children[i], step on), `cr`
  16. // true CREATES it — the two walks the old hl:web
  17. // spells out separately, which differ only in
  18. // where an element comes from.
  19. // b["<for site>"] one `for` body — the row factory the keyed
  20. // region builds a row with.
  21. // t/e["<if site>"] an `if`'s two branches.
  22. // f["<reference site>"] the fragment this component writes into a
  23. // child's `slot` — built in THIS frame, which
  24. // is why it is this component's code.
  25. // p["<element site>"] the paint statements: `p` writes what one
  26. // member feeds (the old hl:web's paint(&m,s,name)),
  27. // `r` rewrites a row's element where the DOM
  28. // does not already hold it (rowPaint).
  29. //
  30. // The generated code calls a FIXED runtime (client.hl) for everything that is not this
  31. // component: the mount records, the keyed region diff, the binding edges, the
  32. // derivations, the socket, navigation. It never looks anything up in a table — the
  33. // names, the sites and the write sets are written into the statements.
  34. //
  35. // It is TEXT the framework produces, served from memory beside the module (WebFramework
  36. // `module`), never a JavaScript file under plugins/.
  37. import { newline, tab } from './view.hl'
  38. import HlwView from './view.hl'
  39. import HlwViewServer from './viewserver.hl'
  40. // The framework supplies its one graph-key → browser-key mapping. Reflection and
  41. // SSR keep the original key; only emitted component identities use this function.
  42. browserKeyOf = null
  43. // ---- the emitted half --------------------------------------------------------------
  44. module(gen, key, nodes, fnTable, fills) {
  45. literalFns = []
  46. fns = [] // the sub-walks: row bodies, if branches, fills
  47. done = {}
  48. rowVars = []
  49. tbl = tableOf(gen, key) // what the language says about this file, read once
  50. regions = regionIndex(tbl) // a `for`'s list reads, an `if`'s condition reads
  51. // A SHELL'S VIEW IS A `body` ELEMENT and the document already has one: the walk runs
  52. // against document.body itself, so the root list is that element's children and the
  53. // element only takes the marks a region rebuild on it would need.
  54. let roots = nodes
  55. let bodySite = null
  56. if (nodes.length == 1 && nodes[0].k == 'el' && nodes[0].tag == 'body') {
  57. roots = nodes[0].children
  58. bodySite = nodes[0].site
  59. }
  60. publicKey = browserKeyOf(key)
  61. let root = walkTop(publicKey, roots)
  62. // THE NAMED-REGION FILLS this View's root writes (`side { … }`): each is a sub-walk of THIS
  63. // component (its members, its handlers), run by the browser into the region a level above holds
  64. let fillNames = '{'
  65. let fillConds = '{'
  66. if (fills != null) {
  67. for (fl of fills) {
  68. sub(publicKey, fl.children, 'R', fl.site)
  69. fillNames = fillNames + (fillNames == '{' ? '' : ',') + str(fl.name) + ':' + str(fl.site)
  70. // a conditional fill (`if (x) { side { … } }`): the condition, read off the filling instance
  71. if (fl.cond != null) { fillConds = fillConds + (fillConds == '{' ? '' : ',') + str(fl.name) + ':function(inst,r){return ' + rawRead(fl.cond) + ';}' }
  72. }
  73. }
  74. fillNames = fillNames + '}'
  75. fillConds = fillConds + '}'
  76. if (bodySite != null) {
  77. root = root.replace('let r=rows;', 'let r=rows;await c.markHost(m,host,' + str(bodySite) + ');')
  78. }
  79. let src = ';(function(){var g=(typeof globalThis!=="undefined"?globalThis:window);'
  80. src = src + 'var C=(g.__hlC=g.__hlC||{});'
  81. // the element a claim takes or a create makes — the one shape both walks share; a create
  82. // inside an svg (or an svg itself) is made in the SVG namespace, as the parser makes it
  83. // THE PRELUDE, one per module: the element a claim takes or a create makes, and the
  84. // two reads. A read written out in full — `(r["title"]!=null?r["title"]:inst["title"])`
  85. // — is 45 bytes and a component's View holds dozens of them; named, it is 16. The
  86. // rule is the same rule (a `for` row variable in scope wins over a member of the
  87. // same name, and a field path walks into it), spelled once.
  88. // A claim also moves the host's CURSOR — the last node the walk took there — which is
  89. // where a text leaf and a region's mark are looked for next (client.hl `leafNode`,
  90. // `markAt`).
  91. // MISSION 505: the five helpers (A, S, X, RV, RF) are bound off the runtime text (`paintHelpers` below) instead of written
  92. // into every module
  93. src = src + 'var A=g.__hlP.A,S=g.__hlP.S,X=g.__hlP.X,RV=g.__hlP.RV,RF=g.__hlP.RF,N=g.__hlP.N,TX=g.__hlP.TX;'
  94. src = src + 'var B={},T={},E={},F={},P={},D={},R={};'
  95. src = src + 'var L=[' + literalFns.join(',') + '];'
  96. // ONE FUNCTION PER LIST, however many sites reach it: a nested walk is written once
  97. // and named — emitting it per site made the reference app's home page 215 KB of the
  98. // same code over and over.
  99. let wi = 0
  100. for (f of fns) {
  101. wi = wi + 1
  102. let name = 'w' + wi
  103. src = src + 'var ' + name + '=' + f.src + ';'
  104. for (site of f.sites) { src = src + f.slot + '[' + str(site) + ']=' + name + ';' }
  105. }
  106. let paints = []
  107. collectPaints(&paints, roots)
  108. for (e of paints) { src = src + 'P[' + str(e.site) + ']={p:' + e.paint + ',r:' + e.row + '};' }
  109. src = src + 'C[' + str(publicKey) + ']={v:' + root + ',b:B,t:T,e:E,f:F,p:P,d:D,r:R,rn:' + fillNames + ',rc:' + fillConds
  110. // THE ANSWERS A LOOKUP STILL NEEDS, and only those. A local event's write set stands
  111. // at its own listener and a region's names at its own region — written into the
  112. // call. These three are asked for by NAME at run time and cannot be: an inbound
  113. // frame names its event, a routine handed down names the member that holds it, and
  114. // a write set names the derivations that follow it. `on` is the one thing run FROM the
  115. // module's own scope: the language's instance-scoped handler (`on page.ev`, the instance's
  116. // own bus: runtime `hlInstanceBus`) with the event named at run time, which client.hl
  117. // `wireUp` registers for a page (#193). The bus class is read off the instance's own class
  118. // (`static __events__`): a module imports no `hlScopedBus` unless it writes an `on x.y`, and
  119. // a minified module renames `EventBus`.
  120. src = src + ',ev:' + eventMap() + ',mw:' + memberMap() + ',dv:' + derivList() + ',fn:' + fnMap(fnTable) + ',on:g.__hlP.O};'
  121. return src + '})();' + newline
  122. }
  123. // MISSION 505: THE SHARED PRELUDE, once per page. The five helpers every module's paint text calls — the element a claim
  124. // takes or a create makes (A), the text of a value (S), a region's sub-walk (X), the two reads (RV, RF) — were written
  125. // into every module: 699 bytes, 25 times on the reference app's start page. They are appended to the runtime text the
  126. // framework serves (WebFramework `runtime`), as `globalThis.__hlP`, and a module binds them by name (`module` above):
  127. // every module imports the runtime first, so they are there when its paint text runs. The two texts must agree on the
  128. // names; this is the only place the helpers are written.
  129. paintHelpers() {
  130. let s = ';(function(){var g=(typeof globalThis!=="undefined"?globalThis:window);var P=(g.__hlP=g.__hlP||{});'
  131. s = s + 'P.A=function(cr,host,i,tag){if(cr){if(tag==="svg"||(host.namespaceURI==="http://www.w3.org/2000/svg"&&host.localName.toLowerCase()!=="foreignobject")){return document.createElementNS("http://www.w3.org/2000/svg",tag);}return document.createElement(tag);}var e=host.children[i];if(e!=null){host.__hlCur=e;}return e;};'
  132. s = s + 'P.S=function(v){return v==null?"":""+v;};'
  133. s = s + 'P.X=async function(t,r,q){return await g.__hlX(t,q,r);};'
  134. s = s + 'P.RV=function(r,q,n){return r[n]!=null?r[n]:q[n];};'
  135. s = s + 'P.RF=function(r,q,n,p){var v=P.RV(r,q,n);for(var k=0;k<p.length;k++){if(v==null)return null;v=v[p[k]];}return v;};'
  136. // W200: the element idiom's fixed part (claim or create, the failed-claim report, the row/site/key stamp and the literal), a
  137. // build walk's text node, and the instance-scoped handler every module's `on:` names (client.hl `wireUp`)
  138. s = s + 'P.N=function(c,cr,host,i,tag,rows,site,key,lit){var el=P.A(cr,host,i,tag);if(el==null){c.acqFail(tag,host);return null;}el.__hlRows=rows;el.__hlSite=site;el.__hlKey=key;el.__hlLit=lit;return el;};'
  139. s = s + 'P.TX=function(h,t){h.appendChild(document.createTextNode(t));};'
  140. s = s + 'P.O=function(i,e,f){if(!Object.prototype.hasOwnProperty.call(i,"__instanceEvents__")){Object.defineProperty(i,"__instanceEvents__",{value:new (i.constructor.__events__.constructor)()});}i.__instanceEvents__.on(e,f);};'
  141. s = s + 'P.L=function(u){return import(u);};'
  142. return s + '})();'
  143. }
  144. tbl = null
  145. regions = {}
  146. // WHAT A FUNCTION VALUE WRITES, by the site it was made at (tickets #98, #99): the
  147. // module announces a function's return with its site, and the browser repaints this
  148. // set — the members it writes, closed over the methods it calls and the events it
  149. // emits, the same closure a handler's set gets. A function that writes nothing has
  150. // no entry.
  151. fnMap(fns) {
  152. let bySite = {}
  153. if (fns != null) {
  154. for (f of fns) {
  155. let names = closeWrites(&tbl, f.writes, f.reads)
  156. if (names.length > 0) { bySite[f.site] = names }
  157. }
  158. }
  159. return mapOf(bySite)
  160. }
  161. // what a DECLARED handler writes, by event: one entry per event name, unioned
  162. eventMap() {
  163. let byEvent = {}
  164. for (h of tbl.handlers) {
  165. if (!h.nested) {
  166. let have = byEvent[h.event] == null ? [] : byEvent[h.event]
  167. for (w of closeWrites(&tbl, h.writes, h.reads)) { if (!have.includes(w)) { have.push(w) } }
  168. byEvent[h.event] = have
  169. }
  170. }
  171. return mapOf(byEvent)
  172. }
  173. // A MEMBER HOLDING A ROUTINE: what calling it writes is what its initializer writes
  174. memberMap() {
  175. let byName = {}
  176. for (m of tbl.members) {
  177. if (m.nodes != null) { byName[m.name] = memberNames(m.nodes.writes) }
  178. }
  179. return mapOf(byName)
  180. }
  181. // EVERY INITIALIZER, IN DECLARATION ORDER, with the members it reads — the whole of
  182. // what a derivation needs; the class carries the computation itself as `__derive__`.
  183. // `srv` (written only when true, same rule as `isStatic` on a read — every byte here
  184. // ships to the browser) marks a SERVER REFERENCE SITE (COMPONENTS.md §9.1/§9.3): an
  185. // initializer that calls an imported class (`import Store from './store.hl'`, then
  186. // `Store.chatsOf(…)` — `hlDenotes`'s own `kind: 'class'`, not a second resolution).
  187. // It is evaluated per request, on the SERVER, and its value ships into the page as
  188. // state; `client.hl`'s `moved()` must never call it locally — routger's `conversations
  189. // = … ? store.chatsOf(session.user.id) : []` reached `hl:time`, which ships no client
  190. // half, the moment a session sync (0b17f65b) made `session` move in the browser and
  191. // `moved()` re-ran every derivation that reads it. A fresh value for a server
  192. // reference site ships in `sync` instead (WebFramework.hl `serverSyncNames`).
  193. derivList() {
  194. let src = '['
  195. let first = true
  196. let own = []
  197. for (m of tbl.members) { if (!m.isStatic) { own.push(m.name) } }
  198. for (d of tbl.derivations) {
  199. if (!first) { src = src + ',' }
  200. first = false
  201. src = src + '{name:' + str(d.name) + ',site:' + str(d.site) + ',reads:' + list(derivedReads(d, own))
  202. if (d.serverSite) { src = src + ',srv:true' }
  203. src = src + '}'
  204. }
  205. return src + ']'
  206. }
  207. // A derivation re-runs when any member it needs moves: the initializer's own reads plus
  208. // the compiler's transitive `inputs` (members read through methods and helpers it calls,
  209. // SPEC "Reflection builtins for frameworks"), kept to this class's instance members.
  210. derivedReads(d, own) {
  211. let out = memberNames(d.reads)
  212. if (d.inputs != null) {
  213. for (i of d.inputs) { if (own.includes(i) && !out.includes(i)) { out.push(i) } }
  214. }
  215. return out
  216. }
  217. mapOf(byName) {
  218. let src = '{'
  219. let first = true
  220. for (k of byName.keys()) {
  221. if (!first) { src = src + ',' }
  222. first = false
  223. src = src + str(k) + ':' + list(byName[k])
  224. }
  225. return src + '}'
  226. }
  227. // the write set and the read set of the handler at this site, closed over the methods
  228. // it calls and the handlers it emits to — computed here, written into the listener
  229. handlerSets(site) {
  230. for (h of tbl.handlers) {
  231. if (h.nested && h.site == site) {
  232. return list(closeWrites(&tbl, h.writes, h.reads)) + ',' + list(closeReads(&tbl, h.reads))
  233. }
  234. }
  235. return '[],[]'
  236. }
  237. // the named regions an `if`'s branch fills (`if (x) { side { … } }`), as a JS list, `null` for none: the
  238. // browser places those regions again when the condition changes
  239. fillNamesIn(nodes) {
  240. let out = ''
  241. for (c of nodes) {
  242. if (c.k == 'if' && c.regionfill != null) { out = out + (out == '' ? '' : ',') + str(c.regionfill) }
  243. }
  244. return out == '' ? 'null' : '[' + out + ']'
  245. }
  246. regionNamesAt(site) {
  247. let names = regions[site]
  248. return list(names == null ? [] : names)
  249. }
  250. fns = []
  251. literalFns = []
  252. // ---- the walk, unrolled ------------------------------------------------------------
  253. // `top` marks the View's own root list: an element there is a COMPOSITION ROOT — a
  254. // reference above may have overwritten some of its events and put classes on it, which
  255. // is what `opt` carries (the old hl:web's rootOverwrites and withRootClasses).
  256. walk(key, nodes) {
  257. return plain(key, nodes)
  258. }
  259. // a list's walk
  260. plain(key, nodes) {
  261. let body = ''
  262. for (n of nodes) { body = body + node(key, n, false, false) }
  263. return 'async function(c,m,o,host,i,rows,rk,fill,cr,opt){let inst=m.instance;let r=rows;' + body + 'return i;}'
  264. }
  265. // the View's own root list, whose elements are composition roots
  266. walkTop(key, nodes) {
  267. let body = ''
  268. for (n of nodes) { body = body + node(key, n, true, false) }
  269. return 'async function(c,m,o,host,i,rows,rk,fill,cr,opt){let inst=m.instance;let r=rows;' + body + 'return i;}'
  270. }
  271. // W200: a text leaf made on the build walk, or taken on the claim walk (the server's text node), the fixed part in `TX`
  272. textLeaf(t) { return 'if(cr){TX(host,' + t + ');}else{await c.leafAt(host,false,i,null,' + t + ');}' }
  273. // a sub-walk, registered under its own site so the runtime can reach it by name
  274. // A SUB-WALK IS WRITTEN ONCE, however often the compile reaches its list.
  275. sub(key, nodes, slot, site) {
  276. if (done[slot + ' ' + site] != null) { return null }
  277. done[slot + ' ' + site] = true
  278. fns.push({ slot = slot; sites = [site]; src = walk(key, nodes); })
  279. return null
  280. }
  281. done = {}
  282. node(key, n, top, filterOns) {
  283. if (n.k == 'el') { return elNode(key, n, top) }
  284. if (n.k == 'text') { return textLeaf(str(n.text)) }
  285. if (n.k == 'on') {
  286. // A REFERENCE ABOVE MAY HAVE OVERWRITTEN THIS EVENT on the composition root:
  287. // the root's own handler for it is dropped and the reference's stands instead
  288. // (the old hl:web's withoutOns, which applies to the root element's direct children).
  289. let guard = filterOns ? 'if(!(opt&&opt.over&&opt.over.indexOf(' + str(n.event) + ')>=0)){' : '{'
  290. return guard + 'await c.onAt(m,host,' + str(n.event) + ',' + str(n.site) + ',rows,' + handlerSets(n.site) + ');}'
  291. }
  292. if (n.k == 'member' && n.name == 'slot') {
  293. // the SHELL's slot is where the route component hangs; a child's slot is the
  294. // fragment its host wrote, and the host's frame builds it
  295. return 'if(m.isShell){i=await c.slotShell(m,host,i,cr);}else if(fill!=null){i=await c.slotFill(m,o,host,i,fill,cr);}'
  296. }
  297. // A TEXT LEAF STANDING IN A LIST — an `if` branch, a `for` body — beside elements or
  298. // alone: its own text node, and a site of the member it reads (or of the row it
  299. // stands in), painted by rewriting that node.
  300. if (n.k == 'member' || n.k == 'field' || n.k == 'expr') {
  301. let names = readNames(n)
  302. return 'await c.textAt(m,host,cr,async function(inst,r){return ' + textRead(n) + ';},' + list(names) + ',rows,rk);'
  303. }
  304. if (n.k == 'for') {
  305. // THE ROW VARIABLE IS IN SCOPE INSIDE THE BODY, and a read of it is the ROW's,
  306. // not a member of the instance — the language resolves it that way and the site
  307. // sets must say the same, or a member of the same name would paint the row.
  308. rowVars.push(n.row)
  309. sub(key, n.body, 'B', n.site)
  310. rowVars.pop()
  311. return 'i=await c.forAt(m,o,host,i,' + str(n.site) + ',' + str(n.row) + ',function(inst,r){return ' + rawRead(n.list) + ';},rows,rk,fill,cr,' + regionNamesAt(n.site) + ');'
  312. }
  313. if (n.k == 'if' && n.regionfill != null) { return '' }
  314. if (n.k == 'if' && n.region != null) {
  315. // A NAMED REGION: the default is this component's own sub-walk; what stands between the
  316. // region's marks is the default, or the fill a lower level wrote (client.hl `regionAt`)
  317. sub(key, n.then, 'D', n.site)
  318. return 'i=await c.namedRegionAt(m,o,host,i,' + str(n.site) + ',' + str(n.region) + ',rows,rk,fill,cr);'
  319. }
  320. if (n.k == 'if') {
  321. sub(key, n.then, 'T', n.site)
  322. sub(key, n.other, 'E', n.site)
  323. return 'i=await c.ifAt(m,o,host,i,' + str(n.site) + ',function(inst,r){return ' + rawRead(n.cond) + ';},rows,rk,fill,cr,' + regionNamesAt(n.site) + ',' + fillNamesIn(n.then) + ');'
  324. }
  325. if (n.k == 'component') {
  326. if (n.fill != null && n.fill.length > 0) { sub(key, n.fill, 'F', n.site) }
  327. return 'i=await c.kidAt(m,host,i,' + kidSpec(n) + ',rows,rk,fill,cr,opt);'
  328. }
  329. return ''
  330. }
  331. // ---- an element --------------------------------------------------------------------
  332. elNode(key, n, top) {
  333. // W200: the element, its claim-or-create, the failed-claim report and the row/site/key/literal stamp are the shared `N`
  334. // A literal reads only its arguments. Create it once at module scope instead of
  335. // allocating a function on every claim/create walk (#107 detached-node regression).
  336. literalIndex = literalFns.length
  337. literalFns.push('function(inst,r){return ' + litNamed(n) + ';}')
  338. let src = '{let el=N(c,cr,host,i,' + str(n.tag) + ',rows,' + str(n.site) + ',' + str(key) + ',L[' + literalIndex + ']);if(!cr){i=i+1;}'
  339. src = src + 'if(el!=null){'
  340. // the attributes, on the walk that BUILDS the element (a claim takes the server's)
  341. src = src + 'if(cr){' + createAttrs(n) + (top ? 'await c.rootClasses(el,opt);' : '') + 'host.appendChild(el);}'
  342. let names = siteNames(n)
  343. let valueMember = 'null'
  344. for (a of n.attrs) { if (a.member != null && a.name == 'value') { valueMember = str(a.member) } }
  345. let sited = ''
  346. if (names.length > 0 || valueMember != 'null') {
  347. sited = 'await c.siteAt(m,el,' + list(names) + ',' + str(n.site) + ',' + valueMember + ',' + (n.tag == 'select' ? 'true' : 'false') + ',rows);'
  348. }
  349. let kids = ''
  350. // AN ELEMENT THAT HOLDS ONLY TEXT is painted whole (`textContent`, see the paints):
  351. // built, it gets that text as one node; claimed, the server's is taken as it stands
  352. let whole = textOf(n)
  353. if (whole != null) {
  354. kids = 'if(cr){TX(host,' + whole + ');}'
  355. for (c of n.children) { if (c.k == 'on') { kids = kids + node(key, c, false, top) } }
  356. }
  357. else if (mixed(n)) { kids = mixedKids(key, n, top) }
  358. else { for (c of n.children) { kids = kids + node(key, c, false, top) } }
  359. let inner = '{let host=el;let i=0;' + kids + '}'
  360. // A SELECT IS SITED AFTER ITS OPTIONS: the member decides which option stands, and
  361. // the read-back that `siteAt` does reports nothing before they exist.
  362. if (n.tag == 'select') { src = src + inner + (selectValue(n) == 'null' ? '' : 'if(cr){await c.applySelectAt(m,el,' + selectValue(n) + ');}') + sited }
  363. else { src = src + sited + inner }
  364. return src + '}}'
  365. }
  366. // A TEXT LEAF BESIDE AN ELEMENT OR A REGION (ticket #86 follow-up): `td { d.n if (…) {…} }`
  367. // cannot be painted through `textContent`, which would wipe the branch. Each RUN of
  368. // adjacent leaves is one text node, held on the element (`__hlLeaves`, by the run's
  369. // index) where the walk builds or claims it, and the paints rewrite that node alone.
  370. mixed(n) {
  371. if (textOf(n) != null) { return false }
  372. for (c of n.children) { if (isReadNode(c)) { return true } }
  373. return false
  374. }
  375. isLeaf(c) { return c.k == 'text' || isReadNode(c) }
  376. // a node that shows a value read at render time: a member, a field path, or an expression
  377. isReadNode(c) { return (c.k == 'member' || c.k == 'field' || c.k == 'expr') && c.name != 'slot' }
  378. // the members whose move repaints a read (`Style` and a `for` row variable are not members
  379. // of the instance), and the guard a paint writes for them
  380. readNames(c) {
  381. let out = []
  382. for (nm of (c.k == 'expr' ? c.names : [c.name])) {
  383. if (nm != 'Style' && !rowVars.includes(nm) && !out.includes(nm)) { out.push(nm) }
  384. }
  385. return out
  386. }
  387. guardOf(c) {
  388. let g = ''
  389. for (nm of readNames(c)) { g = g + (g == '' ? '' : '||') + 'n===' + str(nm) }
  390. return g
  391. }
  392. // the runs of adjacent leaves, in order; an `on` renders nothing and splits none
  393. runsOf(n) {
  394. let out = []
  395. let run = []
  396. for (c of n.children) {
  397. if (isLeaf(c)) { run.push(c) }
  398. else if (c.k != 'on') {
  399. if (run.length > 0) { out.push(run) }
  400. run = []
  401. }
  402. }
  403. if (run.length > 0) { out.push(run) }
  404. return out
  405. }
  406. runText(run) {
  407. let src = '""'
  408. for (c of run) { src = src + '+(' + (c.k == 'text' ? str(c.text) : textRead(c)) + ')' }
  409. return src
  410. }
  411. runFeeds(run) {
  412. for (c of run) { if (c.k != 'text') { return true } }
  413. return false
  414. }
  415. mixedKids(key, n, top) {
  416. let kids = ''
  417. let run = []
  418. let k = 0
  419. for (c of n.children) {
  420. if (isLeaf(c)) { run.push(c) }
  421. else {
  422. if (c.k != 'on' && run.length > 0) { kids = kids + leafRun(run, k) k = k + 1 run = [] }
  423. kids = kids + node(key, c, false, top)
  424. }
  425. }
  426. if (run.length > 0) { kids = kids + leafRun(run, k) }
  427. return kids
  428. }
  429. // EVERY CALL INTO THE CLIENT IS AWAITED: its methods are async in the browser, and one
  430. // not awaited runs its DOM work after the walk has gone on — a built leaf then lands
  431. // after the elements that follow it (ticket #104).
  432. leafRun(run, k) {
  433. if (!runFeeds(run)) { return textLeaf(runText(run)) }
  434. return 'await c.leafAt(host,cr,i,' + k + ',' + runText(run) + ');'
  435. }
  436. // the attributes an element is BUILT with — a bound one written in, a literal one as it
  437. // stands. `value` is a property once the page is live and an attribute as the control's
  438. // default; a textarea has no value attribute at all and a select's value is an option.
  439. createAttrs(n) {
  440. let src = ''
  441. for (a of n.attrs) {
  442. if (isBool(a)) {
  443. src = src + '{' + boolWrite(a, rawRead(a.member != null ? { k = 'member'; name = a.member; } : a.ref)) + '}'
  444. } else if (nullable(a)) {
  445. src = src + '{let v=' + rawRead(a.member != null ? { k = 'member'; name = a.member; } : a.ref) + ';if(v!=null){el.setAttribute(' + str(a.name) + ',""+v);}}'
  446. } else {
  447. let rd = a.member != null ? readOf({ k = 'member'; name = a.member; }) : (a.ref != null ? readOf(a.ref) : str(a.text))
  448. src = src + '{let v=' + rd + ';'
  449. if (a.extra != null) { src = src + 'v=v+" "+' + str(a.extra) + ';' }
  450. if (n.tag == 'select' && a.name == 'value') { src = src + '}' }
  451. else if (a.name == 'value') {
  452. src = src + 'if(el.value!=null){el.value=v;' + (n.tag == 'textarea' ? '' : 'el.setAttribute("value",v);') + '}else{el.setAttribute("value",v);}}'
  453. } else { src = src + 'el.setAttribute(' + str(a.name) + ',v);}' }
  454. }
  455. }
  456. if (boundValue(n)) { src = src + 'el.setAttribute("autocomplete","off");' }
  457. return src
  458. }
  459. // a bound attribute whose null read is NO attribute (#177): not `value` (a control's
  460. // value has its own rules), and not one carrying extra classes
  461. nullable(a) {
  462. return (a.member != null || a.ref != null) && a.name != 'value' && a.extra == null && !v.isBoolAttr(a.name)
  463. }
  464. // a BOUND boolean attribute — a literal one was decided at build (WebFramework `element`)
  465. isBool(a) {
  466. return (a.member != null || a.ref != null) && v.isBoolAttr(a.name)
  467. }
  468. // A BOUND BOOLEAN ATTRIBUTE, WRITTEN (ticket #33): set when the value is on, REMOVED when
  469. // it is off — the markup's rule (viewserver.boolAttrs) — and the DOM property with it, because
  470. // once the page is live `checked` is the property and the attribute only its default.
  471. boolWrite(a, raw) {
  472. props = { allowfullscreen = 'allowFullscreen'; formnovalidate = 'formNoValidate'; ismap = 'isMap'; itemscope = 'itemScope'; nomodule = 'noModule'; novalidate = 'noValidate'; playsinline = 'playsInline'; readonly = 'readOnly'; }
  473. prop = props[a.name] != null ? props[a.name] : a.name
  474. return 'let on=!!' + raw + ';if(on){el.setAttribute(' + str(a.name) + ',"");}else if(el.removeAttribute){el.removeAttribute(' + str(a.name) + ');}if(' + str(prop) + ' in el&&el[' + str(prop) + ']!==on){el[' + str(prop) + ']=on;}'
  475. }
  476. // view.hl's `boundValue`, to the letter: a FORM CONTROL whose `value` reads a member or
  477. // a field, and not one the author gave an `autocomplete` of its own
  478. boundValue(n) {
  479. if (n.tag != 'input' && n.tag != 'textarea' && n.tag != 'select') { return false }
  480. let bound = false
  481. for (a of n.attrs) {
  482. if (a.name == 'autocomplete') { return false }
  483. if (a.name == 'value' && (a.member != null || a.ref != null)) { bound = true }
  484. }
  485. return bound
  486. }
  487. selectValue(n) {
  488. for (a of n.attrs) {
  489. if (a.name == 'value') {
  490. if (a.member != null) { return readOf({ k = 'member'; name = a.member; }) }
  491. if (a.ref != null) { return readOf(a.ref) }
  492. return str(a.text)
  493. }
  494. }
  495. return 'null'
  496. }
  497. // the element's own entries as the literal sees them — its attributes by name, then the
  498. // `for` row variables in scope (the row rides on the value)
  499. litNamed(n) {
  500. let src = '{'
  501. let first = true
  502. for (a of n.attrs) {
  503. if (!first) { src = src + ',' }
  504. first = false
  505. let v = a.member != null ? rawRead({ k = 'member'; name = a.member; }) : (a.ref != null ? rawRead(a.ref) : str(a.text))
  506. src = src + str(a.name) + ':' + v
  507. }
  508. return src + '}'
  509. }
  510. // the reference's own description, written at its use site: what it binds, what it
  511. // overwrites, the classes the host's `#Child` rule puts on it
  512. kidSpec(n) {
  513. let src = '{key:' + str(browserKeyOf(n.key)) + ',kid:' + str(kidKeyOf(n)) + ',site:' + str(n.site) + ',fill:' + ((n.fill != null && n.fill.length > 0) ? 'true' : 'false')
  514. src = src + ',bindings:['
  515. let first = true
  516. for (b of n.bindings) {
  517. if (!first) { src = src + ',' }
  518. first = false
  519. src = src + '{name:' + str(b.name) + ',member:' + (b.member == null ? 'null' : str(b.member))
  520. src = src + ',ref:' + (b.ref == null ? 'null' : 'function(inst,r){return ' + rawRead(b.ref) + ';}')
  521. src = src + ',refName:' + (b.ref == null ? 'null' : str(b.ref.name))
  522. src = src + ',text:' + (b.text == null ? 'null' : 'true') + ',value:' + (b.text == null ? 'null' : refLiteral(b)) + '}'
  523. }
  524. src = src + '],ons:['
  525. first = true
  526. for (o of n.ons) {
  527. if (!first) { src = src + ',' }
  528. first = false
  529. src = src + '{event:' + str(o.event) + ',site:' + str(o.site) + ',sets:[' + handlerSets(o.site) + ']}'
  530. }
  531. src = src + '],classes:' + list(n.classes == null ? [] : n.classes) + '}'
  532. return src
  533. }
  534. // view.hl's kidKey: the reference's path, joined — the key the server mounted it under
  535. kidKeyOf(n) {
  536. let out = ''
  537. for (p of n.path) { out = out + '/' + p }
  538. return out
  539. }
  540. // the value a literal binding carries — view.refValue, folded at compile time
  541. refLiteral(b) {
  542. if (b.kind == 'folded') { return jsValue(b.value) }
  543. if (b.kind == 'number') { return '' + b.text }
  544. if (b.kind == 'boolean') { return b.text == 'true' ? 'true' : 'false' }
  545. if (b.kind == 'null_literal') { return 'null' }
  546. return str(b.text)
  547. }
  548. jsValue(v) {
  549. if (v == null) { return 'null' }
  550. if (hlTypeName(v) == 'String') { return str(v) }
  551. if (hlTypeName(v) == 'Boolean') { return v ? 'true' : 'false' }
  552. if (hlTypeName(v) == 'Number') { return '' + v }
  553. return JSON.stringify(v)
  554. }
  555. // ---- the site set: what this element SHOWS ------------------------------------------
  556. // The old hl:web asked the module's table which members the element at this site reads. The
  557. // answer is a fact about the View, so it is written in: the members its bound
  558. // attributes and its text leaves name. `Style` is folded into a class name at build and
  559. // the shell's `slot` is swapped by navigation — neither is ever painted, and neither is
  560. // a member read that reaches here (a `for` row variable resolves to its row).
  561. siteNames(n) {
  562. let out = []
  563. for (a of n.attrs) {
  564. if (a.member != null && a.member != 'Style' && !rowVars.includes(a.member) && !out.includes(a.member)) { out.push(a.member) }
  565. // A FIELD OF A MEMBER (`value = f.title`, ticket #93) is a read of the member:
  566. // a write to `f.title`, or a new `f`, moves `f`, and this element repaints
  567. if (a.ref != null && a.ref.name != 'Style' && !rowVars.includes(a.ref.name) && !out.includes(a.ref.name)) { out.push(a.ref.name) }
  568. }
  569. for (c of n.children) {
  570. if (isReadNode(c)) {
  571. for (nm of readNames(c)) { if (!out.includes(nm)) { out.push(nm) } }
  572. }
  573. }
  574. return out
  575. }
  576. rowVars = []
  577. // ---- the paints ---------------------------------------------------------------------
  578. collectPaints(&out, nodes) {
  579. for (n of nodes) {
  580. if (n.k == 'el') {
  581. let paint = paintFn(n)
  582. let row = rowFn(n)
  583. if (paint != null || row != 'null') {
  584. out.push({ site = n.site; paint = paint == null ? 'null' : paint; row = row; })
  585. }
  586. collectPaints(&out, n.children)
  587. } else if (n.k == 'for') { collectPaints(&out, n.body) }
  588. else if (n.k == 'if') { collectPaints(&out, n.then) collectPaints(&out, n.other) }
  589. else if (n.k == 'component') { if (n.fill != null) { collectPaints(&out, n.fill) } }
  590. }
  591. return null
  592. }
  593. // `paint(&m, s, name)`, compiled: the bound attributes under the member each reads, and
  594. // the text where the member that moved stands among the leaves.
  595. paintFn(n) {
  596. let body = ''
  597. for (a of n.attrs) {
  598. if (a.member != null) {
  599. body = body + 'if(n===' + str(a.member) + '){' + attrWrite(n, a, readOf({ k = 'member'; name = a.member; })) + '}'
  600. } else if (a.ref != null) {
  601. // a field of a member paints when the MEMBER moves (ticket #93)
  602. body = body + 'if(n===' + str(a.ref.name) + '){' + attrWrite(n, a, readOf(a.ref)) + '}'
  603. }
  604. }
  605. let text = textOf(n)
  606. if (text != null) {
  607. let guard = ''
  608. for (c of n.children) {
  609. if (isReadNode(c)) {
  610. let g = guardOf(c)
  611. if (g != '') {
  612. if (guard != '') { guard = guard + '||' }
  613. guard = guard + g
  614. }
  615. }
  616. }
  617. if (guard != '') { body = body + 'if(' + guard + '){el.textContent=' + text + ';}' }
  618. } else if (mixed(n)) {
  619. let k = 0
  620. for (run of runsOf(n)) {
  621. let guard = ''
  622. for (c of run) {
  623. if (c.k != 'text') {
  624. let g = guardOf(c)
  625. if (g != '') {
  626. if (guard != '') { guard = guard + '||' }
  627. guard = guard + g
  628. }
  629. }
  630. }
  631. if (guard != '') { body = body + 'if((' + guard + ')&&el.__hlLeaves&&el.__hlLeaves[' + k + ']){el.__hlLeaves[' + k + '].data=' + runText(run) + ';}' }
  632. k = k + 1
  633. }
  634. }
  635. if (body == '') { return null }
  636. return 'async function(el,inst,r,n,keepInput){' + body + '}'
  637. }
  638. // `rowPaint(&m, el)`, compiled: every bound spot, written only where the DOM does not
  639. // already hold it — which is why a push into 2000 rows costs the 1999 nothing.
  640. rowFn(n) {
  641. let body = ''
  642. for (a of n.attrs) {
  643. if (isBool(a)) {
  644. body = body + '{' + boolWrite(a, rawRead(a.member != null ? { k = 'member'; name = a.member; } : a.ref)) + '}'
  645. } else if (nullable(a)) {
  646. body = body + '{let v=' + rawRead(a.member != null ? { k = 'member'; name = a.member; } : a.ref) + ';if(v==null){if(el.hasAttribute(' + str(a.name) + ')){el.removeAttribute(' + str(a.name) + ');}}else{v=""+v;if(el.getAttribute(' + str(a.name) + ')!==v){el.setAttribute(' + str(a.name) + ',v);}}}'
  647. } else if (a.member != null || a.ref != null) {
  648. let one = 'let v=' + readOf(a.member != null ? { k = 'member'; name = a.member; } : a.ref) + ';'
  649. if (a.extra != null) { one = one + 'v=v+" "+' + str(a.extra) + ';' }
  650. if (n.tag == 'select' && a.name == 'value') { one = one + 'if(el.value!==v){el.value=v;}' }
  651. else {
  652. one = one + 'if(el.getAttribute(' + str(a.name) + ')!==v){el.setAttribute(' + str(a.name) + ',v);}'
  653. if (a.name == 'value') { one = one + 'if(el.value!=null&&el.value!==v){el.value=v;}' }
  654. }
  655. if (a.name == 'value') { one = 'if(el!==keepInput||el!==document.activeElement){' + one + '}' }
  656. body = body + '{' + one + '}'
  657. }
  658. }
  659. let text = textOf(n)
  660. let feeds = false
  661. for (c of n.children) { if (isReadNode(c)) { feeds = true } }
  662. if (text != null && feeds) { body = body + '{let t=' + text + ';if(el.textContent!==t){el.textContent=t;}}' }
  663. if (text == null && feeds) {
  664. let k = 0
  665. for (run of runsOf(n)) {
  666. if (runFeeds(run)) { body = body + '{let x=el.__hlLeaves&&el.__hlLeaves[' + k + '];let t=' + runText(run) + ';if(x&&x.data!==t){x.data=t;}}' }
  667. k = k + 1
  668. }
  669. }
  670. if (body == '') { return 'null' }
  671. return 'async function(el,inst,r,keepInput){' + body + '}'
  672. }
  673. attrWrite(n, a, v) {
  674. if (isBool(a)) { return boolWrite(a, rawRead(a.member != null ? { k = 'member'; name = a.member; } : a.ref)) }
  675. if (nullable(a)) { return 'let v=' + rawRead(a.member != null ? { k = 'member'; name = a.member; } : a.ref) + ';if(v==null){if(el.hasAttribute(' + str(a.name) + ')){el.removeAttribute(' + str(a.name) + ');}}else{v=""+v;if(el.getAttribute(' + str(a.name) + ')!==v){el.setAttribute(' + str(a.name) + ',v);}}' }
  676. let src = 'let v=' + v + ';'
  677. if (a.extra != null) { src = src + 'v=v+" "+' + str(a.extra) + ';' }
  678. if (n.tag == 'select' && a.name == 'value') { return src + 'if(el!==keepInput||el!==document.activeElement){el.value=v;}' }
  679. // Setting an unchanged src can reload media; compare plain attributes before writing.
  680. if (a.name == 'value') { src = src + 'if(el!==keepInput||el!==document.activeElement){el.setAttribute(' + str(a.name) + ',v);if(el.value!=null&&el.value!==v){el.value=v;}}' }
  681. else { src = src + 'if(el.getAttribute(' + str(a.name) + ')!==v){el.setAttribute(' + str(a.name) + ',v);}' }
  682. return src
  683. }
  684. textOf(n) {
  685. let parts = []
  686. let content = 0
  687. let feeds = false
  688. for (c of n.children) {
  689. if (c.k != 'on') {
  690. content = content + 1
  691. if (c.k == 'text') { parts.push(str(c.text)) }
  692. else if (isReadNode(c)) { parts.push(textRead(c)) feeds = true }
  693. }
  694. }
  695. if (!feeds) { return null }
  696. if (parts.length != content) { return null }
  697. let src = '""'
  698. for (p of parts) { src = src + '+(' + p + ')' }
  699. return src
  700. }
  701. // ---- a read, written in ---------------------------------------------------------------
  702. // `view.value`'s own rule as an expression: a `for` row variable in scope wins over a
  703. // member of the same name, and a field path walks into it. `readOf` answers the STRING
  704. // the DOM takes; `rawRead` the value itself (a binding, a list, a condition).
  705. // A null bound value is empty, matching the server attribute writer.
  706. readOf(node) { return 'S(' + rawRead(node) + ')' }
  707. // A READ SHOWN AS TEXT: null is no text, as the server writes it (view.hl `escape`)
  708. textRead(node) { return 'S(' + rawRead(node) + ')' }
  709. rawRead(node) {
  710. if (node == null) { return 'null' }
  711. if (node.k == 'text') { return node.kind == 'folded' && hlTypeName(node.value) == 'Hybrid' ? JSON.stringify(node.value) : str(node.text) }
  712. if (node.k == 'expr') { return '(await X(' + JSON.stringify(node.x) + ',r,inst))' }
  713. if (node.k != 'field') { return 'RV(r,inst,' + str(node.name) + ')' }
  714. return 'RF(r,inst,' + str(node.name) + ',' + list(node.path) + ')'
  715. }
  716. list(names) {
  717. let src = '['
  718. let first = true
  719. for (n of names) {
  720. if (!first) { src = src + ',' }
  721. first = false
  722. src = src + str(n)
  723. }
  724. return src + ']'
  725. }
  726. // a JavaScript string literal — JSON's escaping is a subset of JavaScript's, so a
  727. // source text's quotes, newlines and backslashes survive into the statement unchanged
  728. str(s) {
  729. if (s == null) { return '""' }
  730. return JSON.stringify('' + s)
  731. }
  732. // ---- WHAT THE LANGUAGE SAYS ABOUT THIS FILE, read HERE and written into the code ----
  733. // The old hl:web shipped the language's answers to the browser as data: `hlJs` writes each file's
  734. // members, handlers and methods — every node of every initializer, with the names it
  735. // reads — into the module, and the client reduces that table on every boot. The answers
  736. // are facts about the source, so this file asks for them once, at compile time, and
  737. // writes the RESULT into the statements: a handler's write set stands at the listener
  738. // that needs it, a region's names at the region, the derivations as a list of what to
  739. // re-run. The module carries no table at all (WebFramework `module` drops the one the
  740. // emitter writes).
  741. //
  742. // The reflection is the framework's own analysis generation — the same `gen` the View
  743. // trees come from. Nothing starts a second one: a handle is only valid inside the
  744. // generation that made it.
  745. tableOf(gen, key) {
  746. let members = []
  747. let derivations = []
  748. let handlers = []
  749. let methods = []
  750. for (m of hlMembers(gen, key)) {
  751. let entry = { name = m.name; nodes = null; isStatic = m.isStatic == true; }
  752. if (m.hasValue) {
  753. let n = syntaxTree(gen, key, m.node)
  754. entry.nodes = n
  755. derivations.push({ name = m.name; site = n.site; reads = n.reads; serverSite = m.serverSite == true; pure = m.pure == true; writtenElsewhere = m.writtenElsewhere == true; inputs = m.inputs; })
  756. nestedHandlers(&handlers, n)
  757. }
  758. members.push(entry)
  759. }
  760. for (h of hlEvents(gen, key).handles) {
  761. let n = syntaxTree(gen, key, h.node)
  762. handlers.push({ event = h.event; site = n.site; reads = n.reads; writes = n.writes; nested = false; })
  763. }
  764. for (mm of hlMethods(gen, key)) {
  765. if (!mm.inlineHandler) {
  766. let n = syntaxTree(gen, key, mm.node)
  767. methods.push({ name = mm.name; reads = n.reads; writes = n.writes; })
  768. }
  769. }
  770. return { members = members; derivations = derivations; handlers = handlers; methods = methods; }
  771. }
  772. // A NESTED `on` IS A DOM HANDLER, filed under its own site — the id the View node
  773. // carries. Its body is not the literal's syntax, so the node answers for it and the
  774. // walk stops there.
  775. nestedHandlers(&into, n) {
  776. if (n == null) { return null }
  777. if (n.tag == 'on_statement') {
  778. into.push({ event = n.event; site = n.site; reads = n.reads; writes = n.writes; nested = true; })
  779. return null
  780. }
  781. for (c of [n.value, n.list, n.body, n.condition, n.consequent, n.alternate, n.object, n.property, n.callee, n.left, n.right, n.operand]) {
  782. if (c != null) { nestedHandlers(&into, c) }
  783. }
  784. for (l of [n.entries, n.args, n.elements]) {
  785. if (l != null) { for (c of l) { nestedHandlers(&into, c) } }
  786. }
  787. return null
  788. }
  789. // the site with its file's base name: everything after the last '/'. The path part
  790. // is not "up to the first ':'" — a package key has a colon of its own
  791. // ('hl:markdown/Markdown.hl:24:3'), and that reading left a package component's
  792. // sites unshortened, so its regions found no reads and never repainted (#111)
  793. shortSite(site) {
  794. if (site == null) { return null }
  795. let cut = site.lastIndexOf('/')
  796. if (cut < 0) { return site }
  797. return site.slice(cut + 1)
  798. }
  799. // the syntax of one node, recursively — hl:core/AST's `tree`, read off the framework's
  800. // own generation instead of starting one of its own
  801. syntaxTree(gen, key, node) {
  802. let n = hlSyntax(gen, key, node)
  803. if (n == null) { return null }
  804. // A SITE IS NAMED BY THE FILE'S BASE NAME. The reflection answers with the project
  805. // key ('components/sort_list.hl:77:26'); the View tree, the emitter's own
  806. // `__derive__` branches and every site this framework writes use the base name
  807. // ('sort_list.hl:77:26'). One spelling, or a lookup by site finds nothing.
  808. let out = { tag = n.tag; site = shortSite(n.site); reads = n.reads; writes = n.writes; }
  809. if (n.tag == 'object_expression') {
  810. let kids = []
  811. for (h of n.entries) { kids.push(syntaxTree(gen, key, h)) }
  812. out.entries = kids
  813. } else if (n.tag == 'object_property') {
  814. out.key = n.key
  815. out.value = syntaxTree(gen, key, n.value)
  816. } else if (n.tag == 'view_for') {
  817. out.list = syntaxTree(gen, key, n.list)
  818. out.body = syntaxTree(gen, key, n.body)
  819. } else if (n.tag == 'view_if') {
  820. out.condition = syntaxTree(gen, key, n.condition)
  821. out.consequent = syntaxTree(gen, key, n.consequent)
  822. out.alternate = syntaxTree(gen, key, n.alternate)
  823. } else if (n.tag == 'on_statement') {
  824. out.event = n.event
  825. } else if (n.tag == 'member_expression') {
  826. out.object = syntaxTree(gen, key, n.object)
  827. out.property = syntaxTree(gen, key, n.property)
  828. out.computed = n.computed
  829. } else if (n.tag == 'identifier') {
  830. out.name = n.name
  831. } else if (n.tag == 'call_expression') {
  832. out.callee = syntaxTree(gen, key, n.callee)
  833. let args = []
  834. for (h of n.args) { args.push(syntaxTree(gen, key, h)) }
  835. out.args = args
  836. } else if (n.tag == 'binary_expression') {
  837. out.left = syntaxTree(gen, key, n.left)
  838. out.right = syntaxTree(gen, key, n.right)
  839. } else if (n.tag == 'unary_expression') {
  840. out.operand = syntaxTree(gen, key, n.operand)
  841. } else if (n.tag == 'conditional_expression') {
  842. out.condition = syntaxTree(gen, key, n.condition)
  843. out.consequent = syntaxTree(gen, key, n.consequent)
  844. out.alternate = syntaxTree(gen, key, n.alternate)
  845. } else if (n.tag == 'array_expression') {
  846. let els = []
  847. for (h of n.elements) { els.push(syntaxTree(gen, key, h)) }
  848. out.elements = els
  849. }
  850. return out
  851. }
  852. // ---- the reductions the browser used to make on every boot --------------------------
  853. // A `for`'s names are what its list reads, an `if`'s what its condition reads — filed
  854. // under the region's own site.
  855. regionIndex(t) {
  856. let idx = {}
  857. for (m of t.members) { if (m.nodes != null) { indexRegions(&idx, m.nodes) } }
  858. return idx
  859. }
  860. indexRegions(&idx, n) {
  861. if (n == null) { return null }
  862. if (n.tag == 'view_for') {
  863. idx[n.site] = memberNames(nodeReads(n.list))
  864. indexRegions(&idx, n.body)
  865. return null
  866. }
  867. if (n.tag == 'view_if') {
  868. idx[n.site] = memberNames(nodeReads(n.condition))
  869. indexRegions(&idx, n.consequent)
  870. indexRegions(&idx, n.alternate)
  871. return null
  872. }
  873. if (n.tag == 'on_statement') { return null }
  874. for (c of [n.value, n.list, n.body, n.condition, n.consequent, n.alternate, n.object, n.property, n.callee, n.left, n.right, n.operand]) {
  875. if (c != null) { indexRegions(&idx, c) }
  876. }
  877. for (l of [n.entries, n.args, n.elements]) {
  878. if (l != null) { for (c of l) { indexRegions(&idx, c) } }
  879. }
  880. return null
  881. }
  882. // the member reads of a read list — the language resolved every name, so this is a
  883. // filter and not a second resolution
  884. memberNames(reads) {
  885. let out = []
  886. if (reads == null) { return out }
  887. for (r of reads) {
  888. if (r.kind == 'member' && r.isStatic != true && !out.includes(r.name)) { out.push(r.name) }
  889. }
  890. return out
  891. }
  892. nodeReads(n) {
  893. if (n == null) { return [] }
  894. if (n.reads != null) { return n.reads }
  895. let out = []
  896. for (c of [n.value, n.list, n.body, n.condition, n.consequent, n.alternate, n.object, n.property, n.callee, n.left, n.right, n.operand]) {
  897. if (c != null) { for (r of nodeReads(c)) { out.push(r) } }
  898. }
  899. for (l of [n.entries, n.args, n.elements]) {
  900. if (l != null) { for (c of l) { for (r of nodeReads(c)) { out.push(r) } } }
  901. }
  902. return out
  903. }
  904. // A ROUTINE'S WRITES, PLUS THE WRITES OF EVERYTHING IT REACHES — the method it calls
  905. // and the handler it emits to, transitively. Both are READS the language resolved, so
  906. // this is a walk of its answer and never a guess.
  907. closeWrites(&t, writes, reads) {
  908. let out = memberNames(writes)
  909. let queue = []
  910. reached(&queue, reads)
  911. let seen = {}
  912. while (queue.length > 0) {
  913. let at = queue.shift()
  914. if (seen[at] == null) {
  915. seen[at] = true
  916. let sp = at.indexOf(' ')
  917. let kind = at.slice(0, sp)
  918. let name = at.slice(sp + 1)
  919. for (mm of t.methods) {
  920. if (kind == 'method' && mm.name == name) {
  921. for (w of memberNames(mm.writes)) { if (!out.includes(w)) { out.push(w) } }
  922. reached(&queue, mm.reads)
  923. }
  924. }
  925. for (h of t.handlers) {
  926. if (kind == 'handler' && !h.nested && h.event == name) {
  927. for (w of memberNames(h.writes)) { if (!out.includes(w)) { out.push(w) } }
  928. reached(&queue, h.reads)
  929. }
  930. }
  931. for (mb of t.members) {
  932. if (kind == 'member' && mb.name == name && mb.nodes != null) {
  933. for (w of memberNames(mb.nodes.writes)) { if (!out.includes(w)) { out.push(w) } }
  934. reached(&queue, nodeReads(mb.nodes))
  935. }
  936. }
  937. }
  938. }
  939. return out
  940. }
  941. // the mirror: a handler's reads plus the reads of everything it reaches — the
  942. // candidates for a routine a host handed down, whose writes only the host's table names
  943. closeReads(&t, reads) {
  944. let out = memberNames(reads)
  945. let queue = []
  946. reached(&queue, reads)
  947. let seen = {}
  948. while (queue.length > 0) {
  949. let at = queue.shift()
  950. if (seen[at] == null) {
  951. seen[at] = true
  952. let sp = at.indexOf(' ')
  953. let kind = at.slice(0, sp)
  954. let name = at.slice(sp + 1)
  955. for (mm of t.methods) {
  956. if (kind == 'method' && mm.name == name) {
  957. for (r of memberNames(mm.reads)) { if (!out.includes(r)) { out.push(r) } }
  958. reached(&queue, mm.reads)
  959. }
  960. }
  961. for (h of t.handlers) {
  962. if (kind == 'handler' && !h.nested && h.event == name) {
  963. for (r of memberNames(h.reads)) { if (!out.includes(r)) { out.push(r) } }
  964. reached(&queue, h.reads)
  965. }
  966. }
  967. for (mb of t.members) {
  968. if (kind == 'member' && mb.name == name && mb.nodes != null) {
  969. for (r of memberNames(nodeReads(mb.nodes))) { if (!out.includes(r)) { out.push(r) } }
  970. reached(&queue, nodeReads(mb.nodes))
  971. }
  972. }
  973. }
  974. }
  975. return out
  976. }
  977. reached(&queue, reads) {
  978. if (reads == null) { return null }
  979. for (r of reads) {
  980. if (r.kind == 'method' || r.kind == 'handler' || (r.kind == 'member' && r.isStatic != true)) { queue.push(r.kind + ' ' + r.name) }
  981. }
  982. return null
  983. }
  984. // ---- THE SERVER RENDER, COMPILED --------------------------------------------------
  985. // The old hl:web rendered a page by WALKING the View tree per request: for every node it asks
  986. // what kind it is, for every element it builds the attribute string, and it decides the
  987. // indentation of every line again, on every request, for every one of the 121 mounts a
  988. // page may hold. Every one of those decisions is a fact about the View.
  989. //
  990. // So a component's render is compiled ONCE into a list of STEPS — constant text, and a
  991. // read with its own closure — and a request is a concatenation. The structure (tags,
  992. // static attributes, the readable form's line breaks, which element is a block) is
  993. // decided at compile time; only the values are asked for per request.
  994. //
  995. // KEYED BY THE INDENT IT IS RENDERED AT, because that is the only thing about a
  996. // component's HTML that its caller decides: the shell renders at one tab, the page at
  997. // the depth the slot stands, a fill compactly (null). An app has a handful of those.
  998. // the framework's `(key) => View tree`, for a kid whose steps are not built yet (set after the trees are)
  999. treeOf = null
  1000. // the steps of a kid mount: the memo when it holds them, else built from the key's tree (read once, when they are built)
  1001. kidSteps(key, indent, classes, slotted) {
  1002. let ck = key + '|' + (indent == null ? '~' : indent) + '|' + joinList(classes) + '|' + (slotted ? '1' : '0')
  1003. if (steps[ck] == null) { return serverSteps(key, treeOf(key), indent, classes, slotted) }
  1004. return steps[ck]
  1005. }
  1006. serverSteps(key, &nodes, indent, classes, slotted) {
  1007. let ck = key + '|' + (indent == null ? '~' : indent) + '|' + joinList(classes) + '|' + (slotted ? '1' : '0')
  1008. if (steps[ck] == null) {
  1009. steps[ck] = blockSteps(classes == null || classes.length == 0 ? nodes : v.withRootClasses(&nodes, &classes), indent, slotted)
  1010. }
  1011. return steps[ck]
  1012. }
  1013. // A `slot` THE HOST FILLED COUNTS AS CONTENT, and an empty one does not — the one
  1014. // thing about a component's shape its caller decides, so it is part of the key.
  1015. staticVoid = [ 'area' 'base' 'br' 'col' 'embed' 'hr' 'img' 'input' 'link' 'meta' 'source' 'track' 'wbr' ]
  1016. staticVerbatim = [ 'textarea' 'pre' 'script' 'style' ]
  1017. blocky(n, slotted) {
  1018. if (staticVerbatim.includes(n.tag)) { return false }
  1019. if (n.children.length == 0) { return false }
  1020. for (c of n.children) {
  1021. if (c.k == 'text' || c.k == 'field' || c.k == 'expr') { return false }
  1022. if (c.k == 'member' && !(c.name == 'slot' && slotted)) { return false }
  1023. }
  1024. return true
  1025. }
  1026. steps = {}
  1027. v = new HlwViewServer
  1028. viewRead = new HlwView
  1029. joinList(l) {
  1030. if (l == null) { return '' }
  1031. let out = ''
  1032. for (c of l) { out = out + ',' + c }
  1033. return out
  1034. }
  1035. // `render(nodes, …, indent)`: the readable form puts each element on its own line at
  1036. // `indent`, the compact one writes them end to end.
  1037. blockSteps(nodes, indent, slotted) {
  1038. let out = []
  1039. for (n of nodes) {
  1040. if (indent != null) {
  1041. if (n.k == 'el') { push(&out, { k = 's'; v = newline + indent; }) nodeSteps(&out, n, indent, slotted) }
  1042. else if (n.k == 'component') { nodeSteps(&out, n, indent, slotted) }
  1043. else if (n.k == 'for') { forSteps(&out, n, indent, slotted) }
  1044. else if (n.k == 'if') { ifSteps(&out, n, indent, slotted) }
  1045. else if (n.k == 'member' && n.name == 'slot') { push(&out, { k = 'slotline'; v = newline + indent; }) }
  1046. else if (n.k != 'on') { nodeSteps(&out, n, indent, slotted) }
  1047. } else {
  1048. nodeSteps(&out, n, null, slotted)
  1049. }
  1050. }
  1051. return out
  1052. }
  1053. forSteps(&out, n, indent, slotted) {
  1054. out.push({ k = 'for'; row = n.row; read = readFn(n.list); body = blockSteps(n.body, indent, slotted); })
  1055. return null
  1056. }
  1057. ifSteps(&out, n, indent, slotted) {
  1058. if (n.regionfill != null) { return null }
  1059. if (n.region != null) {
  1060. out.push({ k = 'region'; name = n.region; ind = indent; late = n.deferred == true; body = n.deferred == true ? [] : blockSteps(n.then, indent, slotted); })
  1061. return null
  1062. }
  1063. out.push({ k = 'if'; read = readFn(n.cond); then = blockSteps(n.then, indent, slotted); other = blockSteps(n.other, indent, slotted); })
  1064. return null
  1065. }
  1066. // a script's children: text and values written as they are (`view.rawText`)
  1067. rawSteps(nodes, slotted) {
  1068. let out = []
  1069. for (n of nodes) {
  1070. if (n.k == 'text') { push(&out, { k = 's'; v = v.rawText(n.text); }) }
  1071. else if (n.k == 'member' || n.k == 'field' || n.k == 'expr') { out.push({ k = 'raw'; read = readFn(n); }) }
  1072. else { nodeSteps(&out, n, null, slotted) }
  1073. }
  1074. return out
  1075. }
  1076. // one node's steps — `html(node, …)`, decided once
  1077. nodeSteps(&out, n, indent, slotted) {
  1078. if (n.k == 'text') { push(&out, { k = 's'; v = v.escape(n.text); }) return null }
  1079. if (n.k == 'on') { return null }
  1080. if (n.k == 'member' && n.name == 'slot') { out.push({ k = 'slot'; }) return null }
  1081. if (n.k == 'member' || n.k == 'field' || n.k == 'expr') { out.push({ k = 'r'; read = readFn(n); }) return null }
  1082. if (n.k == 'for') { forSteps(&out, n, indent, slotted) return null }
  1083. if (n.k == 'if') { ifSteps(&out, n, indent, slotted) return null }
  1084. if (n.k == 'component') {
  1085. out.push({ k = 'kid'; path = n.path; cls = n.cls; key = n.key; classes = n.classes; indent = indent;
  1086. fill = (n.fill == null || n.fill.length == 0) ? null : blockSteps(n.fill, null, slotted); })
  1087. return null
  1088. }
  1089. if (n.k == 'el') { elSteps(&out, n, indent, slotted) return null }
  1090. push(&out, { k = 's'; v = '<!-- ' + n.tag + ' not rendered yet -->'; })
  1091. return null
  1092. }
  1093. elSteps(&out, n, indent, slotted) {
  1094. let attrs = []
  1095. let valueRead = null // a textarea's value is its content
  1096. let selRead = null // a select's value selects an option
  1097. for (a of n.attrs) {
  1098. if (n.tag == 'textarea' && a.name == 'value') { valueRead = attrRead(a) }
  1099. else if (n.tag == 'select' && a.name == 'value') { selRead = attrRead(a) }
  1100. // a bound BOOLEAN attribute is its presence (ticket #33): ` checked=""` or nothing
  1101. else if ((a.member != null || a.ref != null) && v.isBoolAttr(a.name)) { attrs.push({ k = 'b'; name = a.name; read = attrRead(a); }) }
  1102. // a null read is no attribute (#177)
  1103. else if (nullable(a)) { attrs.push({ k = 'a'; name = a.name; read = attrRead(a); }) }
  1104. else if (a.member != null || a.ref != null) {
  1105. push(&attrs, { k = 's'; v = ' ' + a.name + '="'; })
  1106. attrs.push({ k = 'r'; read = attrRead(a); })
  1107. push(&attrs, { k = 's'; v = v.extraOf(a) + '"'; })
  1108. } else {
  1109. push(&attrs, { k = 's'; v = ' ' + a.name + '="' + v.escape(a.text) + '"'; })
  1110. }
  1111. }
  1112. if (v.boundValue(&n)) { push(&attrs, { k = 's'; v = ' autocomplete="off"'; }) }
  1113. // the children, in the form this element takes: a block puts them one per line
  1114. let kids = []
  1115. // a script's and a style's content is raw text (#140, view.rawKids says why)
  1116. if (n.tag == 'script' || n.tag == 'style') { kids = rawSteps(n.children, slotted) }
  1117. else if (indent != null && blocky(n, slotted)) {
  1118. kids = blockSteps(n.children, indent + tab, slotted)
  1119. push(&kids, { k = 's'; v = newline + indent; })
  1120. } else {
  1121. kids = blockSteps(n.children, null, slotted)
  1122. }
  1123. if (valueRead != null) { kids = [{ k = 'r'; read = valueRead; }] }
  1124. // AN OPTION IS THE ONE ELEMENT WHOSE OWN TAG DEPENDS ON THE VALUE ABOVE IT: it
  1125. // carries `selected` when its value is the select's. Everything else is settled.
  1126. if (n.tag == 'option') {
  1127. out.push({ k = 'opt'; attrs = attrs; body = kids; ov = optionRead(n); })
  1128. return null
  1129. }
  1130. push(&out, { k = 's'; v = '<' + n.tag; })
  1131. for (a of attrs) { push(&out, a) }
  1132. if (staticVoid.includes(n.tag)) { push(&out, { k = 's'; v = '>'; }) return null }
  1133. push(&out, { k = 's'; v = '>'; })
  1134. // A SELECT HANDS ITS VALUE TO ITS OPTIONS, however deep they stand: its children
  1135. // run under it, and it is the only element that changes anything for them.
  1136. if (n.tag == 'select') { out.push({ k = 'sel'; read = selRead; body = kids; }) }
  1137. else { for (kk of kids) { push(&out, kk) } }
  1138. push(&out, { k = 's'; v = '</' + n.tag + '>'; })
  1139. return null
  1140. }
  1141. // CONSTANT TEXT MERGES. Two literal steps in a row are one string decided at compile
  1142. // time — which is what makes a request a concatenation of a handful of pieces instead
  1143. // of one per node.
  1144. push(&out, step) {
  1145. if (step.k == 's' && out.length > 0 && out[out.length - 1].k == 's') {
  1146. let last = out[out.length - 1]
  1147. last.v = last.v + step.v
  1148. out[out.length - 1] = last
  1149. return null
  1150. }
  1151. out.push(step)
  1152. return null
  1153. }
  1154. // ---- the reads, each with its own closure ------------------------------------------
  1155. // `view.value`'s rule, split once: a `for` row variable in scope wins over a member of
  1156. // the same name, and a field path walks into it. The closure holds the name — there is
  1157. // no node to look at per request.
  1158. readFn(node) {
  1159. if (node == null) { return (inst, rows) => { return null } }
  1160. if (node.k == 'text') { let t = viewRead.refValue(node) return (inst, rows) => { return t } }
  1161. if (node.k == 'expr') { let x = node.x return (inst, rows) => { return viewRead.evalExpr(&x, &inst, &rows) } }
  1162. let name = node.name
  1163. if (node.k != 'field') {
  1164. return (inst, rows) => { return rows[name] != null ? rows[name] : inst[name] }
  1165. }
  1166. let path = node.path
  1167. return (inst, rows) => {
  1168. let val = rows[name] != null ? rows[name] : inst[name]
  1169. for (f of path) {
  1170. if (val == null) { return null }
  1171. val = val[f]
  1172. }
  1173. return val
  1174. }
  1175. }
  1176. attrRead(a) {
  1177. if (a.member != null) { return readFn({ k = 'member'; name = a.member; }) }
  1178. if (a.ref != null) { return readFn(a.ref) }
  1179. let t = a.text
  1180. return (inst, rows) => { return t }
  1181. }
  1182. // an option's own value: its `value` attribute, or null when it has none (the browser
  1183. // then reports its text, and the run compares against what it rendered)
  1184. optionRead(n) {
  1185. for (a of n.attrs) {
  1186. if (a.name == 'value') { return attrRead(a) }
  1187. }
  1188. return null
  1189. }
  1190. // ---- the run: a concatenation ------------------------------------------------------
  1191. // EVERY REGION IS WRITTEN BETWEEN TWO MARKS (tickets #103, #104): an `if` around the
  1192. // branch that stands, a `for` around its rows and each row around its own nodes. The
  1193. // client claims them as they are and builds the same ones, and a region's nodes are
  1194. // exactly what stands between its two marks — nothing it holds has to be remembered
  1195. // node by node, and text beside a region can never run into the region's text.
  1196. regionOpen = '<!--hl:rg:'
  1197. regionClose = '<!--hl:/rg:'
  1198. markOpen = '<!--[-->'
  1199. markClose = '<!--]-->'
  1200. // THE PIECES ARE JOINED ONCE, AT THE END (ticket #127). `out = out + piece` copied
  1201. // the whole page so far for every piece: a 3.5 MB page of 2000 rows allocated 2.3 GB
  1202. // in growing copies, 7 GB per render all told — 12 s a load once the collector ran
  1203. // by bytes (#126), where the joined pieces take 2.5 s.
  1204. runSteps(&list, &inst, &rows, &ctx, &mounts) {
  1205. let out = []
  1206. runInto(&out, &list, &inst, &rows, &ctx, &mounts)
  1207. return out.join('')
  1208. }
  1209. // the same run, its pieces pushed onto the ONE list the caller joins: a nested region used to be
  1210. // joined into a string and then concatenated into its parent's list, so every piece was copied once
  1211. // per level it sat in (a README's blocks sit several levels deep)
  1212. runInto(&out, &list, &inst, &rows, &ctx, &mounts) {
  1213. for (s of list) {
  1214. if (s.k == 's') { out.push(s.v) }
  1215. else if (s.k == 'r') { let f = s.read out.push(v.escape(f(&inst, &rows))) }
  1216. else if (s.k == 'raw') { let f = s.read out.push(v.rawText(f(&inst, &rows))) }
  1217. else if (s.k == 'a') { let f = s.read let av = f(&inst, &rows) if (av != null) { out.push(' ' + s.name + '="' + v.escape(av) + '"') } }
  1218. else if (s.k == 'b') { let f = s.read if (v.boolOn(f(&inst, &rows))) { out.push(' ' + s.name + '=""') } }
  1219. else if (s.k == 'slot') { if (ctx.slot != null) { out.push(ctx.slot) } }
  1220. else if (s.k == 'slotline') { if (ctx.slot != null) { out.push(s.v + ctx.slot) } }
  1221. else if (s.k == 'for') {
  1222. let f = s.read
  1223. let list2 = f(&inst, &rows)
  1224. out.push(markOpen)
  1225. if (list2 != null) {
  1226. // THE ROW IS SET IN PLACE, and the name it shadows put back after the loop:
  1227. // `rows + {}` copied every enclosing row per iteration, and an outer row holds the
  1228. // whole list its inner `for` walks (a list block holding its N items): N rows of N items
  1229. let held = rows[s.row]
  1230. let ri = 0
  1231. let keys = viewRead.listKeys(&list2)
  1232. for (entry of list2) {
  1233. rows[s.row] = entry
  1234. let rc = v.rowCtx(&ctx, keys[ri])
  1235. out.push(markOpen)
  1236. runInto(&out, &s.body, &inst, &rows, &rc, &mounts)
  1237. out.push(markClose)
  1238. ri = ri + 1
  1239. }
  1240. rows[s.row] = held
  1241. }
  1242. out.push(markClose)
  1243. }
  1244. else if (s.k == 'region') {
  1245. // the region's default, between PLACEHOLDERS the document replaces once the page is known
  1246. // (a level above is rendered before the page below it is constructed): WebFramework `regions`
  1247. out.push(regionOpen + s.name + ':' + (s.ind == null ? '-' : '' + s.ind.length) + (s.late == true ? '!' : '') + '-->')
  1248. runInto(&out, &s.body, &inst, &rows, &ctx, &mounts)
  1249. out.push(regionClose + s.name + '-->')
  1250. }
  1251. else if (s.k == 'if') {
  1252. let f = s.read
  1253. out.push(markOpen)
  1254. if (f(&inst, &rows)) { runInto(&out, &s.then, &inst, &rows, &ctx, &mounts) }
  1255. else { runInto(&out, &s.other, &inst, &rows, &ctx, &mounts) }
  1256. out.push(markClose)
  1257. }
  1258. else if (s.k == 'opt') {
  1259. let head = runSteps(&s.attrs, &inst, &rows, &ctx, &mounts)
  1260. let body = runSteps(&s.body, &inst, &rows, &ctx, &mounts)
  1261. let mark = ''
  1262. if (ctx.sel != null) {
  1263. let ov = body
  1264. if (s.ov != null) { let f = s.ov ov = '' + f(&inst, &rows) }
  1265. if (ov == ctx.sel) { mark = ' selected' }
  1266. }
  1267. out.push('<option' + head + mark + '>' + body + '</option>')
  1268. }
  1269. else if (s.k == 'sel') {
  1270. let f = s.read
  1271. let inner = ctx + {}
  1272. inner.sel = f == null ? null : '' + f(&inst, &rows)
  1273. runInto(&out, &s.body, &inst, &rows, &inner, &mounts)
  1274. }
  1275. else if (s.k == 'kid') {
  1276. // THE KID IS READ IN PLACE: `let kid = ctx.kids[…]` copied the whole mount (its tree, its
  1277. // params, its state, its own kids) once per mount rendered. And the mounts a level holds
  1278. // travel as their own reference (`mounts`), not inside `ctx`: every `for` row copies the
  1279. // ctx, and a ctx holding the kids copied ALL of them per row (N rows of N mounts).
  1280. let kk = v.kidKeyIn(&s.path, &ctx)
  1281. if (mounts[kk] == null) { out.push('<!-- ' + s.cls + ' not mounted -->') }
  1282. else {
  1283. let fillText = s.fill == null ? null : runSteps(&s.fill, &inst, &rows, &ctx, &mounts)
  1284. let kidCtx = { slot = fillText; }
  1285. let empty = {}
  1286. let ksteps = kidSteps(s.key, s.indent, s.classes, fillText != null)
  1287. runInto(&out, &ksteps, &mounts[kk].page, &empty, &kidCtx, &mounts[kk].kids)
  1288. }
  1289. }
  1290. }
  1291. }

Branches

Latest commits

  • 4d1a4cf4log: #25 numbersmre
  • 1af0a60ddocs: H25 run() correctionmre
  • 8c8ba2f1log: PR flow announcedmre
  • fa00cd35log: Kunibert pings provenmre
  • 3a68cfaclog: components decisionmre
  • 87de8e31log: Kunibert connected to 9 app reposmre
  • c22aff69log: PR-only rollout startedmre
  • 25309981log: STOP and paused workers 2026-11-08mre
  • 5286803alog: worker briefs and reports of 2026-11-08mre
  • 85c86605log: 2026-11-08 Arachne on list shapemre
  • cb634512log: 2026-11-08 keyed lists livemre
  • 07c98d4aLists: keyed rows with @id, remove(id) and one whole-list assignment instead of hand-rebuilt loopsmre
  • 0db0d81elog: 2026-11-08 day52 live, W30 startedmre
  • b05f6d92tests/status: the gate's 3 s app token expired during the restart; it lives 60 s like status-keyedmre
  • 1e8f4f0avendor: Hybriel set-day52 (fault-path leak fix #335, keyed rows #331)mre
  • f5f0fb7blog: 2026-11-08 day50/#29 live, H25 correction, V52 startedmre
  • dc77fb95main: offline note from __hlOnline, tick removed (#29)mre
  • 37a86d93tests/reviews: seeded fake hook's DNS failures are not server errors (flaky gate)mre
  • 07ab845bvendor: Hybriel set-day50 (run() leak fix #335)mre
  • 71b2fa4blog: hybriel#335mre