Skip to content

Commit

Permalink
v0.6.3
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanblake4 committed Oct 7, 2023
1 parent 6dea21c commit 5133d5a
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 99 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## 0.6.3
- Support for cascades
- Support for null coalescing assignment operator `??=`
- Support for many `List` and `Iterable` methods (thanks @kodjodevf)
- Fix error with do-while loops
- Fix scope leak when using arrow functions
- Fix properties not being properly boxed/unboxed when passed to
a function
- Fix constructor field initializer boxing
- Improve test coverage
- Add topics to pubspec

## 0.6.2+1
- Hotfix to increase size of globals array in runtime

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ may vary when bridging.
| Late initialization || N/A |
| Cascades || [[1]](https://github.com/ethanblake4/dart_eval/blob/master/test/expression_test.dart#L136), [[2]](https://github.com/ethanblake4/dart_eval/blob/master/test/expression_test.dart#L160) |
| Ternary expressions || [[1]](https://github.com/ethanblake4/dart_eval/blob/master/test/expression_test.dart#L118) |
| Null coalescing expressions || [[1]](https://github.com/ethanblake4/dart_eval/blob/master/test/expression_test.dart#L64) |
| Null coalescing expressions || [[1]](https://github.com/ethanblake4/dart_eval/blob/master/test/expression_test.dart#L64), [[1]](https://github.com/ethanblake4/dart_eval/blob/master/test/expression_test.dart#L186) |
| Extension methods || N/A |
| Const expressions | Partial | N/A |
| Isolates || N/A |
Expand Down
75 changes: 71 additions & 4 deletions lib/src/eval/shared/stdlib/core/iterable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,28 @@ class $Iterable<E> implements Iterable<E>, $Instance {
@override
$Value? $getProperty(Runtime runtime, String identifier) {
switch (identifier) {
case 'join':
return $Function(__join);
case 'map':
return $Function(__map);
case 'any':
return __any;
case 'elementAt':
return __elementAt;
case 'every':
return __every;
case 'iterator':
return $Iterator.wrap($value.iterator);
case 'followedBy':
return __followedBy;
case 'skip':
return __skip;
case 'skipWhile':
return __skipWhile;
case 'join':
return __join;
case 'map':
return __map;
case 'take':
return __take;
case 'toSet':
return __toSet;
case 'toList':
return __toList;
default:
Expand Down Expand Up @@ -91,6 +107,57 @@ class $Iterable<E> implements Iterable<E>, $Instance {
return $List.wrap((target!.$value as Iterable).toList(growable: args[0]?.$value ?? true));
}

static const $Function __any = $Function(_any);

static $Value? _any(Runtime runtime, $Value? target, List<$Value?> args) {
final test = args[0] as EvalCallable;
return $bool((target!.$value as Iterable).any((e) => test.call(runtime, null, [e])!.$value as bool));
}

static const $Function __every = $Function(_every);

static $Value? _every(Runtime runtime, $Value? target, List<$Value?> args) {
final test = args[0] as EvalCallable;
return $bool((target!.$value as Iterable).every((e) => test.call(runtime, null, [e])!.$value as bool));
}

static const $Function __elementAt = $Function(_elementAt);

static $Value? _elementAt(Runtime runtime, $Value? target, List<$Value?> args) {
return (target!.$value as List).elementAt(args[0]!.$value);
}

static const $Function __followedBy = $Function(_followedBy);

static $Value? _followedBy(Runtime runtime, $Value? target, List<$Value?> args) {
return $Iterable.wrap((target!.$value as Iterable).followedBy(args[0]!.$value as Iterable));
}

static const $Function __skip = $Function(_skip);

static $Value? _skip(Runtime runtime, $Value? target, List<$Value?> args) {
return $Iterable.wrap((target!.$value as Iterable).skip(args[0]!.$value));
}

static const $Function __skipWhile = $Function(_skipWhile);

static $Value? _skipWhile(Runtime runtime, $Value? target, List<$Value?> args) {
final test = args[0] as EvalCallable;
return $Iterable.wrap((target!.$value as List).skipWhile((e) => test.call(runtime, null, [e])!.$value as bool));
}

static const $Function __take = $Function(_take);

static $Value? _take(Runtime runtime, $Value? target, List<$Value?> args) {
return $Iterable.wrap((target!.$value as Iterable).take(args[0]!.$value));
}

static const $Function __toSet = $Function(_toSet);

static $Value? _toSet(Runtime runtime, $Value? target, List<$Value?> args) {
return $List.wrap((target!.$value as Iterable).toSet().toList());
}

@override
bool any(bool Function(E element) test) => $value.any(test);

Expand Down
93 changes: 0 additions & 93 deletions lib/src/eval/shared/stdlib/core/list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,6 @@ class $List<E> implements List<E>, $Instance {
return $super.first;
case 'contains':
return __listContains;
case 'map':
return __map;
case 'where':
return __where;
case 'isEmpty':
Expand All @@ -248,8 +246,6 @@ class $List<E> implements List<E>, $Instance {
return $super.last;
case 'reversed':
return $Iterable.wrap($value.reversed);
case 'toSet':
return __toSet;
case 'iterator':
return $Iterator.wrap($value.iterator);
case 'insert':
Expand All @@ -258,8 +254,6 @@ class $List<E> implements List<E>, $Instance {
return __insertAll;
case 'remove':
return __remove;
case 'any':
return __any;
case 'asMap':
return __asMap;
case 'hashCode':
Expand All @@ -268,38 +262,22 @@ class $List<E> implements List<E>, $Instance {
return __lastIndexOf;
case 'indexOf':
return __indexOf;
case 'elementAt':
return __elementAt;
case 'every':
return __every;
case 'retainWhere':
return __retainWhere;
case 'replaceRange':
return __replaceRange;
case 'followedBy':
return __followedBy;
case 'getRange':
return __getRange;
case 'join':
return __join;
case 'sort':
return __sort;
case 'removeAt':
return __removeAt;
case 'removeLast':
return __removeLast;
case 'skip':
return __skip;
case 'skipWhile':
return __skipWhile;
case 'sublist':
return __sublist;
case 'take':
return __take;
case 'takeWhile':
return __takeWhile;
case 'toString':
return __toString;
case 'clear':
return __clear;
}
Expand All @@ -311,19 +289,6 @@ class $List<E> implements List<E>, $Instance {
throw EvalUnknownPropertyException(identifier);
}

static const $Function __map = $Function(_map);

static $Value? _map(Runtime runtime, $Value? target, List<$Value?> args) {
final toElement = args[0] as EvalCallable;
return $Iterable.wrap((target!.$value as Iterable).map((e) => toElement.call(runtime, null, [e])!.$value));
}

static const $Function __followedBy = $Function(_followedBy);

static $Value? _followedBy(Runtime runtime, $Value? target, List<$Value?> args) {
return $Iterable.wrap((target!.$value as Iterable).followedBy(args[0]!.$value as Iterable));
}

static const $Function __getRange = $Function(_getRange);

static $Value? _getRange(Runtime runtime, $Value? target, List<$Value?> args) {
Expand All @@ -337,26 +302,13 @@ class $List<E> implements List<E>, $Instance {
return $Iterable.wrap((target!.$value as Iterable).where((e) => test.call(runtime, null, [e])!.$value as bool));
}

static const $Function __skipWhile = $Function(_skipWhile);

static $Value? _skipWhile(Runtime runtime, $Value? target, List<$Value?> args) {
final test = args[0] as EvalCallable;
return $Iterable.wrap((target!.$value as List).skipWhile((e) => test.call(runtime, null, [e])!.$value as bool));
}

static const $Function __takeWhile = $Function(_takeWhile);

static $Value? _takeWhile(Runtime runtime, $Value? target, List<$Value?> args) {
final test = args[0] as EvalCallable;
return $Iterable.wrap((target!.$value as List).takeWhile((e) => test.call(runtime, null, [e])!.$value as bool));
}

static const $Function __toString = $Function(_toString);

static $Value? _toString(Runtime runtime, $Value? target, List<$Value?> args) {
return $String((target!.$value as List).toString());
}

static const $Function __clear = $Function(_clear);

static $Value? _clear(Runtime runtime, $Value? target, List<$Value?> args) {
Expand Down Expand Up @@ -391,26 +343,6 @@ class $List<E> implements List<E>, $Instance {
return $int((target!.$value as List).indexOf(args[0], args[1]?.$value ?? 0));
}

static const $Function __elementAt = $Function(_elementAt);

static $Value? _elementAt(Runtime runtime, $Value? target, List<$Value?> args) {
return (target!.$value as List).elementAt(args[0]!.$value);
}

static const $Function __any = $Function(_any);

static $Value? _any(Runtime runtime, $Value? target, List<$Value?> args) {
final test = args[0] as EvalCallable;
return $bool((target!.$value as List).any((e) => test.call(runtime, null, [e])!.$value as bool));
}

static const $Function __every = $Function(_every);

static $Value? _every(Runtime runtime, $Value? target, List<$Value?> args) {
final test = args[0] as EvalCallable;
return $bool((target!.$value as List).every((e) => test.call(runtime, null, [e])!.$value as bool));
}

static const $Function __sort = $Function(_sort);

static $Value? _sort(Runtime runtime, $Value? target, List<$Value?> args) {
Expand Down Expand Up @@ -443,31 +375,12 @@ class $List<E> implements List<E>, $Instance {
return (target!.$value as List)[idx.$value];
}

static const $Function __join = $Function(_join);

static $Value? _join(Runtime runtime, $Value? target, List<$Value?> args) {
final separator = args[0]?.$value ?? '';
return $String((target!.$value as List).join(separator));
}

static const $Function __sublist = $Function(_sublist);

static $Value? _sublist(Runtime runtime, $Value? target, List<$Value?> args) {
return $List.wrap((target!.$value as List).sublist(args[0]!.$value, args[1]?.$value));
}

static const $Function __skip = $Function(_skip);

static $Value? _skip(Runtime runtime, $Value? target, List<$Value?> args) {
return $Iterable.wrap((target!.$value as List).skip(args[0]!.$value));
}

static const $Function __take = $Function(_take);

static $Value? _take(Runtime runtime, $Value? target, List<$Value?> args) {
return $Iterable.wrap((target!.$value as List).take(args[0]!.$value));
}

static const $Function __listContains = $Function(_listContains);

static $Value? _listContains(Runtime runtime, $Value? target, List<$Value?> args) {
Expand Down Expand Up @@ -523,12 +436,6 @@ class $List<E> implements List<E>, $Instance {
return $Map.wrap((target!.$value as List).asMap());
}

static const $Function __toSet = $Function(_toSet);

static $Value? _toSet(Runtime runtime, $Value? target, List<$Value?> args) {
return $List.wrap((target!.$value as List).toSet().toList());
}

@override
List get $reified => $value.map((e) => e is $Value ? e.$reified : e).toList();

Expand Down
8 changes: 7 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: dart_eval
description: A flexible Dart bytecode compiler and interpreter written in Dart, enabling dynamic execution and code push for AOT Dart apps.
version: 0.6.2+1
version: 0.6.3
homepage: https://github.com/ethanblake4/dart_eval
platforms:
android:
Expand All @@ -9,6 +9,12 @@ platforms:
macos:
web:
windows:
topics:
- vm
- compiler
- interpreter
- dart
- codepush

environment:
sdk: '>=2.17.0 <4.0.0'
Expand Down

0 comments on commit 5133d5a

Please sign in to comment.