visitRoutine method

void visitRoutine(
  1. List<int?> params
)

Implementation

void visitRoutine(List<int?> params) {
  //Debugger.verbose('  Calling Routine at ${pc.toRadixString(16)}');

  // assign any params passed to locals and push locals onto the call stack
  final locals = readb();

  stack.push(stackMarker);

  //Debugger.verbose('    # Locals: ${locals}');

  assert(locals < 17);

  // add param length to call stack (v5+ needs this)
  callStack.push(params.length);

  //set the routine to default locals (V3...)

  for (int i = 0; i < locals; i++) {
    if (i < params.length) {
      //if param avail, store it
      callStack.push(params[i]!);
      //Debugger.verbose('    Local ${i}: 0x${(params[i-1]).toRadixString(16)}');
      //mem.storew(pc, params[i - 1]);
    } else {
      //push otherwise push the local
      callStack.push(mem.loadw(programCounter));
      //Debugger.verbose('    Local ${i}: 0x${mem.loadw(pc).toRadixString(16)}');
    }

    programCounter += 2;
  }

  //push total locals onto the call stack
  callStack.push(locals);
}