@@ -245,6 +245,7 @@ block extendVoodooAstAndCodeGen:
245245 gen.lookup (formalParams[0 ])
246246 else :
247247 gen.module.sym " void"
248+
248249 # create a new proc
249250 var (sym, theProc) =
250251 gen.script.newProc (name, impl = node,
@@ -407,3 +408,72 @@ block extendVoodooAstAndCodeGen:
407408
408409 if gen.kind == gkHtmlNest:
409410 gen.kind = gkToplevel
411+
412+ block extendVM:
413+ extendEnum Opcode :
414+ opcBeginHtml = " beginHtml" # # construct HTML object
415+ opcBeginHtmlWithAttrs = " behinHtmlWithAttrs" # # construct HTML object with attributes
416+ opcAttrEnd = " attrEnd" # # ends HTML object
417+ opcInnerHtml = " innerHtml" # # ends HTML object
418+ opcTextHtml = " textHtml" # # adds text to HTML object
419+ opcCloseHtml = " closeHtml" # # closes HTML object
420+
421+ opcAttrClass = " attrClass" # # adds class to HTML object
422+ opcAttrId = " attrId" # # adds id to HTML object
423+ opcAttr = " attr"
424+ opcAttrKey = " attrKey" # # adds a key to HTML object attribute
425+ opcWSpace = " space" # # adds whitespace to HTML result
426+
427+ extendCaseStmt " vmParseChunkCase" :
428+ case oc:
429+ of opcAttrClass, opcAttrId, opcBeginHtmlWithAttrs, opcBeginHtml, opcCloseHtml:
430+ let sid = readArg [uint16 ](pc)
431+ addOp (oc, sid.int64 , 0 , akString)
432+
433+ extendCaseStmt " vmInterpretCase" :
434+ case oc:
435+ # HTML generation
436+ of opcAttrClass:
437+ # special case for class attribute
438+ result .add (" class=\" " & co.getArg1Str (pcIdx, currentChunk) & " \" " )
439+ of opcAttrId:
440+ result .add (" id=\" " & co.getArg1Str (pcIdx, currentChunk) & " \" " )
441+ of opcWSpace:
442+ result .add (" " )
443+ of opcAttrEnd:
444+ result .add (" >" )
445+ of opcAttr:
446+ let key = stack.pop ().stringVal[]
447+ let value = stack.pop ()
448+ result .add (key & " =\" " )
449+ case value.typeId
450+ of tyString: result .add (value.stringVal[])
451+ of tyInt: result .add ($ value.intVal)
452+ of tyFloat: result .add ($ value.floatVal)
453+ of tyBool: result .add ($ (value.boolVal))
454+ of tyJsonStorage:
455+ result .add (value.jsonVal.toString ())
456+ else : discard
457+ result .add (" \" " )
458+ of opcAttrKey:
459+ let attr = stack.pop ()
460+ if attr.stringVal[].len > 0 :
461+ result .add (" " ) # leading space
462+ result .add (attr.stringVal[])
463+ of opcBeginHtmlWithAttrs:
464+ result .add (" <" & co.getArg1Str (pcIdx, currentChunk))
465+ of opcBeginHtml:
466+ result .add (" <" & co.getArg1Str (pcIdx, currentChunk) & " >" )
467+ of opcTextHtml:
468+ let v = stack.pop ()
469+ case v.typeId
470+ of tyString: result .add (v.stringVal[])
471+ of tyInt: result .add ($ v.intVal)
472+ of tyFloat: result .add ($ v.floatVal)
473+ of tyBool: result .add ($ (v.boolVal))
474+ of tyJsonStorage: result .add (v.jsonVal.toString ())
475+ else : discard
476+ of opcInnerHtml:
477+ discard
478+ of opcCloseHtml:
479+ result .add (" </" & co.getArg1Str (pcIdx, currentChunk) & " >" )
0 commit comments