1 #define // This is the master file for minified source, containing various tricks to shrink it as far as possible.
2 #define // After being fed through gpp, all leading whitespace on every line is removed, and then all line breaks are removed.
3 #define // End result, an ECMAScript module of fully minified code.
5 #define Opcode.CreateElement 0
6 #define Opcode.CreateSvgElement 1
7 #define Opcode.CreateTextNode 2
8 #define Opcode.CreateComment 3
9 #define Opcode.CreateDocumentFragment 4
10 #define Opcode.SetData 5
11 #define Opcode.SetAttribute 6
12 #define Opcode.RemoveAttribute 7
13 #define Opcode.AppendChild 8
14 #define Opcode.InsertBefore 9
15 #define Opcode.Free 10
17 #define // Global variables (the textDecoder/var1 collision is fine)
20 #define // Local variables of execute(), readString() and maybe a little else
21 #define instructions e
28 #define // Local variables of push_node (also uses nodes)
31 #define // VM instance properties
36 export default class VM{
38 # define // FIXME: is 0 document or what? (Perhaps I should define a “document” opcode rather than prefilling it?)
39 # ifdef WITH_REALLOCATOR
45 #ifdef WITH_REALLOCATOR
49 id<nodes.length||nodes.push(id+1),
50 this.NEXT_ID=nodes[id],
53 # define PUSH_NODE this.push_node
55 # define PUSH_NODE nodes.push
58 execute(instructions){
64 length=instructions.byteLength,
70 var3=instructions[offset++],
71 var1=instructions[offset++]<<24|instructions[offset++]<<16|instructions[offset++]<<8|instructions[offset++],
74 case Opcode.CreateElement:
76 case Opcode.CreateSvgElement:
78 [var2,offset]=readString(instructions,offset),
82 #define // The way I’m abusing #define for comments here gets veeeeery close to falling apart on the next line! 😀
83 nodes[var1].createElementNS("http://www.w3.org/2000/svg",var2):
85 nodes[var1].createElement(var2)
88 case Opcode.CreateTextNode:
89 [var2,offset]=readString(instructions,offset),
90 PUSH_NODE(nodes[var1].createTextNode(var2));
93 case Opcode.CreateComment:
94 [var2,offset]=readString(instructions,offset),
95 PUSH_NODE(nodes[var1].createComment(var2));
98 #ifdef WITH_DOCUMENT_FRAGMENT
99 case Opcode.CreateDocumentFragment:
100 PUSH_NODE(nodes[var1].createDocumentFragment());
104 [var2,offset]=readString(instructions,offset),
105 nodes[var1].data=var2;
107 case Opcode.SetAttribute:
108 [var2,offset]=readString(instructions,offset),
109 [var3,offset]=readString(instructions,offset),
110 nodes[var1].setAttribute(var2,var3);
112 case Opcode.RemoveAttribute:
113 [var2,offset]=readString(instructions,offset),
114 nodes[var1].removeAttribute(var2);
116 case Opcode.AppendChild:
117 nodes[var1].appendChild(nodes[instructions[offset++]<<24|instructions[offset++]<<16|instructions[offset++]<<8|instructions[offset++]]);
119 case Opcode.InsertBefore:
120 var2=nodes[instructions[offset++]<<24|instructions[offset++]<<16|instructions[offset++]<<8|instructions[offset++]],
121 nodes[var1].insertBefore(
122 nodes[instructions[offset++]<<24|instructions[offset++]<<16|instructions[offset++]<<8|instructions[offset++]],
133 var textDecoder=new TextDecoder,
134 function readString(instructions,offset){
135 var length=instructions[offset++]<<24|instructions[offset++]<<16|instructions[offset++]<<8|instructions[offset++];
137 textDecoder.decode(new Uint8Array(instructions.buffer,instructions.byteOffset+offset,length)),