Skip to content

Maker & Generator Functions

A maker function simply creates an atomic functionality such as binary operation, unary operation, load from memory, store to memory and many others. Maker functions are prefixed with the word "Make".

Example

Wasm++

MakeBinary(Opcpde::I32Add, MakeI32Const(1), MakeI32Const(2));

WebAssembly (Wat)

i32.const 1
i32.const 2
i32.add

Generator functions are a little more complicated as they build on top of makers to create more complex semantic. Generator functions are prefixed with the word "Generate".

Example

Below is an example of a generator for building a for loop ranging from i=0 to 100 while incrementing by 1.

Wasm++

// param 1: Label manager pointer
// param 2: Local variables
// param 3: Range from
// param 4: Range to
// param 5: Increment value
// param 6: Loop return value
// param 7: Body code of the loop
GenerateRangeLoop(label_manager, i, 0, 100, 1, {}, [&](BlockBody* body) {
  // Loop body: e.g. body->Insert(MakeCall(...));
});

WebAssembly (Wat)

i32.const 0
set_local $i
loop $loop_1
  // Loop body ...
  get_local $i
  i32.const 1
  i32.add
  tee_local $i
  i32.const 100
  i32.ne
  br_if $loop_1
end