|
| 1 | +import 'package:primal/compiler/errors/runtime_error.dart'; |
| 2 | +import 'package:primal/compiler/models/parameter.dart'; |
| 3 | +import 'package:primal/compiler/platform/base/platform_cli.dart' |
| 4 | + if (dart.library.html) 'package:primal/compiler/platform/base/platform_web.dart'; |
| 5 | +import 'package:primal/compiler/runtime/node.dart'; |
| 6 | + |
| 7 | +class DirectoryMove extends NativeFunctionNode { |
| 8 | + DirectoryMove() |
| 9 | + : super( |
| 10 | + name: 'directory.move', |
| 11 | + parameters: [ |
| 12 | + Parameter.directory('a'), |
| 13 | + Parameter.directory('b'), |
| 14 | + ], |
| 15 | + ); |
| 16 | + |
| 17 | + @override |
| 18 | + Node node(List<Node> arguments) => NodeWithArguments( |
| 19 | + name: name, |
| 20 | + parameters: parameters, |
| 21 | + arguments: arguments, |
| 22 | + ); |
| 23 | +} |
| 24 | + |
| 25 | +class NodeWithArguments extends NativeFunctionNodeWithArguments { |
| 26 | + const NodeWithArguments({ |
| 27 | + required super.name, |
| 28 | + required super.parameters, |
| 29 | + required super.arguments, |
| 30 | + }); |
| 31 | + |
| 32 | + @override |
| 33 | + Node evaluate() { |
| 34 | + final Node a = arguments[0].evaluate(); |
| 35 | + final Node b = arguments[1].evaluate(); |
| 36 | + |
| 37 | + if ((a is DirectoryNode) && (b is DirectoryNode)) { |
| 38 | + final bool moved = PlatformInterface().directory.move(a.value, b.value); |
| 39 | + |
| 40 | + return BooleanNode(moved); |
| 41 | + } else { |
| 42 | + throw InvalidArgumentTypesError( |
| 43 | + function: name, |
| 44 | + expected: parameterTypes, |
| 45 | + actual: [a.type], |
| 46 | + ); |
| 47 | + } |
| 48 | + } |
| 49 | +} |
0 commit comments