invoke method

dynamic invoke(
  1. String funcName, {
  2. String? moduleName,
  3. String? sourceName,
  4. bool isConstructorCall = false,
  5. List positionalArgs = const [],
  6. Map<String, dynamic> namedArgs = const {},
  7. List<HTType> typeArgs = const [],
})

Invoke a top level function defined in a certain namespace. It's possible to use this method to invoke a HTClass or HTNamedStruct name as a contruct call, you will get a HTInstance or HTStruct as return value.

Implementation

dynamic invoke(String funcName,
    {String? moduleName,
    String? sourceName,
    bool isConstructorCall = false,
    List<dynamic> positionalArgs = const [],
    Map<String, dynamic> namedArgs = const {},
    List<HTType> typeArgs = const []}) {
  try {
    stackTraceList.clear();
    final savedModuleName = _currentBytecodeModule.id;
    HTNamespace nsp = globalNamespace;
    if (moduleName != null) {
      if (_currentBytecodeModule.id != moduleName) {
        _currentBytecodeModule = cachedModules[moduleName]!;
      }
      if (sourceName != null) {
        if (nsp.fullName != sourceName) {
          assert(_currentBytecodeModule.namespaces.containsKey(sourceName));
          nsp = _currentBytecodeModule.namespaces[sourceName]!;
        }
      } else if (_currentBytecodeModule.namespaces.isNotEmpty) {
        nsp = _currentBytecodeModule.namespaces.values.last;
      }
    } else if (sourceName != null) {
      assert(_currentBytecodeModule.namespaces.containsKey(sourceName));
      nsp = _currentBytecodeModule.namespaces[sourceName]!;
    }
    final callee = nsp.memberGet(funcName, isRecursive: false);
    final result = _call(
      callee,
      positionalArgs: positionalArgs,
      namedArgs: namedArgs,
      typeArgs: typeArgs,
    );
    if (_currentBytecodeModule.id != savedModuleName) {
      _currentBytecodeModule = cachedModules[savedModuleName]!;
    }
    return result;
  } catch (error, stackTrace) {
    if (config.processError) {
      processError(error, stackTrace);
    } else {
      rethrow;
    }
  }
}