simple-squiggle

A restricted subset of Squiggle
Log | Files | Refs | README

index.js (1500B)


      1 import * as encoder from "./encoder";
      2 export function encodeNode(n) {
      3   switch (n.type) {
      4     case "ModuleImport":
      5       // $FlowIgnore: ModuleImport ensure that the node is well formated
      6       return encoder.encodeModuleImport(n);
      7 
      8     case "SectionMetadata":
      9       // $FlowIgnore: SectionMetadata ensure that the node is well formated
     10       return encoder.encodeSectionMetadata(n);
     11 
     12     case "CallInstruction":
     13       // $FlowIgnore: SectionMetadata ensure that the node is well formated
     14       return encoder.encodeCallInstruction(n);
     15 
     16     case "CallIndirectInstruction":
     17       // $FlowIgnore: SectionMetadata ensure that the node is well formated
     18       return encoder.encodeCallIndirectInstruction(n);
     19 
     20     case "TypeInstruction":
     21       return encoder.encodeTypeInstruction(n);
     22 
     23     case "Instr":
     24       // $FlowIgnore
     25       return encoder.encodeInstr(n);
     26 
     27     case "ModuleExport":
     28       // $FlowIgnore: SectionMetadata ensure that the node is well formated
     29       return encoder.encodeModuleExport(n);
     30 
     31     case "Global":
     32       // $FlowIgnore
     33       return encoder.encodeGlobal(n);
     34 
     35     case "Func":
     36       return encoder.encodeFuncBody(n);
     37 
     38     case "IndexInFuncSection":
     39       return encoder.encodeIndexInFuncSection(n);
     40 
     41     case "StringLiteral":
     42       return encoder.encodeStringLiteral(n);
     43 
     44     case "Elem":
     45       return encoder.encodeElem(n);
     46 
     47     default:
     48       throw new Error("Unsupported encoding for node of type: " + JSON.stringify(n.type));
     49   }
     50 }
     51 export var encodeU32 = encoder.encodeU32;