From 32eef2c1d2dfbbb2616cc1644e4cb5400211375c Mon Sep 17 00:00:00 2001 From: Noobware1 <110553648+Noobware1@users.noreply.github.com> Date: Sun, 16 Jun 2024 17:08:34 +0530 Subject: [PATCH 1/7] fixed bridge subclass issue --- lib/src/eval/compiler/compiler.dart | 4 +- .../compiler/declaration/constructor.dart | 31 ++++-- lib/src/eval/shared/stdlib/core/iterable.dart | 12 +-- test/bridge_test.dart | 101 ++++++++++++++++++ 4 files changed, 128 insertions(+), 20 deletions(-) diff --git a/lib/src/eval/compiler/compiler.dart b/lib/src/eval/compiler/compiler.dart index f9091fb6..e2af12e4 100644 --- a/lib/src/eval/compiler/compiler.dart +++ b/lib/src/eval/compiler/compiler.dart @@ -220,6 +220,7 @@ class Compiler implements BridgeDeclarationRegistry, EvalPluginRegistry { // Iterate over bridge libraries for (final bridgeLibrary in _bridgeDeclarations.keys) { // Wrap bridge declarations in this library as [DeclarationOrBridge]s + final bridgeLibDeclarations = [ for (final bridgeDeclaration in _bridgeDeclarations[bridgeLibrary]!) DeclarationOrBridge(-1, bridge: bridgeDeclaration) @@ -412,7 +413,6 @@ class Compiler implements BridgeDeclarationRegistry, EvalPluginRegistry { _ctx.instanceDeclarationsMap = _instanceDeclarationsMap; _ctx.visibleDeclarations = visibleDeclarationsByIndex; _ctx.visibleTypes = visibleTypesByIndex; - unboxedAcrossFunctionBoundaries = { CoreTypes.int.ref(_ctx), CoreTypes.double.ref(_ctx), @@ -422,6 +422,7 @@ class Compiler implements BridgeDeclarationRegistry, EvalPluginRegistry { for (final library in reachableLibraries) { final libraryIndex = libraryIndexMap[library]!; + // print(library.uri.toString()); for (final dec in library.declarations) { if (dec.isBridge) { final bridge = dec.bridge; @@ -560,7 +561,6 @@ class Compiler implements BridgeDeclarationRegistry, EvalPluginRegistry { if (!_instanceDeclarationsMap.containsKey(libraryIndex)) { _instanceDeclarationsMap[libraryIndex] = {}; } - if (declarationOrBridge.isBridge) { final bridge = declarationOrBridge.bridge!; if (bridge is BridgeClassDef) { diff --git a/lib/src/eval/compiler/declaration/constructor.dart b/lib/src/eval/compiler/declaration/constructor.dart index 5fc75514..e968fb05 100644 --- a/lib/src/eval/compiler/declaration/constructor.dart +++ b/lib/src/eval/compiler/declaration/constructor.dart @@ -28,7 +28,7 @@ void compileConstructorDeclaration( final dName = (d.name?.lexeme) ?? ""; final n = '$parentName.$dName'; final isEnum = parent is EnumDeclaration; - + bool doesExtendsBridge = false; if (d.factoryKeyword != null && d.initializers.isNotEmpty) { throw CompileError('Factory constructors cannot have initializers', d); } @@ -183,9 +183,10 @@ void compileConstructorDeclaration( return; } - final $extends = parent is EnumDeclaration + var $extends = parent is EnumDeclaration ? null : (parent as ClassDeclaration).extendsClause; + Variable $super; DeclarationOrPrefix? extendsWhat; @@ -193,16 +194,22 @@ void compileConstructorDeclaration( final namedArgTypes = {}; var constructorName = $superInitializer?.constructorName?.name ?? ''; - if ($extends == null) { $super = BuiltinValue().push(ctx); } else { extendsWhat = ctx .visibleDeclarations[ctx.library]![$extends.superclass.name2.lexeme]!; - final decl = extendsWhat.declaration!; - - if (decl.isBridge) { + doesExtendsBridge = (decl.declaration is ClassDeclaration && + ctx.visibleDeclarations[ctx.library]?[ + (decl.declaration as ClassDeclaration) + .extendsClause + ?.superclass + .name2 + .lexeme] != + null); + + if (decl.isBridge || doesExtendsBridge) { ctx.pushOp(PushBridgeSuperShim.make(), PushBridgeSuperShim.length); $super = Variable.alloc(ctx, CoreTypes.dynamic.ref(ctx)); } else { @@ -321,10 +328,17 @@ void compileConstructorDeclaration( ctx.endAllocScope(); } - if ($extends != null && extendsWhat!.declaration!.isBridge) { + if ($extends != null && + (extendsWhat!.declaration!.isBridge || doesExtendsBridge)) { + if (doesExtendsBridge) { + $extends = (extendsWhat.declaration!.declaration as ClassDeclaration) + .extendsClause!; + extendsWhat = ctx + .visibleDeclarations[ctx.library]![$extends.superclass.name2.lexeme]!; + } + final decl = extendsWhat.declaration!; final bridge = decl.bridge! as BridgeClassDef; - if (!bridge.bridge) { throw CompileError( 'Bridge class ${$extends.superclass} is a wrapper, not a bridge, so you can\'t extend it'); @@ -340,7 +354,6 @@ void compileConstructorDeclaration( namedArgTypes .addAll(_namedArgs.map((key, value) => MapEntry(key, value.type))); } - final op = BridgeInstantiate.make( instOffset, ctx.bridgeStaticFunctionIndices[decl.sourceLib]![ diff --git a/lib/src/eval/shared/stdlib/core/iterable.dart b/lib/src/eval/shared/stdlib/core/iterable.dart index 5fab3861..72621d62 100644 --- a/lib/src/eval/shared/stdlib/core/iterable.dart +++ b/lib/src/eval/shared/stdlib/core/iterable.dart @@ -931,9 +931,7 @@ class $Iterable implements Iterable, $Instance { 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, [])!, + orElse: orElse == null ? null : () => orElse.call(runtime, null, [])!, ); return $result; } @@ -949,9 +947,7 @@ class $Iterable implements Iterable, $Instance { 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, [])!, + orElse: orElse == null ? null : () => orElse.call(runtime, null, [])!, ); return $result; } @@ -967,9 +963,7 @@ class $Iterable implements Iterable, $Instance { 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, [])!, + orElse: orElse == null ? null : () => orElse.call(runtime, null, [])!, ); return $result; } diff --git a/test/bridge_test.dart b/test/bridge_test.dart index dac3214c..050304c6 100644 --- a/test/bridge_test.dart +++ b/test/bridge_test.dart @@ -113,6 +113,107 @@ void main() { expect(res.runTest(2), false); }); + test( + 'Creating and using multiple subclassed bridge class inside the runtime', + () { + compiler.defineBridgeClasses([$TestClass.$declaration]); + + final program = compiler.compile({ + 'example': { + 'main.dart': ''' + import 'package:bridge_lib/bridge_lib.dart'; + + class MyTestClass1 extends TestClass { + MyTestClass1(int someNumber) : super(someNumber); + + @override + bool runTest(int a, {String b = 'wow'}) { + return super.runTest(a + 2 + someNumber, b: b); + } + } + + class MyTestClass2 extends TestClass { + MyTestClass2(int someNumber) : super(someNumber); + + @override + bool runTest(int a, {String b = 'wow'}) { + return super.runTest(a + 0 + someNumber, b: b); + } + } + + void main() { + final test1 = MyTestClass1(18); + print(test1.runTest(5, b: 'cool')); + final test2 = MyTestClass2(1); + print(test2.runTest(0, b: 'idk')); + } + ''' + } + }); + + final runtime = Runtime.ofProgram(program); + + runtime.registerBridgeFunc('package:bridge_lib/bridge_lib.dart', + 'TestClass.', $TestClass.$construct, + isBridge: true); + + expect(() => runtime.executeLib('package:example/main.dart', 'main'), + prints('true\nfalse\n')); + }); + + test( + 'Creating and using multiple subclassed bridge class outside the runtime', + () { + compiler.defineBridgeClasses([$TestClass.$declaration]); + + final program = compiler.compile({ + 'example': { + 'main.dart': ''' + import 'package:bridge_lib/bridge_lib.dart'; + + class MyTestClass1 extends TestClass { + MyTestClass1(int someNumber) : super(someNumber); + + @override + bool runTest(int a, {String b = 'wow'}) { + return super.runTest(a + 2 + someNumber, b: b); + } + } + + class MyTestClass2 extends TestClass { + MyTestClass2(int someNumber) : super(someNumber); + + @override + bool runTest(int a, {String b = 'wow'}) { + return super.runTest(a + 0 + someNumber, b: b); + } + } + + List main() { + final test1 = MyTestClass1(18); + final test2 = MyTestClass2(1); + return [test1, test2]; + } + ''' + } + }); + + final runtime = Runtime.ofProgram(program); + + runtime.registerBridgeFunc('package:bridge_lib/bridge_lib.dart', + 'TestClass.', $TestClass.$construct, + isBridge: true); + + final res = runtime.executeLib('package:example/main.dart', 'main'); + + expect(res is List, true); + res as List; + final test1 = res[0] as TestClass; + expect(test1.runTest(5, b: 'cool'), true); + final test2 = res[1] as TestClass; + expect(test2.runTest(0, b: 'idk'), false); + }); + test('Using an external static method', () { compiler.defineBridgeClasses([$TestClass.$declaration]); From ed1551ae3262f80d65a6c0639744d4645f88f2d9 Mon Sep 17 00:00:00 2001 From: Noobware1 <110553648+Noobware1@users.noreply.github.com> Date: Mon, 17 Jun 2024 19:30:55 +0530 Subject: [PATCH 2/7] bridge fix in progress --- .../compiler/declaration/constructor.dart | 25 +++++++++++-------- lib/src/eval/runtime/ops/bridge.dart | 2 +- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/lib/src/eval/compiler/declaration/constructor.dart b/lib/src/eval/compiler/declaration/constructor.dart index e968fb05..43ba5adb 100644 --- a/lib/src/eval/compiler/declaration/constructor.dart +++ b/lib/src/eval/compiler/declaration/constructor.dart @@ -200,14 +200,17 @@ void compileConstructorDeclaration( extendsWhat = ctx .visibleDeclarations[ctx.library]![$extends.superclass.name2.lexeme]!; final decl = extendsWhat.declaration!; - doesExtendsBridge = (decl.declaration is ClassDeclaration && - ctx.visibleDeclarations[ctx.library]?[ - (decl.declaration as ClassDeclaration) - .extendsClause - ?.superclass - .name2 - .lexeme] != - null); + + if (decl.declaration is ClassDeclaration) { + final bridgeDecl = ctx.visibleDeclarations[decl.sourceLib]?[ + (decl.declaration as ClassDeclaration) + .extendsClause + ?.superclass + .name2 + .lexeme]!; + doesExtendsBridge = + bridgeDecl != null && bridgeDecl.declaration!.isBridge; + } if (decl.isBridge || doesExtendsBridge) { ctx.pushOp(PushBridgeSuperShim.make(), PushBridgeSuperShim.length); @@ -258,6 +261,7 @@ void compileConstructorDeclaration( AlwaysReturnType(CoreTypes.dynamic.ref(ctx), true); ctx.pushOp(PushReturnValue.make(), PushReturnValue.LEN); + $super = Variable.alloc(ctx, mReturnType.type ?? CoreTypes.dynamic.ref(ctx)); } @@ -333,8 +337,9 @@ void compileConstructorDeclaration( if (doesExtendsBridge) { $extends = (extendsWhat.declaration!.declaration as ClassDeclaration) .extendsClause!; - extendsWhat = ctx - .visibleDeclarations[ctx.library]![$extends.superclass.name2.lexeme]!; + + extendsWhat = ctx.visibleDeclarations[extendsWhat + .declaration!.sourceLib]![$extends.superclass.name2.lexeme]!; } final decl = extendsWhat.declaration!; diff --git a/lib/src/eval/runtime/ops/bridge.dart b/lib/src/eval/runtime/ops/bridge.dart index 3eafa1b9..55ca42aa 100644 --- a/lib/src/eval/runtime/ops/bridge.dart +++ b/lib/src/eval/runtime/ops/bridge.dart @@ -17,7 +17,6 @@ class BridgeInstantiate implements EvcOp { @override void run(Runtime runtime) { final $subclass = runtime.frame[_subclass] as $Instance?; - final _args = runtime.args; final _argsLen = _args.length; @@ -32,6 +31,7 @@ class BridgeInstantiate implements EvcOp { final instance = runtime._bridgeFunctions[_constructor](runtime, null, _mappedArgs) as $Instance; + Runtime.bridgeData[instance] = BridgeData(runtime, $runtimeType, $subclass ?? BridgeDelegatingShim()); From 7b95e81f2feaa7de2f5ee784e9cfedd8a99dc7f5 Mon Sep 17 00:00:00 2001 From: Noobware1 <110553648+Noobware1@users.noreply.github.com> Date: Mon, 17 Jun 2024 20:03:34 +0530 Subject: [PATCH 3/7] reverted changes --- .../compiler/declaration/constructor.dart | 34 +++++-------------- 1 file changed, 8 insertions(+), 26 deletions(-) diff --git a/lib/src/eval/compiler/declaration/constructor.dart b/lib/src/eval/compiler/declaration/constructor.dart index 43ba5adb..5fc75514 100644 --- a/lib/src/eval/compiler/declaration/constructor.dart +++ b/lib/src/eval/compiler/declaration/constructor.dart @@ -28,7 +28,7 @@ void compileConstructorDeclaration( final dName = (d.name?.lexeme) ?? ""; final n = '$parentName.$dName'; final isEnum = parent is EnumDeclaration; - bool doesExtendsBridge = false; + if (d.factoryKeyword != null && d.initializers.isNotEmpty) { throw CompileError('Factory constructors cannot have initializers', d); } @@ -183,10 +183,9 @@ void compileConstructorDeclaration( return; } - var $extends = parent is EnumDeclaration + final $extends = parent is EnumDeclaration ? null : (parent as ClassDeclaration).extendsClause; - Variable $super; DeclarationOrPrefix? extendsWhat; @@ -194,25 +193,16 @@ void compileConstructorDeclaration( final namedArgTypes = {}; var constructorName = $superInitializer?.constructorName?.name ?? ''; + if ($extends == null) { $super = BuiltinValue().push(ctx); } else { extendsWhat = ctx .visibleDeclarations[ctx.library]![$extends.superclass.name2.lexeme]!; - final decl = extendsWhat.declaration!; - if (decl.declaration is ClassDeclaration) { - final bridgeDecl = ctx.visibleDeclarations[decl.sourceLib]?[ - (decl.declaration as ClassDeclaration) - .extendsClause - ?.superclass - .name2 - .lexeme]!; - doesExtendsBridge = - bridgeDecl != null && bridgeDecl.declaration!.isBridge; - } + final decl = extendsWhat.declaration!; - if (decl.isBridge || doesExtendsBridge) { + if (decl.isBridge) { ctx.pushOp(PushBridgeSuperShim.make(), PushBridgeSuperShim.length); $super = Variable.alloc(ctx, CoreTypes.dynamic.ref(ctx)); } else { @@ -261,7 +251,6 @@ void compileConstructorDeclaration( AlwaysReturnType(CoreTypes.dynamic.ref(ctx), true); ctx.pushOp(PushReturnValue.make(), PushReturnValue.LEN); - $super = Variable.alloc(ctx, mReturnType.type ?? CoreTypes.dynamic.ref(ctx)); } @@ -332,18 +321,10 @@ void compileConstructorDeclaration( ctx.endAllocScope(); } - if ($extends != null && - (extendsWhat!.declaration!.isBridge || doesExtendsBridge)) { - if (doesExtendsBridge) { - $extends = (extendsWhat.declaration!.declaration as ClassDeclaration) - .extendsClause!; - - extendsWhat = ctx.visibleDeclarations[extendsWhat - .declaration!.sourceLib]![$extends.superclass.name2.lexeme]!; - } - + if ($extends != null && extendsWhat!.declaration!.isBridge) { final decl = extendsWhat.declaration!; final bridge = decl.bridge! as BridgeClassDef; + if (!bridge.bridge) { throw CompileError( 'Bridge class ${$extends.superclass} is a wrapper, not a bridge, so you can\'t extend it'); @@ -359,6 +340,7 @@ void compileConstructorDeclaration( namedArgTypes .addAll(_namedArgs.map((key, value) => MapEntry(key, value.type))); } + final op = BridgeInstantiate.make( instOffset, ctx.bridgeStaticFunctionIndices[decl.sourceLib]![ From 8f44bca9e6ae0a8f463921f7dbdb8f2d835746a9 Mon Sep 17 00:00:00 2001 From: Noobware1 <110553648+Noobware1@users.noreply.github.com> Date: Sun, 23 Jun 2024 17:49:12 +0530 Subject: [PATCH 4/7] . --- .../compiler/declaration/constructor.dart | 45 +++- lib/src/eval/runtime/ops/bridge.dart | 1 - lib/src/eval/runtime/ops/objects.dart | 1 - test/bridge_test.dart | 200 +++++++++--------- 4 files changed, 143 insertions(+), 104 deletions(-) diff --git a/lib/src/eval/compiler/declaration/constructor.dart b/lib/src/eval/compiler/declaration/constructor.dart index 5fc75514..4007ee76 100644 --- a/lib/src/eval/compiler/declaration/constructor.dart +++ b/lib/src/eval/compiler/declaration/constructor.dart @@ -1,5 +1,6 @@ import 'package:analyzer/dart/ast/ast.dart'; import 'package:dart_eval/dart_eval_bridge.dart'; +import 'package:dart_eval/src/eval/bridge/declaration.dart'; import 'package:dart_eval/src/eval/compiler/builtins.dart'; import 'package:dart_eval/src/eval/compiler/context.dart'; import 'package:dart_eval/src/eval/compiler/errors.dart'; @@ -183,7 +184,7 @@ void compileConstructorDeclaration( return; } - final $extends = parent is EnumDeclaration + var $extends = parent is EnumDeclaration ? null : (parent as ClassDeclaration).extendsClause; Variable $super; @@ -193,14 +194,25 @@ void compileConstructorDeclaration( final namedArgTypes = {}; var constructorName = $superInitializer?.constructorName?.name ?? ''; - + // final bool doesExtendBridge; if ($extends == null) { $super = BuiltinValue().push(ctx); + // doesExtendBridge = false; } else { extendsWhat = ctx .visibleDeclarations[ctx.library]![$extends.superclass.name2.lexeme]!; final decl = extendsWhat.declaration!; + // if (!decl.isBridge) { + // final $doesExtendBridge = _doesExtendBridge(decl, ctx); + // doesExtendBridge = $doesExtendBridge[0] as bool; + // if (doesExtendBridge) { + // extendsWhat = $doesExtendBridge[1] as DeclarationOrPrefix; + // $extends = $doesExtendBridge[2] as ExtendsClause; + // } + // } else { + // doesExtendBridge = false; + // } if (decl.isBridge) { ctx.pushOp(PushBridgeSuperShim.make(), PushBridgeSuperShim.length); @@ -250,7 +262,11 @@ void compileConstructorDeclaration( ?.toAlwaysReturnType(ctx, clsType, argTypes, namedArgTypes) ?? AlwaysReturnType(CoreTypes.dynamic.ref(ctx), true); + // if (doesExtendBridge) { + // ctx.pushOp(PushBridgeSuperShim.make(), PushBridgeSuperShim.length); + // } else { ctx.pushOp(PushReturnValue.make(), PushReturnValue.LEN); + // } $super = Variable.alloc(ctx, mReturnType.type ?? CoreTypes.dynamic.ref(ctx)); } @@ -346,6 +362,7 @@ void compileConstructorDeclaration( ctx.bridgeStaticFunctionIndices[decl.sourceLib]![ '${$extends.superclass.name2.value()}.$constructorName']!); ctx.pushOp(op, BridgeInstantiate.len(op)); + final bridgeInst = Variable.alloc(ctx, CoreTypes.dynamic.ref(ctx)); ctx.pushOp( @@ -518,3 +535,27 @@ void _compileUnusedFields(CompilerContext ctx, List fields, } } } + +List _doesExtendBridge( + DeclarationOrBridge? decl, CompilerContext ctx) { + if (decl != null && decl.declaration is ClassDeclaration) { + var $decl = ctx.visibleDeclarations[decl.sourceLib]?[ + (decl.declaration as ClassDeclaration) + .extendsClause + ?.superclass + .name2 + .lexeme]; + if ($decl != null && $decl.declaration!.isBridge) { + return [ + true, + $decl, + (decl.declaration as ClassDeclaration).extendsClause + ]; + } else if ($decl == null || $decl.declaration == null) { + return [false]; + } + return _doesExtendBridge($decl.declaration!, ctx); + } else { + return [false]; + } +} diff --git a/lib/src/eval/runtime/ops/bridge.dart b/lib/src/eval/runtime/ops/bridge.dart index 55ca42aa..e93b1695 100644 --- a/lib/src/eval/runtime/ops/bridge.dart +++ b/lib/src/eval/runtime/ops/bridge.dart @@ -34,7 +34,6 @@ class BridgeInstantiate implements EvcOp { Runtime.bridgeData[instance] = BridgeData(runtime, $runtimeType, $subclass ?? BridgeDelegatingShim()); - runtime.frame[runtime.frameOffset++] = instance; } diff --git a/lib/src/eval/runtime/ops/objects.dart b/lib/src/eval/runtime/ops/objects.dart index 6f47725f..fcbddb53 100644 --- a/lib/src/eval/runtime/ops/objects.dart +++ b/lib/src/eval/runtime/ops/objects.dart @@ -191,7 +191,6 @@ class CreateClass implements EvcOp { void run(Runtime runtime) { final $super = runtime.frame[_super] as $Instance?; final $cls = runtime.declaredClasses[_library]![_name]!; - final instance = $InstanceImpl($cls, $super, List.filled(_valuesLen, null)); runtime.frame[runtime.frameOffset++] = instance; } diff --git a/test/bridge_test.dart b/test/bridge_test.dart index 050304c6..fb2efc18 100644 --- a/test/bridge_test.dart +++ b/test/bridge_test.dart @@ -113,106 +113,106 @@ void main() { expect(res.runTest(2), false); }); - test( - 'Creating and using multiple subclassed bridge class inside the runtime', - () { - compiler.defineBridgeClasses([$TestClass.$declaration]); - - final program = compiler.compile({ - 'example': { - 'main.dart': ''' - import 'package:bridge_lib/bridge_lib.dart'; - - class MyTestClass1 extends TestClass { - MyTestClass1(int someNumber) : super(someNumber); - - @override - bool runTest(int a, {String b = 'wow'}) { - return super.runTest(a + 2 + someNumber, b: b); - } - } - - class MyTestClass2 extends TestClass { - MyTestClass2(int someNumber) : super(someNumber); - - @override - bool runTest(int a, {String b = 'wow'}) { - return super.runTest(a + 0 + someNumber, b: b); - } - } - - void main() { - final test1 = MyTestClass1(18); - print(test1.runTest(5, b: 'cool')); - final test2 = MyTestClass2(1); - print(test2.runTest(0, b: 'idk')); - } - ''' - } - }); - - final runtime = Runtime.ofProgram(program); - - runtime.registerBridgeFunc('package:bridge_lib/bridge_lib.dart', - 'TestClass.', $TestClass.$construct, - isBridge: true); - - expect(() => runtime.executeLib('package:example/main.dart', 'main'), - prints('true\nfalse\n')); - }); - - test( - 'Creating and using multiple subclassed bridge class outside the runtime', - () { - compiler.defineBridgeClasses([$TestClass.$declaration]); - - final program = compiler.compile({ - 'example': { - 'main.dart': ''' - import 'package:bridge_lib/bridge_lib.dart'; - - class MyTestClass1 extends TestClass { - MyTestClass1(int someNumber) : super(someNumber); - - @override - bool runTest(int a, {String b = 'wow'}) { - return super.runTest(a + 2 + someNumber, b: b); - } - } - - class MyTestClass2 extends TestClass { - MyTestClass2(int someNumber) : super(someNumber); - - @override - bool runTest(int a, {String b = 'wow'}) { - return super.runTest(a + 0 + someNumber, b: b); - } - } - - List main() { - final test1 = MyTestClass1(18); - final test2 = MyTestClass2(1); - return [test1, test2]; - } - ''' - } - }); - - final runtime = Runtime.ofProgram(program); - - runtime.registerBridgeFunc('package:bridge_lib/bridge_lib.dart', - 'TestClass.', $TestClass.$construct, - isBridge: true); - - final res = runtime.executeLib('package:example/main.dart', 'main'); - - expect(res is List, true); - res as List; - final test1 = res[0] as TestClass; - expect(test1.runTest(5, b: 'cool'), true); - final test2 = res[1] as TestClass; - expect(test2.runTest(0, b: 'idk'), false); - }); + // test( + // 'Creating and using multiple subclassed bridge class inside the runtime', + // () { + // compiler.defineBridgeClasses([$TestClass.$declaration]); + + // final program = compiler.compile({ + // 'example': { + // 'main.dart': ''' + // import 'package:bridge_lib/bridge_lib.dart'; + + // class MyTestClass1 extends TestClass { + // MyTestClass1(int someNumber) : super(someNumber); + + // @override + // bool runTest(int a, {String b = 'wow'}) { + // return super.runTest(a + 2 + someNumber, b: b); + // } + // } + + // class MyTestClass2 extends TestClass1 { + // MyTestClass2(int someNumber) : super(someNumber); + + // @override + // bool runTest(int a, {String b = 'wow'}) { + // return super.runTest(a + 0 + someNumber, b: b); + // } + // } + + // void main() { + // final test1 = MyTestClass1(18); + // print(test1.runTest(5, b: 'cool')); + // final test2 = MyTestClass2(1); + // print(test2.runTest(0, b: 'idk')); + // } + // ''' + // } + // }); + + // final runtime = Runtime.ofProgram(program); + + // runtime.registerBridgeFunc('package:bridge_lib/bridge_lib.dart', + // 'TestClass.', $TestClass.$construct, + // isBridge: true); + + // expect(() => runtime.executeLib('package:example/main.dart', 'main'), + // prints('true\nfalse\n')); + // }); + + // test( + // 'Creating and using multiple subclassed bridge class outside the runtime', + // () { + // compiler.defineBridgeClasses([$TestClass.$declaration]); + + // final program = compiler.compile({ + // 'example': { + // 'main.dart': ''' + // import 'package:bridge_lib/bridge_lib.dart'; + + // class MyTestClass1 extends TestClass { + // MyTestClass1(int someNumber) : super(someNumber); + + // @override + // bool runTest(int a, {String b = 'wow'}) { + // return super.runTest(a + 2 + someNumber, b: b); + // } + // } + + // class MyTestClass2 extends TestClass1 { + // MyTestClass2(int someNumber) : super(someNumber); + + // @override + // bool runTest(int a, {String b = 'wow'}) { + // return super.runTest(a + 0 + someNumber, b: b); + // } + // } + + // List main() { + // final test1 = MyTestClass1(18); + // final test2 = MyTestClass2(1); + // return [test1, test2]; + // } + // ''' + // } + // }); + + // final runtime = Runtime.ofProgram(program); + + // runtime.registerBridgeFunc('package:bridge_lib/bridge_lib.dart', + // 'TestClass.', $TestClass.$construct, + // isBridge: true); + + // final res = runtime.executeLib('package:example/main.dart', 'main'); + + // expect(res is List, true); + // res as List; + // final test1 = res[0] as TestClass; + // expect(test1.runTest(5, b: 'cool'), true); + // final test2 = res[1] as TestClass; + // expect(test2.runTest(0, b: 'idk'), false); + // }); test('Using an external static method', () { compiler.defineBridgeClasses([$TestClass.$declaration]); From a66d05daca3cfc45dffadd8a51bdbdbb8245bd3b Mon Sep 17 00:00:00 2001 From: Noobware1 <110553648+Noobware1@users.noreply.github.com> Date: Fri, 19 Jul 2024 13:48:50 +0530 Subject: [PATCH 5/7] Maybe fixed bridge subclass issue --- .../compiler/declaration/constructor.dart | 659 +++++++++++++++++- test/bridge_test.dart | 200 +++--- 2 files changed, 724 insertions(+), 135 deletions(-) diff --git a/lib/src/eval/compiler/declaration/constructor.dart b/lib/src/eval/compiler/declaration/constructor.dart index 4007ee76..5b6a8bf6 100644 --- a/lib/src/eval/compiler/declaration/constructor.dart +++ b/lib/src/eval/compiler/declaration/constructor.dart @@ -194,25 +194,23 @@ void compileConstructorDeclaration( final namedArgTypes = {}; var constructorName = $superInitializer?.constructorName?.name ?? ''; - // final bool doesExtendBridge; + bool doesExtendBridge = false; + if ($extends == null) { $super = BuiltinValue().push(ctx); - // doesExtendBridge = false; } else { extendsWhat = ctx .visibleDeclarations[ctx.library]![$extends.superclass.name2.lexeme]!; final decl = extendsWhat.declaration!; - // if (!decl.isBridge) { - // final $doesExtendBridge = _doesExtendBridge(decl, ctx); - // doesExtendBridge = $doesExtendBridge[0] as bool; - // if (doesExtendBridge) { - // extendsWhat = $doesExtendBridge[1] as DeclarationOrPrefix; - // $extends = $doesExtendBridge[2] as ExtendsClause; - // } - // } else { - // doesExtendBridge = false; - // } + if (!decl.isBridge) { + final $checkResults = _doesExtendBridge(decl, ctx); + if ($checkResults.extendsBridge) { + doesExtendBridge = true; + extendsWhat = $checkResults.declaration; + $extends = $checkResults.extendsClause; + } + } if (decl.isBridge) { ctx.pushOp(PushBridgeSuperShim.make(), PushBridgeSuperShim.length); @@ -262,11 +260,7 @@ void compileConstructorDeclaration( ?.toAlwaysReturnType(ctx, clsType, argTypes, namedArgTypes) ?? AlwaysReturnType(CoreTypes.dynamic.ref(ctx), true); - // if (doesExtendBridge) { - // ctx.pushOp(PushBridgeSuperShim.make(), PushBridgeSuperShim.length); - // } else { ctx.pushOp(PushReturnValue.make(), PushReturnValue.LEN); - // } $super = Variable.alloc(ctx, mReturnType.type ?? CoreTypes.dynamic.ref(ctx)); } @@ -365,6 +359,10 @@ void compileConstructorDeclaration( final bridgeInst = Variable.alloc(ctx, CoreTypes.dynamic.ref(ctx)); + if (doesExtendBridge) { + ctx.pushOp(PushBridgeSuperShim.make(), PushBridgeSuperShim.length); + $super = Variable.alloc(ctx, CoreTypes.dynamic.ref(ctx)); + } ctx.pushOp( ParentBridgeSuperShim.make( $super.scopeFrameOffset, bridgeInst.scopeFrameOffset), @@ -393,11 +391,12 @@ void compileDefaultConstructor(CompilerContext ctx, final fieldIndices = _getFieldIndices(fields); final fieldIdx = fieldIndices.length; - final $extends = parent is EnumDeclaration + var $extends = parent is EnumDeclaration ? null : (parent as ClassDeclaration).extendsClause; Variable $super; DeclarationOrPrefix? extendsWhat; + bool doesExtendBridge = false; final argTypes = []; final namedArgTypes = {}; @@ -412,6 +411,15 @@ void compileDefaultConstructor(CompilerContext ctx, final decl = extendsWhat.declaration!; + if (!decl.isBridge) { + final $checkResults = _doesExtendBridge(decl, ctx); + if ($checkResults.extendsBridge) { + doesExtendBridge = true; + extendsWhat = $checkResults.declaration; + $extends = $checkResults.extendsClause; + } + } + if (decl.isBridge) { ctx.pushOp(PushBridgeSuperShim.make(), PushBridgeSuperShim.length); $super = Variable.alloc(ctx, CoreTypes.dynamic.ref(ctx)); @@ -489,6 +497,11 @@ void compileDefaultConstructor(CompilerContext ctx, ctx.pushOp(op, BridgeInstantiate.len(op)); final bridgeInst = Variable.alloc(ctx, CoreTypes.dynamic.ref(ctx)); + if (doesExtendBridge) { + ctx.pushOp(PushBridgeSuperShim.make(), PushBridgeSuperShim.length); + $super = Variable.alloc(ctx, CoreTypes.dynamic.ref(ctx)); + } + ctx.pushOp( ParentBridgeSuperShim.make( $super.scopeFrameOffset, bridgeInst.scopeFrameOffset), @@ -536,26 +549,602 @@ void _compileUnusedFields(CompilerContext ctx, List fields, } } -List _doesExtendBridge( +_BridgeCheckResult _doesExtendBridge( DeclarationOrBridge? decl, CompilerContext ctx) { if (decl != null && decl.declaration is ClassDeclaration) { - var $decl = ctx.visibleDeclarations[decl.sourceLib]?[ - (decl.declaration as ClassDeclaration) - .extendsClause - ?.superclass - .name2 - .lexeme]; - if ($decl != null && $decl.declaration!.isBridge) { - return [ - true, - $decl, - (decl.declaration as ClassDeclaration).extendsClause - ]; - } else if ($decl == null || $decl.declaration == null) { - return [false]; + var classDecl = decl.declaration as ClassDeclaration; + var superClassName = classDecl.extendsClause?.superclass.name2.lexeme; + var superClassDecl = + ctx.visibleDeclarations[decl.sourceLib]?[superClassName]; + + if (superClassDecl != null && superClassDecl.declaration!.isBridge) { + return _BridgeCheckResult( + declaration: superClassDecl, + extendsClause: classDecl.extendsClause, + ); + } else if (superClassDecl == null || superClassDecl.declaration == null) { + return _BridgeCheckResult.fail(); } - return _doesExtendBridge($decl.declaration!, ctx); - } else { - return [false]; + + return _doesExtendBridge(superClassDecl.declaration!, ctx); } + return _BridgeCheckResult.fail(); } + +class _BridgeCheckResult { + final bool extendsBridge; + final DeclarationOrPrefix? declaration; + final ExtendsClause? extendsClause; + + const _BridgeCheckResult.fail() + : extendsBridge = false, + declaration = null, + extendsClause = null; + + const _BridgeCheckResult({ + required this.declaration, + required this.extendsClause, + }) : extendsBridge = true; +} + +// import 'package:analyzer/dart/ast/ast.dart'; +// import 'package:dart_eval/dart_eval_bridge.dart'; +// import 'package:dart_eval/src/eval/bridge/declaration.dart'; +// import 'package:dart_eval/src/eval/compiler/builtins.dart'; +// import 'package:dart_eval/src/eval/compiler/context.dart'; +// import 'package:dart_eval/src/eval/compiler/errors.dart'; +// import 'package:dart_eval/src/eval/compiler/expression/expression.dart'; +// import 'package:dart_eval/src/eval/compiler/expression/method_invocation.dart'; +// import 'package:dart_eval/src/eval/compiler/helpers/argument_list.dart'; +// import 'package:dart_eval/src/eval/compiler/helpers/fpl.dart'; +// import 'package:dart_eval/src/eval/compiler/helpers/return.dart'; +// import 'package:dart_eval/src/eval/compiler/offset_tracker.dart'; +// import 'package:dart_eval/src/eval/compiler/reference.dart'; +// import 'package:dart_eval/src/eval/compiler/scope.dart'; +// import 'package:dart_eval/src/eval/compiler/source.dart'; +// import 'package:dart_eval/src/eval/compiler/statement/block.dart'; +// import 'package:dart_eval/src/eval/compiler/statement/statement.dart'; +// import 'package:dart_eval/src/eval/compiler/type.dart'; +// import 'package:dart_eval/src/eval/runtime/runtime.dart'; + +// import '../variable.dart'; + +// void compileConstructorDeclaration( +// CompilerContext ctx, +// ConstructorDeclaration d, +// NamedCompilationUnitMember parent, +// List fields) { +// final parentName = parent.name.lexeme; +// final dName = (d.name?.lexeme) ?? ""; +// final n = '$parentName.$dName'; +// final isEnum = parent is EnumDeclaration; + +// if (d.factoryKeyword != null && d.initializers.isNotEmpty) { +// throw CompileError('Factory constructors cannot have initializers', d); +// } + +// ctx.topLevelDeclarationPositions[ctx.library]![n] = +// beginMethod(ctx, d, d.offset, '$n()'); + +// ctx.beginAllocScope( +// existingAllocLen: d.parameters.parameters.length + (isEnum ? 2 : 0)); +// ctx.scopeFrameOffset = d.parameters.parameters.length + (isEnum ? 2 : 0); + +// SuperConstructorInvocation? $superInitializer; +// RedirectingConstructorInvocation? $redirectingInitializer; +// final otherInitializers = []; +// for (final initializer in d.initializers) { +// if (initializer is SuperConstructorInvocation) { +// $superInitializer = initializer; +// } else if (initializer is RedirectingConstructorInvocation) { +// if (d.initializers.length > 1) { +// throw CompileError( +// 'Redirecting constructor invocation must be the only initializer', +// d); +// } +// $redirectingInitializer = initializer; +// } else if ($superInitializer != null) { +// throw CompileError( +// 'Super constructor invocation must be last in the initializer list', +// d); +// } else { +// otherInitializers.add(initializer); +// } +// } + +// final fieldIndices = { +// if (parent is EnumDeclaration) ...{'index': 0, 'name': 1}, +// ..._getFieldIndices(fields, parent is EnumDeclaration ? 2 : 0) +// }; + +// final fieldIdx = fieldIndices.length; + +// final fieldFormalNames = []; +// final resolvedParams = resolveFPLDefaults(ctx, d.parameters, false, +// allowUnboxed: true, isEnum: parent is EnumDeclaration); + +// final superParams = []; +// var i = parent is EnumDeclaration ? 2 : 0; + +// for (final param in resolvedParams) { +// final p = param.parameter; +// final V = param.V; +// Variable vrep; +// if ($redirectingInitializer != null && !(p is SimpleFormalParameter)) { +// throw CompileError( +// 'Redirecting constructor invocation cannot have super or this parameters', +// d); +// } +// if (p is FieldFormalParameter) { +// TypeRef? _type; +// if (p.type != null) { +// _type = TypeRef.fromAnnotation(ctx, ctx.library, p.type!); +// } +// _type ??= TypeRef.lookupFieldType(ctx, +// TypeRef.lookupDeclaration(ctx, ctx.library, parent), p.name.lexeme, +// source: p); +// _type ??= V?.type; +// _type ??= CoreTypes.dynamic.ref(ctx); + +// vrep = Variable(i, +// _type.copyWith(boxed: !_type.isUnboxedAcrossFunctionBoundaries)) +// .boxIfNeeded(ctx) +// ..name = p.name.lexeme; + +// fieldFormalNames.add(p.name.lexeme); +// } else if (p is SuperFormalParameter) { +// final type = resolveSuperFormalType(ctx, ctx.library, p, d); +// vrep = Variable( +// i, type.copyWith(boxed: !type.isUnboxedAcrossFunctionBoundaries)) +// .boxIfNeeded(ctx) +// ..name = p.name.lexeme; +// superParams.add(p.name.lexeme); +// } else { +// p as SimpleFormalParameter; +// var type = CoreTypes.dynamic.ref(ctx); +// if (p.type != null) { +// type = TypeRef.fromAnnotation(ctx, ctx.library, p.type!); +// } +// type = +// type.copyWith(boxed: !unboxedAcrossFunctionBoundaries.contains(type)); +// vrep = Variable(i, type)..name = p.name!.lexeme; +// } + +// ctx.setLocal(vrep.name!, vrep); + +// i++; +// } + +// final clsType = TypeRef.lookupDeclaration(ctx, ctx.library, parent); + +// // Handle factory constructor +// if (d.factoryKeyword != null) { +// final b = d.body; + +// if (b.isAsynchronous || b.isGenerator) { +// throw CompileError( +// 'Factory constructors cannot be async and/or generators', d); +// } + +// StatementInfo? stInfo; + +// if (b is BlockFunctionBody) { +// stInfo = compileBlock(b.block, AlwaysReturnType(clsType, false), ctx, +// name: '$n()'); +// } else if (b is ExpressionFunctionBody) { +// ctx.beginAllocScope(); +// final V = compileExpression(b.expression, ctx); +// stInfo = doReturn(ctx, AlwaysReturnType(clsType, false), V, +// isAsync: b.isAsynchronous); +// ctx.endAllocScope(); +// } else { +// throw CompileError('Unknown function body type ${b.runtimeType}', d); +// } + +// if (!(stInfo.willAlwaysReturn || stInfo.willAlwaysThrow)) { +// throw CompileError( +// 'Factory constructor must always return a value or throw', d); +// } + +// ctx.endAllocScope(popValues: false); +// return; +// } + +// // Handle redirecting constructor +// if ($redirectingInitializer != null) { +// final name = $redirectingInitializer.constructorName?.name ?? ''; +// final _dec = resolveStaticMethod(ctx, clsType, name); +// final dec = _dec.declaration!; +// final fpl = (dec as ConstructorDeclaration).parameters.parameters; + +// compileArgumentList( +// ctx, $redirectingInitializer.argumentList, clsType.file, fpl, dec, +// source: $redirectingInitializer.argumentList); + +// final offset = +// DeferredOrOffset.lookupStatic(ctx, clsType.file, clsType.name, name); +// final loc = ctx.pushOp(Call.make(offset.offset ?? -1), Call.length); +// if (offset.offset == null) { +// ctx.offsetTracker.setOffset(loc, offset); +// } +// ctx.pushOp(PushReturnValue.make(), PushReturnValue.LEN); +// final V = Variable.alloc(ctx, clsType); +// doReturn(ctx, AlwaysReturnType(clsType, false), V); +// return; +// } + +// var $extends = parent is EnumDeclaration +// ? null +// : (parent as ClassDeclaration).extendsClause; +// Variable $super; +// DeclarationOrPrefix? extendsWhat; + +// final argTypes = []; +// final namedArgTypes = {}; + +// var constructorName = $superInitializer?.constructorName?.name ?? ''; +// // final bool doesExtendBridge; +// if ($extends == null) { +// $super = BuiltinValue().push(ctx); +// // doesExtendBridge = false; +// } else { +// extendsWhat = ctx +// .visibleDeclarations[ctx.library]![$extends.superclass.name2.lexeme]!; + +// final decl = extendsWhat.declaration!; +// // if (!decl.isBridge) { +// // final $doesExtendBridge = _doesExtendBridge(decl, ctx); +// // doesExtendBridge = $doesExtendBridge[0] as bool; +// // if (doesExtendBridge) { +// // extendsWhat = $doesExtendBridge[1] as DeclarationOrPrefix; +// // $extends = $doesExtendBridge[2] as ExtendsClause; +// // } +// // } else { +// // doesExtendBridge = false; +// // } + +// if (decl.isBridge) { +// ctx.pushOp(PushBridgeSuperShim.make(), PushBridgeSuperShim.length); +// $super = Variable.alloc(ctx, CoreTypes.dynamic.ref(ctx)); +// } else { +// final extendsType = TypeRef.lookupDeclaration( +// ctx, ctx.library, decl.declaration as ClassDeclaration); + +// AlwaysReturnType? mReturnType; + +// if ($superInitializer != null) { +// final _constructor = ctx.topLevelDeclarationsMap[decl.sourceLib]![ +// '${extendsType.name}.$constructorName']!; +// final constructor = _constructor.declaration as ConstructorDeclaration; + +// final argsPair = compileArgumentList( +// ctx, +// $superInitializer.argumentList, +// decl.sourceLib, +// constructor.parameters.parameters, +// constructor, +// superParams: superParams, +// source: $superInitializer); +// final _args = argsPair.first; +// final _namedArgs = argsPair.second; + +// argTypes.addAll(_args.map((e) => e.type).toList()); +// namedArgTypes +// .addAll(_namedArgs.map((key, value) => MapEntry(key, value.type))); +// } + +// final method = +// IdentifierReference(null, '${extendsType.name}.$constructorName') +// .getValue(ctx); +// if (method.methodOffset == null) { +// throw CompileError( +// 'Cannot call $constructorName as it is not a valid method'); +// } + +// final offset = method.methodOffset!; +// final loc = ctx.pushOp(Call.make(offset.offset ?? -1), Call.length); +// if (offset.offset == null) { +// ctx.offsetTracker.setOffset(loc, offset); +// } + +// mReturnType = method.methodReturnType +// ?.toAlwaysReturnType(ctx, clsType, argTypes, namedArgTypes) ?? +// AlwaysReturnType(CoreTypes.dynamic.ref(ctx), true); + +// // if (doesExtendBridge) { +// // ctx.pushOp(PushBridgeSuperShim.make(), PushBridgeSuperShim.length); +// // } else { +// ctx.pushOp(PushReturnValue.make(), PushReturnValue.LEN); +// // } +// $super = +// Variable.alloc(ctx, mReturnType.type ?? CoreTypes.dynamic.ref(ctx)); +// } +// } + +// final op = CreateClass.make(ctx.library, $super.scopeFrameOffset, +// parent.name.lexeme, fieldIdx + (isEnum ? 2 : 0)); +// ctx.pushOp(op, CreateClass.len(op)); +// final instOffset = ctx.scopeFrameOffset++; + +// if (parent is EnumDeclaration) { +// /// Add implicit index and name fields +// ctx.inferredFieldTypes +// .putIfAbsent(ctx.library, () => {}) +// .putIfAbsent(ctx.currentClass!.name.lexeme, () => {}) +// ..['index'] = CoreTypes.int.ref(ctx) +// ..['name'] = CoreTypes.string.ref(ctx); +// } + +// if (parent is EnumDeclaration) { +// ctx.pushOp(SetObjectPropertyImpl.make(instOffset, 0, 0), +// SetObjectPropertyImpl.length); +// ctx.pushOp(SetObjectPropertyImpl.make(instOffset, 1, 1), +// SetObjectPropertyImpl.length); +// } + +// for (final fieldFormal in fieldFormalNames) { +// ctx.pushOp( +// SetObjectPropertyImpl.make(instOffset, fieldIndices[fieldFormal]!, +// ctx.lookupLocal(fieldFormal)!.scopeFrameOffset), +// SetObjectPropertyImpl.length); +// } + +// final usedNames = {...fieldFormalNames}; + +// for (final init in otherInitializers) { +// if (init is ConstructorFieldInitializer) { +// final fType = TypeRef.lookupFieldType( +// ctx, +// TypeRef.lookupDeclaration(ctx, ctx.library, parent), +// init.fieldName.name, +// source: init); +// final V = compileExpression(init.expression, ctx, fType).boxIfNeeded(ctx); +// ctx.pushOp( +// SetObjectPropertyImpl.make(instOffset, +// fieldIndices[init.fieldName.name]!, V.scopeFrameOffset), +// SetObjectPropertyImpl.length); +// usedNames.add(init.fieldName.name); +// } else { +// throw CompileError('${init.runtimeType} initializer is not supported'); +// } +// } + +// _compileUnusedFields(ctx, fields, {}, instOffset); + +// final body = d.body; +// if (d.factoryKeyword == null && !(body is EmptyFunctionBody)) { +// ctx.beginAllocScope(); +// ctx.setLocal('#this', Variable(instOffset, TypeRef.$this(ctx)!)); +// if (body is BlockFunctionBody) { +// compileBlock( +// body.block, AlwaysReturnType(CoreTypes.voidType.ref(ctx), false), ctx, +// name: '$n()'); +// } else if (body is ExpressionFunctionBody) { +// final V = compileExpression(body.expression, ctx); +// doReturn(ctx, AlwaysReturnType(CoreTypes.voidType.ref(ctx), false), V); +// } +// ctx.endAllocScope(); +// } + +// if ($extends != null && extendsWhat!.declaration!.isBridge) { +// final decl = extendsWhat.declaration!; +// final bridge = decl.bridge! as BridgeClassDef; + +// if (!bridge.bridge) { +// throw CompileError( +// 'Bridge class ${$extends.superclass} is a wrapper, not a bridge, so you can\'t extend it'); +// } + +// if ($superInitializer != null) { +// final constructor = bridge.constructors[constructorName]!; +// final argsPair = compileArgumentListWithBridge( +// ctx, $superInitializer.argumentList, constructor.functionDescriptor); +// final _args = argsPair.first; +// final _namedArgs = argsPair.second; +// argTypes.addAll(_args.map((e) => e.type).toList()); +// namedArgTypes +// .addAll(_namedArgs.map((key, value) => MapEntry(key, value.type))); +// } + +// final op = BridgeInstantiate.make( +// instOffset, +// ctx.bridgeStaticFunctionIndices[decl.sourceLib]![ +// '${$extends.superclass.name2.value()}.$constructorName']!); +// ctx.pushOp(op, BridgeInstantiate.len(op)); + +// final bridgeInst = Variable.alloc(ctx, CoreTypes.dynamic.ref(ctx)); + +// ctx.pushOp( +// ParentBridgeSuperShim.make( +// $super.scopeFrameOffset, bridgeInst.scopeFrameOffset), +// ParentBridgeSuperShim.LEN); + +// ctx.pushOp(Return.make(bridgeInst.scopeFrameOffset), Return.LEN); +// } else { +// ctx.pushOp(Return.make(instOffset), Return.LEN); +// } + +// ctx.endAllocScope(popValues: false); +// } + +// void compileDefaultConstructor(CompilerContext ctx, +// NamedCompilationUnitMember parent, List fields) { +// final parentName = parent.name.lexeme; +// final n = '$parentName.'; + +// ctx.topLevelDeclarationPositions[ctx.library]![n] = +// beginMethod(ctx, parent, parent.offset, '$n()'); + +// final isEnum = parent is EnumDeclaration; +// ctx.beginAllocScope(existingAllocLen: isEnum ? 2 : 0); +// ctx.scopeFrameOffset += isEnum ? 2 : 0; + +// final fieldIndices = _getFieldIndices(fields); +// final fieldIdx = fieldIndices.length; + +// final $extends = parent is EnumDeclaration +// ? null +// : (parent as ClassDeclaration).extendsClause; +// Variable $super; +// DeclarationOrPrefix? extendsWhat; + +// final argTypes = []; +// final namedArgTypes = {}; + +// final constructorName = ''; + +// if ($extends == null) { +// $super = BuiltinValue().push(ctx); +// } else { +// extendsWhat = ctx +// .visibleDeclarations[ctx.library]![$extends.superclass.name2.lexeme]!; + +// final decl = extendsWhat.declaration!; + +// if (decl.isBridge) { +// ctx.pushOp(PushBridgeSuperShim.make(), PushBridgeSuperShim.length); +// $super = Variable.alloc(ctx, CoreTypes.dynamic.ref(ctx)); +// } else { +// final extendsType = TypeRef.lookupDeclaration( +// ctx, ctx.library, decl.declaration as ClassDeclaration); + +// AlwaysReturnType? mReturnType; + +// final method = +// IdentifierReference(null, '${extendsType.name}.$constructorName') +// .getValue(ctx); +// if (method.methodOffset == null) { +// throw CompileError( +// 'Cannot call $constructorName as it is not a valid method'); +// } + +// final offset = method.methodOffset!; +// final loc = ctx.pushOp(Call.make(offset.offset ?? -1), Call.length); +// if (offset.offset == null) { +// ctx.offsetTracker.setOffset(loc, offset); +// } +// final clsType = TypeRef.lookupDeclaration(ctx, ctx.library, parent); +// mReturnType = method.methodReturnType +// ?.toAlwaysReturnType(ctx, clsType, argTypes, namedArgTypes) ?? +// AlwaysReturnType(CoreTypes.dynamic.ref(ctx), true); + +// ctx.pushOp(PushReturnValue.make(), PushReturnValue.LEN); +// $super = +// Variable.alloc(ctx, mReturnType.type ?? CoreTypes.dynamic.ref(ctx)); +// } +// } + +// final op = CreateClass.make(ctx.library, $super.scopeFrameOffset, +// parent.name.lexeme, fieldIdx + (isEnum ? 2 : 0)); +// ctx.pushOp(op, CreateClass.len(op)); +// final instOffset = ctx.scopeFrameOffset++; + +// if (parent is EnumDeclaration) { +// /// Add implicit index and name fields +// ctx.inferredFieldTypes +// .putIfAbsent(ctx.library, () => {}) +// .putIfAbsent(ctx.currentClass!.name.lexeme, () => {}) +// ..['index'] = CoreTypes.int.ref(ctx) +// ..['name'] = CoreTypes.string.ref(ctx); +// } + +// if (parent is EnumDeclaration) { +// ctx.pushOp(SetObjectPropertyImpl.make(instOffset, 0, 0), +// SetObjectPropertyImpl.length); +// ctx.pushOp(SetObjectPropertyImpl.make(instOffset, 1, 1), +// SetObjectPropertyImpl.length); +// } + +// _compileUnusedFields( +// ctx, +// fields, +// parent is EnumDeclaration ? {'index', 'name'} : {}, +// instOffset, +// parent is EnumDeclaration ? 2 : 0); + +// if ($extends != null && extendsWhat!.declaration!.isBridge) { +// final decl = extendsWhat.declaration!; +// final bridge = decl.bridge! as BridgeClassDef; + +// if (!bridge.bridge) { +// throw CompileError( +// 'Bridge class ${$extends.superclass} is a wrapper, not a bridge, so you can\'t extend it'); +// } + +// final op = BridgeInstantiate.make( +// instOffset, +// ctx.bridgeStaticFunctionIndices[decl.sourceLib]![ +// '${$extends.superclass.name2.lexeme}.$constructorName']!); +// ctx.pushOp(op, BridgeInstantiate.len(op)); +// final bridgeInst = Variable.alloc(ctx, CoreTypes.dynamic.ref(ctx)); + +// ctx.pushOp( +// ParentBridgeSuperShim.make( +// $super.scopeFrameOffset, bridgeInst.scopeFrameOffset), +// ParentBridgeSuperShim.LEN); + +// ctx.pushOp(Return.make(bridgeInst.scopeFrameOffset), Return.LEN); +// } else { +// ctx.pushOp(Return.make(instOffset), Return.LEN); +// } + +// ctx.endAllocScope(popValues: false); +// } + +// Map _getFieldIndices(List fields, +// [int fieldIdx = 0]) { +// final fieldIndices = {}; +// var _fieldIdx = fieldIdx; +// for (final fd in fields) { +// for (final field in fd.fields.variables) { +// fieldIndices[field.name.lexeme] = _fieldIdx; +// _fieldIdx++; +// } +// } +// return fieldIndices; +// } + +// void _compileUnusedFields(CompilerContext ctx, List fields, +// Set usedNames, int instOffset, +// [int fieldIdx = 0]) { +// var _fieldIdx = fieldIdx; +// for (final fd in fields) { +// for (final field in fd.fields.variables) { +// if (!usedNames.contains(field.name.lexeme) && field.initializer != null) { +// final V = compileExpression(field.initializer!, ctx).boxIfNeeded(ctx); +// ctx.inferredFieldTypes.putIfAbsent(ctx.library, () => {}).putIfAbsent( +// ctx.currentClass!.name.lexeme, () => {})[field.name.lexeme] = +// V.type; +// ctx.pushOp( +// SetObjectPropertyImpl.make( +// instOffset, _fieldIdx, V.scopeFrameOffset), +// SetObjectPropertyImpl.length); +// } +// _fieldIdx++; +// } +// } +// } + +// List _doesExtendBridge( +// DeclarationOrBridge? decl, CompilerContext ctx) { +// if (decl != null && decl.declaration is ClassDeclaration) { +// var $decl = ctx.visibleDeclarations[decl.sourceLib]?[ +// (decl.declaration as ClassDeclaration) +// .extendsClause +// ?.superclass +// .name2 +// .lexeme]; +// if ($decl != null && $decl.declaration!.isBridge) { +// return [ +// true, +// $decl, +// (decl.declaration as ClassDeclaration).extendsClause +// ]; +// } else if ($decl == null || $decl.declaration == null) { +// return [false]; +// } +// return _doesExtendBridge($decl.declaration!, ctx); +// } else { +// return [false]; +// } +// } diff --git a/test/bridge_test.dart b/test/bridge_test.dart index fb2efc18..96f776e9 100644 --- a/test/bridge_test.dart +++ b/test/bridge_test.dart @@ -113,106 +113,106 @@ void main() { expect(res.runTest(2), false); }); - // test( - // 'Creating and using multiple subclassed bridge class inside the runtime', - // () { - // compiler.defineBridgeClasses([$TestClass.$declaration]); - - // final program = compiler.compile({ - // 'example': { - // 'main.dart': ''' - // import 'package:bridge_lib/bridge_lib.dart'; - - // class MyTestClass1 extends TestClass { - // MyTestClass1(int someNumber) : super(someNumber); - - // @override - // bool runTest(int a, {String b = 'wow'}) { - // return super.runTest(a + 2 + someNumber, b: b); - // } - // } - - // class MyTestClass2 extends TestClass1 { - // MyTestClass2(int someNumber) : super(someNumber); - - // @override - // bool runTest(int a, {String b = 'wow'}) { - // return super.runTest(a + 0 + someNumber, b: b); - // } - // } - - // void main() { - // final test1 = MyTestClass1(18); - // print(test1.runTest(5, b: 'cool')); - // final test2 = MyTestClass2(1); - // print(test2.runTest(0, b: 'idk')); - // } - // ''' - // } - // }); - - // final runtime = Runtime.ofProgram(program); - - // runtime.registerBridgeFunc('package:bridge_lib/bridge_lib.dart', - // 'TestClass.', $TestClass.$construct, - // isBridge: true); - - // expect(() => runtime.executeLib('package:example/main.dart', 'main'), - // prints('true\nfalse\n')); - // }); - - // test( - // 'Creating and using multiple subclassed bridge class outside the runtime', - // () { - // compiler.defineBridgeClasses([$TestClass.$declaration]); - - // final program = compiler.compile({ - // 'example': { - // 'main.dart': ''' - // import 'package:bridge_lib/bridge_lib.dart'; - - // class MyTestClass1 extends TestClass { - // MyTestClass1(int someNumber) : super(someNumber); - - // @override - // bool runTest(int a, {String b = 'wow'}) { - // return super.runTest(a + 2 + someNumber, b: b); - // } - // } - - // class MyTestClass2 extends TestClass1 { - // MyTestClass2(int someNumber) : super(someNumber); - - // @override - // bool runTest(int a, {String b = 'wow'}) { - // return super.runTest(a + 0 + someNumber, b: b); - // } - // } - - // List main() { - // final test1 = MyTestClass1(18); - // final test2 = MyTestClass2(1); - // return [test1, test2]; - // } - // ''' - // } - // }); - - // final runtime = Runtime.ofProgram(program); - - // runtime.registerBridgeFunc('package:bridge_lib/bridge_lib.dart', - // 'TestClass.', $TestClass.$construct, - // isBridge: true); - - // final res = runtime.executeLib('package:example/main.dart', 'main'); - - // expect(res is List, true); - // res as List; - // final test1 = res[0] as TestClass; - // expect(test1.runTest(5, b: 'cool'), true); - // final test2 = res[1] as TestClass; - // expect(test2.runTest(0, b: 'idk'), false); - // }); + test( + 'Creating and using multiple subclassed bridge class inside the runtime', + () { + compiler.defineBridgeClasses([$TestClass.$declaration]); + + final program = compiler.compile({ + 'example': { + 'main.dart': ''' + import 'package:bridge_lib/bridge_lib.dart'; + + class MyTestClass1 extends TestClass { + MyTestClass1(int someNumber) : super(someNumber); + + @override + bool runTest(int a, {String b = 'wow'}) { + return super.runTest(a + 2 + someNumber, b: b); + } + } + + class MyTestClass2 extends MyTestClass1 { + MyTestClass2(int someNumber) : super(someNumber); + + @override + bool runTest(int a, {String b = 'wow'}) { + return !super.runTest(a, b: b); + } + } + + void main() { + final test1 = MyTestClass1(18); + print(test1.runTest(5, b: 'cool')); + final test2 = MyTestClass2(1); + print(test2.runTest(0, b: 'idk')); + } + ''' + } + }); + + final runtime = Runtime.ofProgram(program); + + runtime.registerBridgeFunc('package:bridge_lib/bridge_lib.dart', + 'TestClass.', $TestClass.$construct, + isBridge: true); + + expect(() => runtime.executeLib('package:example/main.dart', 'main'), + prints('true\nfalse\n')); + }); + + test( + 'Creating and using multiple subclassed bridge class outside the runtime', + () { + compiler.defineBridgeClasses([$TestClass.$declaration]); + + final program = compiler.compile({ + 'example': { + 'main.dart': ''' + import 'package:bridge_lib/bridge_lib.dart'; + + class TestClass1 extends TestClass { + TestClass1(int someNumber) : super(someNumber); + + @override + bool runTest(int a, {String b = 'wow'}) { + return super.runTest(a + 2 + someNumber, b: b); + } + } + + class TestClass2 extends TestClass1 { + TestClass2(int someNumber) : super(someNumber); + + @override + bool runTest(int a, {String b = 'wow'}) { + return !super.runTest(a, b: b); + } + } + + List main() { + final test1 = TestClass1(18); + final test2 = TestClass2(1); + return [test1, test2]; + } + ''' + } + }); + + final runtime = Runtime.ofProgram(program); + + runtime.registerBridgeFunc('package:bridge_lib/bridge_lib.dart', + 'TestClass.', $TestClass.$construct, + isBridge: true); + + final res = runtime.executeLib('package:example/main.dart', 'main'); + + expect(res is List, true); + res as List; + final test1 = res[0] as TestClass; + expect(test1.runTest(5, b: 'cool'), true); + final test2 = res[1] as TestClass; + expect(test2.runTest(0, b: 'idk'), false); + }); test('Using an external static method', () { compiler.defineBridgeClasses([$TestClass.$declaration]); From 0313bfe322dafc70644172d7b5f6257334192de1 Mon Sep 17 00:00:00 2001 From: Noobware1 <110553648+Noobware1@users.noreply.github.com> Date: Sat, 20 Jul 2024 22:02:32 +0530 Subject: [PATCH 6/7] Complete future & uri wrapper --- .../compiler/declaration/constructor.dart | 562 ----- lib/src/eval/shared/stdlib/core/base.dart | 3 +- lib/src/eval/shared/stdlib/core/future.dart | 499 +++- lib/src/eval/shared/stdlib/core/uri.dart | 2088 +++++++++++++---- lib/src/eval/shared/types.dart | 3 + lib/src/eval/utils/wap_helper.dart | 29 - 6 files changed, 2073 insertions(+), 1111 deletions(-) delete mode 100644 lib/src/eval/utils/wap_helper.dart diff --git a/lib/src/eval/compiler/declaration/constructor.dart b/lib/src/eval/compiler/declaration/constructor.dart index 5b6a8bf6..ab863c7f 100644 --- a/lib/src/eval/compiler/declaration/constructor.dart +++ b/lib/src/eval/compiler/declaration/constructor.dart @@ -586,565 +586,3 @@ class _BridgeCheckResult { required this.extendsClause, }) : extendsBridge = true; } - -// import 'package:analyzer/dart/ast/ast.dart'; -// import 'package:dart_eval/dart_eval_bridge.dart'; -// import 'package:dart_eval/src/eval/bridge/declaration.dart'; -// import 'package:dart_eval/src/eval/compiler/builtins.dart'; -// import 'package:dart_eval/src/eval/compiler/context.dart'; -// import 'package:dart_eval/src/eval/compiler/errors.dart'; -// import 'package:dart_eval/src/eval/compiler/expression/expression.dart'; -// import 'package:dart_eval/src/eval/compiler/expression/method_invocation.dart'; -// import 'package:dart_eval/src/eval/compiler/helpers/argument_list.dart'; -// import 'package:dart_eval/src/eval/compiler/helpers/fpl.dart'; -// import 'package:dart_eval/src/eval/compiler/helpers/return.dart'; -// import 'package:dart_eval/src/eval/compiler/offset_tracker.dart'; -// import 'package:dart_eval/src/eval/compiler/reference.dart'; -// import 'package:dart_eval/src/eval/compiler/scope.dart'; -// import 'package:dart_eval/src/eval/compiler/source.dart'; -// import 'package:dart_eval/src/eval/compiler/statement/block.dart'; -// import 'package:dart_eval/src/eval/compiler/statement/statement.dart'; -// import 'package:dart_eval/src/eval/compiler/type.dart'; -// import 'package:dart_eval/src/eval/runtime/runtime.dart'; - -// import '../variable.dart'; - -// void compileConstructorDeclaration( -// CompilerContext ctx, -// ConstructorDeclaration d, -// NamedCompilationUnitMember parent, -// List fields) { -// final parentName = parent.name.lexeme; -// final dName = (d.name?.lexeme) ?? ""; -// final n = '$parentName.$dName'; -// final isEnum = parent is EnumDeclaration; - -// if (d.factoryKeyword != null && d.initializers.isNotEmpty) { -// throw CompileError('Factory constructors cannot have initializers', d); -// } - -// ctx.topLevelDeclarationPositions[ctx.library]![n] = -// beginMethod(ctx, d, d.offset, '$n()'); - -// ctx.beginAllocScope( -// existingAllocLen: d.parameters.parameters.length + (isEnum ? 2 : 0)); -// ctx.scopeFrameOffset = d.parameters.parameters.length + (isEnum ? 2 : 0); - -// SuperConstructorInvocation? $superInitializer; -// RedirectingConstructorInvocation? $redirectingInitializer; -// final otherInitializers = []; -// for (final initializer in d.initializers) { -// if (initializer is SuperConstructorInvocation) { -// $superInitializer = initializer; -// } else if (initializer is RedirectingConstructorInvocation) { -// if (d.initializers.length > 1) { -// throw CompileError( -// 'Redirecting constructor invocation must be the only initializer', -// d); -// } -// $redirectingInitializer = initializer; -// } else if ($superInitializer != null) { -// throw CompileError( -// 'Super constructor invocation must be last in the initializer list', -// d); -// } else { -// otherInitializers.add(initializer); -// } -// } - -// final fieldIndices = { -// if (parent is EnumDeclaration) ...{'index': 0, 'name': 1}, -// ..._getFieldIndices(fields, parent is EnumDeclaration ? 2 : 0) -// }; - -// final fieldIdx = fieldIndices.length; - -// final fieldFormalNames = []; -// final resolvedParams = resolveFPLDefaults(ctx, d.parameters, false, -// allowUnboxed: true, isEnum: parent is EnumDeclaration); - -// final superParams = []; -// var i = parent is EnumDeclaration ? 2 : 0; - -// for (final param in resolvedParams) { -// final p = param.parameter; -// final V = param.V; -// Variable vrep; -// if ($redirectingInitializer != null && !(p is SimpleFormalParameter)) { -// throw CompileError( -// 'Redirecting constructor invocation cannot have super or this parameters', -// d); -// } -// if (p is FieldFormalParameter) { -// TypeRef? _type; -// if (p.type != null) { -// _type = TypeRef.fromAnnotation(ctx, ctx.library, p.type!); -// } -// _type ??= TypeRef.lookupFieldType(ctx, -// TypeRef.lookupDeclaration(ctx, ctx.library, parent), p.name.lexeme, -// source: p); -// _type ??= V?.type; -// _type ??= CoreTypes.dynamic.ref(ctx); - -// vrep = Variable(i, -// _type.copyWith(boxed: !_type.isUnboxedAcrossFunctionBoundaries)) -// .boxIfNeeded(ctx) -// ..name = p.name.lexeme; - -// fieldFormalNames.add(p.name.lexeme); -// } else if (p is SuperFormalParameter) { -// final type = resolveSuperFormalType(ctx, ctx.library, p, d); -// vrep = Variable( -// i, type.copyWith(boxed: !type.isUnboxedAcrossFunctionBoundaries)) -// .boxIfNeeded(ctx) -// ..name = p.name.lexeme; -// superParams.add(p.name.lexeme); -// } else { -// p as SimpleFormalParameter; -// var type = CoreTypes.dynamic.ref(ctx); -// if (p.type != null) { -// type = TypeRef.fromAnnotation(ctx, ctx.library, p.type!); -// } -// type = -// type.copyWith(boxed: !unboxedAcrossFunctionBoundaries.contains(type)); -// vrep = Variable(i, type)..name = p.name!.lexeme; -// } - -// ctx.setLocal(vrep.name!, vrep); - -// i++; -// } - -// final clsType = TypeRef.lookupDeclaration(ctx, ctx.library, parent); - -// // Handle factory constructor -// if (d.factoryKeyword != null) { -// final b = d.body; - -// if (b.isAsynchronous || b.isGenerator) { -// throw CompileError( -// 'Factory constructors cannot be async and/or generators', d); -// } - -// StatementInfo? stInfo; - -// if (b is BlockFunctionBody) { -// stInfo = compileBlock(b.block, AlwaysReturnType(clsType, false), ctx, -// name: '$n()'); -// } else if (b is ExpressionFunctionBody) { -// ctx.beginAllocScope(); -// final V = compileExpression(b.expression, ctx); -// stInfo = doReturn(ctx, AlwaysReturnType(clsType, false), V, -// isAsync: b.isAsynchronous); -// ctx.endAllocScope(); -// } else { -// throw CompileError('Unknown function body type ${b.runtimeType}', d); -// } - -// if (!(stInfo.willAlwaysReturn || stInfo.willAlwaysThrow)) { -// throw CompileError( -// 'Factory constructor must always return a value or throw', d); -// } - -// ctx.endAllocScope(popValues: false); -// return; -// } - -// // Handle redirecting constructor -// if ($redirectingInitializer != null) { -// final name = $redirectingInitializer.constructorName?.name ?? ''; -// final _dec = resolveStaticMethod(ctx, clsType, name); -// final dec = _dec.declaration!; -// final fpl = (dec as ConstructorDeclaration).parameters.parameters; - -// compileArgumentList( -// ctx, $redirectingInitializer.argumentList, clsType.file, fpl, dec, -// source: $redirectingInitializer.argumentList); - -// final offset = -// DeferredOrOffset.lookupStatic(ctx, clsType.file, clsType.name, name); -// final loc = ctx.pushOp(Call.make(offset.offset ?? -1), Call.length); -// if (offset.offset == null) { -// ctx.offsetTracker.setOffset(loc, offset); -// } -// ctx.pushOp(PushReturnValue.make(), PushReturnValue.LEN); -// final V = Variable.alloc(ctx, clsType); -// doReturn(ctx, AlwaysReturnType(clsType, false), V); -// return; -// } - -// var $extends = parent is EnumDeclaration -// ? null -// : (parent as ClassDeclaration).extendsClause; -// Variable $super; -// DeclarationOrPrefix? extendsWhat; - -// final argTypes = []; -// final namedArgTypes = {}; - -// var constructorName = $superInitializer?.constructorName?.name ?? ''; -// // final bool doesExtendBridge; -// if ($extends == null) { -// $super = BuiltinValue().push(ctx); -// // doesExtendBridge = false; -// } else { -// extendsWhat = ctx -// .visibleDeclarations[ctx.library]![$extends.superclass.name2.lexeme]!; - -// final decl = extendsWhat.declaration!; -// // if (!decl.isBridge) { -// // final $doesExtendBridge = _doesExtendBridge(decl, ctx); -// // doesExtendBridge = $doesExtendBridge[0] as bool; -// // if (doesExtendBridge) { -// // extendsWhat = $doesExtendBridge[1] as DeclarationOrPrefix; -// // $extends = $doesExtendBridge[2] as ExtendsClause; -// // } -// // } else { -// // doesExtendBridge = false; -// // } - -// if (decl.isBridge) { -// ctx.pushOp(PushBridgeSuperShim.make(), PushBridgeSuperShim.length); -// $super = Variable.alloc(ctx, CoreTypes.dynamic.ref(ctx)); -// } else { -// final extendsType = TypeRef.lookupDeclaration( -// ctx, ctx.library, decl.declaration as ClassDeclaration); - -// AlwaysReturnType? mReturnType; - -// if ($superInitializer != null) { -// final _constructor = ctx.topLevelDeclarationsMap[decl.sourceLib]![ -// '${extendsType.name}.$constructorName']!; -// final constructor = _constructor.declaration as ConstructorDeclaration; - -// final argsPair = compileArgumentList( -// ctx, -// $superInitializer.argumentList, -// decl.sourceLib, -// constructor.parameters.parameters, -// constructor, -// superParams: superParams, -// source: $superInitializer); -// final _args = argsPair.first; -// final _namedArgs = argsPair.second; - -// argTypes.addAll(_args.map((e) => e.type).toList()); -// namedArgTypes -// .addAll(_namedArgs.map((key, value) => MapEntry(key, value.type))); -// } - -// final method = -// IdentifierReference(null, '${extendsType.name}.$constructorName') -// .getValue(ctx); -// if (method.methodOffset == null) { -// throw CompileError( -// 'Cannot call $constructorName as it is not a valid method'); -// } - -// final offset = method.methodOffset!; -// final loc = ctx.pushOp(Call.make(offset.offset ?? -1), Call.length); -// if (offset.offset == null) { -// ctx.offsetTracker.setOffset(loc, offset); -// } - -// mReturnType = method.methodReturnType -// ?.toAlwaysReturnType(ctx, clsType, argTypes, namedArgTypes) ?? -// AlwaysReturnType(CoreTypes.dynamic.ref(ctx), true); - -// // if (doesExtendBridge) { -// // ctx.pushOp(PushBridgeSuperShim.make(), PushBridgeSuperShim.length); -// // } else { -// ctx.pushOp(PushReturnValue.make(), PushReturnValue.LEN); -// // } -// $super = -// Variable.alloc(ctx, mReturnType.type ?? CoreTypes.dynamic.ref(ctx)); -// } -// } - -// final op = CreateClass.make(ctx.library, $super.scopeFrameOffset, -// parent.name.lexeme, fieldIdx + (isEnum ? 2 : 0)); -// ctx.pushOp(op, CreateClass.len(op)); -// final instOffset = ctx.scopeFrameOffset++; - -// if (parent is EnumDeclaration) { -// /// Add implicit index and name fields -// ctx.inferredFieldTypes -// .putIfAbsent(ctx.library, () => {}) -// .putIfAbsent(ctx.currentClass!.name.lexeme, () => {}) -// ..['index'] = CoreTypes.int.ref(ctx) -// ..['name'] = CoreTypes.string.ref(ctx); -// } - -// if (parent is EnumDeclaration) { -// ctx.pushOp(SetObjectPropertyImpl.make(instOffset, 0, 0), -// SetObjectPropertyImpl.length); -// ctx.pushOp(SetObjectPropertyImpl.make(instOffset, 1, 1), -// SetObjectPropertyImpl.length); -// } - -// for (final fieldFormal in fieldFormalNames) { -// ctx.pushOp( -// SetObjectPropertyImpl.make(instOffset, fieldIndices[fieldFormal]!, -// ctx.lookupLocal(fieldFormal)!.scopeFrameOffset), -// SetObjectPropertyImpl.length); -// } - -// final usedNames = {...fieldFormalNames}; - -// for (final init in otherInitializers) { -// if (init is ConstructorFieldInitializer) { -// final fType = TypeRef.lookupFieldType( -// ctx, -// TypeRef.lookupDeclaration(ctx, ctx.library, parent), -// init.fieldName.name, -// source: init); -// final V = compileExpression(init.expression, ctx, fType).boxIfNeeded(ctx); -// ctx.pushOp( -// SetObjectPropertyImpl.make(instOffset, -// fieldIndices[init.fieldName.name]!, V.scopeFrameOffset), -// SetObjectPropertyImpl.length); -// usedNames.add(init.fieldName.name); -// } else { -// throw CompileError('${init.runtimeType} initializer is not supported'); -// } -// } - -// _compileUnusedFields(ctx, fields, {}, instOffset); - -// final body = d.body; -// if (d.factoryKeyword == null && !(body is EmptyFunctionBody)) { -// ctx.beginAllocScope(); -// ctx.setLocal('#this', Variable(instOffset, TypeRef.$this(ctx)!)); -// if (body is BlockFunctionBody) { -// compileBlock( -// body.block, AlwaysReturnType(CoreTypes.voidType.ref(ctx), false), ctx, -// name: '$n()'); -// } else if (body is ExpressionFunctionBody) { -// final V = compileExpression(body.expression, ctx); -// doReturn(ctx, AlwaysReturnType(CoreTypes.voidType.ref(ctx), false), V); -// } -// ctx.endAllocScope(); -// } - -// if ($extends != null && extendsWhat!.declaration!.isBridge) { -// final decl = extendsWhat.declaration!; -// final bridge = decl.bridge! as BridgeClassDef; - -// if (!bridge.bridge) { -// throw CompileError( -// 'Bridge class ${$extends.superclass} is a wrapper, not a bridge, so you can\'t extend it'); -// } - -// if ($superInitializer != null) { -// final constructor = bridge.constructors[constructorName]!; -// final argsPair = compileArgumentListWithBridge( -// ctx, $superInitializer.argumentList, constructor.functionDescriptor); -// final _args = argsPair.first; -// final _namedArgs = argsPair.second; -// argTypes.addAll(_args.map((e) => e.type).toList()); -// namedArgTypes -// .addAll(_namedArgs.map((key, value) => MapEntry(key, value.type))); -// } - -// final op = BridgeInstantiate.make( -// instOffset, -// ctx.bridgeStaticFunctionIndices[decl.sourceLib]![ -// '${$extends.superclass.name2.value()}.$constructorName']!); -// ctx.pushOp(op, BridgeInstantiate.len(op)); - -// final bridgeInst = Variable.alloc(ctx, CoreTypes.dynamic.ref(ctx)); - -// ctx.pushOp( -// ParentBridgeSuperShim.make( -// $super.scopeFrameOffset, bridgeInst.scopeFrameOffset), -// ParentBridgeSuperShim.LEN); - -// ctx.pushOp(Return.make(bridgeInst.scopeFrameOffset), Return.LEN); -// } else { -// ctx.pushOp(Return.make(instOffset), Return.LEN); -// } - -// ctx.endAllocScope(popValues: false); -// } - -// void compileDefaultConstructor(CompilerContext ctx, -// NamedCompilationUnitMember parent, List fields) { -// final parentName = parent.name.lexeme; -// final n = '$parentName.'; - -// ctx.topLevelDeclarationPositions[ctx.library]![n] = -// beginMethod(ctx, parent, parent.offset, '$n()'); - -// final isEnum = parent is EnumDeclaration; -// ctx.beginAllocScope(existingAllocLen: isEnum ? 2 : 0); -// ctx.scopeFrameOffset += isEnum ? 2 : 0; - -// final fieldIndices = _getFieldIndices(fields); -// final fieldIdx = fieldIndices.length; - -// final $extends = parent is EnumDeclaration -// ? null -// : (parent as ClassDeclaration).extendsClause; -// Variable $super; -// DeclarationOrPrefix? extendsWhat; - -// final argTypes = []; -// final namedArgTypes = {}; - -// final constructorName = ''; - -// if ($extends == null) { -// $super = BuiltinValue().push(ctx); -// } else { -// extendsWhat = ctx -// .visibleDeclarations[ctx.library]![$extends.superclass.name2.lexeme]!; - -// final decl = extendsWhat.declaration!; - -// if (decl.isBridge) { -// ctx.pushOp(PushBridgeSuperShim.make(), PushBridgeSuperShim.length); -// $super = Variable.alloc(ctx, CoreTypes.dynamic.ref(ctx)); -// } else { -// final extendsType = TypeRef.lookupDeclaration( -// ctx, ctx.library, decl.declaration as ClassDeclaration); - -// AlwaysReturnType? mReturnType; - -// final method = -// IdentifierReference(null, '${extendsType.name}.$constructorName') -// .getValue(ctx); -// if (method.methodOffset == null) { -// throw CompileError( -// 'Cannot call $constructorName as it is not a valid method'); -// } - -// final offset = method.methodOffset!; -// final loc = ctx.pushOp(Call.make(offset.offset ?? -1), Call.length); -// if (offset.offset == null) { -// ctx.offsetTracker.setOffset(loc, offset); -// } -// final clsType = TypeRef.lookupDeclaration(ctx, ctx.library, parent); -// mReturnType = method.methodReturnType -// ?.toAlwaysReturnType(ctx, clsType, argTypes, namedArgTypes) ?? -// AlwaysReturnType(CoreTypes.dynamic.ref(ctx), true); - -// ctx.pushOp(PushReturnValue.make(), PushReturnValue.LEN); -// $super = -// Variable.alloc(ctx, mReturnType.type ?? CoreTypes.dynamic.ref(ctx)); -// } -// } - -// final op = CreateClass.make(ctx.library, $super.scopeFrameOffset, -// parent.name.lexeme, fieldIdx + (isEnum ? 2 : 0)); -// ctx.pushOp(op, CreateClass.len(op)); -// final instOffset = ctx.scopeFrameOffset++; - -// if (parent is EnumDeclaration) { -// /// Add implicit index and name fields -// ctx.inferredFieldTypes -// .putIfAbsent(ctx.library, () => {}) -// .putIfAbsent(ctx.currentClass!.name.lexeme, () => {}) -// ..['index'] = CoreTypes.int.ref(ctx) -// ..['name'] = CoreTypes.string.ref(ctx); -// } - -// if (parent is EnumDeclaration) { -// ctx.pushOp(SetObjectPropertyImpl.make(instOffset, 0, 0), -// SetObjectPropertyImpl.length); -// ctx.pushOp(SetObjectPropertyImpl.make(instOffset, 1, 1), -// SetObjectPropertyImpl.length); -// } - -// _compileUnusedFields( -// ctx, -// fields, -// parent is EnumDeclaration ? {'index', 'name'} : {}, -// instOffset, -// parent is EnumDeclaration ? 2 : 0); - -// if ($extends != null && extendsWhat!.declaration!.isBridge) { -// final decl = extendsWhat.declaration!; -// final bridge = decl.bridge! as BridgeClassDef; - -// if (!bridge.bridge) { -// throw CompileError( -// 'Bridge class ${$extends.superclass} is a wrapper, not a bridge, so you can\'t extend it'); -// } - -// final op = BridgeInstantiate.make( -// instOffset, -// ctx.bridgeStaticFunctionIndices[decl.sourceLib]![ -// '${$extends.superclass.name2.lexeme}.$constructorName']!); -// ctx.pushOp(op, BridgeInstantiate.len(op)); -// final bridgeInst = Variable.alloc(ctx, CoreTypes.dynamic.ref(ctx)); - -// ctx.pushOp( -// ParentBridgeSuperShim.make( -// $super.scopeFrameOffset, bridgeInst.scopeFrameOffset), -// ParentBridgeSuperShim.LEN); - -// ctx.pushOp(Return.make(bridgeInst.scopeFrameOffset), Return.LEN); -// } else { -// ctx.pushOp(Return.make(instOffset), Return.LEN); -// } - -// ctx.endAllocScope(popValues: false); -// } - -// Map _getFieldIndices(List fields, -// [int fieldIdx = 0]) { -// final fieldIndices = {}; -// var _fieldIdx = fieldIdx; -// for (final fd in fields) { -// for (final field in fd.fields.variables) { -// fieldIndices[field.name.lexeme] = _fieldIdx; -// _fieldIdx++; -// } -// } -// return fieldIndices; -// } - -// void _compileUnusedFields(CompilerContext ctx, List fields, -// Set usedNames, int instOffset, -// [int fieldIdx = 0]) { -// var _fieldIdx = fieldIdx; -// for (final fd in fields) { -// for (final field in fd.fields.variables) { -// if (!usedNames.contains(field.name.lexeme) && field.initializer != null) { -// final V = compileExpression(field.initializer!, ctx).boxIfNeeded(ctx); -// ctx.inferredFieldTypes.putIfAbsent(ctx.library, () => {}).putIfAbsent( -// ctx.currentClass!.name.lexeme, () => {})[field.name.lexeme] = -// V.type; -// ctx.pushOp( -// SetObjectPropertyImpl.make( -// instOffset, _fieldIdx, V.scopeFrameOffset), -// SetObjectPropertyImpl.length); -// } -// _fieldIdx++; -// } -// } -// } - -// List _doesExtendBridge( -// DeclarationOrBridge? decl, CompilerContext ctx) { -// if (decl != null && decl.declaration is ClassDeclaration) { -// var $decl = ctx.visibleDeclarations[decl.sourceLib]?[ -// (decl.declaration as ClassDeclaration) -// .extendsClause -// ?.superclass -// .name2 -// .lexeme]; -// if ($decl != null && $decl.declaration!.isBridge) { -// return [ -// true, -// $decl, -// (decl.declaration as ClassDeclaration).extendsClause -// ]; -// } else if ($decl == null || $decl.declaration == null) { -// return [false]; -// } -// return _doesExtendBridge($decl.declaration!, ctx); -// } else { -// return [false]; -// } -// } diff --git a/lib/src/eval/shared/stdlib/core/base.dart b/lib/src/eval/shared/stdlib/core/base.dart index c352ce9b..ba619ea6 100644 --- a/lib/src/eval/shared/stdlib/core/base.dart +++ b/lib/src/eval/shared/stdlib/core/base.dart @@ -3,7 +3,6 @@ import 'package:dart_eval/src/eval/runtime/exception.dart'; import 'package:dart_eval/src/eval/shared/stdlib/core/collection.dart'; import 'package:dart_eval/src/eval/shared/stdlib/core/object.dart'; import 'package:dart_eval/src/eval/shared/stdlib/core/pattern.dart'; -import 'package:dart_eval/src/eval/utils/wap_helper.dart'; import 'num.dart'; const $dynamicCls = BridgeClassDef( @@ -236,7 +235,7 @@ class $String implements $Instance { case 'codeUnitAt': return __codeUnitAt; case 'codeUnits': - return wrapList($value.codeUnits, (e) => $int(e)); + return $List.wrap($value.codeUnits.map((e) => $int(e)).toList()); case 'compareTo': return __compareTo; case 'contains': diff --git a/lib/src/eval/shared/stdlib/core/future.dart b/lib/src/eval/shared/stdlib/core/future.dart index 679ee0be..19295383 100644 --- a/lib/src/eval/shared/stdlib/core/future.dart +++ b/lib/src/eval/shared/stdlib/core/future.dart @@ -3,6 +3,7 @@ import 'dart:async'; import 'package:dart_eval/dart_eval_bridge.dart'; +import 'package:dart_eval/src/eval/shared/stdlib/async/stream.dart'; import 'package:dart_eval/stdlib/core.dart'; /// Wrapper for [Future] @@ -10,30 +11,334 @@ class $Future implements Future, $Instance { /// Configure [$Future] for runtime in a [Runtime] static void configureForRuntime(Runtime runtime) { runtime.registerBridgeFunc( - 'dart:core', 'Future.delayed', const _$Future_delayed().call); + $type.spec!.library, 'Future.microtask', __$Future$microtask.call, + isBridge: false); + runtime.registerBridgeFunc( + $type.spec!.library, 'Future.sync', __$Future$sync.call, + isBridge: false); + runtime.registerBridgeFunc( + $type.spec!.library, 'Future.value', __$Future$value.call, + isBridge: false); + runtime.registerBridgeFunc( + $type.spec!.library, 'Future.error', __$Future$error.call, + isBridge: false); + runtime.registerBridgeFunc( + $type.spec!.library, 'Future.delayed', __$Future$delayed.call, + isBridge: false); + runtime.registerBridgeFunc( + $type.spec!.library, 'Future.wait', __$static$method$wait.call, + isBridge: false); + runtime.registerBridgeFunc( + $type.spec!.library, 'Future.any', __$static$method$any.call, + isBridge: false); + runtime.registerBridgeFunc( + $type.spec!.library, 'Future.forEach', __$static$method$forEach.call, + isBridge: false); + runtime.registerBridgeFunc( + $type.spec!.library, 'Future.doWhile', __$static$method$doWhile.call, + isBridge: false); } static const $declaration = BridgeClassDef( BridgeClassType(BridgeTypeRef(CoreTypes.future), isAbstract: true), constructors: { - 'delayed': BridgeConstructorDef(BridgeFunctionDef( - returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.future)), + 'microtask': BridgeConstructorDef( + BridgeFunctionDef( + generics: { + 'T': BridgeGenericParam(), + }, + returns: BridgeTypeAnnotation($type), params: [ BridgeParameter( - 'duration', BridgeTypeAnnotation($Duration.$type), false) + 'computation', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.function, []), + nullable: false), + false) ], - namedParams: [])) - }, - methods: { - 'then': BridgeMethodDef(BridgeFunctionDef( - returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.future)), + namedParams: [], + ), + isFactory: true, + ), + 'sync': BridgeConstructorDef( + BridgeFunctionDef( + generics: { + 'T': BridgeGenericParam(), + }, + returns: BridgeTypeAnnotation($type), params: [ BridgeParameter( - 'onValue', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.function)), + 'computation', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.function, []), + nullable: false), false) ], - namedParams: [])) + namedParams: [], + ), + isFactory: true, + ), + 'value': BridgeConstructorDef( + BridgeFunctionDef( + generics: { + 'T': BridgeGenericParam(), + }, + returns: BridgeTypeAnnotation($type), + params: [ + BridgeParameter( + 'value', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.dynamic, []), + nullable: true), + true) + ], + namedParams: [], + ), + isFactory: true, + ), + 'error': BridgeConstructorDef( + BridgeFunctionDef( + generics: { + 'T': BridgeGenericParam(), + }, + returns: BridgeTypeAnnotation($type), + params: [ + BridgeParameter( + 'error', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.object, []), + nullable: false), + false), + BridgeParameter( + 'stackTrace', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.stackTrace, []), + nullable: true), + true) + ], + namedParams: [], + ), + isFactory: true, + ), + 'delayed': BridgeConstructorDef( + BridgeFunctionDef( + generics: { + 'T': BridgeGenericParam(), + }, + returns: BridgeTypeAnnotation($type), + params: [ + BridgeParameter( + 'duration', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.duration, []), + nullable: false), + false), + BridgeParameter( + 'computation', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.function, []), + nullable: false), + true) + ], + namedParams: [], + ), + isFactory: true, + ) + }, + methods: { + 'wait': BridgeMethodDef( + BridgeFunctionDef( + generics: { + 'T': BridgeGenericParam(), + }, + returns: BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.future, [ + BridgeTypeRef(CoreTypes.list, [BridgeTypeRef.ref('T', [])]), + ]), + nullable: false), + params: [ + BridgeParameter( + 'futures', + BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.iterable, [ + BridgeTypeRef( + CoreTypes.future, [BridgeTypeRef.ref('T', [])]), + ]), + nullable: false), + false) + ], + namedParams: [ + BridgeParameter( + 'eagerError', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool, []), + nullable: false), + true), + BridgeParameter( + 'cleanUp', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.function, []), + nullable: false), + true) + ], + ), + isStatic: true), + 'any': BridgeMethodDef( + BridgeFunctionDef( + generics: { + 'T': BridgeGenericParam(), + }, + returns: BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.future, [BridgeTypeRef.ref('T', [])]), + nullable: false), + params: [ + BridgeParameter( + 'futures', + BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.iterable, [ + BridgeTypeRef( + CoreTypes.future, [BridgeTypeRef.ref('T', [])]), + ]), + nullable: false), + false) + ], + namedParams: [], + ), + isStatic: true), + 'forEach': BridgeMethodDef( + BridgeFunctionDef( + generics: { + 'T': BridgeGenericParam(), + }, + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.future), + nullable: false), + params: [ + BridgeParameter( + 'elements', + BridgeTypeAnnotation( + BridgeTypeRef( + CoreTypes.iterable, [BridgeTypeRef.ref('T', [])]), + nullable: false), + false), + BridgeParameter( + 'action', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.function, []), + nullable: false), + false) + ], + namedParams: [], + ), + isStatic: true), + 'doWhile': BridgeMethodDef( + BridgeFunctionDef( + generics: { + 'T': BridgeGenericParam(), + }, + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.future), + nullable: false), + params: [ + BridgeParameter( + 'action', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.function), + nullable: false), + false) + ], + namedParams: [], + ), + isStatic: true), + 'then': BridgeMethodDef( + BridgeFunctionDef( + generics: { + 'R': BridgeGenericParam(), + }, + returns: BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.future, [BridgeTypeRef.ref('R', [])]), + nullable: false), + params: [ + BridgeParameter( + 'onValue', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.function), + nullable: false), + false) + ], + namedParams: [ + BridgeParameter( + 'onError', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.function, []), + nullable: true), + true) + ], + ), + isStatic: false), + 'catchError': BridgeMethodDef( + BridgeFunctionDef( + generics: { + 'T': BridgeGenericParam(), + }, + returns: BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.future, [BridgeTypeRef.ref('T', [])]), + nullable: false), + params: [ + BridgeParameter( + 'onError', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.function, []), + nullable: false), + false) + ], + namedParams: [ + BridgeParameter( + 'test', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.function, []), + nullable: false), + true) + ], + ), + isStatic: false), + 'whenComplete': BridgeMethodDef( + BridgeFunctionDef( + generics: { + 'T': BridgeGenericParam(), + }, + returns: BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.future, [BridgeTypeRef.ref('T', [])]), + nullable: false), + params: [ + BridgeParameter( + 'action', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.function), + nullable: false), + false) + ], + namedParams: [], + ), + isStatic: false), + 'asStream': BridgeMethodDef( + BridgeFunctionDef( + generics: { + 'T': BridgeGenericParam(), + }, + returns: BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.stream, [BridgeTypeRef.ref('T', [])]), + nullable: false), + params: [], + namedParams: [], + ), + isStatic: false), + 'timeout': BridgeMethodDef( + BridgeFunctionDef( + generics: { + 'T': BridgeGenericParam(), + }, + returns: BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.future, [BridgeTypeRef.ref('T', [])]), + nullable: false), + params: [ + BridgeParameter( + 'timeLimit', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.duration, []), + nullable: false), + false) + ], + namedParams: [ + BridgeParameter( + 'onTimeout', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.function), + nullable: false), + true) + ], + ), + isStatic: false), }, getters: {}, setters: {}, @@ -51,18 +356,30 @@ class $Future implements Future, $Instance { final $Instance _superclass; + static const $type = BridgeTypeRef(CoreTypes.future); + @override $Value? $getProperty(Runtime runtime, String identifier) { switch (identifier) { + case 'asStream': + return __$asStream; + case 'catchError': + return __$catchError; case 'then': - return __then; + return __$then; + case 'timeout': + return __$timeout; + case 'whenComplete': + return __$whenComplete; default: return _superclass.$getProperty(runtime, identifier); } } @override - void $setProperty(Runtime runtime, String identifier, $Value value) {} + void $setProperty(Runtime runtime, String identifier, $Value value) { + _superclass.$setProperty(runtime, identifier, value); + } @override int $getRuntimeType(Runtime runtime) => runtime.lookupType(CoreTypes.future); @@ -70,17 +387,30 @@ class $Future implements Future, $Instance { @override Stream asStream() => $value.asStream(); + static const __$asStream = $Function(_$asStream); + static $Value? _$asStream( + Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as Future; + final $result = $this.asStream(); + return $Stream.wrap($result); + } + @override Future catchError(Function onError, {bool Function(Object error)? test}) => $value.catchError(onError, test: test); - static const $Function __then = $Function(_then); + static const __$catchError = $Function(_$catchError); + static $Value? _$catchError( + Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as Future; + final onError = args[0]?.$reified as Function; + final test = args[1] as EvalCallable?; + final $result = $this.catchError(onError, + test: test == null + ? null + : (error) => test + .call(runtime, target, [runtime.wrap(error)])?.$value as bool); - static $Value? _then(Runtime runtime, $Value? target, List<$Value?> args) { - final $t = target as $Future; - final $then = args[0] as EvalFunction; - final $result = ($t.$value) - .then((value) => $then.call(runtime, target, [runtime.wrap(value)])); return $Future.wrap($result); } @@ -89,20 +419,137 @@ class $Future implements Future, $Instance { {Function? onError}) => $value.then(onValue, onError: onError); + static const __$then = $Function(_$then); + static $Value? _$then(Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as Future; + final onValue = args[0] as EvalCallable; + final onError = args[1] as EvalCallable?; + final $result = $this.then( + (value) => onValue.call(runtime, target, [runtime.wrap(value)]), + onError: onError == null + ? null + : (err, stack) { + onError.call(runtime, target, + [runtime.wrap(err), $StackTrace.wrap(stack)]); + }, + ); + return $Future.wrap($result); + } + @override Future timeout(Duration timeLimit, {FutureOr Function()? onTimeout}) => $value.timeout(timeLimit, onTimeout: onTimeout); + static const __$timeout = $Function(_$timeout); + static $Value? _$timeout( + Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as Future; + final timeLimit = args[0]!.$value as Duration; + final onTimeout = args[1] as EvalCallable?; + final $result = $this.timeout(timeLimit, + onTimeout: onTimeout == null + ? null + : () => onTimeout.call(runtime, target, [])); + return $Future.wrap($result); + } + @override Future whenComplete(FutureOr Function() action) => $value.whenComplete(action); -} -class _$Future_delayed implements EvalCallable { - const _$Future_delayed(); + static const __$whenComplete = $Function(_$whenComplete); + static $Value? _$whenComplete( + Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as Future; + final action = args[0] as EvalCallable; + final $result = $this.whenComplete(() => action.call(runtime, target, [])); + return $Future.wrap($result); + } + + static const __$static$method$wait = $Function(_$static$method$wait); + static $Value? _$static$method$wait( + Runtime runtime, $Value? target, List<$Value?> args) { + final futures = (args[0]!.$value as Iterable).cast(); + final eagerError = (args[1]?.$value as bool?) ?? false; + final cleanUp = args[2] as EvalCallable?; + final $result = Future.wait( + futures, + eagerError: eagerError, + cleanUp: cleanUp == null + ? null + : (value) => cleanUp.call(runtime, target, [runtime.wrap(value)]), + ); + return $Future.wrap($result) as $Value?; + } - @override - $Value? call(Runtime runtime, $Value? target, List<$Value?> args) { - return $Future.wrap(Future.delayed(args[0]!.$value)); + static const __$static$method$any = $Function(_$static$method$any); + static $Value? _$static$method$any( + Runtime runtime, $Value? target, List<$Value?> args) { + final futures = (args[0]!.$value as Iterable).cast(); + final $result = Future.any(futures); + return $Future.wrap($result); + } + + static const __$static$method$forEach = $Function(_$static$method$forEach); + static $Value? _$static$method$forEach( + Runtime runtime, $Value? target, List<$Value?> args) { + final elements = args[0]!.$value as Iterable; + final action = args[1] as EvalCallable; + final $result = Future.forEach( + elements, + (element) => action.call(runtime, target, [element]), + ); + return $Future.wrap($result); + } + + static const __$static$method$doWhile = $Function(_$static$method$doWhile); + static $Value? _$static$method$doWhile( + Runtime runtime, $Value? target, List<$Value?> args) { + final action = args[0] as EvalCallable; + final $result = + Future.doWhile(() => action.call(runtime, target, [])!.$value); + return $Future.wrap($result); + } + + static const __$Future$microtask = $Function(_$Future$microtask); + static $Value? _$Future$microtask( + Runtime runtime, $Value? target, List<$Value?> args) { + final computation = args[0] as EvalCallable; + return $Future + .wrap(Future.microtask(() => computation.call(runtime, target, []))); + } + + static const __$Future$sync = $Function(_$Future$sync); + static $Value? _$Future$sync( + Runtime runtime, $Value? target, List<$Value?> args) { + final computation = args[0] as EvalCallable; + return $Future + .wrap(Future.sync(() => computation.call(runtime, target, []))); + } + + static const __$Future$value = $Function(_$Future$value); + static $Value? _$Future$value( + Runtime runtime, $Value? target, List<$Value?> args) { + final value = args[0]; + return $Future.wrap(Future.value(value)); + } + + static const __$Future$error = $Function(_$Future$error); + static $Value? _$Future$error( + Runtime runtime, $Value? target, List<$Value?> args) { + final error = args[0]!.$value as Object; + final stackTrace = args[1]?.$value as StackTrace?; + return $Future.wrap(Future.error(error, stackTrace)); + } + + static const __$Future$delayed = $Function(_$Future$delayed); + static $Value? _$Future$delayed( + Runtime runtime, $Value? target, List<$Value?> args) { + final duration = args[0]!.$value as Duration; + final computation = args[1] as EvalCallable?; + return $Future.wrap(Future.delayed( + duration, + computation == null ? null : () => computation.call(runtime, target, []), + )); } } diff --git a/lib/src/eval/shared/stdlib/core/uri.dart b/lib/src/eval/shared/stdlib/core/uri.dart index 0187e5e7..592a8222 100644 --- a/lib/src/eval/shared/stdlib/core/uri.dart +++ b/lib/src/eval/shared/stdlib/core/uri.dart @@ -1,422 +1,875 @@ import 'dart:convert'; +import 'dart:typed_data'; import 'package:dart_eval/dart_eval_bridge.dart'; -import 'package:dart_eval/src/eval/utils/wap_helper.dart'; import 'package:dart_eval/stdlib/core.dart'; +import 'package:dart_eval/stdlib/typed_data.dart'; /// dart_eval wrapper for [Uri] class $Uri implements $Instance { - /// Configures the runtime for the [Uri] class + /// Configure the [$Uri] wrapper for use in a [Runtime] + static void configureForCompile(BridgeDeclarationRegistry registry) { + registry.defineBridgeClass($declaration); + } + static void configureForRuntime(Runtime runtime) { - runtime.registerBridgeFunc('dart:core', 'Uri.parse', $parse); - runtime.registerBridgeFunc('dart:core', 'Uri.tryParse', $tryParse); - runtime.registerBridgeFunc('dart:core', 'Uri.encodeFull', $encodeFull); - runtime.registerBridgeFunc('dart:core', 'Uri.decodeFull', $decodeFull); + runtime.registerBridgeFunc($type.spec!.library, 'Uri.', __$Uri$new.call, + isBridge: false); + runtime.registerBridgeFunc( + $type.spec!.library, 'Uri.http', __$Uri$http.call, + isBridge: false); runtime.registerBridgeFunc( - 'dart:core', 'Uri.encodeComponent', $encodeComponent); + $type.spec!.library, 'Uri.https', __$Uri$https.call, + isBridge: false); runtime.registerBridgeFunc( - 'dart:core', 'Uri.decodeComponent', $decodeComponent); + $type.spec!.library, 'Uri.file', __$Uri$file.call, + isBridge: false); runtime.registerBridgeFunc( - 'dart:core', 'Uri.decodeQueryComponent', $decodeQueryComponent); + $type.spec!.library, 'Uri.directory', __$Uri$directory.call, + isBridge: false); runtime.registerBridgeFunc( - 'dart:core', 'Uri.encodeQueryComponent', $encodeQueryComponent); + $type.spec!.library, 'Uri.dataFromString', __$Uri$dataFromString.call, + isBridge: false); runtime.registerBridgeFunc( - 'dart:core', 'Uri.dataFromBytes', $dataFromBytes); + $type.spec!.library, 'Uri.dataFromBytes', __$Uri$dataFromBytes.call, + isBridge: false); runtime.registerBridgeFunc( - 'dart:core', 'Uri.dataFromString', $dataFromString); - runtime.registerBridgeFunc('dart:core', 'Uri.directory', $directory); - runtime.registerBridgeFunc('dart:core', 'Uri.file', $file); - runtime.registerBridgeFunc('dart:core', 'Uri.http', $http); - runtime.registerBridgeFunc('dart:core', 'Uri.https', $https); + $type.spec!.library, 'Uri.base*g', __$static$getter$base.call, + isBridge: false); runtime.registerBridgeFunc( - 'dart:core', 'Uri.parseIPv4Address', $parseIPv4Address); + $type.spec!.library, 'Uri.parse', __$static$method$parse.call, + isBridge: false); runtime.registerBridgeFunc( - 'dart:core', 'Uri.parseIPv6Address', $parseIPv6Address); + $type.spec!.library, 'Uri.tryParse', __$static$method$tryParse.call, + isBridge: false); + runtime.registerBridgeFunc($type.spec!.library, 'Uri.encodeComponent', + __$static$method$encodeComponent.call, + isBridge: false); + runtime.registerBridgeFunc($type.spec!.library, 'Uri.encodeQueryComponent', + __$static$method$encodeQueryComponent.call, + isBridge: false); + runtime.registerBridgeFunc($type.spec!.library, 'Uri.decodeComponent', + __$static$method$decodeComponent.call, + isBridge: false); + runtime.registerBridgeFunc($type.spec!.library, 'Uri.decodeQueryComponent', + __$static$method$decodeQueryComponent.call, + isBridge: false); runtime.registerBridgeFunc( - 'dart:core', 'Uri.splitQueryString', $splitQueryString); + $type.spec!.library, 'Uri.encodeFull', __$static$method$encodeFull.call, + isBridge: false); + runtime.registerBridgeFunc( + $type.spec!.library, 'Uri.decodeFull', __$static$method$decodeFull.call, + isBridge: false); + runtime.registerBridgeFunc($type.spec!.library, 'Uri.splitQueryString', + __$static$method$splitQueryString.call, + isBridge: false); + runtime.registerBridgeFunc($type.spec!.library, 'Uri.parseIPv4Address', + __$static$method$parseIPv4Address.call, + isBridge: false); + runtime.registerBridgeFunc($type.spec!.library, 'Uri.parseIPv6Address', + __$static$method$parseIPv6Address.call, + isBridge: false); } - /// Bridge type spec for [$Uri] + late final $Instance _superclass = $Object($value); + static const $type = BridgeTypeRef(CoreTypes.uri); - /// Bridge class declaration for [$Uri] - static const $declaration = BridgeClassDef(BridgeClassType($type), - constructors: {}, - methods: { - 'parse': BridgeMethodDef( - BridgeFunctionDef(returns: BridgeTypeAnnotation($type), params: [ - BridgeParameter('uri', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string)), false) - ], namedParams: []), - isStatic: true), - 'tryParse': BridgeMethodDef( - BridgeFunctionDef( - returns: BridgeTypeAnnotation($type, nullable: true), - params: [ - BridgeParameter( - 'uri', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string)), - false) - ], - namedParams: []), - isStatic: true), - 'encodeFull': BridgeMethodDef( - BridgeFunctionDef( - returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string)), - params: [ - BridgeParameter( - 'uri', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string)), - false) - ], - namedParams: []), - isStatic: true), - 'decodeFull': BridgeMethodDef( - BridgeFunctionDef( - returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string)), - params: [ - BridgeParameter( - 'uri', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string)), - false) - ], - namedParams: []), - isStatic: true), - 'encodeComponent': BridgeMethodDef( - BridgeFunctionDef( - returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string)), - params: [ - BridgeParameter( - 'component', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string)), - false) - ], - namedParams: []), - isStatic: true), - 'decodeComponent': BridgeMethodDef( - BridgeFunctionDef( - returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string)), - params: [ - BridgeParameter( - 'encodedComponent', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string)), - false) - ], - namedParams: []), - isStatic: true), - 'decodeQueryComponent': BridgeMethodDef( - BridgeFunctionDef( - returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string)), - params: [ - BridgeParameter( - 'encodedComponent', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string)), - false), - ], - namedParams: [ - BridgeParameter( - 'encoding', - BridgeTypeAnnotation( - BridgeTypeRef(ConvertTypes.encoding)), - true) - ]), - isStatic: true), - 'encodeQueryComponent': BridgeMethodDef( - BridgeFunctionDef( - returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string)), - params: [ - BridgeParameter( - 'component', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string)), - false), - ], - namedParams: [ - BridgeParameter( - 'encoding', - BridgeTypeAnnotation( - BridgeTypeRef(ConvertTypes.encoding)), - true) + static const $declaration = BridgeClassDef( + BridgeClassType( + $type, + $extends: null, + $implements: [], + isAbstract: true, + ), + constructors: { + '': BridgeConstructorDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation($type), + params: [], + namedParams: [ + BridgeParameter( + 'scheme', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: true), + true), + BridgeParameter( + 'userInfo', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: true), + true), + BridgeParameter( + 'host', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: true), + true), + BridgeParameter( + 'port', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int, []), + nullable: true), + true), + BridgeParameter( + 'path', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: true), + true), + BridgeParameter( + 'pathSegments', + BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.iterable, [ + BridgeTypeRef(CoreTypes.string, []), + ]), + nullable: true), + true), + BridgeParameter( + 'query', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: true), + true), + BridgeParameter( + 'queryParameters', + BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.map, [ + BridgeTypeRef(CoreTypes.string, []), + BridgeTypeRef(CoreTypes.dynamic, []), + ]), + nullable: true), + true), + BridgeParameter( + 'fragment', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: true), + true) + ], + ), + isFactory: true, + ), + 'http': BridgeConstructorDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation($type), + params: [ + BridgeParameter( + 'authority', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: false), + false), + BridgeParameter( + 'unencodedPath', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: false), + true), + BridgeParameter( + 'queryParameters', + BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.map, [ + BridgeTypeRef(CoreTypes.string, []), + BridgeTypeRef(CoreTypes.dynamic, []), + ]), + nullable: true), + true) + ], + namedParams: [], + ), + isFactory: true, + ), + 'https': BridgeConstructorDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation($type), + params: [ + BridgeParameter( + 'authority', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: false), + false), + BridgeParameter( + 'unencodedPath', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: false), + true), + BridgeParameter( + 'queryParameters', + BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.map, [ + BridgeTypeRef(CoreTypes.string, []), + BridgeTypeRef(CoreTypes.dynamic, []), + ]), + nullable: true), + true) + ], + namedParams: [], + ), + isFactory: true, + ), + 'file': BridgeConstructorDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation($type), + params: [ + BridgeParameter( + 'path', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: false), + false) + ], + namedParams: [ + BridgeParameter( + 'windows', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool, []), + nullable: true), + true) + ], + ), + isFactory: true, + ), + 'directory': BridgeConstructorDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation($type), + params: [ + BridgeParameter( + 'path', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: false), + false) + ], + namedParams: [ + BridgeParameter( + 'windows', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool, []), + nullable: true), + true) + ], + ), + isFactory: true, + ), + 'dataFromString': BridgeConstructorDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation($type), + params: [ + BridgeParameter( + 'content', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: false), + false) + ], + namedParams: [ + BridgeParameter( + 'mimeType', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: true), + true), + BridgeParameter( + 'encoding', + BridgeTypeAnnotation(BridgeTypeRef(ConvertTypes.encoding, []), + nullable: true), + true), + BridgeParameter( + 'parameters', + BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.map, [ + BridgeTypeRef(CoreTypes.string, []), + BridgeTypeRef(CoreTypes.string, []), + ]), + nullable: true), + true), + BridgeParameter( + 'base64', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool, []), + nullable: false), + true) + ], + ), + isFactory: true, + ), + 'dataFromBytes': BridgeConstructorDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation($type), + params: [ + BridgeParameter( + 'bytes', + BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.list, [ + BridgeTypeRef(CoreTypes.int, []), + ]), + nullable: false), + false) + ], + namedParams: [ + BridgeParameter( + 'mimeType', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: false), + true), + BridgeParameter( + 'parameters', + BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.map, [ + BridgeTypeRef(CoreTypes.string, []), + BridgeTypeRef(CoreTypes.string, []), + ]), + nullable: true), + true), + BridgeParameter( + 'percentEncoded', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool, []), + nullable: false), + true) + ], + ), + isFactory: true, + ) + }, + fields: {}, + methods: { + 'parse': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.uri, []), + nullable: false), + params: [ + BridgeParameter( + 'uri', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: false), + false), + BridgeParameter( + 'start', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int, []), + nullable: false), + true), + BridgeParameter( + 'end', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int, []), + nullable: true), + true) + ], + namedParams: [], + ), + isStatic: true), + 'tryParse': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.uri, []), + nullable: true), + params: [ + BridgeParameter( + 'uri', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: false), + false), + BridgeParameter( + 'start', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int, []), + nullable: false), + true), + BridgeParameter( + 'end', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int, []), + nullable: true), + true) + ], + namedParams: [], + ), + isStatic: true), + 'encodeComponent': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: false), + params: [ + BridgeParameter( + 'component', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: false), + false) + ], + namedParams: [], + ), + isStatic: true), + 'encodeQueryComponent': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: false), + params: [ + BridgeParameter( + 'component', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: false), + false) + ], + namedParams: [ + BridgeParameter( + 'encoding', + BridgeTypeAnnotation(BridgeTypeRef(ConvertTypes.encoding, []), + nullable: false), + true) + ], + ), + isStatic: true), + 'decodeComponent': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: false), + params: [ + BridgeParameter( + 'encodedComponent', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: false), + false) + ], + namedParams: [], + ), + isStatic: true), + 'decodeQueryComponent': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: false), + params: [ + BridgeParameter( + 'encodedComponent', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: false), + false) + ], + namedParams: [ + BridgeParameter( + 'encoding', + BridgeTypeAnnotation(BridgeTypeRef(ConvertTypes.encoding, []), + nullable: false), + true) + ], + ), + isStatic: true), + 'encodeFull': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: false), + params: [ + BridgeParameter( + 'uri', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: false), + false) + ], + namedParams: [], + ), + isStatic: true), + 'decodeFull': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: false), + params: [ + BridgeParameter( + 'uri', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: false), + false) + ], + namedParams: [], + ), + isStatic: true), + 'splitQueryString': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.map, [ + BridgeTypeRef(CoreTypes.string, []), + BridgeTypeRef(CoreTypes.string, []), ]), - isStatic: true), - 'dataFromBytes': BridgeMethodDef( - BridgeFunctionDef( - returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string)), - params: [ - BridgeParameter( - 'bytes', - BridgeTypeAnnotation(BridgeTypeRef( - CoreTypes.list, [BridgeTypeRef(CoreTypes.int)])), - false), - ], - namedParams: [ - BridgeParameter( - 'mimeType', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string)), - true), - BridgeParameter( - 'parameters', - BridgeTypeAnnotation( - BridgeTypeRef(CoreTypes.map, [ - BridgeTypeRef(CoreTypes.string), - BridgeTypeRef(CoreTypes.string) - ]), - ), - true), - BridgeParameter( - 'percentEncoded', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool)), - true), + nullable: false), + params: [ + BridgeParameter( + 'query', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: false), + false) + ], + namedParams: [ + BridgeParameter( + 'encoding', + BridgeTypeAnnotation(BridgeTypeRef(ConvertTypes.encoding, []), + nullable: false), + true) + ], + ), + isStatic: true), + 'parseIPv4Address': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.list, [ + BridgeTypeRef(CoreTypes.int, []), ]), - isStatic: true), - 'dataFromString': BridgeMethodDef( - BridgeFunctionDef( - returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string)), - params: [ - BridgeParameter( - 'content', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string)), - false), - ], - namedParams: [ - BridgeParameter( - 'mimeType', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string)), - true), - BridgeParameter( - 'parameters', - BridgeTypeAnnotation( - BridgeTypeRef(CoreTypes.map, [ - BridgeTypeRef(CoreTypes.string), - BridgeTypeRef(CoreTypes.string) - ]), - nullable: true), - true), - BridgeParameter( - 'base64', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool)), - true), + nullable: false), + params: [ + BridgeParameter( + 'host', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: false), + false) + ], + namedParams: [], + ), + isStatic: true), + 'parseIPv6Address': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.list, [ + BridgeTypeRef(CoreTypes.int, []), ]), - isStatic: true), - 'directory': BridgeMethodDef( - BridgeFunctionDef( - returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string)), - params: [ - BridgeParameter( - 'path', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string)), - false), - ], - namedParams: [ - BridgeParameter('windows', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool)), true) + nullable: false), + params: [ + BridgeParameter( + 'host', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: false), + false), + BridgeParameter( + 'start', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int, []), + nullable: false), + true), + BridgeParameter( + 'end', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int, []), + nullable: true), + true) + ], + namedParams: [], + ), + isStatic: true), + 'isScheme': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool, []), + nullable: false), + params: [ + BridgeParameter( + 'scheme', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: false), + false) + ], + namedParams: [], + ), + isStatic: false), + 'toFilePath': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: false), + params: [], + namedParams: [ + BridgeParameter( + 'windows', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool, []), + nullable: true), + true) + ], + ), + isStatic: false), + 'replace': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.uri, []), + nullable: false), + params: [], + namedParams: [ + BridgeParameter( + 'scheme', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: true), + true), + BridgeParameter( + 'userInfo', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: true), + true), + BridgeParameter( + 'host', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: true), + true), + BridgeParameter( + 'port', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int, []), + nullable: true), + true), + BridgeParameter( + 'path', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: true), + true), + BridgeParameter( + 'pathSegments', + BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.iterable, [ + BridgeTypeRef(CoreTypes.string, []), + ]), + nullable: true), + true), + BridgeParameter( + 'query', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: true), + true), + BridgeParameter( + 'queryParameters', + BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.map, [ + BridgeTypeRef(CoreTypes.string, []), + BridgeTypeRef(CoreTypes.dynamic, []), + ]), + nullable: true), + true), + BridgeParameter( + 'fragment', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: true), + true) + ], + ), + isStatic: false), + 'removeFragment': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.uri, []), + nullable: false), + params: [], + namedParams: [], + ), + isStatic: false), + 'resolve': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.uri, []), + nullable: false), + params: [ + BridgeParameter( + 'reference', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: false), + false) + ], + namedParams: [], + ), + isStatic: false), + 'resolveUri': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.uri, []), + nullable: false), + params: [ + BridgeParameter( + 'reference', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.uri, []), + nullable: false), + false) + ], + namedParams: [], + ), + isStatic: false), + 'normalizePath': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.uri, []), + nullable: false), + params: [], + namedParams: [], + ), + isStatic: false), + }, + getters: { + 'base': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.uri, []), + nullable: false), + params: [], + namedParams: [], + ), + isStatic: false), + 'scheme': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: false), + params: [], + namedParams: [], + ), + isStatic: false), + 'authority': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: false), + params: [], + namedParams: [], + ), + isStatic: false), + 'userInfo': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: false), + params: [], + namedParams: [], + ), + isStatic: false), + 'host': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: false), + params: [], + namedParams: [], + ), + isStatic: false), + 'port': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int, []), + nullable: false), + params: [], + namedParams: [], + ), + isStatic: false), + 'path': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: false), + params: [], + namedParams: [], + ), + isStatic: false), + 'query': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: false), + params: [], + namedParams: [], + ), + isStatic: false), + 'fragment': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: false), + params: [], + namedParams: [], + ), + isStatic: false), + 'pathSegments': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.list, [ + BridgeTypeRef(CoreTypes.string, []), ]), - isStatic: true), - 'file': BridgeMethodDef( - BridgeFunctionDef( - returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string)), - params: [ - BridgeParameter( - 'path', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string)), - false), - ], - namedParams: [ - BridgeParameter('windows', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool)), true) + nullable: false), + params: [], + namedParams: [], + ), + isStatic: false), + 'queryParameters': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.map, [ + BridgeTypeRef(CoreTypes.string, []), + BridgeTypeRef(CoreTypes.string, []), ]), - isStatic: true), - 'http': BridgeMethodDef( - BridgeFunctionDef( - returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string)), - params: [ - BridgeParameter( - 'authority', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string)), - false), - BridgeParameter( - 'unencodedPath', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string)), - true), - BridgeParameter( - 'queryParameters', - BridgeTypeAnnotation( - BridgeTypeRef(CoreTypes.map, [ - BridgeTypeRef(CoreTypes.string), - BridgeTypeRef(CoreTypes.dynamic) - ]), - nullable: true), - true), - ], - namedParams: []), - isStatic: true), - 'https': BridgeMethodDef( - BridgeFunctionDef( - returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string)), - params: [ - BridgeParameter( - 'authority', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string)), - false), - BridgeParameter( - 'unencodedPath', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string)), - true), - BridgeParameter( - 'queryParameters', - BridgeTypeAnnotation( - BridgeTypeRef(CoreTypes.map, [ - BridgeTypeRef(CoreTypes.string), - BridgeTypeRef(CoreTypes.dynamic) - ]), - nullable: true), - true), - ], - namedParams: []), - isStatic: true), - 'parseIPv4Address': BridgeMethodDef( - BridgeFunctionDef( - returns: BridgeTypeAnnotation(BridgeTypeRef( - CoreTypes.list, [BridgeTypeRef(CoreTypes.int)])), - params: [ - BridgeParameter( - 'host', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string)), - false), - ], - namedParams: []), - isStatic: true), - 'parseIPv6Address': BridgeMethodDef( - BridgeFunctionDef( - returns: BridgeTypeAnnotation(BridgeTypeRef( - CoreTypes.list, [BridgeTypeRef(CoreTypes.int)])), - params: [ - BridgeParameter( - 'host', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string)), - false), - BridgeParameter( - 'start', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string)), - true), - BridgeParameter( - 'end', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string), - nullable: true), - true), - ], - namedParams: []), - isStatic: true), - 'splitQueryString': BridgeMethodDef( - BridgeFunctionDef( - returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.map, [ - BridgeTypeRef(CoreTypes.string), - BridgeTypeRef(CoreTypes.string) - ])), - params: [ - BridgeParameter( - 'query', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string)), - false), - ], - namedParams: [ - BridgeParameter( - 'encoding', - BridgeTypeAnnotation( - BridgeTypeRef(ConvertTypes.encoding)), - true) + nullable: false), + params: [], + namedParams: [], + ), + isStatic: false), + 'queryParametersAll': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.map, [ + BridgeTypeRef(CoreTypes.string, []), + BridgeTypeRef(CoreTypes.list, [ + BridgeTypeRef(CoreTypes.string, []), + ]), ]), - isStatic: true), - 'resolve': BridgeMethodDef( - BridgeFunctionDef( - returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.uri)), - params: [ - BridgeParameter( - 'reference', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string)), - false), - ], - namedParams: []), - isStatic: true), - 'normalizePath': BridgeMethodDef( - BridgeFunctionDef( - returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.uri)), - params: [], - namedParams: []), - isStatic: true), - 'removeFragment': BridgeMethodDef( - BridgeFunctionDef( - returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.uri)), - params: [], - namedParams: []), - isStatic: true), - 'resolveUri': BridgeMethodDef( - BridgeFunctionDef( - returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.uri)), - params: [ - BridgeParameter( - 'reference', - BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string)), - false), - ], - namedParams: []), - isStatic: true), - }, - getters: { - 'scheme': BridgeMethodDef(BridgeFunctionDef( - returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string)))), - 'authority': BridgeMethodDef(BridgeFunctionDef( - returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string)))), - 'userInfo': BridgeMethodDef(BridgeFunctionDef( - returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string)))), - 'host': BridgeMethodDef(BridgeFunctionDef( - returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string)))), - 'port': BridgeMethodDef(BridgeFunctionDef( - returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int)))), - 'path': BridgeMethodDef(BridgeFunctionDef( - returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string)))), - 'query': BridgeMethodDef(BridgeFunctionDef( - returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string)))), - 'fragment': BridgeMethodDef(BridgeFunctionDef( - returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string)))), - 'pathSegments': BridgeMethodDef(BridgeFunctionDef( - returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.list)))), - 'queryParameters': BridgeMethodDef(BridgeFunctionDef( - returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.map)))), - 'queryParametersAll': BridgeMethodDef(BridgeFunctionDef( - returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.map)))), - 'isAbsolute': BridgeMethodDef(BridgeFunctionDef( - returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool)))), - 'hasScheme': BridgeMethodDef(BridgeFunctionDef( - returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool)))), - 'hasAuthority': BridgeMethodDef(BridgeFunctionDef( - returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool)))), - 'hasPort': BridgeMethodDef(BridgeFunctionDef( - returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool)))), - 'hasQuery': BridgeMethodDef(BridgeFunctionDef( - returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool)))), - 'hasFragment': BridgeMethodDef(BridgeFunctionDef( - returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool)))), - 'hasEmptyPath': BridgeMethodDef(BridgeFunctionDef( - returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool)))), - 'hasAbsolutePath': BridgeMethodDef(BridgeFunctionDef( - returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool)))), - 'origin': BridgeMethodDef(BridgeFunctionDef( - returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string)))), - }, - setters: {}, - fields: {}, - wrap: true); - - late final $Instance _superclass = $Object($value); + nullable: false), + params: [], + namedParams: [], + ), + isStatic: false), + 'isAbsolute': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool, []), + nullable: false), + params: [], + namedParams: [], + ), + isStatic: false), + 'hasScheme': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool, []), + nullable: false), + params: [], + namedParams: [], + ), + isStatic: false), + 'hasAuthority': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool, []), + nullable: false), + params: [], + namedParams: [], + ), + isStatic: false), + 'hasPort': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool, []), + nullable: false), + params: [], + namedParams: [], + ), + isStatic: false), + 'hasQuery': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool, []), + nullable: false), + params: [], + namedParams: [], + ), + isStatic: false), + 'hasFragment': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool, []), + nullable: false), + params: [], + namedParams: [], + ), + isStatic: false), + 'hasEmptyPath': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool, []), + nullable: false), + params: [], + namedParams: [], + ), + isStatic: false), + 'hasAbsolutePath': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool, []), + nullable: false), + params: [], + namedParams: [], + ), + isStatic: false), + 'origin': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: false), + params: [], + namedParams: [], + ), + isStatic: false), + 'data': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.uriData, []), + nullable: true), + params: [], + namedParams: [], + ), + isStatic: false), + 'hashCode': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int, []), + nullable: false), + params: [], + namedParams: [], + ), + isStatic: false), + }, + setters: {}, + bridge: false, + wrap: true, + ); - /// The wrapped [Uri] - @override - final Uri $value; - - @override - Uri get $reified => $value; - - /// Wrap a [Uri] in a [$Uri] + /// Wrap an [Uri] in an [$Uri] $Uri.wrap(this.$value); @override @@ -439,15 +892,27 @@ class $Uri implements $Instance { case 'fragment': return $String($value.fragment); case 'pathSegments': - return wrapList($value.pathSegments, (e) => $String(e)); + return $List.wrap(List.generate($value.pathSegments.length, (index) { + return $String($value.pathSegments[index]); + })); case 'queryParameters': - return wrapMap($value.queryParameters, - (key, value) => MapEntry($String(key), $String(value))); + return $Map.wrap($value.queryParameters.map((key, value) { + return $MapEntry.wrap(MapEntry( + key is $Value ? key : $String(key), + value is $Value ? value : $String(value), + )); + })); case 'queryParametersAll': - return wrapMap>( - $value.queryParametersAll, - (key, value) => MapEntry( - $String(key), wrapList(value, (e) => $String(e)))); + return $Map.wrap($value.queryParametersAll.map((key, value) { + return $MapEntry.wrap(MapEntry( + key is $Value ? key : $String(key), + value is $Value + ? value + : $List.wrap(List.generate(value.length, (index) { + return $String(value[index]); + })), + )); + })); case 'isAbsolute': return $bool($value.isAbsolute); case 'hasScheme': @@ -466,168 +931,807 @@ class $Uri implements $Instance { return $bool($value.hasAbsolutePath); case 'origin': return $String($value.origin); - case 'resolve': - return __resolve; - case 'normalizePath': - return __normalizePath; + case 'data': + return $value.data == null ? $null() : $UriData.wrap($value.data!); + case 'hashCode': + return $int($value.hashCode); + case 'isScheme': + return __$isScheme; + case 'toFilePath': + return __$toFilePath; + case 'replace': + return __$replace; case 'removeFragment': - return __removeFragment; + return __$removeFragment; + case 'resolve': + return __$resolve; case 'resolveUri': - return __resolveUri; - + return __$resolveUri; + case 'normalizePath': + return __$normalizePath; default: return _superclass.$getProperty(runtime, identifier); } } + @override + int $getRuntimeType(Runtime runtime) => runtime.lookupType($type.spec!); + + @override + Uri get $reified => $value; + @override void $setProperty(Runtime runtime, String identifier, $Value value) { - return _superclass.$setProperty(runtime, identifier, value); + switch (identifier) { + default: + _superclass.$setProperty(runtime, identifier, value); + } } - static const $Function __resolve = $Function(_resolve); - static $Value? _resolve( - final Runtime runtime, final $Value? target, final List<$Value?> args) { - return $Uri.wrap((target as $Uri).$value.resolve(args[0]!.$value)); + @override + final Uri $value; + + static const __$static$getter$base = $Function(_$static$getter$base); + static $Value? _$static$getter$base( + Runtime runtime, $Value? target, List<$Value?> args) { + return $Uri.wrap(Uri.base); } - static const $Function __normalizePath = $Function(_normalizePath); - static $Value? _normalizePath( - final Runtime runtime, final $Value? target, final List<$Value?> args) { - return $Uri.wrap((target as $Uri).$value.normalizePath()); + static const __$isScheme = $Function(_$isScheme); + static $Value? _$isScheme( + Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as Uri; + final scheme = args[0]?.$value as String; + final $result = $this.isScheme(scheme); + return $bool($result); } - static const $Function __removeFragment = $Function(_removeFragment); - static $Value? _removeFragment( - final Runtime runtime, final $Value? target, final List<$Value?> args) { - return $Uri.wrap((target as $Uri).$value.removeFragment()); + static const __$toFilePath = $Function(_$toFilePath); + static $Value? _$toFilePath( + Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as Uri; + final windows = args[0]?.$value as bool?; + final $result = $this.toFilePath(windows: windows); + return $String($result); } - static const $Function __resolveUri = $Function(_resolveUri); - static $Value? _resolveUri( - final Runtime runtime, final $Value? target, final List<$Value?> args) { - return $Uri.wrap((target as $Uri).$value.resolveUri(args[0]!.$value)); + static const __$replace = $Function(_$replace); + static $Value? _$replace( + Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as Uri; + final scheme = args[0]?.$value as String?; + final userInfo = args[1]?.$value as String?; + final host = args[2]?.$value as String?; + final port = args[3]?.$value as int?; + final path = args[4]?.$value as String?; + final pathSegments = (args[5]?.$reified as Iterable?)?.cast(); + final query = args[6]?.$value as String?; + final queryParameters = + (args[7]?.$reified as Map?)?.cast(); + final fragment = args[8]?.$value as String?; + final $result = $this.replace( + scheme: scheme, + userInfo: userInfo, + host: host, + port: port, + path: path, + pathSegments: pathSegments, + query: query, + queryParameters: queryParameters, + fragment: fragment, + ); + return $Uri.wrap($result); } - static $Value? $parse(Runtime runtime, $Value? target, List<$Value?> args) { - final uri = args[0]!.$value as String; - return $Uri.wrap(Uri.parse(uri)); + static const __$removeFragment = $Function(_$removeFragment); + static $Value? _$removeFragment( + Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as Uri; + final $result = $this.removeFragment(); + return $Uri.wrap($result); + } + + static const __$resolve = $Function(_$resolve); + static $Value? _$resolve( + Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as Uri; + final reference = args[0]?.$value as String; + final $result = $this.resolve(reference); + return $Uri.wrap($result); + } + + static const __$resolveUri = $Function(_$resolveUri); + static $Value? _$resolveUri( + Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as Uri; + final reference = args[0]?.$value as Uri; + final $result = $this.resolveUri(reference); + return $Uri.wrap($result); + } + + static const __$normalizePath = $Function(_$normalizePath); + static $Value? _$normalizePath( + Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as Uri; + final $result = $this.normalizePath(); + return $Uri.wrap($result); + } + + static const __$static$method$parse = $Function(_$static$method$parse); + static $Value? _$static$method$parse( + Runtime runtime, $Value? target, List<$Value?> args) { + final uri = args[0]?.$value as String; + final start = args[1]?.$value as int? ?? 0; + final end = args[2]?.$value as int?; + final $result = Uri.parse(uri, start, end); + return $Uri.wrap($result); + } + + static const __$static$method$tryParse = $Function(_$static$method$tryParse); + static $Value? _$static$method$tryParse( + Runtime runtime, $Value? target, List<$Value?> args) { + final uri = args[0]?.$value as String; + final start = args[1]?.$value as int? ?? 0; + final end = args[2]?.$value as int?; + final $result = Uri.tryParse(uri, start, end); + return $result == null ? $null() : $Uri.wrap($result); } - static $Value? $tryParse( + static const __$static$method$encodeComponent = + $Function(_$static$method$encodeComponent); + static $Value? _$static$method$encodeComponent( Runtime runtime, $Value? target, List<$Value?> args) { - final uri = args[0]!.$value as String; - final result = Uri.tryParse(uri); - return result == null ? $null() : $Uri.wrap(result); + final component = args[0]?.$value as String; + final $result = Uri.encodeComponent(component); + return $String($result); } - static $Value? $encodeFull( + static const __$static$method$encodeQueryComponent = + $Function(_$static$method$encodeQueryComponent); + static $Value? _$static$method$encodeQueryComponent( Runtime runtime, $Value? target, List<$Value?> args) { - final uri = args[0]!.$value as String; - return $String(Uri.encodeFull(uri)); + final component = args[0]?.$value as String; + final encoding = args[1]?.$value as Encoding? ?? utf8; + final $result = Uri.encodeQueryComponent(component, encoding: encoding); + return $String($result); } - static $Value? $decodeFull( + static const __$static$method$decodeComponent = + $Function(_$static$method$decodeComponent); + static $Value? _$static$method$decodeComponent( Runtime runtime, $Value? target, List<$Value?> args) { - final uri = args[0]!.$value as String; - return $String(Uri.decodeFull(uri)); + final encodedComponent = args[0]?.$value as String; + final $result = Uri.decodeComponent(encodedComponent); + return $String($result); } - static $Value? $encodeComponent( + static const __$static$method$decodeQueryComponent = + $Function(_$static$method$decodeQueryComponent); + static $Value? _$static$method$decodeQueryComponent( Runtime runtime, $Value? target, List<$Value?> args) { - return $String(Uri.encodeComponent(args[0]!.$value)); + final encodedComponent = args[0]?.$value as String; + final encoding = args[1]?.$value as Encoding? ?? utf8; + final $result = + Uri.decodeQueryComponent(encodedComponent, encoding: encoding); + return $String($result); } - static $Value? $decodeComponent( + static const __$static$method$encodeFull = + $Function(_$static$method$encodeFull); + static $Value? _$static$method$encodeFull( Runtime runtime, $Value? target, List<$Value?> args) { - return $String(Uri.decodeComponent(args[0]!.$value)); + final uri = args[0]?.$value as String; + final $result = Uri.encodeFull(uri); + return $String($result); } - static $Value? $decodeQueryComponent( + static const __$static$method$decodeFull = + $Function(_$static$method$decodeFull); + static $Value? _$static$method$decodeFull( Runtime runtime, $Value? target, List<$Value?> args) { - return $String(Uri.decodeQueryComponent(args[0]!.$value, - encoding: (args[1]?.$value as Encoding?) ?? utf8)); + final uri = args[0]?.$value as String; + final $result = Uri.decodeFull(uri); + return $String($result); } - static $Value? $encodeQueryComponent( + static const __$static$method$splitQueryString = + $Function(_$static$method$splitQueryString); + static $Value? _$static$method$splitQueryString( Runtime runtime, $Value? target, List<$Value?> args) { - return $String(Uri.encodeQueryComponent(args[0]!.$value, - encoding: (args[1]?.$value as Encoding?) ?? utf8)); + final query = args[0]?.$value as String; + final encoding = args[1]?.$value as Encoding? ?? utf8; + final $result = Uri.splitQueryString( + query, + encoding: encoding, + ); + return $Map.wrap($result.map((key, value) { + return $MapEntry.wrap(MapEntry( + key is $Value ? key : $String(key), + value is $Value ? value : $String(value), + )); + })); } - static $Value? $dataFromBytes( + static const __$static$method$parseIPv4Address = + $Function(_$static$method$parseIPv4Address); + static $Value? _$static$method$parseIPv4Address( Runtime runtime, $Value? target, List<$Value?> args) { - final bytes = (args[0]!.$value as List) - .map((e) => (e is $Value ? e.$reified : e) as int) - .toList(); - final parameters = (args[2]?.$value as Map?)?.map((key, value) => - MapEntry(key.$reified.toString(), value.$reified.toString())); - return $Uri.wrap(Uri.dataFromBytes(bytes, - mimeType: args[1]?.$value ?? "application/octet-stream", - parameters: parameters, - percentEncoded: args[3]?.$value ?? false)); + final host = args[0]?.$value as String; + final $result = Uri.parseIPv4Address(host); + return $List.wrap(List.generate($result.length, (index) { + return $int($result[index]); + })); } - static $Value? $dataFromString( + static const __$static$method$parseIPv6Address = + $Function(_$static$method$parseIPv6Address); + static $Value? _$static$method$parseIPv6Address( Runtime runtime, $Value? target, List<$Value?> args) { - final parameters = (args[2]?.$value as Map?)?.map((key, value) => - MapEntry(key.$reified.toString(), value.$reified.toString())); - return $Uri.wrap(Uri.dataFromString(args[0]!.$value, - mimeType: args[1]?.$value ?? "application/octet-stream", - parameters: parameters, - base64: args[3]?.$value ?? false)); + final host = args[0]?.$value as String; + final start = args[1]?.$value as int? ?? 0; + final end = args[2]?.$value as int?; + final $result = Uri.parseIPv6Address(host, start, end); + return $List.wrap(List.generate($result.length, (index) { + return $int($result[index]); + })); } - static $Value? $directory( + static const __$Uri$new = $Function(_$Uri$new); + static $Value? _$Uri$new( Runtime runtime, $Value? target, List<$Value?> args) { - return $Uri.wrap(Uri.directory(args[0]!.$value, - windows: (args[1]?.$value as bool?) ?? false)); + final scheme = args[0]?.$value as String?; + final userInfo = args[1]?.$value as String?; + final host = args[2]?.$value as String?; + final port = args[3]?.$value as int?; + final path = args[4]?.$value as String?; + final pathSegments = (args[5]?.$reified as Iterable?)?.cast(); + final query = args[6]?.$value as String?; + final queryParameters = + (args[7]?.$reified as Map?)?.cast(); + final fragment = args[8]?.$value as String?; + return $Uri.wrap(Uri( + scheme: scheme, + userInfo: userInfo, + host: host, + port: port, + path: path, + pathSegments: pathSegments, + query: query, + queryParameters: queryParameters, + fragment: fragment, + )); } - static $Value? $file(Runtime runtime, $Value? target, List<$Value?> args) { - return $Uri.wrap(Uri.file(args[0]!.$value, - windows: (args[1]?.$value as bool?) ?? false)); + static const __$Uri$http = $Function(_$Uri$http); + static $Value? _$Uri$http( + Runtime runtime, $Value? target, List<$Value?> args) { + final authority = args[0]?.$value as String; + final unencodedPath = args[1]?.$value as String; + final queryParameters = + (args[2]?.$reified as Map?)?.cast(); + return $Uri.wrap(Uri.http( + authority, + unencodedPath, + queryParameters, + )); } - static $Value? $http(Runtime runtime, $Value? target, List<$Value?> args) { - final queryParameters = (args[2]?.$value as Map?)?.map( - (key, value) => MapEntry(key.$reified.toString(), value.$reified)); - return $Uri.wrap( - Uri.http(args[0]!.$value, args[1]?.$value ?? "", queryParameters)); + static const __$Uri$https = $Function(_$Uri$https); + static $Value? _$Uri$https( + Runtime runtime, $Value? target, List<$Value?> args) { + final authority = args[0]?.$value as String; + final unencodedPath = args[1]?.$value as String; + final queryParameters = + (args[2]?.$reified as Map?)?.cast(); + return $Uri.wrap(Uri.https( + authority, + unencodedPath, + queryParameters, + )); } - static $Value? $https(Runtime runtime, $Value? target, List<$Value?> args) { - final queryParameters = (args[2]?.$value as Map?)?.map( - (key, value) => MapEntry(key.$reified.toString(), value.$reified)); - return $Uri.wrap( - Uri.https(args[0]!.$value, args[1]?.$value ?? "", queryParameters)); + static const __$Uri$file = $Function(_$Uri$file); + static $Value? _$Uri$file( + Runtime runtime, $Value? target, List<$Value?> args) { + final path = args[0]?.$value as String; + final windows = args[1]?.$value as bool?; + return $Uri.wrap(Uri.file(path, windows: windows)); } - static $Value? $parseIPv4Address( + static const __$Uri$directory = $Function(_$Uri$directory); + static $Value? _$Uri$directory( Runtime runtime, $Value? target, List<$Value?> args) { - return $List.wrap( - Uri.parseIPv4Address(args[0]!.$value).map((e) => $int(e)).toList()); + final path = args[0]?.$value as String; + final windows = args[1]?.$value as bool?; + return $Uri.wrap(Uri.directory(path, windows: windows)); } - static $Value? $parseIPv6Address( + static const __$Uri$dataFromString = $Function(_$Uri$dataFromString); + static $Value? _$Uri$dataFromString( Runtime runtime, $Value? target, List<$Value?> args) { - return $List.wrap(Uri.parseIPv6Address( - args[0]!.$value, args[1]?.$value ?? 0, args[2]?.$value) - .map((e) => $int(e)) - .toList()); + final content = args[0]?.$value as String; + final mimeType = args[1]?.$value as String?; + final encoding = args[2]?.$value as Encoding?; + final parameters = (args[3]?.$reified as Map?)?.cast(); + final base64 = (args[4]?.$value as bool?) ?? false; + return $Uri.wrap(Uri.dataFromString( + content, + mimeType: mimeType, + encoding: encoding, + parameters: parameters, + base64: base64, + )); } - static $Value? $splitQueryString( + static const __$Uri$dataFromBytes = $Function(_$Uri$dataFromBytes); + static $Value? _$Uri$dataFromBytes( Runtime runtime, $Value? target, List<$Value?> args) { - return wrapMap( - Uri.splitQueryString(args[0]!.$value, - encoding: (args[1]?.$value as Encoding?) ?? utf8), - (key, value) => MapEntry($String(key), $String(value))); + final bytes = (args[0]?.$reified as List).cast(); + final mimeType = args[1]?.$value as String? ?? "application/octet-stream"; + final parameters = (args[2]?.$reified as Map?)?.cast(); + final percentEncoded = (args[3]?.$value as bool?) ?? false; + return $Uri.wrap(Uri.dataFromBytes( + bytes, + mimeType: mimeType, + parameters: parameters, + percentEncoded: percentEncoded, + )); + } +} + +/// dart_eval wrapper for [UriData] +class $UriData implements UriData, $Instance { + /// Configure the [$UriData] wrapper for use in a [Runtime] + static void configureForCompile(BridgeDeclarationRegistry registry) { + registry.defineBridgeClass($declaration); + } + + static void configureForRuntime(Runtime runtime) { + runtime.registerBridgeFunc( + $type.spec!.library, 'UriData.fromString', __$UriData$fromString.call, + isBridge: false); + runtime.registerBridgeFunc( + $type.spec!.library, 'UriData.fromBytes', __$UriData$fromBytes.call, + isBridge: false); + runtime.registerBridgeFunc( + $type.spec!.library, 'UriData.fromUri', __$UriData$fromUri.call, + isBridge: false); + runtime.registerBridgeFunc( + $type.spec!.library, 'UriData.parse', __$static$method$parse.call, + isBridge: false); + } + + late final $Instance _superclass = $Object($value); + + static const $type = BridgeTypeRef(CoreTypes.uriData); + + static const $declaration = BridgeClassDef( + BridgeClassType( + $type, + $extends: null, + $implements: [], + isAbstract: false, + ), + constructors: { + 'fromString': BridgeConstructorDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation($type), + params: [ + BridgeParameter( + 'content', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: false), + false) + ], + namedParams: [ + BridgeParameter( + 'mimeType', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: true), + true), + BridgeParameter( + 'encoding', + BridgeTypeAnnotation(BridgeTypeRef(ConvertTypes.encoding, []), + nullable: true), + true), + BridgeParameter( + 'parameters', + BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.map, [ + BridgeTypeRef(CoreTypes.string, []), + BridgeTypeRef(CoreTypes.string, []), + ]), + nullable: true), + true), + BridgeParameter( + 'base64', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool, []), + nullable: false), + true) + ], + ), + isFactory: true, + ), + 'fromBytes': BridgeConstructorDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation($type), + params: [ + BridgeParameter( + 'bytes', + BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.list, [ + BridgeTypeRef(CoreTypes.int, []), + ]), + nullable: false), + false) + ], + namedParams: [ + BridgeParameter( + 'mimeType', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: false), + true), + BridgeParameter( + 'parameters', + BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.map, [ + BridgeTypeRef(CoreTypes.string, []), + BridgeTypeRef(CoreTypes.string, []), + ]), + nullable: true), + true), + BridgeParameter( + 'percentEncoded', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool, []), + nullable: false), + true) + ], + ), + isFactory: true, + ), + 'fromUri': BridgeConstructorDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation($type), + params: [ + BridgeParameter( + 'uri', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.uri, []), + nullable: false), + false) + ], + namedParams: [], + ), + isFactory: true, + ) + }, + fields: {}, + methods: { + 'parse': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.uriData, []), + nullable: false), + params: [ + BridgeParameter( + 'uri', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: false), + false) + ], + namedParams: [], + ), + isStatic: true), + 'isMimeType': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool, []), + nullable: false), + params: [ + BridgeParameter( + 'mimeType', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: false), + false) + ], + namedParams: [], + ), + isStatic: false), + 'isCharset': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool, []), + nullable: false), + params: [ + BridgeParameter( + 'charset', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: false), + false) + ], + namedParams: [], + ), + isStatic: false), + 'isEncoding': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool, []), + nullable: false), + params: [ + BridgeParameter( + 'encoding', + BridgeTypeAnnotation(BridgeTypeRef(ConvertTypes.encoding, []), + nullable: false), + false) + ], + namedParams: [], + ), + isStatic: false), + 'contentAsBytes': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation( + BridgeTypeRef(TypedDataTypes.uint8List, []), + nullable: false), + params: [], + namedParams: [], + ), + isStatic: false), + 'contentAsString': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: false), + params: [], + namedParams: [ + BridgeParameter( + 'encoding', + BridgeTypeAnnotation(BridgeTypeRef(ConvertTypes.encoding, []), + nullable: true), + true) + ], + ), + isStatic: false), + 'toString': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: false), + params: [], + namedParams: [], + ), + isStatic: false), + }, + getters: { + 'uri': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.uri, []), + nullable: false), + params: [], + namedParams: [], + ), + isStatic: false), + 'mimeType': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: false), + params: [], + namedParams: [], + ), + isStatic: false), + 'charset': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: false), + params: [], + namedParams: [], + ), + isStatic: false), + 'isBase64': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool, []), + nullable: false), + params: [], + namedParams: [], + ), + isStatic: false), + 'contentText': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, []), + nullable: false), + params: [], + namedParams: [], + ), + isStatic: false), + 'parameters': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.map, [ + BridgeTypeRef(CoreTypes.string, []), + BridgeTypeRef(CoreTypes.string, []), + ]), + nullable: false), + params: [], + namedParams: [], + ), + isStatic: false), + }, + setters: {}, + bridge: false, + wrap: true, + ); + + /// Wrap an [UriData] in an [$UriData] + $UriData.wrap(this.$value); + + @override + $Value? $getProperty(Runtime runtime, String identifier) { + switch (identifier) { + case 'uri': + return $Uri.wrap($value.uri); + case 'mimeType': + return $String($value.mimeType); + case 'charset': + return $String($value.charset); + case 'isBase64': + return $bool($value.isBase64); + case 'contentText': + return $String($value.contentText); + case 'parameters': + return $Map.wrap($value.parameters.map((key, value) { + return $MapEntry.wrap(MapEntry( + key is $Value ? key : $String(key), + value is $Value ? value : $String(value), + )); + })); + case 'isMimeType': + return __$isMimeType; + case 'isCharset': + return __$isCharset; + case 'isEncoding': + return __$isEncoding; + case 'contentAsBytes': + return __$contentAsBytes; + case 'contentAsString': + return __$contentAsString; + default: + return _superclass.$getProperty(runtime, identifier); + } } @override int $getRuntimeType(Runtime runtime) => runtime.lookupType($type.spec!); @override - String toString() => $value.toString(); + UriData get $reified => $value; + + @override + void $setProperty(Runtime runtime, String identifier, $Value value) { + switch (identifier) { + default: + _superclass.$setProperty(runtime, identifier, value); + } + } + + @override + final UriData $value; + + @override + String get charset => $value.charset; + + @override + String get contentText => $value.contentText; + + @override + bool get isBase64 => $value.isBase64; + + @override + String get mimeType => $value.mimeType; + + @override + Map get parameters => $value.parameters; + + @override + Uri get uri => $value.uri; + + @override + bool isMimeType(String mimeType) => $value.isMimeType(mimeType); + + static const __$isMimeType = $Function(_$isMimeType); + static $Value? _$isMimeType( + Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as UriData; + final mimeType = args[0]?.$value as String; + final $result = $this.isMimeType(mimeType); + return $bool($result); + } + + @override + bool isCharset(String charset) => $value.isCharset(charset); + + static const __$isCharset = $Function(_$isCharset); + static $Value? _$isCharset( + Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as UriData; + final charset = args[0]?.$value as String; + final $result = $this.isCharset(charset); + return $bool($result); + } + + @override + bool isEncoding(Encoding encoding) => $value.isEncoding(encoding); + + static const __$isEncoding = $Function(_$isEncoding); + static $Value? _$isEncoding( + Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as UriData; + final encoding = args[0]?.$value as Encoding; + final $result = $this.isEncoding(encoding); + return $bool($result); + } + + @override + Uint8List contentAsBytes() => $value.contentAsBytes(); + + static const __$contentAsBytes = $Function(_$contentAsBytes); + static $Value? _$contentAsBytes( + Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as UriData; + final $result = $this.contentAsBytes(); + return $Uint8List.wrap($result); + } + + @override + String contentAsString({Encoding? encoding}) => + $value.contentAsString(encoding: encoding); + + static const __$contentAsString = $Function(_$contentAsString); + static $Value? _$contentAsString( + Runtime runtime, $Value? target, List<$Value?> args) { + final $this = target?.$value as UriData; + final encoding = args[0]?.$value as Encoding?; + final $result = $this.contentAsString(encoding: encoding); + return $String($result); + } + + static const __$static$method$parse = $Function(_$static$method$parse); + static $Value? _$static$method$parse( + Runtime runtime, $Value? target, List<$Value?> args) { + final uri = args[0]?.$value as String; + final $result = UriData.parse(uri); + return $UriData.wrap($result); + } + + static const __$UriData$fromString = $Function(_$UriData$fromString); + static $Value? _$UriData$fromString( + Runtime runtime, $Value? target, List<$Value?> args) { + final content = args[0]?.$value as String; + final mimeType = args[1]?.$value as String?; + final encoding = args[2]?.$value as Encoding?; + final parameters = (args[3]?.$reified as Map?)?.cast(); + final base64 = ((args[4]?.$value as bool?)) ?? false; + return $UriData.wrap(UriData.fromString( + content, + mimeType: mimeType, + encoding: encoding, + parameters: parameters, + base64: base64, + )); + } + + static const __$UriData$fromBytes = $Function(_$UriData$fromBytes); + static $Value? _$UriData$fromBytes( + Runtime runtime, $Value? target, List<$Value?> args) { + final bytes = (args[0]?.$reified as List).cast(); + final mimeType = args[1]?.$value as String? ?? "application/octet-stream"; + final parameters = (args[2]?.$reified as Map?)?.cast(); + final percentEncoded = args[3]?.$value as bool? ?? false; + return $UriData.wrap(UriData.fromBytes( + bytes, + mimeType: mimeType, + parameters: parameters, + percentEncoded: percentEncoded, + )); + } + + static const __$UriData$fromUri = $Function(_$UriData$fromUri); + static $Value? _$UriData$fromUri( + Runtime runtime, $Value? target, List<$Value?> args) { + final uri = args[0]?.$value as Uri; + return $UriData.wrap(UriData.fromUri( + uri, + )); + } } diff --git a/lib/src/eval/shared/types.dart b/lib/src/eval/shared/types.dart index d5c500f9..4224e6b5 100644 --- a/lib/src/eval/shared/types.dart +++ b/lib/src/eval/shared/types.dart @@ -79,6 +79,9 @@ class CoreTypes { /// Bridge type spec for [$Uri] static const uri = BridgeTypeSpec('dart:core', 'Uri'); + /// Bridge type spec for [$UriData] + static const uriData = BridgeTypeSpec('dart:core', 'UriData'); + /// Bridge type spec for [$Pattern] static const pattern = BridgeTypeSpec('dart:core', 'Pattern'); diff --git a/lib/src/eval/utils/wap_helper.dart b/lib/src/eval/utils/wap_helper.dart deleted file mode 100644 index 814756bd..00000000 --- a/lib/src/eval/utils/wap_helper.dart +++ /dev/null @@ -1,29 +0,0 @@ -import 'package:dart_eval/dart_eval_bridge.dart'; -import 'package:dart_eval/stdlib/core.dart'; - -/// Converts a Dart list of generic type `T` into a `$List` of `$Value` by -/// applying a wrapping function to each element in the list. -$List<$Value> wrapList(List list, $Value Function(T element) wrap) { - return $List.wrap([for (var e in list) wrap(e)]); -} - -/// Converts a Dart list of nullable generic type `T` into a `$List` of `$Value?` -/// by applying a wrapping function to each non-null element and using `$null()` for null elements. -$List<$Value?> wrapNullableList( - List list, $Value Function(T element) wrap) { - return $List.wrap([for (var e in list) e == null ? $null() : wrap(e)]); -} - -/// Converts a Dart map with keys of type `K` and values of type `V` into a -/// `$Map` of `$Value` by applying a wrapping function to each entry in the map. -$Map<$Value, $Value> wrapMap( - Map map, MapEntry<$Value, $Value> Function(K key, V value) wrap) { - return $Map.wrap(map.map((key, value) => $MapEntry.wrap(wrap(key, value)))); -} - -/// Converts a Dart map with keys of type `K` and nullable values of type `V` -/// into a `$Map` of `$Value` by applying a wrapping function to each entry in the map. -$Map<$Value, $Value?> wrapNullableMap( - Map map, MapEntry<$Value, $Value?> Function(K key, V? value) wrap) { - return $Map.wrap(map.map((key, value) => $MapEntry.wrap(wrap(key, value)))); -} From 44093222c6a8d9d69e6a7817132da07ed8ac7d95 Mon Sep 17 00:00:00 2001 From: Noobware1 <110553648+Noobware1@users.noreply.github.com> Date: Sun, 21 Jul 2024 16:57:28 +0530 Subject: [PATCH 7/7] fixed uri extends --- .../eval/compiler/declaration/constructor.dart | 16 ++++++++-------- lib/src/eval/shared/stdlib/core/uri.dart | 2 -- lib/src/eval/shared/stdlib/io/socket.dart | 2 -- lib/src/eval/shared/stdlib/math/random.dart | 1 - 4 files changed, 8 insertions(+), 13 deletions(-) diff --git a/lib/src/eval/compiler/declaration/constructor.dart b/lib/src/eval/compiler/declaration/constructor.dart index ab863c7f..f18cfcee 100644 --- a/lib/src/eval/compiler/declaration/constructor.dart +++ b/lib/src/eval/compiler/declaration/constructor.dart @@ -204,11 +204,11 @@ void compileConstructorDeclaration( final decl = extendsWhat.declaration!; if (!decl.isBridge) { - final $checkResults = _doesExtendBridge(decl, ctx); - if ($checkResults.extendsBridge) { + final checkResults = _doesExtendBridge(decl, ctx); + if (checkResults.extendsBridge) { doesExtendBridge = true; - extendsWhat = $checkResults.declaration; - $extends = $checkResults.extendsClause; + extendsWhat = checkResults.declaration; + $extends = checkResults.extendsClause; } } @@ -412,11 +412,11 @@ void compileDefaultConstructor(CompilerContext ctx, final decl = extendsWhat.declaration!; if (!decl.isBridge) { - final $checkResults = _doesExtendBridge(decl, ctx); - if ($checkResults.extendsBridge) { + final checkResults = _doesExtendBridge(decl, ctx); + if (checkResults.extendsBridge) { doesExtendBridge = true; - extendsWhat = $checkResults.declaration; - $extends = $checkResults.extendsClause; + extendsWhat = checkResults.declaration; + $extends = checkResults.extendsClause; } } diff --git a/lib/src/eval/shared/stdlib/core/uri.dart b/lib/src/eval/shared/stdlib/core/uri.dart index 592a8222..a1955650 100644 --- a/lib/src/eval/shared/stdlib/core/uri.dart +++ b/lib/src/eval/shared/stdlib/core/uri.dart @@ -78,7 +78,6 @@ class $Uri implements $Instance { static const $declaration = BridgeClassDef( BridgeClassType( $type, - $extends: null, $implements: [], isAbstract: true, ), @@ -1308,7 +1307,6 @@ class $UriData implements UriData, $Instance { static const $declaration = BridgeClassDef( BridgeClassType( $type, - $extends: null, $implements: [], isAbstract: false, ), diff --git a/lib/src/eval/shared/stdlib/io/socket.dart b/lib/src/eval/shared/stdlib/io/socket.dart index e4ca838e..a6022ac0 100644 --- a/lib/src/eval/shared/stdlib/io/socket.dart +++ b/lib/src/eval/shared/stdlib/io/socket.dart @@ -30,7 +30,6 @@ class $InternetAddressType implements InternetAddressType, $Instance { static const $declaration = BridgeClassDef( BridgeClassType( $type, - $extends: null, $implements: [], isAbstract: false, ), @@ -187,7 +186,6 @@ class $InternetAddress implements InternetAddress, $Instance { static const $declaration = BridgeClassDef( BridgeClassType( $type, - $extends: null, $implements: [], isAbstract: true, ), diff --git a/lib/src/eval/shared/stdlib/math/random.dart b/lib/src/eval/shared/stdlib/math/random.dart index 500c4096..97db7eb6 100644 --- a/lib/src/eval/shared/stdlib/math/random.dart +++ b/lib/src/eval/shared/stdlib/math/random.dart @@ -26,7 +26,6 @@ class $Random implements Random, $Instance { static const $declaration = BridgeClassDef( BridgeClassType( $type, - $extends: null, $implements: [], isAbstract: true, ),