diff --git a/lib/src/eval/compiler/reference.dart b/lib/src/eval/compiler/reference.dart index c0b89ef..570cbe4 100644 --- a/lib/src/eval/compiler/reference.dart +++ b/lib/src/eval/compiler/reference.dart @@ -515,6 +515,7 @@ class IndexedReference implements Reference { final result = _variable.invoke(ctx, '[]', [_index]); _variable = result.target!; _index = result.args[0]; + return result.result; } diff --git a/lib/src/eval/runtime/ops/objects.dart b/lib/src/eval/runtime/ops/objects.dart index d48233a..6f47725 100644 --- a/lib/src/eval/runtime/ops/objects.dart +++ b/lib/src/eval/runtime/ops/objects.dart @@ -95,7 +95,6 @@ class InvokeDynamic implements EvcOp { runtime._prOffset = object.offset; return; } - final method = ((object as $Instance).$getProperty(runtime, _method) as EvalFunction); try { diff --git a/lib/src/eval/shared/stdlib/core.dart b/lib/src/eval/shared/stdlib/core.dart index 504b1c9..fb59b4a 100644 --- a/lib/src/eval/shared/stdlib/core.dart +++ b/lib/src/eval/shared/stdlib/core.dart @@ -1,3 +1,4 @@ +import 'package:dart_eval/dart_eval.dart'; import 'package:dart_eval/dart_eval_bridge.dart'; import 'package:dart_eval/src/eval/shared/stdlib/async/stream.dart'; import 'package:dart_eval/src/eval/shared/stdlib/core/base.dart'; diff --git a/lib/src/eval/shared/stdlib/core/collection.dart b/lib/src/eval/shared/stdlib/core/collection.dart index f7cf0f0..10db5e8 100644 --- a/lib/src/eval/shared/stdlib/core/collection.dart +++ b/lib/src/eval/shared/stdlib/core/collection.dart @@ -1,9 +1,7 @@ import 'dart:math'; import 'package:dart_eval/dart_eval_bridge.dart'; -import 'package:dart_eval/src/eval/shared/stdlib/core/iterator.dart'; import 'package:dart_eval/stdlib/core.dart'; -import 'package:dart_eval/src/eval/runtime/exception.dart'; part 'iterable.dart'; part 'list.dart'; diff --git a/lib/src/eval/shared/stdlib/core/iterable.dart b/lib/src/eval/shared/stdlib/core/iterable.dart index dce332e..5fab386 100644 --- a/lib/src/eval/shared/stdlib/core/iterable.dart +++ b/lib/src/eval/shared/stdlib/core/iterable.dart @@ -1,316 +1,1043 @@ -// ignore_for_file: non_constant_identifier_names - part of 'collection.dart'; /// dart_eval bimodal wrapper for [Iterable] class $Iterable implements Iterable, $Instance { /// Configure the [$Iterable] wrapper for use in a [Runtime] + static void configureForCompile(BridgeDeclarationRegistry registry) { + registry.defineBridgeClass($declaration); + } + static void configureForRuntime(Runtime runtime) { runtime.registerBridgeFunc( - 'dart:core', 'Iterable.generate', _$Iterable_generate.call); + $type.spec!.library, 'Iterable.generate', __$Iterable$generate.call, + isBridge: false); + runtime.registerBridgeFunc( + $type.spec!.library, 'Iterable.empty', __$Iterable$empty.call, + isBridge: false); + runtime.registerBridgeFunc($type.spec!.library, 'Iterable.castFrom', + __$static$method$castFrom.call, + isBridge: false); + runtime.registerBridgeFunc( + $type.spec!.library, + 'Iterable.iterableToShortString', + __$static$method$iterableToShortString.call, + isBridge: false); + runtime.registerBridgeFunc( + $type.spec!.library, + 'Iterable.iterableToFullString', + __$static$method$iterableToFullString.call, + isBridge: false); } - /// Compile-time class definition for [$Iterable] + late final $Instance _superclass = $Object($value); + + static const $type = BridgeTypeRef(CoreTypes.iterable); + static const $declaration = BridgeClassDef( - BridgeClassType(BridgeTypeRef(CoreTypes.iterable), - generics: {'E': BridgeGenericParam()}), - constructors: { - 'generate': BridgeConstructorDef(BridgeFunctionDef( + BridgeClassType( + $type, + generics: {'E': BridgeGenericParam()}, + ), + constructors: { + '': BridgeConstructorDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation($type), + params: [], + namedParams: [], + ), + isFactory: false, + ), + 'generate': BridgeConstructorDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation($type), + params: [ + BridgeParameter( + 'count', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int, []), + nullable: false), + false), + BridgeParameter( + 'generator', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.function, []), + nullable: true), + true) + ], + namedParams: [], + generics: {'E': BridgeGenericParam()}, + ), + isFactory: true, + ), + 'empty': BridgeConstructorDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation($type), + params: [], + namedParams: [], + generics: {'E': BridgeGenericParam()}), + isFactory: true, + ) + }, + fields: {}, + methods: { + 'castFrom': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.iterable, [ + BridgeTypeRef.ref('T', []), + ]), + nullable: false), + params: [ + BridgeParameter( + 'source', + BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.iterable, [ + BridgeTypeRef.ref('S', []), + ]), + nullable: false), + false) + ], + namedParams: [], + generics: { + 'S': BridgeGenericParam(), + 'T': BridgeGenericParam(), + }), + isStatic: true), + 'iterableToShortString': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: false), params: [ - BridgeParameter('count', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int)), false), BridgeParameter( - 'generator', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.function)), + 'iterable', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.iterable, []), + nullable: false), + false), + BridgeParameter( + 'leftDelimiter', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: false), true), + BridgeParameter( + 'rightDelimiter', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: false), + true) + ], + namedParams: [], + ), + isStatic: true), + 'iterableToFullString': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: false), + params: [ + BridgeParameter( + 'iterable', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.iterable, []), + nullable: false), + false), + BridgeParameter( + 'leftDelimiter', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: false), + true), + BridgeParameter( + 'rightDelimiter', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: false), + true) + ], + namedParams: [], + ), + isStatic: true), + 'cast': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.iterable, [ + BridgeTypeRef.ref('R', []), + ]), + nullable: false), + params: [], + namedParams: [], + generics: {'R': BridgeGenericParam()}, + ), + isStatic: false), + 'followedBy': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.iterable, [ + BridgeTypeRef.ref('E', []), + ]), + nullable: false), + params: [ + BridgeParameter( + 'other', + BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.iterable, [ + BridgeTypeRef.ref('E', []), + ]), + nullable: false), + false) + ], + namedParams: [], + ), + isStatic: false), + 'map': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.iterable, [ + BridgeTypeRef.ref('T', []), + ]), + nullable: false), + params: [ + BridgeParameter( + 'toElement', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.function, []), + nullable: false), + false) + ], + namedParams: [], + generics: {'T': BridgeGenericParam()}, + ), + isStatic: false), + 'where': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.iterable, [ + BridgeTypeRef.ref('E', []), + ]), + nullable: false), + params: [ + BridgeParameter( + 'test', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.function, []), + nullable: false), + false) + ], + namedParams: [], + ), + isStatic: false), + 'whereType': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.iterable, [ + BridgeTypeRef.ref('T', []), + ]), + nullable: false), + params: [], + namedParams: [], + generics: {'T': BridgeGenericParam()}, + ), + isStatic: false), + 'expand': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.iterable, [ + BridgeTypeRef.ref('T', []), + ]), + nullable: false), + params: [ + BridgeParameter( + 'toElements', + BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.iterable, [ + BridgeTypeRef.ref('T', []), + ]), + nullable: false), + false) + ], + namedParams: [], + generics: {'T': BridgeGenericParam()}, + ), + isStatic: false), + 'contains': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool, []), + nullable: false), + params: [ + BridgeParameter( + 'element', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.object, []), + nullable: true), + false) + ], + namedParams: [], + ), + isStatic: false), + 'forEach': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.voidType, []), + nullable: false), + params: [ + BridgeParameter( + 'action', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.function, []), + nullable: false), + false) + ], + namedParams: [], + ), + isStatic: false), + 'reduce': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef.ref('E', []), + nullable: false), + params: [ + BridgeParameter( + 'combine', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.function, []), + nullable: false), + false) + ], + namedParams: [], + ), + isStatic: false), + 'fold': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef.ref('T', []), + nullable: false), + params: [ + BridgeParameter( + 'initialValue', + BridgeTypeAnnotation(BridgeTypeRef.ref('T', []), + nullable: false), + false), + BridgeParameter( + 'combine', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.function, []), + nullable: false), + false) + ], + namedParams: [], + generics: { + 'T': BridgeGenericParam() + }), + isStatic: false), + 'every': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool, []), + nullable: false), + params: [ + BridgeParameter( + 'test', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.function, []), + nullable: false), + false) + ], + namedParams: [], + ), + isStatic: false), + 'join': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: false), + params: [ + BridgeParameter( + 'separator', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: false), + true) + ], + namedParams: [], + ), + isStatic: false), + 'any': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool, []), + nullable: false), + params: [ + BridgeParameter( + 'test', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.function, []), + nullable: false), + false) + ], + namedParams: [], + ), + isStatic: false), + 'toList': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.list, [ + BridgeTypeRef.ref('E', []), + ]), + nullable: false), + params: [], + namedParams: [ + BridgeParameter( + 'growable', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool, []), + nullable: false), + true) + ], + ), + isStatic: false), + 'toSet': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.list, [ + BridgeTypeRef.ref('E', []), + ]), + nullable: false), + params: [], + namedParams: [], + ), + isStatic: false), + 'take': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.iterable, [ + BridgeTypeRef.ref('E', []), + ]), + nullable: false), + params: [ + BridgeParameter( + 'count', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int, []), + nullable: false), + false) + ], + namedParams: [], + ), + isStatic: false), + 'takeWhile': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.iterable, [ + BridgeTypeRef.ref('E', []), + ]), + nullable: false), + params: [ + BridgeParameter( + 'test', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.function, []), + nullable: false), + false) + ], + namedParams: [], + ), + isStatic: false), + 'skip': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.iterable, [ + BridgeTypeRef.ref('E', []), + ]), + nullable: false), + params: [ + BridgeParameter( + 'count', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int, []), + nullable: false), + false) ], + namedParams: [], + ), + isStatic: false), + 'skipWhile': BridgeMethodDef( + BridgeFunctionDef( returns: BridgeTypeAnnotation( - BridgeTypeRef(CoreTypes.iterable, [BridgeTypeRef.ref('E')])), - generics: {'E': BridgeGenericParam()})), - }, - methods: { - 'join': BridgeMethodDef( - BridgeFunctionDef(params: [ - BridgeParameter('separator', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string)), true), - ], returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string))), - isStatic: false), - 'map': BridgeMethodDef( - BridgeFunctionDef( - params: [ - BridgeParameter( - 'toElement', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.function)), - false), - ], - returns: BridgeTypeAnnotation( - BridgeTypeRef(BridgeTypeSpec('dart:core', 'Iterable')))), - isStatic: false), - 'toList': BridgeMethodDef( - BridgeFunctionDef( - params: [ - BridgeParameter( - 'growable', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool)), - true), - ], - returns: BridgeTypeAnnotation(BridgeTypeRef( - CoreTypes.list, [BridgeTypeRef(CoreTypes.dynamic)]))), - isStatic: false), - }, - getters: { - 'iterator': BridgeMethodDef( - BridgeFunctionDef( - params: [], - returns: - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.iterator, [ - BridgeTypeRef.ref('E'), - ]))), - isStatic: false), - }, - setters: {}, - fields: {}, - wrap: true); + BridgeTypeRef(CoreTypes.iterable, [ + BridgeTypeRef.ref('E', []), + ]), + nullable: false), + params: [ + BridgeParameter( + 'test', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.function, []), + nullable: false), + false) + ], + namedParams: [], + ), + isStatic: false), + 'firstWhere': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef.ref('E', []), + nullable: false), + params: [ + BridgeParameter( + 'test', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.function, []), + nullable: false), + false) + ], + namedParams: [ + BridgeParameter( + 'orElse', + BridgeTypeAnnotation(BridgeTypeRef.ref('E', []), + nullable: false), + true) + ], + ), + isStatic: false), + 'lastWhere': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef.ref('E', []), + nullable: false), + params: [ + BridgeParameter( + 'test', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.function, []), + nullable: false), + false) + ], + namedParams: [ + BridgeParameter( + 'orElse', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.function), + nullable: false), + true) + ], + ), + isStatic: false), + 'singleWhere': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef.ref('E', []), + nullable: false), + params: [ + BridgeParameter( + 'test', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.function, []), + nullable: false), + false) + ], + namedParams: [ + BridgeParameter( + 'orElse', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.function, []), + nullable: false), + true) + ], + ), + isStatic: false), + 'elementAt': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef.ref('E', []), + nullable: false), + params: [ + BridgeParameter( + 'index', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int, []), + nullable: false), + false) + ], + namedParams: [], + ), + isStatic: false), + }, + getters: { + 'iterator': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.iterator, [ + BridgeTypeRef.ref('E', []), + ]), + nullable: false), + params: [], + namedParams: [], + ), + isStatic: false), + 'length': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int, []), + nullable: false), + params: [], + namedParams: [], + ), + isStatic: false), + 'isEmpty': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool, []), + nullable: false), + params: [], + namedParams: [], + ), + isStatic: false), + 'isNotEmpty': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool, []), + nullable: false), + params: [], + namedParams: [], + ), + isStatic: false), + 'first': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef.ref('E', []), + nullable: false), + params: [], + namedParams: [], + ), + isStatic: false), + 'last': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef.ref('E', []), + nullable: false), + params: [], + namedParams: [], + ), + isStatic: false), + 'single': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef.ref('E', []), + nullable: false), + params: [], + namedParams: [], + ), + isStatic: false), + }, + setters: {}, + bridge: false, + wrap: true, + ); /// Wrap an [Iterable] in an [$Iterable] $Iterable.wrap(this.$value); - @override - final Iterable $value; - - @override - Iterable get $reified => $value; - - late final $Instance _superclass = $Object($value); - @override $Value? $getProperty(Runtime runtime, String identifier) { switch (identifier) { - case 'any': - return __any; - case 'elementAt': - return __elementAt; - case 'every': - return __every; case 'iterator': return $Iterator.wrap($value.iterator); + case 'length': + return $int($value.length); + case 'isEmpty': + return $bool($value.isEmpty); + case 'isNotEmpty': + return $bool($value.isNotEmpty); + case 'first': + return $value.first as $Value?; + case 'last': + return $value.last as $Value?; + case 'single': + return $value.single as $Value?; + case 'cast': + return __$cast; case 'followedBy': - return __followedBy; - case 'skip': - return __skip; - case 'skipWhile': - return __skipWhile; - case 'join': - return __join; + return __$followedBy; case 'map': - return __map; - case 'take': - return __take; - case 'toSet': - return __toSet; + return __$map; + case 'where': + return __$where; + case 'whereType': + return __$whereType; + case 'expand': + return __$expand; + case 'contains': + return __$contains; + case 'forEach': + return __$forEach; + case 'reduce': + return __$reduce; + case 'fold': + return __$fold; + case 'every': + return __$every; + case 'join': + return __$join; + case 'any': + return __$any; case 'toList': - return __toList; + return __$toList; + case 'toSet': + return __$toSet; + case 'take': + return __$take; + case 'takeWhile': + return __$takeWhile; + case 'skip': + return __$skip; + case 'skipWhile': + return __$skipWhile; + case 'firstWhere': + return __$firstWhere; + case 'lastWhere': + return __$lastWhere; + case 'singleWhere': + return __$singleWhere; + case 'elementAt': + return __$elementAt; default: return _superclass.$getProperty(runtime, identifier); } } @override - void $setProperty(Runtime runtime, String identifier, $Value value) { - return _superclass.$setProperty(runtime, identifier, value); - } - - static const $Function __join = $Function(_join); - - static $Value? _join(Runtime runtime, $Value? target, List<$Value?> args) { - final separator = (args[0]?.$value as String?) ?? ''; - return $String((target!.$value as Iterable) - .map((v) => v is $Value ? runtime.valueToString(v) : v) - .join(separator)); - } + int $getRuntimeType(Runtime runtime) => runtime.lookupType($type.spec!); - static const $Function __map = $Function(_map); - - static $Value? _map(Runtime runtime, $Value? target, List<$Value?> args) { - final toElement = args[0] as EvalCallable; - return $Iterable.wrap((target!.$value as Iterable) - .map((e) => toElement.call(runtime, null, [e])!.$value)); - } - - static const $Function __toList = $Function(_toList); - - static $Value? _toList(Runtime runtime, $Value? target, List<$Value?> args) { - return $List.wrap( - (target!.$value as Iterable).toList(growable: args[0]?.$value ?? true)); - } - - static const $Function __any = $Function(_any); - - static $Value? _any(Runtime runtime, $Value? target, List<$Value?> args) { - final test = args[0] as EvalCallable; - return $bool((target!.$value as Iterable) - .any((e) => test.call(runtime, null, [e])!.$value as bool)); - } - - static const $Function __every = $Function(_every); - - static $Value? _every(Runtime runtime, $Value? target, List<$Value?> args) { - final test = args[0] as EvalCallable; - return $bool((target!.$value as Iterable) - .every((e) => test.call(runtime, null, [e])!.$value as bool)); - } - - static const $Function __elementAt = $Function(_elementAt); - - static $Value? _elementAt( - Runtime runtime, $Value? target, List<$Value?> args) { - return (target!.$value as List).elementAt(args[0]!.$value); - } - - static const $Function __followedBy = $Function(_followedBy); - - static $Value? _followedBy( - Runtime runtime, $Value? target, List<$Value?> args) { - return $Iterable.wrap( - (target!.$value as Iterable).followedBy(args[0]!.$value as Iterable)); - } - - static const $Function __skip = $Function(_skip); - - static $Value? _skip(Runtime runtime, $Value? target, List<$Value?> args) { - return $Iterable.wrap((target!.$value as Iterable).skip(args[0]!.$value)); - } - - static const $Function __skipWhile = $Function(_skipWhile); - - static $Value? _skipWhile( - Runtime runtime, $Value? target, List<$Value?> args) { - final test = args[0] as EvalCallable; - return $Iterable.wrap((target!.$value as List) - .skipWhile((e) => test.call(runtime, null, [e])!.$value as bool)); - } - - static const $Function __take = $Function(_take); - - static $Value? _take(Runtime runtime, $Value? target, List<$Value?> args) { - return $Iterable.wrap((target!.$value as Iterable).take(args[0]!.$value)); - } - - static const $Function __toSet = $Function(_toSet); + @override + Iterable get $reified => $value; - static $Value? _toSet(Runtime runtime, $Value? target, List<$Value?> args) { - return $List.wrap((target!.$value as Iterable).toSet().toList()); + @override + void $setProperty(Runtime runtime, String identifier, $Value value) { + switch (identifier) { + default: + _superclass.$setProperty(runtime, identifier, value); + } } @override - bool any(bool Function(E element) test) => $value.any(test); + final Iterable $value; @override - Iterable cast() => $value.cast(); + Iterator get iterator => $value.iterator; @override - bool contains(Object? element) => $value.contains(element); + int get length => $value.length; @override - E elementAt(int index) => $value.elementAt(index); + bool get isEmpty => $value.isEmpty; @override - bool every(bool Function(E element) test) => $value.every(test); + bool get isNotEmpty => $value.isNotEmpty; @override - Iterable expand(Iterable Function(E element) toElements) => - $value.expand(toElements); + E get first => $value.first; @override - E get first => $value.first; + E get last => $value.last; @override - E firstWhere(bool Function(E element) test, {E Function()? orElse}) => - $value.firstWhere(test, orElse: orElse); + E get single => $value.single; @override - T fold(T initialValue, T Function(T previousValue, E element) combine) => - $value.fold(initialValue, combine); + Iterable cast() => $value.cast(); + static const __$cast = $Function(_$cast); + static $Value? _$cast(Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as Iterable; + final $result = $this.cast(); + return $Iterable.wrap($result); + } @override Iterable followedBy(Iterable other) => $value.followedBy(other); + static const __$followedBy = $Function(_$followedBy); + static $Value? _$followedBy( + Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as Iterable; + final other = args[0]?.$value as Iterable; + final $result = $this.followedBy(other); + return $Iterable.wrap($result); + } @override - void forEach(void Function(E element) action) => $value.forEach(action); + Iterable map(T Function(E e) toElement) => $value.map(toElement); + static const __$map = $Function(_$map); + static $Value? _$map(Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as Iterable; + final toElement = args[0] as EvalCallable; + final $result = $this.map((e) => toElement.call(runtime, null, [e])); + return $Iterable.wrap($result); + } @override - bool get isEmpty => $value.isEmpty; + Iterable where(bool Function(E element) test) => $value.where(test); + static const __$where = $Function(_$where); + static $Value? _$where(Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as Iterable; + final test = args[0] as EvalCallable; + final $result = $this.where( + (element) => + test.call(runtime, null, [element as $Value?])!.$value as bool, + ); + return $Iterable.wrap($result); + } @override - bool get isNotEmpty => $value.isNotEmpty; + Iterable whereType() => $value.whereType(); + static const __$whereType = $Function(_$whereType); + static $Value? _$whereType( + Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as Iterable; + final $result = $this.whereType(); + return $Iterable.wrap($result); + } @override - Iterator get iterator => $value.iterator; + Iterable expand(Iterable Function(E element) toElements) => + $value.expand(toElements); + static const __$expand = $Function(_$expand); + static $Value? _$expand(Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as Iterable; + final toElements = args[0] as EvalCallable; + final $result = $this.expand( + (element) => + toElements.call(runtime, null, [element])!.$value as Iterable, + ); + return $Iterable.wrap($result); + } @override - String join([String separator = '']) => $value.join(separator); + bool contains(Object? element) => $value.contains(element); + static const __$contains = $Function(_$contains); + static $Value? _$contains( + Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as Iterable; + final element = args[0]; + final $result = $this.contains(element); + return $bool($result); + } @override - E get last => $value.last; + void forEach(void Function(E element) action) => $value.forEach(action); + static const __$forEach = $Function(_$forEach); + static $Value? _$forEach( + Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as Iterable; + final action = args[0] as EvalCallable; + $this.forEach( + (element) => action.call(runtime, null, [element]), + ); + return null; + } @override - E lastWhere(bool Function(E element) test, {E Function()? orElse}) => - $value.lastWhere(test, orElse: orElse); + E reduce(E Function(E value, E element) combine) => $value.reduce(combine); + static const __$reduce = $Function(_$reduce); + static $Value? _$reduce(Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as Iterable; + final combine = args[0] as EvalCallable; + final $result = $this.reduce( + (value, element) => combine.call(runtime, null, [value, element]), + ); + return $result; + } @override - int get length => $value.length; + T fold(T initialValue, T Function(T previousValue, E element) combine) => + $value.fold(initialValue, combine); + static const __$fold = $Function(_$fold); + static $Value? _$fold(Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as Iterable; + final initialValue = args[0]; + final combine = args[1] as EvalCallable; + final $result = $this.fold( + initialValue, + (previousValue, element) => + combine.call(runtime, null, [previousValue, element]), + ); + return $result; + } @override - Iterable map(T Function(E e) toElement) => $value.map(toElement); + bool every(bool Function(E element) test) => $value.every(test); + static const __$every = $Function(_$every); + static $Value? _$every(Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as Iterable; + final test = args[0] as EvalCallable; + final $result = $this.every( + (element) => test.call(runtime, null, [element])!.$value as bool, + ); + return $bool($result); + } @override - E reduce(E Function(E value, E element) combine) => $value.reduce(combine); + String join([String separator = ""]) => $value.join(separator); + static const __$join = $Function(_$join); + static $Value? _$join(Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as Iterable; + final separator = args[0]?.$value as String? ?? ""; + final $result = $this + .map((v) => v is $Value ? runtime.valueToString(v) : v) + .join(separator); + return $String($result); + } @override - E get single => $value.single; + bool any(bool Function(E element) test) => $value.any(test); + static const __$any = $Function(_$any); + static $Value? _$any(Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as Iterable; + final test = args[0] as EvalCallable; + final $result = $this.any( + (element) => test.call(runtime, null, [element])!.$value as bool, + ); + return $bool($result); + } @override - E singleWhere(bool Function(E element) test, {E Function()? orElse}) => - $value.singleWhere(test, orElse: orElse); + List toList({bool growable = true}) => $value.toList(growable: growable); + static const __$toList = $Function(_$toList); + static $Value? _$toList(Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as Iterable; + final growable = args[0]?.$value as bool? ?? true; + final $result = $this.toList(growable: growable); + return $List.wrap($result); + } @override - Iterable skip(int count) => $value.skip(count); + Set toSet() => $value.toSet(); + static const __$toSet = $Function(_$toSet); + static $Value? _$toSet(Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as Iterable; + final $result = $this.toList(); + return $List.wrap($result); + } @override - Iterable skipWhile(bool Function(E value) test) => $value.skipWhile(test); + Iterable take(int count) => $value.take(count); + static const __$take = $Function(_$take); + static $Value? _$take(Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as Iterable; + final count = args[0]?.$value as int; + final $result = $this.take(count); + return $Iterable.wrap($result); + } @override - Iterable take(int count) => $value.take(count); + Iterable takeWhile(bool test(E value)) => $value.takeWhile(test); + static const __$takeWhile = $Function(_$takeWhile); + static $Value? _$takeWhile( + Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as Iterable; + final test = args[0] as EvalCallable; + final $result = $this.takeWhile( + (value) => test.call(runtime, null, [value])!.$value as bool, + ); + return $Iterable.wrap($result); + } @override - Iterable takeWhile(bool Function(E value) test) => $value.takeWhile(test); + Iterable skip(int count) => $value.skip(count); + static const __$skip = $Function(_$skip); + static $Value? _$skip(Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as Iterable; + final count = args[0]?.$value as int; + final $result = $this.skip(count); + return $Iterable.wrap($result); + } @override - List toList({bool growable = true}) => $value.toList(growable: growable); + Iterable skipWhile(bool test(E value)) => $value.skipWhile(test); + static const __$skipWhile = $Function(_$skipWhile); + static $Value? _$skipWhile( + Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as Iterable; + final test = args[0] as EvalCallable; + final $result = $this.skipWhile( + (value) => test.call(runtime, null, [value])!.$value as bool, + ); + return $Iterable.wrap($result); + } @override - Set toSet() => $value.toSet(); + E firstWhere(bool Function(E element) test, {E Function()? orElse}) => + $value.firstWhere(test, orElse: orElse); + static const __$firstWhere = $Function(_$firstWhere); + static $Value? _$firstWhere( + Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as Iterable; + final test = args[0] as EvalCallable; + final orElse = args[1] as EvalCallable?; + final $result = $this.firstWhere( + (element) => test.call(runtime, null, [element])!.$value as bool, + orElse: orElse == null + ? null + : () => orElse.call(runtime, null, [])!, + ); + return $result; + } @override - Iterable where(bool Function(E element) test) => $value.where(test); + E lastWhere(bool Function(E element) test, {E Function()? orElse}) => + $value.lastWhere(test, orElse: orElse); + static const __$lastWhere = $Function(_$lastWhere); + static $Value? _$lastWhere( + Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as Iterable; + final test = args[0] as EvalCallable; + final orElse = args[1] as EvalCallable?; + final $result = $this.lastWhere( + (element) => test.call(runtime, null, [element])!.$value as bool, + orElse: orElse == null + ? null + : () => orElse.call(runtime, null, [])!, + ); + return $result; + } @override - Iterable whereType() => $value.whereType(); + E singleWhere(bool Function(E element) test, {E Function()? orElse}) => + $value.singleWhere(test, orElse: orElse); + static const __$singleWhere = $Function(_$singleWhere); + static $Value? _$singleWhere( + Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as Iterable; + final test = args[0] as EvalCallable; + final orElse = args[1] as EvalCallable?; + final $result = $this.singleWhere( + (element) => test.call(runtime, null, [element])!.$value as bool, + orElse: orElse == null + ? null + : () => orElse.call(runtime, null, [])!, + ); + return $result; + } @override - int $getRuntimeType(Runtime runtime) => - runtime.lookupType(CoreTypes.iterable); -} + E elementAt(int index) => $value.elementAt(index); + static const __$elementAt = $Function(_$elementAt); + static $Value? _$elementAt( + Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as Iterable; + final index = args[0]?.$value as int; + final $result = $this.elementAt(index); + return $result; + } -$Function get$Iterable_generate(Runtime _) => _$Iterable_generate; + static const __$static$method$castFrom = $Function(_$static$method$castFrom); + static $Value? _$static$method$castFrom( + Runtime runtime, $Value? target, List<$Value?> args) { + final source = (args[0]?.$reified as Iterable).cast(); + final $result = Iterable.castFrom(source); + return $Iterable.wrap($result); + } -const _$Iterable_generate = $Function(_Iterable_generate); + static const __$static$method$iterableToShortString = + $Function(_$static$method$iterableToShortString); + static $Value? _$static$method$iterableToShortString( + Runtime runtime, $Value? target, List<$Value?> args) { + final iterable = (args[0]?.$reified as Iterable).cast(); + final leftDelimiter = args[1]?.$value as String? ?? '('; + final rightDelimiter = args[2]?.$value as String? ?? ')'; + final $result = Iterable.iterableToShortString( + iterable, + leftDelimiter, + rightDelimiter, + ); + return $String($result); + } -final _defaultIterableGenerator = $Function((runtime, target, args) => args[0]); -$Value? _Iterable_generate( - Runtime runtime, $Value? target, List<$Value?> args) { - var generator = args[1] as EvalFunction?; - generator ??= _defaultIterableGenerator; - return $Iterable.wrap(Iterable.generate( - args[0]!.$value, (i) => generator!(runtime, target, [$int(i)]))); + static const __$static$method$iterableToFullString = + $Function(_$static$method$iterableToFullString); + static $Value? _$static$method$iterableToFullString( + Runtime runtime, $Value? target, List<$Value?> args) { + final iterable = (args[0]?.$reified as Iterable).cast(); + final leftDelimiter = args[1]?.$value as String? ?? '('; + final rightDelimiter = args[2]?.$value as String? ?? ')'; + final $result = Iterable.iterableToFullString( + iterable, + leftDelimiter, + rightDelimiter, + ); + return $String($result); + } + + static const __$Iterable$generate = $Function(_$Iterable$generate); + static $Value? _$Iterable$generate( + Runtime runtime, $Value? target, List<$Value?> args) { + final count = args[0]?.$value as int; + final generator = args[1] as EvalFunction? ?? + $Function((runtime, target, args) => args[0]); + return $Iterable.wrap(Iterable.generate( + count, + (index) => generator.call(runtime, null, [$int(index)]), + )); + } + + static const __$Iterable$empty = $Function(_$Iterable$empty); + static $Value? _$Iterable$empty( + Runtime runtime, $Value? target, List<$Value?> args) { + return $Iterable.wrap(Iterable.empty()); + } } diff --git a/lib/src/eval/shared/stdlib/core/list.dart b/lib/src/eval/shared/stdlib/core/list.dart index e44bb99..bff31d4 100644 --- a/lib/src/eval/shared/stdlib/core/list.dart +++ b/lib/src/eval/shared/stdlib/core/list.dart @@ -1,707 +1,1376 @@ -// ignore_for_file: non_constant_identifier_names - part of 'collection.dart'; /// dart_eval bimodal wrapper for [List] class $List implements List, $Instance { /// Configure the [$List] wrapper for use in a [Runtime] + static void configureForCompile(BridgeDeclarationRegistry registry) { + registry.defineBridgeClass($declaration); + } + static void configureForRuntime(Runtime runtime) { - runtime.registerBridgeFunc('dart:core', 'List.filled', _$List_filled.call); runtime.registerBridgeFunc( - 'dart:core', 'List.generate', _$List_generate.call); - runtime.registerBridgeFunc('dart:core', 'List.of', _$List_of.call); - runtime.registerBridgeFunc('dart:core', 'List.from', _$List_from.call); + $type.spec!.library, 'List.filled', __$List$filled.call, + isBridge: false); + runtime.registerBridgeFunc( + $type.spec!.library, 'List.empty', __$List$empty.call, + isBridge: false); + runtime.registerBridgeFunc( + $type.spec!.library, 'List.from', __$List$from.call, + isBridge: false); + runtime.registerBridgeFunc($type.spec!.library, 'List.of', __$List$of.call, + isBridge: false); + runtime.registerBridgeFunc( + $type.spec!.library, 'List.generate', __$List$generate.call, + isBridge: false); + runtime.registerBridgeFunc( + $type.spec!.library, 'List.unmodifiable', __$List$unmodifiable.call, + isBridge: false); + runtime.registerBridgeFunc( + $type.spec!.library, 'List.castFrom', __$static$method$castFrom.call, + isBridge: false); + runtime.registerBridgeFunc( + $type.spec!.library, 'List.copyRange', __$static$method$copyRange.call, + isBridge: false); + runtime.registerBridgeFunc($type.spec!.library, 'List.writeIterable', + __$static$method$writeIterable.call, + isBridge: false); } - /// Bridge class declaration for [$List] + late final $Iterable _superclass = $Iterable.wrap($value); + + static const $type = BridgeTypeRef(CoreTypes.list); + static const $declaration = BridgeClassDef( - BridgeClassType(BridgeTypeRef(CoreTypes.list), - $extends: BridgeTypeRef(CoreTypes.iterable), - generics: {'E': BridgeGenericParam()}), - constructors: { - 'filled': BridgeConstructorDef(BridgeFunctionDef( + BridgeClassType($type, + $extends: BridgeTypeRef(CoreTypes.iterable), + generics: {'E': BridgeGenericParam()}), + constructors: { + 'filled': BridgeConstructorDef( + BridgeFunctionDef(returns: BridgeTypeAnnotation($type), params: [ + BridgeParameter( + 'length', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int, []), + nullable: false), + false), + BridgeParameter( + 'fill', + BridgeTypeAnnotation(BridgeTypeRef.ref('E', []), nullable: false), + false) + ], namedParams: [ + BridgeParameter( + 'growable', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool, []), + nullable: false), + true) + ], generics: { + 'E': BridgeGenericParam() + }), + isFactory: true, + ), + 'empty': BridgeConstructorDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation($type), + params: [], + namedParams: [ + BridgeParameter( + 'growable', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool, []), + nullable: false), + true) + ], + generics: { + 'E': BridgeGenericParam() + }), + isFactory: true, + ), + 'from': BridgeConstructorDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation($type), + params: [ + BridgeParameter( + 'elements', + BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.iterable, [BridgeTypeRef.ref('E')]), + nullable: false), + false) + ], + namedParams: [ + BridgeParameter( + 'growable', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool, []), + nullable: false), + true) + ], + generics: {'E': BridgeGenericParam()}, + ), + isFactory: true, + ), + 'of': BridgeConstructorDef( + BridgeFunctionDef(returns: BridgeTypeAnnotation($type), params: [ + BridgeParameter( + 'elements', + BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.iterable, [ + BridgeTypeRef.ref('E', []), + ]), + nullable: false), + false) + ], namedParams: [ + BridgeParameter( + 'growable', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool, []), + nullable: false), + true) + ], generics: { + 'E': BridgeGenericParam() + }), + isFactory: true, + ), + 'generate': BridgeConstructorDef( + BridgeFunctionDef(returns: BridgeTypeAnnotation($type), params: [ + BridgeParameter( + 'length', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int, []), + nullable: false), + false), + BridgeParameter( + 'generator', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.function, []), + nullable: false), + false) + ], namedParams: [ + BridgeParameter( + 'growable', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool, []), + nullable: false), + true) + ], generics: { + 'E': BridgeGenericParam() + }), + isFactory: true, + ), + 'unmodifiable': BridgeConstructorDef( + BridgeFunctionDef(returns: BridgeTypeAnnotation($type), params: [ + BridgeParameter( + 'elements', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.iterable, []), + nullable: false), + false) + ], namedParams: [], generics: { + 'E': BridgeGenericParam() + }), + isFactory: true, + ) + }, + fields: {}, + methods: { + 'castFrom': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.list, [ + BridgeTypeRef.ref('T', []), + ]), + nullable: false), + params: [ + BridgeParameter( + 'source', + BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.list, [ + BridgeTypeRef.ref('S', []), + ]), + nullable: false), + false) + ], + namedParams: [], + generics: { + 'S': BridgeGenericParam(), + 'T': BridgeGenericParam(), + }), + isStatic: true), + 'copyRange': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.voidType, []), + nullable: false), + params: [ + BridgeParameter( + 'target', + BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.list, [ + BridgeTypeRef.ref('T', []), + ]), + nullable: false), + false), + BridgeParameter( + 'at', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int, []), + nullable: false), + false), + BridgeParameter( + 'source', + BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.list, [ + BridgeTypeRef.ref('T', []), + ]), + nullable: false), + false), + BridgeParameter( + 'start', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int, []), + nullable: true), + true), + BridgeParameter( + 'end', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int, []), + nullable: true), + true) + ], + namedParams: [], + generics: { + 'T': BridgeGenericParam(), + }), + isStatic: true), + 'writeIterable': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.voidType, []), + nullable: false), + params: [ + BridgeParameter( + 'target', + BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.list, [ + BridgeTypeRef.ref('T', []), + ]), + nullable: false), + false), + BridgeParameter( + 'at', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int, []), + nullable: false), + false), + BridgeParameter( + 'source', + BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.iterable, [ + BridgeTypeRef.ref('T', []), + ]), + nullable: false), + false) + ], + namedParams: [], + generics: { + 'T': BridgeGenericParam(), + }), + isStatic: true), + 'cast': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.list, [ + BridgeTypeRef.ref('R', []), + ]), + nullable: false), + params: [], + namedParams: [], + generics: {'R': BridgeGenericParam()}, + ), + isStatic: false), + '[]': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef.ref('E', []), + nullable: false), params: [ - BridgeParameter('length', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int)), false), BridgeParameter( - 'fill', BridgeTypeAnnotation(BridgeTypeRef.ref('E')), false), + 'index', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int, []), + nullable: false), + false) ], - namedParams: [ - BridgeParameter('growable', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool)), true), + namedParams: [], + ), + isStatic: false), + '[]=': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.voidType, []), + nullable: false), + params: [ + BridgeParameter( + 'index', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int, []), + nullable: false), + false), + BridgeParameter( + 'value', + BridgeTypeAnnotation(BridgeTypeRef.ref('E', []), + nullable: false), + false) ], - returns: BridgeTypeAnnotation( - BridgeTypeRef(CoreTypes.list, [BridgeTypeRef.ref('E')])), - generics: {'E': BridgeGenericParam()})), - 'generate': BridgeConstructorDef(BridgeFunctionDef( + namedParams: [], + ), + isStatic: false), + 'add': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.voidType, []), + nullable: false), + params: [ + BridgeParameter( + 'value', + BridgeTypeAnnotation(BridgeTypeRef.ref('E', []), + nullable: false), + false) + ], + namedParams: [], + ), + isStatic: false), + 'addAll': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.voidType, []), + nullable: false), + params: [ + BridgeParameter( + 'iterable', + BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.iterable, [ + BridgeTypeRef.ref('E', []), + ]), + nullable: false), + false) + ], + namedParams: [], + ), + isStatic: false), + 'sort': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.voidType, []), + nullable: false), params: [ - BridgeParameter('length', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int)), false), BridgeParameter( - 'generator', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.function)), + 'compare', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.function, []), + nullable: true), + true) + ], + namedParams: [], + ), + isStatic: false), + 'shuffle': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.voidType, []), + nullable: false), + params: [ + BridgeParameter( + 'random', + BridgeTypeAnnotation(BridgeTypeRef(MathTypes.random, []), + nullable: true), + true) + ], + namedParams: [], + ), + isStatic: false), + 'indexOf': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int, []), + nullable: false), + params: [ + BridgeParameter( + 'element', + BridgeTypeAnnotation(BridgeTypeRef.ref('E', []), + nullable: false), false), + BridgeParameter( + 'start', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int, []), + nullable: false), + true) ], - namedParams: [ - BridgeParameter('growable', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool)), true), + namedParams: [], + ), + isStatic: false), + 'indexWhere': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int, []), + nullable: false), + params: [ + BridgeParameter( + 'test', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool, []), + nullable: false), + false), + BridgeParameter( + 'start', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int, []), + nullable: false), + true) ], - returns: BridgeTypeAnnotation( - BridgeTypeRef(CoreTypes.list, [BridgeTypeRef.ref('E')])), - generics: {'E': BridgeGenericParam()})), - 'of': BridgeConstructorDef(BridgeFunctionDef( + namedParams: [], + ), + isStatic: false), + 'lastIndexWhere': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int, []), + nullable: false), params: [ BridgeParameter( - 'elements', - BridgeTypeAnnotation(BridgeTypeRef( - CoreTypes.iterable, [BridgeTypeRef.ref('E')])), + 'test', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool, []), + nullable: false), false), + BridgeParameter( + 'start', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int, []), + nullable: true), + true) ], - namedParams: [ - BridgeParameter('growable', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool)), true), + namedParams: [], + ), + isStatic: false), + 'lastIndexOf': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int, []), + nullable: false), + params: [ + BridgeParameter( + 'element', + BridgeTypeAnnotation(BridgeTypeRef.ref('E', []), + nullable: false), + false), + BridgeParameter( + 'start', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int, []), + nullable: true), + true) ], - returns: BridgeTypeAnnotation( - BridgeTypeRef(CoreTypes.list, [BridgeTypeRef.ref('E')])), - generics: {'E': BridgeGenericParam()})), - 'from': BridgeConstructorDef(BridgeFunctionDef( + namedParams: [], + ), + isStatic: false), + 'clear': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.voidType, []), + nullable: false), + params: [], + namedParams: [], + ), + isStatic: false), + 'insert': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.voidType, []), + nullable: false), params: [ BridgeParameter( - 'elements', - BridgeTypeAnnotation(BridgeTypeRef( - CoreTypes.iterable, [BridgeTypeRef(CoreTypes.dynamic)])), + 'index', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int, []), + nullable: false), false), + BridgeParameter( + 'element', + BridgeTypeAnnotation(BridgeTypeRef.ref('E', []), + nullable: false), + false) ], - namedParams: [ - BridgeParameter('growable', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool)), true), + namedParams: [], + ), + isStatic: false), + 'insertAll': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.voidType, []), + nullable: false), + params: [ + BridgeParameter( + 'index', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int, []), + nullable: false), + false), + BridgeParameter( + 'iterable', + BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.iterable, [ + BridgeTypeRef.ref('E', []), + ]), + nullable: false), + false) ], - returns: BridgeTypeAnnotation( - BridgeTypeRef(CoreTypes.list, [BridgeTypeRef.ref('E')])), - generics: {'E': BridgeGenericParam()})), - }, - methods: { - '[]': BridgeMethodDef(BridgeFunctionDef(params: [ - BridgeParameter('index', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int)), false), - ], returns: BridgeTypeAnnotation(BridgeTypeRef.ref('E')))), - 'contains': BridgeMethodDef(BridgeFunctionDef(params: [ - BridgeParameter( - 'element', BridgeTypeAnnotation(BridgeTypeRef.ref('E')), false), - ], returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool)))), - '[]=': BridgeMethodDef(BridgeFunctionDef(params: [ - BridgeParameter('index', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int)), false), - BridgeParameter( - 'value', BridgeTypeAnnotation(BridgeTypeRef.ref('E')), false), - ], returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.voidType)))), - 'add': BridgeMethodDef(BridgeFunctionDef(params: [ - BridgeParameter( - 'value', BridgeTypeAnnotation(BridgeTypeRef.ref('E')), false), - ], returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.voidType)))), - 'lastIndexOf': BridgeMethodDef(BridgeFunctionDef(params: [ - BridgeParameter( - 'element', BridgeTypeAnnotation(BridgeTypeRef.ref('E')), false), - BridgeParameter( - 'start', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int), - nullable: true), - true), - ], returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int)))), - 'join': BridgeMethodDef( - BridgeFunctionDef(params: [ - BridgeParameter('separator', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string)), true), - ], returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string))), - isStatic: false), - 'indexOf': BridgeMethodDef(BridgeFunctionDef(params: [ - BridgeParameter( - 'element', BridgeTypeAnnotation(BridgeTypeRef.ref('E')), false), - BridgeParameter( - 'start', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int), - nullable: true), - true), - ], returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int)))), - 'elementAt': BridgeMethodDef(BridgeFunctionDef(params: [ - BridgeParameter('index', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int)), false), - ], returns: BridgeTypeAnnotation(BridgeTypeRef.ref('E')))), - 'remove': BridgeMethodDef(BridgeFunctionDef(params: [ - BridgeParameter( - 'value', BridgeTypeAnnotation(BridgeTypeRef.ref('E')), false), - ], returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool)))), - 'removeAt': BridgeMethodDef(BridgeFunctionDef( - params: [ - BridgeParameter('index', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int)), false), - ], - returns: BridgeTypeAnnotation(BridgeTypeRef.ref('E')), - )), - 'removeLast': BridgeMethodDef(BridgeFunctionDef( - returns: BridgeTypeAnnotation(BridgeTypeRef.ref('E')), - )), - 'insert': BridgeMethodDef(BridgeFunctionDef(params: [ - BridgeParameter('index', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int)), false), - BridgeParameter( - 'element', BridgeTypeAnnotation(BridgeTypeRef.ref('E')), false), - ], returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.voidType)))), - 'toSet': BridgeMethodDef(BridgeFunctionDef( + namedParams: [], + ), + isStatic: false), + 'setAll': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.voidType, []), + nullable: false), + params: [ + BridgeParameter( + 'index', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int, []), + nullable: false), + false), + BridgeParameter( + 'iterable', + BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.iterable, [ + BridgeTypeRef.ref('E', []), + ]), + nullable: false), + false) + ], + namedParams: [], + ), + isStatic: false), + 'remove': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool, []), + nullable: false), + params: [ + BridgeParameter( + 'value', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.object, []), + nullable: true), + false) + ], + namedParams: [], + ), + isStatic: false), + 'removeAt': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef.ref('E', []), + nullable: false), + params: [ + BridgeParameter( + 'index', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int, []), + nullable: false), + false) + ], + namedParams: [], + ), + isStatic: false), + 'removeLast': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef.ref('E', []), + nullable: false), params: [], - returns: BridgeTypeAnnotation( - BridgeTypeRef(BridgeTypeSpec('dart:core', 'Iterable'))))), - 'map': BridgeMethodDef( - BridgeFunctionDef( - params: [ - BridgeParameter( - 'toElement', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.function)), - false), - ], - returns: BridgeTypeAnnotation( - BridgeTypeRef(BridgeTypeSpec('dart:core', 'Iterable')))), - isStatic: false), - 'followedBy': BridgeMethodDef( - BridgeFunctionDef( - params: [ - BridgeParameter( - 'other', - BridgeTypeAnnotation(BridgeTypeRef( - BridgeTypeSpec('dart:core', 'Iterable'))), - false), - ], - returns: BridgeTypeAnnotation( - BridgeTypeRef(BridgeTypeSpec('dart:core', 'Iterable')))), - isStatic: false), - 'getRange': BridgeMethodDef( - BridgeFunctionDef( - params: [ - BridgeParameter( - 'start', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int)), - false), - BridgeParameter( - 'end', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int)), - false), - ], - returns: BridgeTypeAnnotation( - BridgeTypeRef(BridgeTypeSpec('dart:core', 'Iterable')))), - isStatic: false), - 'where': BridgeMethodDef( - BridgeFunctionDef( - params: [ - BridgeParameter( - 'test', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.function)), - false), - ], - returns: BridgeTypeAnnotation( - BridgeTypeRef(BridgeTypeSpec('dart:core', 'Iterable')))), - isStatic: false), - 'skipWhile': BridgeMethodDef( - BridgeFunctionDef( - params: [ - BridgeParameter( - 'test', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.function)), - false), - ], - returns: BridgeTypeAnnotation( - BridgeTypeRef(BridgeTypeSpec('dart:core', 'Iterable')))), - isStatic: false), - 'takeWhile': BridgeMethodDef( - BridgeFunctionDef( - params: [ - BridgeParameter( - 'test', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.function)), - false), - ], - returns: BridgeTypeAnnotation( - BridgeTypeRef(BridgeTypeSpec('dart:core', 'Iterable')))), - isStatic: false), - 'sort': BridgeMethodDef( - BridgeFunctionDef( - params: [ - BridgeParameter( - 'compare', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.function)), - false), - ], - returns: - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.voidType))), - isStatic: false), - 'retainWhere': BridgeMethodDef( - BridgeFunctionDef( - params: [ - BridgeParameter( - 'test', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.function)), - false), - ], - returns: - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.voidType))), - isStatic: false), - 'replaceRange': BridgeMethodDef( - BridgeFunctionDef( - params: [ - BridgeParameter( - 'start', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int)), - false), - BridgeParameter( - 'end', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int)), - false), - BridgeParameter( - 'replacements', - BridgeTypeAnnotation(BridgeTypeRef( - BridgeTypeSpec('dart:core', 'Iterable'))), - false), - ], - returns: - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.voidType))), - isStatic: false), - 'removeWhere': BridgeMethodDef( - BridgeFunctionDef( - params: [ - BridgeParameter( - 'test', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.function)), - false), - ], - returns: - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.voidType))), - isStatic: false), - 'firstWhere': BridgeMethodDef( - BridgeFunctionDef(params: [ + namedParams: [], + ), + isStatic: false), + 'removeWhere': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.voidType, []), + nullable: false), + params: [ + BridgeParameter( + 'test', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.function, []), + nullable: false), + false) + ], + namedParams: [], + ), + isStatic: false), + 'retainWhere': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.voidType, []), + nullable: false), + params: [ BridgeParameter( 'test', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.function)), + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.function, []), + nullable: false), + false) + ], + namedParams: [], + ), + isStatic: false), + '+': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.list, [ + BridgeTypeRef.ref('E', []), + ]), + nullable: false), + params: [ + BridgeParameter( + 'other', + BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.list, [ + BridgeTypeRef.ref('E', []), + ]), + nullable: false), + false) + ], + namedParams: [], + ), + isStatic: false), + 'sublist': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.list, [ + BridgeTypeRef.ref('E', []), + ]), + nullable: false), + params: [ + BridgeParameter( + 'start', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int, []), + nullable: false), false), - ], namedParams: [ BridgeParameter( - 'orElse', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.function)), + 'end', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int, []), + nullable: true), + true) + ], + namedParams: [], + ), + isStatic: false), + 'getRange': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.iterable, [ + BridgeTypeRef.ref('E', []), + ]), + nullable: false), + params: [ + BridgeParameter( + 'start', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int, []), + nullable: false), false), - ], returns: BridgeTypeAnnotation(BridgeTypeRef.ref('E'))), - isStatic: false), - 'sublist': BridgeMethodDef( - BridgeFunctionDef( - params: [ - BridgeParameter( - 'start', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int)), - false), - BridgeParameter( - 'end', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int), - nullable: true), - true), - ], - returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.list, [ - BridgeTypeRef.ref('E'), - ]))), - isStatic: false), - 'any': BridgeMethodDef( - BridgeFunctionDef(params: [ BridgeParameter( - 'test', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.function)), + 'end', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int, []), + nullable: false), + false) + ], + namedParams: [], + ), + isStatic: false), + 'setRange': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.voidType, []), + nullable: false), + params: [ + BridgeParameter( + 'start', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int, []), + nullable: false), false), - ], returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool))), - isStatic: false), - 'every': BridgeMethodDef( - BridgeFunctionDef(params: [ BridgeParameter( - 'test', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.function)), + 'end', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int, []), + nullable: false), false), - ], returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool))), - isStatic: false), - 'skip': BridgeMethodDef( - BridgeFunctionDef( - params: [ - BridgeParameter( - 'count', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int)), - false), - ], - returns: BridgeTypeAnnotation( - BridgeTypeRef(BridgeTypeSpec('dart:core', 'Iterable')))), - isStatic: false), - 'take': BridgeMethodDef( - BridgeFunctionDef( - params: [ - BridgeParameter( - 'count', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int)), - false), - ], - returns: BridgeTypeAnnotation( - BridgeTypeRef(BridgeTypeSpec('dart:core', 'Iterable')))), - isStatic: false), - 'asMap': BridgeMethodDef( - BridgeFunctionDef( - returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.map))), - isStatic: false), - 'toString': BridgeMethodDef( - BridgeFunctionDef( - returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string))), - isStatic: false), - 'clear': BridgeMethodDef( - BridgeFunctionDef( - returns: - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.voidType))), - isStatic: false), - 'addAll': BridgeMethodDef(BridgeFunctionDef(params: [ - BridgeParameter( - 'iterable', - BridgeTypeAnnotation( - BridgeTypeRef(BridgeTypeSpec('dart:core', 'Iterable'))), - false), - ], returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.voidType)))), - 'insertAll': BridgeMethodDef(BridgeFunctionDef(params: [ - BridgeParameter('index', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int)), false), - BridgeParameter( - 'iterable', - BridgeTypeAnnotation( - BridgeTypeRef(BridgeTypeSpec('dart:core', 'Iterable'))), - false), - ], returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.voidType)))), - 'cast': BridgeMethodDef( - BridgeFunctionDef( - generics: {'R': BridgeGenericParam()}, - returns: BridgeTypeAnnotation( - BridgeTypeRef(CoreTypes.list, [BridgeTypeRef.ref('R')]))), - isStatic: false), - }, - getters: { - 'length': BridgeMethodDef(BridgeFunctionDef( - returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int)))), - 'hashCode': BridgeMethodDef(BridgeFunctionDef( - returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int)))), - 'iterator': BridgeMethodDef( - BridgeFunctionDef( - params: [], - returns: - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.iterator, [ - BridgeTypeRef.ref('E'), - ]))), - isStatic: false), - 'reversed': BridgeMethodDef( - BridgeFunctionDef( - returns: BridgeTypeAnnotation( - BridgeTypeRef(BridgeTypeSpec('dart:core', 'Iterable')))), - isStatic: false), - 'first': BridgeMethodDef(BridgeFunctionDef( - returns: BridgeTypeAnnotation(BridgeTypeRef.ref('E')))), - 'last': BridgeMethodDef(BridgeFunctionDef( - returns: BridgeTypeAnnotation(BridgeTypeRef.ref('E')))), - 'isEmpty': BridgeMethodDef(BridgeFunctionDef( - returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool)))), - 'isNotEmpty': BridgeMethodDef(BridgeFunctionDef( - returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool)))), - }, - setters: {}, - fields: {}, - wrap: true); - - /// Wrap a [List] in a [$List] + BridgeParameter( + 'iterable', + BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.iterable, [ + BridgeTypeRef.ref('E', []), + ]), + nullable: false), + false), + BridgeParameter( + 'skipCount', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int, []), + nullable: false), + true) + ], + namedParams: [], + ), + isStatic: false), + 'removeRange': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.voidType, []), + nullable: false), + params: [ + BridgeParameter( + 'start', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int, []), + nullable: false), + false), + BridgeParameter( + 'end', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int, []), + nullable: false), + false) + ], + namedParams: [], + ), + isStatic: false), + 'fillRange': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.voidType, []), + nullable: false), + params: [ + BridgeParameter( + 'start', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int, []), + nullable: false), + false), + BridgeParameter( + 'end', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int, []), + nullable: false), + false), + BridgeParameter( + 'fillValue', + BridgeTypeAnnotation(BridgeTypeRef.ref('E', []), + nullable: true), + true) + ], + namedParams: [], + ), + isStatic: false), + 'replaceRange': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.voidType, []), + nullable: false), + params: [ + BridgeParameter( + 'start', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int, []), + nullable: false), + false), + BridgeParameter( + 'end', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int, []), + nullable: false), + false), + BridgeParameter( + 'replacements', + BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.iterable, [ + BridgeTypeRef.ref('E', []), + ]), + nullable: false), + false) + ], + namedParams: [], + ), + isStatic: false), + 'asMap': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.map, [ + BridgeTypeRef(CoreTypes.int, []), + BridgeTypeRef.ref('E', []), + ]), + nullable: false), + params: [], + namedParams: [], + ), + isStatic: false), + }, + getters: { + 'length': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int, []), + nullable: false), + params: [], + namedParams: [], + ), + isStatic: false), + 'reversed': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.iterable, [ + BridgeTypeRef.ref('E', []), + ]), + nullable: false), + params: [], + namedParams: [], + ), + isStatic: false), + }, + setters: { + 'first': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.voidType, []), + nullable: false), + params: [ + BridgeParameter( + 'value', + BridgeTypeAnnotation(BridgeTypeRef.ref('E', []), + nullable: false), + false) + ], + namedParams: [], + ), + isStatic: false), + 'last': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.voidType, []), + nullable: false), + params: [ + BridgeParameter( + 'value', + BridgeTypeAnnotation(BridgeTypeRef.ref('E', []), + nullable: false), + false) + ], + namedParams: [], + ), + isStatic: false), + 'length': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.voidType, []), + nullable: false), + params: [ + BridgeParameter( + 'newLength', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int, []), + nullable: false), + false) + ], + namedParams: [], + ), + isStatic: false), + }, + bridge: false, + wrap: true, + ); + + /// Wrap an [List] in an [$List] $List.wrap(this.$value); /// Create a view of a [List] as a [$List] (supports writeback) - factory $List.view(List value, $Value Function(E value)) = _$List$view; - - @override - final List $value; - - late final $Iterable _superclass = $Iterable.wrap($value); + factory $List.view(List value, $Value Function(E value) mapper) = + _$List$view; @override $Value? $getProperty(Runtime runtime, String identifier) { switch (identifier) { - case '[]': - return __indexGet; - case '[]=': - return __indexSet; - case 'add': - return __add; case 'length': return $int($value.length); - case 'addAll': - return __addAll; - case 'first': - return _superclass.first; - case 'contains': - return __listContains; - case 'where': - return __where; - case 'isEmpty': - return $bool(_superclass.isEmpty); - case 'isNotEmpty': - return $bool(_superclass.isNotEmpty); - case 'last': - return _superclass.last; case 'reversed': return $Iterable.wrap($value.reversed); - case 'iterator': - return $Iterator.wrap($value.iterator); + case 'cast': + return __$cast; + case '[]': + return __$indexGet; + case '[]=': + return __$indexSet; + case 'add': + return __$add; + case 'addAll': + return __$addAll; + case 'sort': + return __$sort; + case 'shuffle': + return __$shuffle; + case 'indexOf': + return __$indexOf; + case 'indexWhere': + return __$indexWhere; + case 'lastIndexWhere': + return __$lastIndexWhere; + case 'lastIndexOf': + return __$lastIndexOf; + case 'clear': + return __$clear; case 'insert': - return __insert; + return __$insert; case 'insertAll': - return __insertAll; + return __$insertAll; + case 'setAll': + return __$setAll; case 'remove': - return __remove; - case 'asMap': - return __asMap; - case 'hashCode': - return $int($value.hashCode); - case 'lastIndexOf': - return __lastIndexOf; - case 'indexOf': - return __indexOf; - case 'retainWhere': - return __retainWhere; - case 'removeWhere': - return __removeWhere; - case 'firstWhere': - return __firstWhere; - case 'replaceRange': - return __replaceRange; - case 'getRange': - return __getRange; - case 'sort': - return __sort; + return __$remove; case 'removeAt': - return __removeAt; + return __$removeAt; case 'removeLast': - return __removeLast; + return __$removeLast; + case 'removeWhere': + return __$removeWhere; + case 'retainWhere': + return __$retainWhere; + case '+': + return __$combine; case 'sublist': - return __sublist; - case 'takeWhile': - return __takeWhile; - case 'clear': - return __clear; - case 'cast': - return __cast; + return __$sublist; + case 'getRange': + return __$getRange; + case 'setRange': + return __$setRange; + case 'removeRange': + return __$removeRange; + case 'fillRange': + return __$fillRange; + case 'replaceRange': + return __$replaceRange; + case 'asMap': + return __$asMap; + default: + return _superclass.$getProperty(runtime, identifier); } - return _superclass.$getProperty(runtime, identifier); } + @override + int $getRuntimeType(Runtime runtime) => runtime.lookupType($type.spec!); + + @override + List get $reified => $value.map((e) => e is $Value ? e.$reified : e).toList(); + @override void $setProperty(Runtime runtime, String identifier, $Value value) { - throw EvalUnknownPropertyException(identifier); + switch (identifier) { + case 'first': + first = value as E; + break; + case 'last': + last = value as E; + break; + case 'length': + length = value.$value as int; + break; + default: + _superclass.$setProperty(runtime, identifier, value); + } } - static const $Function __getRange = $Function(_getRange); + @override + final List $value; - static $Value? _getRange( + @override + int get length => $value.length; + + @override + Iterable get reversed => $value.reversed; + + @override + set first(E value) { + $value.first = value; + } + + @override + set last(E value) { + $value.last = value; + } + + @override + set length(int newLength) { + $value.length = newLength; + } + + @override + List cast() => $value.cast(); + static const __$cast = $Function(_$cast); + static $Value? _$cast(Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as List; + final $result = $this.cast(); + return $List.wrap($result); + } + + @override + E operator [](int index) => $value[index]; + static const __$indexGet = $Function(_$indexGet); + static $Value? _$indexGet( + Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as List; + final index = args[0]?.$value as int; + final $result = $this[index]; + return $result; + } + + @override + void operator []=(int index, E value) => $value[index] = value; + static const __$indexSet = $Function(_$indexSet); + static $Value? _$indexSet( + Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as List; + final index = args[0]?.$value as int; + final value = args[1]; + $this[index] = value; + return null; + } + + @override + void add(E value) => $value.add(value); + static const __$add = $Function(_$add); + static $Value? _$add(Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as List; + final value = args[0]; + $this.add(value); + return null; + } + + @override + void addAll(Iterable iterable) => $value.addAll(iterable); + static const __$addAll = $Function(_$addAll); + static $Value? _$addAll(Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as List; + final iterable = args[0]?.$value as Iterable; + $this.addAll(iterable); + return null; + } + + @override + void sort([int Function(E a, E b)? compare]) => $value.sort(compare); + static const __$sort = $Function(_$sort); + static $Value? _$sort(Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as List; + final compare = args[0] as EvalFunction? ?? + $Function((runtime, target, args) => + $int(Comparable.compare(args[0]?.$value, args[0]?.$value))); + $this.sort((a, b) => compare.call(runtime, null, [a, b])?.$value as int); + return null; + } + + @override + void shuffle([Random? random]) => $value.shuffle(random); + static const __$shuffle = $Function(_$shuffle); + static $Value? _$shuffle( + Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as List; + final random = args[0]?.$value as Random?; + $this.shuffle(random); + return null; + } + + @override + int indexOf(E element, [int start = 0]) => $value.indexOf(element, start); + static const __$indexOf = $Function(_$indexOf); + static $Value? _$indexOf( + Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as List; + final element = args[0]; + final start = args[1]?.$value as int? ?? 0; + final $result = $this.indexOf(element, start); + return $int($result); + } + + @override + int indexWhere(bool Function(E element) test, [int start = 0]) => + $value.indexWhere(test, start); + static const __$indexWhere = $Function(_$indexWhere); + static $Value? _$indexWhere( + Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as List; + final test = args[0] as EvalCallable; + final start = args[1]?.$value as int? ?? 0; + final $result = $this.indexWhere( + (element) => test.call(runtime, null, [element])!.$value as bool, + start, + ); + return $int($result); + } + + @override + int lastIndexWhere(bool Function(E element) test, [int? start]) => + $value.lastIndexWhere(test, start); + static const __$lastIndexWhere = $Function(_$lastIndexWhere); + static $Value? _$lastIndexWhere( + Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as List; + final test = args[0] as EvalCallable; + final start = args[1]?.$value as int?; + final $result = $this.lastIndexWhere( + (element) => test.call(runtime, null, [element])!.$value as bool, + start, + ); + return $int($result); + } + + @override + int lastIndexOf(E element, [int? start]) => + $value.lastIndexOf(element, start); + static const __$lastIndexOf = $Function(_$lastIndexOf); + static $Value? _$lastIndexOf( + Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as List; + final element = args[0]; + final start = args[1]?.$value as int?; + final $result = $this.lastIndexOf(element, start); + return $int($result); + } + + @override + void clear() => $value.clear(); + static const __$clear = $Function(_$clear); + static $Value? _$clear(Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as List; + $this.clear(); + return null; + } + + @override + void insert(int index, E element) => $value.insert(index, element); + static const __$insert = $Function(_$insert); + static $Value? _$insert(Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as List; + final index = args[0]?.$value as int; + final element = args[1]; + $this.insert(index, element); + return null; + } + + @override + void insertAll(int index, Iterable iterable) => + $value.insertAll(index, iterable); + static const __$insertAll = $Function(_$insertAll); + static $Value? _$insertAll( Runtime runtime, $Value? target, List<$Value?> args) { - return $Iterable.wrap( - (target!.$value as List).getRange(args[0]!.$value, args[1]!.$value)); + final $this = target?.$value as List; + final index = args[0]?.$value as int; + final iterable = (args[1]?.$value as Iterable); + $this.insertAll(index, iterable); + return null; } - static const $Function __where = $Function(_where); - - static $Value? _where(Runtime runtime, $Value? target, List<$Value?> args) { - final test = args[0] as EvalCallable; - return $Iterable.wrap((target!.$value as Iterable) - .where((e) => test.call(runtime, null, [e])!.$value as bool)); + @override + void setAll(int index, Iterable iterable) => + $value.setAll(index, iterable); + static const __$setAll = $Function(_$setAll); + static $Value? _$setAll(Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as List; + final index = args[0]?.$value as int; + final iterable = args[1]?.$value as Iterable; + $this.setAll(index, iterable); + return null; } - static const $Function __takeWhile = $Function(_takeWhile); + @override + bool remove(Object? value) => $value.remove(value); + static const __$remove = $Function(_$remove); + static $Value? _$remove(Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as List; + final value = args[0]; + final $result = $this.remove(value); + return $bool($result); + } - static $Value? _takeWhile( + @override + E removeAt(int index) => $value.removeAt(index); + static const __$removeAt = $Function(_$removeAt); + static $Value? _$removeAt( Runtime runtime, $Value? target, List<$Value?> args) { - final test = args[0] as EvalCallable; - return $Iterable.wrap((target!.$value as List) - .takeWhile((e) => test.call(runtime, null, [e])!.$value as bool)); + final $this = target?.$value as List; + final index = args[0]?.$value as int; + final $result = $this.removeAt(index); + return $result; } - static const $Function __clear = $Function(_clear); - - static $Value? _clear(Runtime runtime, $Value? target, List<$Value?> args) { - (target!.$value as List).clear(); - return null; + @override + E removeLast() => $value.removeLast(); + static const __$removeLast = $Function(_$removeLast); + static $Value? _$removeLast( + Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as List; + final $result = $this.removeLast(); + return $result; } - static const $Function __retainWhere = $Function(_retainWhere); - - static $Value? _retainWhere( + @override + void removeWhere(bool Function(E element) test) => $value.removeWhere(test); + static const __$removeWhere = $Function(_$removeWhere); + static $Value? _$removeWhere( Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as List; final test = args[0] as EvalCallable; - (target!.$value as List) - .retainWhere((e) => test.call(runtime, null, [e])!.$value as bool); + $this.removeWhere( + (element) => test.call(runtime, null, [element])!.$value as bool, + ); return null; } - static const $Function __removeWhere = $Function(_removeWhere); - - static $Value? _removeWhere( + @override + void retainWhere(bool Function(E element) test) => $value.retainWhere(test); + static const __$retainWhere = $Function(_$retainWhere); + static $Value? _$retainWhere( Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as List; final test = args[0] as EvalCallable; - (target!.$value as List) - .removeWhere((e) => test.call(runtime, null, [e])!.$value as bool); + $this.retainWhere( + (element) => test.call(runtime, null, [element])!.$value as bool, + ); return null; } - static const $Function __replaceRange = $Function(_replaceRange); - - static $Value? _replaceRange( + @override + List operator +(List other) => $value + other; + static const __$combine = $Function(_$combine); + static $Value? _$combine( Runtime runtime, $Value? target, List<$Value?> args) { - (target!.$value as List).replaceRange( - args[0]!.$value, args[1]!.$value, args[2]!.$value as Iterable); - return null; + final $this = target?.$value as List; + final other = args[0]?.$value as List; + final $result = $this + other; + return $List.wrap($result); } - static const $Function __lastIndexOf = $Function(_lastIndexOf); - - static $Value? _lastIndexOf( + @override + List sublist(int start, [int? end]) => $value.sublist(start, end); + static const __$sublist = $Function(_$sublist); + static $Value? _$sublist( Runtime runtime, $Value? target, List<$Value?> args) { - return $int((target!.$value as List).lastIndexOf(args[0], args[1]?.$value)); + final $this = target?.$value as List; + final start = args[0]?.$value as int; + final end = args[1]?.$value as int?; + final $result = $this.sublist(start, end); + return $List.wrap($result); } - static const $Function __indexOf = $Function(_indexOf); - - static $Value? _indexOf(Runtime runtime, $Value? target, List<$Value?> args) { - return $int( - (target!.$value as List).indexOf(args[0], args[1]?.$value ?? 0)); + @override + Iterable getRange(int start, int end) => $value.getRange(start, end); + static const __$getRange = $Function(_$getRange); + static $Value? _$getRange( + Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as List; + final start = args[0]?.$value as int; + final end = args[1]?.$value as int; + final $result = $this.getRange(start, end); + return $Iterable.wrap($result); } - static const $Function __sort = $Function(_sort); - - static $Value? _sort(Runtime runtime, $Value? target, List<$Value?> args) { - final compare = args[0] as EvalCallable; - - (target!.$value as List).sort( - (a, b) => compare.call(runtime, null, [a, b])?.$value, - ); + @override + void setRange(int start, int end, Iterable iterable, + [int skipCount = 0]) => + $value.setRange(start, end, iterable, skipCount); + static const __$setRange = $Function(_$setRange); + static $Value? _$setRange( + Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as List; + final start = args[0]?.$value as int; + final end = args[1]?.$value as int; + final iterable = args[2]?.$value as Iterable; + final skipCount = args[3]?.$value as int? ?? 0; + $this.setRange(start, end, iterable, skipCount); return null; } - static const $Function __addAll = $Function(_addAll); - - static $Value? _addAll(Runtime runtime, $Value? target, List<$Value?> args) { - (target!.$value as List).addAll(args[0]!.$value as Iterable); + @override + void removeRange(int start, int end) => $value.removeRange(start, end); + static const __$removeRange = $Function(_$removeRange); + static $Value? _$removeRange( + Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as List; + final start = args[0]?.$value as int; + final end = args[1]?.$value as int; + $this.removeRange(start, end); return null; } - static const $Function __insertAll = $Function(_insertAll); - - static $Value? _insertAll( + @override + void fillRange(int start, int end, [E? fillValue]) => + $value.fillRange(start, end, fillValue); + static const __$fillRange = $Function(_$fillRange); + static $Value? _$fillRange( Runtime runtime, $Value? target, List<$Value?> args) { - (target!.$value as List) - .insertAll(args[0]!.$value, args[1]!.$value as Iterable); + final $this = target?.$value as List; + final start = args[0]?.$value as int; + final end = args[1]?.$value as int; + final fillValue = args[2]; + $this.fillRange(start, end, fillValue); return null; } - static const $Function __indexGet = $Function(_indexGet); - - static $Value? _indexGet( + @override + void replaceRange(int start, int end, Iterable replacements) => + $value.replaceRange(start, end, replacements); + static const __$replaceRange = $Function(_$replaceRange); + static $Value? _$replaceRange( Runtime runtime, $Value? target, List<$Value?> args) { - final idx = args[0]!; - return (target!.$value as List)[idx.$value]; + final $this = target?.$value as List; + final start = args[0]?.$value as int; + final end = args[1]?.$value as int; + final replacements = args[2]?.$value as Iterable; + $this.replaceRange(start, end, replacements); + return null; } - static const $Function __sublist = $Function(_sublist); - - static $Value? _sublist(Runtime runtime, $Value? target, List<$Value?> args) { - return $List.wrap( - (target!.$value as List).sublist(args[0]!.$value, args[1]?.$value)); + @override + Map asMap() => $value.asMap(); + static const __$asMap = $Function(_$asMap); + static $Value? _$asMap(Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as List; + final $result = $this.asMap(); + return $Map.wrap($result.map((key, value) { + return $MapEntry.wrap(MapEntry($int(key), value)); + })); } - static const $Function __listContains = $Function(_listContains); - - static $Value? _listContains( + static const __$static$method$castFrom = $Function(_$static$method$castFrom); + static $Value? _$static$method$castFrom( Runtime runtime, $Value? target, List<$Value?> args) { - return $bool((target!.$value as List).contains(args[0])); + final source = args[0]?.$value; + final $result = List.castFrom(source); + return $List.wrap($result); } - static const $Function __indexSet = $Function(_indexSet); - - static $Value? _indexSet( + static const __$static$method$copyRange = + $Function(_$static$method$copyRange); + static $Value? _$static$method$copyRange( Runtime runtime, $Value? target, List<$Value?> args) { - final idx = args[0]!; - final value = args[1]!; - return (target!.$value as List)[idx.$value] = value; - } - - static const $Function __insert = $Function(_insert); - - static $Value? _insert(Runtime runtime, $Value? target, List<$Value?> args) { - final idx = args[0]!; - final value = args[1]!; - (target!.$value as List).insert(idx.$value, value); + final target = args[0]?.$value as List; + final at = args[1]?.$value as int; + final source = args[2]?.$value as List; + final start = args[3]?.$value as int?; + final end = args[4]?.$value as int?; + List.copyRange(target, at, source, start, end); return null; } - static const $Function __remove = $Function(_remove); - - static $Value? _remove(Runtime runtime, $Value? target, List<$Value?> args) { - return $bool((target!.$value as List).remove(args[0]!)); + static const __$static$method$writeIterable = + $Function(_$static$method$writeIterable); + static $Value? _$static$method$writeIterable( + Runtime runtime, $Value? target, List<$Value?> args) { + final target = args[0]?.$value as List; + final at = args[1]?.$value as int; + final source = args[2]?.$value as Iterable; + List.writeIterable(target, at, source); + return null; } - static const $Function __removeAt = $Function(_removeAt); - - static $Value? _removeAt( + static const __$List$filled = $Function(_$List$filled); + static $Value? _$List$filled( Runtime runtime, $Value? target, List<$Value?> args) { - return (target!.$value as List).removeAt(args[0]!.$value) as $Value?; + final length = args[0]?.$value as int; + final fill = args[1]; + final growable = args[2]?.$value as bool? ?? false; + return $List.wrap(List.filled(length, fill, growable: growable)); } - static const $Function __removeLast = $Function(_removeLast); - - static $Value? _removeLast( + static const __$List$empty = $Function(_$List$empty); + static $Value? _$List$empty( Runtime runtime, $Value? target, List<$Value?> args) { - return (target!.$value as List).removeLast() as $Value?; + final growable = args[0]?.$value as bool? ?? false; + return $List.wrap(List.empty(growable: growable)); } - static const $Function __add = $Function(_add); - - static $Value? _add(Runtime runtime, $Value? target, List<$Value?> args) { - final value = args[0]!; - (target!.$value as List).add(value); - return null; + static const __$List$from = $Function(_$List$from); + static $Value? _$List$from( + Runtime runtime, $Value? target, List<$Value?> args) { + final elements = args[0]?.$value as Iterable; + final growable = args[1]?.$value as bool? ?? true; + return $List.wrap(List.from(elements, growable: growable)); } - static const $Function __asMap = $Function(_asMap); - - static $Value? _asMap(Runtime runtime, $Value? target, List<$Value?> args) { - return $Map.wrap((target!.$value as List) - .asMap() - .map((key, value) => MapEntry($int(key), value))); + static const __$List$of = $Function(_$List$of); + static $Value? _$List$of( + Runtime runtime, $Value? target, List<$Value?> args) { + final elements = args[0]?.$value; + final growable = args[1]?.$value as bool? ?? true; + return $List.wrap(List.of(elements, growable: growable)); } - static const $Function __cast = $Function(_cast); - - static $Value? _cast(Runtime runtime, $Value? target, List<$Value?> args) { - return target; + static const __$List$generate = $Function(_$List$generate); + static $Value? _$List$generate( + Runtime runtime, $Value? target, List<$Value?> args) { + final length = args[0]?.$value as int; + final generator = args[1] as EvalCallable; + final growable = args[2]?.$value as bool? ?? true; + return $List.wrap(List.generate( + length, + (index) => generator.call(runtime, null, [$int(index)]), + growable: growable, + )); } - static const $Function __firstWhere = $Function(_firstWhere); - - static $Value? _firstWhere( + static const __$List$unmodifiable = $Function(_$List$unmodifiable); + static $Value? _$List$unmodifiable( Runtime runtime, $Value? target, List<$Value?> args) { - final test = args[0] as EvalCallable; - final orElse = args[1] as EvalCallable?; - return (target!.$value as List).firstWhere( - (element) => test.call(runtime, null, args)?.$value as bool, - orElse: orElse == null ? null : () => orElse.call(runtime, null, args), - ) as $Value?; + final elements = args[0]?.$value as Iterable; + return $List.wrap(List.unmodifiable(elements)); } - @override - List get $reified => $value.map((e) => e is $Value ? e.$reified : e).toList(); - @override bool any(bool Function(E element) test) => $value.any(test); - @override - List cast() => $value.cast(); - @override bool contains(Object? element) => $value.contains(element); @@ -713,7 +1382,7 @@ class $List implements List, $Instance { @override Iterable expand(Iterable Function(E element) toElements) => - $value.expand(toElements); + $value.expand(toElements); @override E get first => $value.first; @@ -742,7 +1411,7 @@ class $List implements List, $Instance { Iterator get iterator => $value.iterator; @override - String join([String separator = '']) => $value.join(separator); + String join([String separator = ""]) => $value.join(separator); @override E get last => $value.last; @@ -751,9 +1420,6 @@ class $List implements List, $Instance { E lastWhere(bool Function(E element) test, {E Function()? orElse}) => $value.lastWhere(test, orElse: orElse); - @override - int get length => $value.length; - @override Iterable map(T Function(E e) toElement) => $value.map(toElement); @@ -790,151 +1456,6 @@ class $List implements List, $Instance { @override Iterable whereType() => $value.whereType(); - - @override - Map asMap() => $value.asMap(); - - @override - void replaceRange(int start, int end, Iterable replacements) => - $value.replaceRange(start, end, replacements); - - @override - void fillRange(int start, int end, [E? fillValue]) => - $value.fillRange(start, end, fillValue); - - @override - void removeRange(int start, int end) => $value.removeRange(start, end); - - @override - void setRange(int start, int end, Iterable iterable, - [int skipCount = 0]) => - $value.setRange(start, end, iterable, skipCount); - - @override - Iterable getRange(int start, int end) => $value.getRange(start, end); - - @override - List sublist(int start, [int? end]) => $value.sublist(start, end); - - @override - List operator +(List other) => $value + other; - - @override - void retainWhere(bool Function(E element) test) => $value.retainWhere(test); - - @override - void removeWhere(bool Function(E element) test) => $value.removeWhere(test); - - @override - E removeLast() => $value.removeLast(); - - @override - E removeAt(int index) => $value.removeAt(index); - - @override - bool remove(Object? value) => $value.remove(value); - - @override - void setAll(int index, Iterable iterable) => - $value.setAll(index, iterable); - - @override - void insertAll(int index, Iterable iterable) => - $value.insertAll(index, iterable); - - @override - void insert(int index, E element) => $value.insert(index, element); - - @override - void clear() => $value.clear(); - - @override - int lastIndexOf(E element, [int? start]) => - $value.lastIndexOf(element, start); - - @override - int lastIndexWhere(bool Function(E element) test, [int? start]) => - $value.lastIndexWhere(test, start); - - @override - int indexWhere(bool Function(E element) test, [int start = 0]) => - $value.indexWhere(test, start); - - @override - int indexOf(E element, [int start = 0]) => $value.indexOf(element, start); - - @override - void shuffle([Random? random]) => $value.shuffle(random); - - @override - void sort([int Function(E a, E b)? compare]) => $value.sort(compare); - - @override - Iterable get reversed => $value.reversed; - - @override - void addAll(Iterable iterable) => $value.addAll(iterable); - - @override - void add(E value) => $value.add(value); - - @override - set length(int newLength) => $value.length = newLength; - - @override - set last(E value) => $value.last = value; - - @override - set first(E value) => $value.first = value; - - @override - void operator []=(int index, E value) => $value[index] = value; - - @override - E operator [](int index) => $value[index]; - - @override - int $getRuntimeType(Runtime runtime) => runtime.lookupType(CoreTypes.list); -} - -$Function get$List_filled(Runtime _) => _$List_filled; - -const _$List_filled = $Function(_List_filled); - -$Value? _List_filled(Runtime runtime, $Value? target, List<$Value?> args) { - return $List.wrap(List.filled(args[0]!.$value, args[1])); -} - -$Function get$List_generate(Runtime _) => _$List_generate; - -const _$List_generate = $Function(_List_generate); - -$Value? _List_generate(Runtime runtime, $Value? target, List<$Value?> args) { - final generator = args[1] as EvalFunction; - return $List.wrap( - List.generate(args[0]!.$value, (i) => generator(runtime, target, [$int(i)]), - growable: args[2]?.$value ?? true), - ); -} - -$Function get$List_of(Runtime _) => _$List_of; - -const _$List_of = $Function(_List_of); - -$Value? _List_of(Runtime runtime, $Value? target, List<$Value?> args) { - return $List.wrap( - List.of(args[0]!.$value, growable: args[1]?.$value ?? true), - ); -} - -$Function get$List_from(Runtime _) => _$List_from; - -const _$List_from = $Function(_List_from); - -$Value? _List_from(Runtime runtime, $Value? target, List<$Value?> args) { - return $List.wrap( - List.from(args[0]!.$value, growable: args[1]?.$value ?? true), - ); } /// Writeback-capable wrapper for [List] with type mapping function diff --git a/lib/src/eval/shared/stdlib/io/string_sink.dart b/lib/src/eval/shared/stdlib/io/string_sink.dart index af7d904..24b44f2 100644 --- a/lib/src/eval/shared/stdlib/io/string_sink.dart +++ b/lib/src/eval/shared/stdlib/io/string_sink.dart @@ -93,7 +93,7 @@ class $StringSink implements $Instance { static $Value? _write(Runtime runtime, $Value? target, List<$Value?> args) { final object = args[0]; - target!.$value.write(runtime.valueToString(object)); + (target!.$value as StringSink).write(runtime.valueToString(object)); return null; } @@ -103,15 +103,16 @@ class $StringSink implements $Instance { Runtime runtime, $Value? target, List<$Value?> args) { final objects = args[0]!.$value; final separator = args[1]?.$value; - target!.$value.writeAll(objects!.$reified, separator); + (target!.$value as StringSink).writeAll(objects!.$reified, separator); return null; } static final $Function __writeln = $Function(_writeln); static $Value? _writeln(Runtime runtime, $Value? target, List<$Value?> args) { - final object = args[0]?.$value; - target!.$value.writeln(object); + final object = args[0]; + (target!.$value as StringSink) + .writeln(object == null ? "" : runtime.valueToString(object)); return null; } @@ -120,7 +121,7 @@ class $StringSink implements $Instance { static $Value? __writeCharCode( Runtime runtime, $Value? target, List<$Value?> args) { final charCode = args[0]!.$value; - target!.$value.writeCharCode(charCode); + (target!.$value as StringSink).writeCharCode(charCode); return null; } diff --git a/lib/src/eval/shared/stdlib/math.dart b/lib/src/eval/shared/stdlib/math.dart index be1c956..33cad4d 100644 --- a/lib/src/eval/shared/stdlib/math.dart +++ b/lib/src/eval/shared/stdlib/math.dart @@ -1,6 +1,7 @@ import 'dart:math' as math; import 'package:dart_eval/dart_eval_bridge.dart'; import 'package:dart_eval/src/eval/shared/stdlib/core/num.dart'; +import 'package:dart_eval/src/eval/shared/stdlib/math/random.dart'; import 'math/point.dart'; const mathSource = ''' @@ -24,6 +25,7 @@ class DartMathPlugin implements EvalPlugin { @override void configureForCompile(BridgeDeclarationRegistry registry) { $Point.configureForCompile(registry); + $Random.configureForCompile(registry); registry.addSource(DartSource('dart:math', mathSource)); registry.defineBridgeTopLevelFunction(BridgeFunctionDeclaration( 'dart:math', @@ -133,6 +135,7 @@ class DartMathPlugin implements EvalPlugin { @override void configureForRuntime(Runtime runtime) { $Point.configureForRuntime(runtime); + $Random.configureForRuntime(runtime); runtime.registerBridgeFunc('dart:math', 'atan2', const _$atan2().call); runtime.registerBridgeFunc('dart:math', 'pow', const _$pow().call); runtime.registerBridgeFunc('dart:math', 'cos', const _$cos().call); diff --git a/lib/src/eval/shared/stdlib/math/point.dart b/lib/src/eval/shared/stdlib/math/point.dart index 08b01a6..40fae2f 100644 --- a/lib/src/eval/shared/stdlib/math/point.dart +++ b/lib/src/eval/shared/stdlib/math/point.dart @@ -18,7 +18,7 @@ class $Point implements Point, $Instance { runtime.registerBridgeFunc('dart:math', 'Point.', const _$Point_new().call); } - static const _$type = BridgeTypeRef(BridgeTypeSpec('dart:math', 'Point')); + static const _$type = BridgeTypeRef(MathTypes.point); /// The bridge class definition for this class. static const $declaration = BridgeClassDef( diff --git a/lib/src/eval/shared/stdlib/math/random.dart b/lib/src/eval/shared/stdlib/math/random.dart new file mode 100644 index 0000000..500c409 --- /dev/null +++ b/lib/src/eval/shared/stdlib/math/random.dart @@ -0,0 +1,169 @@ +import 'dart:math'; + +import 'package:dart_eval/dart_eval_bridge.dart'; +import 'package:dart_eval/stdlib/core.dart'; + +/// dart_eval bimodal wrapper for [Random] +class $Random implements Random, $Instance { + /// Configure the [$Random] wrapper for use in a [Runtime] + static void configureForCompile(BridgeDeclarationRegistry registry) { + registry.defineBridgeClass($declaration); + } + + static void configureForRuntime(Runtime runtime) { + runtime.registerBridgeFunc( + $type.spec!.library, 'Random.', __$Random$new.call, + isBridge: false); + runtime.registerBridgeFunc( + $type.spec!.library, 'Random.secure', __$Random$secure.call, + isBridge: false); + } + + late final $Instance _superclass = $Object($value); + + static const $type = BridgeTypeRef(MathTypes.random); + + static const $declaration = BridgeClassDef( + BridgeClassType( + $type, + $extends: null, + $implements: [], + isAbstract: true, + ), + constructors: { + '': BridgeConstructorDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation($type), + params: [ + BridgeParameter( + 'seed', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int, []), + nullable: true), + true) + ], + namedParams: [], + ), + isFactory: true, + ), + 'secure': BridgeConstructorDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation($type), + params: [], + namedParams: [], + ), + isFactory: true, + ) + }, + fields: {}, + methods: { + 'nextInt': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int, []), + nullable: false), + params: [ + BridgeParameter( + 'max', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int, []), + nullable: false), + false) + ], + namedParams: [], + ), + isStatic: false), + 'nextDouble': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.double, []), + nullable: false), + params: [], + namedParams: [], + ), + isStatic: false), + 'nextBool': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool, []), + nullable: false), + params: [], + namedParams: [], + ), + isStatic: false), + }, + getters: {}, + setters: {}, + bridge: false, + wrap: true, + ); + + /// Wrap an [Random] in an [$Random] + $Random.wrap(this.$value); + + @override + $Value? $getProperty(Runtime runtime, String identifier) { + switch (identifier) { + case 'nextInt': + return __$nextInt; + case 'nextDouble': + return __$nextDouble; + case 'nextBool': + return __$nextBool; + default: + return _superclass.$getProperty(runtime, identifier); + } + } + + @override + int $getRuntimeType(Runtime runtime) => runtime.lookupType($type.spec!); + + @override + Random get $reified => $value; + + @override + void $setProperty(Runtime runtime, String identifier, $Value value) => + _superclass.$setProperty(runtime, identifier, value); + + @override + final Random $value; + + @override + int nextInt(int max) => $value.nextInt(max); + static const __$nextInt = $Function(_$nextInt); + static $Value? _$nextInt( + Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as Random; + final max = args[0]?.$value as int; + final $result = $this.nextInt(max); + return $int($result); + } + + @override + double nextDouble() => $value.nextDouble(); + static const __$nextDouble = $Function(_$nextDouble); + static $Value? _$nextDouble( + Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as Random; + final $result = $this.nextDouble(); + return $double($result); + } + + @override + bool nextBool() => $value.nextBool(); + static const __$nextBool = $Function(_$nextBool); + static $Value? _$nextBool( + Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as Random; + final $result = $this.nextBool(); + return $bool($result); + } + + static const __$Random$new = $Function(_$Random$new); + static $Value? _$Random$new( + Runtime runtime, $Value? target, List<$Value?> args) { + final seed = args[0]?.$value as int?; + return $Random.wrap(Random(seed)); + } + + static const __$Random$secure = $Function(_$Random$secure); + static $Value? _$Random$secure( + Runtime runtime, $Value? target, List<$Value?> args) { + return $Random.wrap(Random.secure()); + } +} diff --git a/lib/src/eval/shared/types.dart b/lib/src/eval/shared/types.dart index b99d90a..d5c500f 100644 --- a/lib/src/eval/shared/types.dart +++ b/lib/src/eval/shared/types.dart @@ -3,7 +3,6 @@ import 'package:dart_eval/src/eval/shared/stdlib/async/future.dart'; import 'package:dart_eval/src/eval/shared/stdlib/async/stream.dart'; import 'package:dart_eval/src/eval/shared/stdlib/async/stream_controller.dart'; import 'package:dart_eval/src/eval/shared/stdlib/convert/converter.dart'; -import 'package:dart_eval/src/eval/shared/stdlib/core/iterator.dart'; import 'package:dart_eval/stdlib/core.dart'; /// This class contains dart:core bridge type specs for convenience @@ -294,6 +293,14 @@ class IoTypes { BridgeTypeSpec('dart:io/http_status.dart', 'HttpStatus'); } +class MathTypes { + /// Bridge type spec for [$Point] + static const point = BridgeTypeSpec('dart:math', 'Point'); + + /// Bridge type spec for [$Random] + static const random = BridgeTypeSpec('dart:math', 'Random'); +} + class TypedDataTypes { /// Bridge type spec for [$ByteBuffer] static const byteBuffer = BridgeTypeSpec('dart:typed_data', 'ByteBuffer'); diff --git a/lib/stdlib/core.dart b/lib/stdlib/core.dart index 3ea2adb..c51d70b 100644 --- a/lib/stdlib/core.dart +++ b/lib/stdlib/core.dart @@ -3,6 +3,7 @@ library dart_eval.stdlib.core; export '../src/eval/shared/stdlib/core/base.dart'; export '../src/eval/shared/stdlib/core/collection.dart'; +export '../src/eval/shared/stdlib/core/iterator.dart'; export '../src/eval/shared/stdlib/core/comparable.dart'; export '../src/eval/shared/stdlib/core/date_time.dart'; export '../src/eval/shared/stdlib/core/duration.dart';