Skip to content

Commit

Permalink
Merge pull request #171 from Noobware1/fixes
Browse files Browse the repository at this point in the history
Fixes
  • Loading branch information
ethanblake4 authored Mar 1, 2024
2 parents 6407645 + 2214472 commit f08ac04
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 3 deletions.
1 change: 0 additions & 1 deletion lib/src/eval/compiler/expression/binary.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ Variable compileBinaryExpression(CompilerContext ctx, BinaryExpression e,

var method = opMap[e.operator.type] ??
(throw CompileError('Unknown binary operator ${e.operator.type}'));

return L.invoke(ctx, method, [R]).result;
}

Expand Down
1 change: 1 addition & 0 deletions lib/src/eval/compiler/macros/branch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ StatementInfo macroBranch(
AstNode? source}) {
ctx.beginAllocScope();
ctx.enterTypeInferenceContext();

final conditionResult = condition(ctx).unboxIfNeeded(ctx);
if (!conditionResult.type.isAssignableTo(ctx, CoreTypes.bool.ref(ctx))) {
throw CompileError("Conditions must have a static type of 'bool'", source);
Expand Down
8 changes: 7 additions & 1 deletion lib/src/eval/compiler/statement/variable_declaration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@ void compileVariableDeclarationList(
res = res.boxIfNeeded(ctx);
}
if (res.name != null) {
var _v = Variable.alloc(ctx, type ?? res.type);
final _type = type ?? res.type;
var _v = Variable.alloc(
ctx,
_type.isUnboxedAcrossFunctionBoundaries
? _type.copyWith(boxed: false)
: _type,
);
ctx.pushOp(PushNull.make(), PushNull.LEN);
ctx.pushOp(CopyValue.make(_v.scopeFrameOffset, res.scopeFrameOffset),
CopyValue.LEN);
Expand Down
2 changes: 2 additions & 0 deletions lib/src/eval/shared/stdlib/core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class DartCorePlugin implements EvalPlugin {
registry.defineBridgeClass($Iterator.$declaration);
registry.defineBridgeClass($List.$declaration);
registry.defineBridgeClass($Map.$declaration);
registry.defineBridgeClass($MapEntry.$declaration);
registry.defineBridgeClass($Duration.$declaration);
registry.defineBridgeClass($Future.$declaration);
registry.defineBridgeClass($Stream.$declaration);
Expand Down Expand Up @@ -79,6 +80,7 @@ class DartCorePlugin implements EvalPlugin {
configureIdenticalForRuntime(runtime);
$String.configureForRuntime(runtime);
$List.configureForRuntime(runtime);
$MapEntry.configureForRuntime(runtime);
$Iterable.configureForRuntime(runtime);
$Duration.configureForRuntime(runtime);
$Future.configureForRuntime(runtime);
Expand Down
27 changes: 27 additions & 0 deletions lib/src/eval/shared/stdlib/core/list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,19 @@ class $List<E> implements List<E>, $Instance {
returns:
BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.voidType))),
isStatic: false),
'firstWhere': BridgeMethodDef(
BridgeFunctionDef(params: [
BridgeParameter(
'test',
BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.function)),
false),
], namedParams: [
BridgeParameter(
'orElse',
BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.function)),
false),
], returns: BridgeTypeAnnotation(BridgeTypeRef.ref('E'))),
isStatic: false),
'sublist': BridgeMethodDef(
BridgeFunctionDef(
params: [
Expand Down Expand Up @@ -455,6 +468,8 @@ class $List<E> implements List<E>, $Instance {
return __retainWhere;
case 'removeWhere':
return __removeWhere;
case 'firstWhere':
return __firstWhere;
case 'replaceRange':
return __replaceRange;
case 'getRange':
Expand Down Expand Up @@ -666,6 +681,18 @@ class $List<E> implements List<E>, $Instance {
return target;
}

static const $Function __firstWhere = $Function(_firstWhere);

static $Value? _firstWhere(
Runtime runtime, $Value? target, List<$Value?> args) {
final test = args[0] as EvalCallable;
final orElse = args[1] as EvalCallable?;
return (target!.$value as List).firstWhere(
(element) => test.call(runtime, null, args)?.$value as bool,
orElse: orElse == null ? null : () => orElse.call(runtime, null, args),
) as $Value?;
}

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

Expand Down
6 changes: 5 additions & 1 deletion lib/src/eval/shared/stdlib/core/map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,10 @@ class $MapEntry<K, V> implements MapEntry<K, V>, $Instance {
/// Wrap a [MapEntry] in a [$MapEntry]
$MapEntry.wrap(this.$value);

static void configureForRuntime(Runtime runtime) {
return runtime.registerBridgeFunc('dart:core', 'MapEntry.', _$new.call);
}

static const $declaration = BridgeClassDef(
BridgeClassType(BridgeTypeRef(CoreTypes.mapEntry),
generics: {'K': BridgeGenericParam(), 'V': BridgeGenericParam()}),
Expand Down Expand Up @@ -296,7 +300,7 @@ class $MapEntry<K, V> implements MapEntry<K, V>, $Instance {

late final $Instance _superclass = $Object($value);

static $Value? $new(
static $Value? _$new(
final Runtime runtime, final $Value? target, final List<$Value?> args) {
return $MapEntry.wrap(MapEntry(args[0], args[1]));
}
Expand Down
2 changes: 2 additions & 0 deletions lib/src/eval/shared/stdlib/io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:dart_eval/src/eval/shared/stdlib/io/directory.dart';
import 'package:dart_eval/src/eval/shared/stdlib/io/file.dart';
import 'package:dart_eval/src/eval/shared/stdlib/io/file_system_entity.dart';
import 'package:dart_eval/src/eval/shared/stdlib/io/http.dart';
import 'package:dart_eval/src/eval/shared/stdlib/io/http_status.dart';
import 'package:dart_eval/src/eval/shared/stdlib/io/io_sink.dart';
import 'package:dart_eval/src/eval/shared/stdlib/io/socket.dart';
import 'package:dart_eval/src/eval/shared/stdlib/io/string_sink.dart';
Expand All @@ -25,6 +26,7 @@ class DartIoPlugin implements EvalPlugin {
registry.defineBridgeClass($Directory.$declaration);
$InternetAddress.configureForCompile(registry);
$InternetAddressType.configureForCompile(registry);
registry.addSource($HttpStatusSource());
}

@override
Expand Down
73 changes: 73 additions & 0 deletions lib/src/eval/shared/stdlib/io/http_status.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import 'package:dart_eval/dart_eval_bridge.dart';

class $HttpStatusSource extends DartSource {
$HttpStatusSource() : super(IoTypes.httpStatus.library, _source);

static const String _source = '''
abstract class HttpStatus {
static const int continue_ = 100;
static const int switchingProtocols = 101;
static const int processing = 102;
static const int ok = 200;
static const int created = 201;
static const int accepted = 202;
static const int nonAuthoritativeInformation = 203;
static const int noContent = 204;
static const int resetContent = 205;
static const int partialContent = 206;
static const int multiStatus = 207;
static const int alreadyReported = 208;
static const int imUsed = 226;
static const int multipleChoices = 300;
static const int movedPermanently = 301;
static const int found = 302;
static const int movedTemporarily = 302;
static const int seeOther = 303;
static const int notModified = 304;
static const int useProxy = 305;
static const int temporaryRedirect = 307;
static const int permanentRedirect = 308;
static const int badRequest = 400;
static const int unauthorized = 401;
static const int paymentRequired = 402;
static const int forbidden = 403;
static const int notFound = 404;
static const int methodNotAllowed = 405;
static const int notAcceptable = 406;
static const int proxyAuthenticationRequired = 407;
static const int requestTimeout = 408;
static const int conflict = 409;
static const int gone = 410;
static const int lengthRequired = 411;
static const int preconditionFailed = 412;
static const int requestEntityTooLarge = 413;
static const int requestUriTooLong = 414;
static const int unsupportedMediaType = 415;
static const int requestedRangeNotSatisfiable = 416;
static const int expectationFailed = 417;
static const int misdirectedRequest = 421;
static const int unprocessableEntity = 422;
static const int locked = 423;
static const int failedDependency = 424;
static const int upgradeRequired = 426;
static const int preconditionRequired = 428;
static const int tooManyRequests = 429;
static const int requestHeaderFieldsTooLarge = 431;
static const int connectionClosedWithoutResponse = 444;
static const int unavailableForLegalReasons = 451;
static const int clientClosedRequest = 499;
static const int internalServerError = 500;
static const int notImplemented = 501;
static const int badGateway = 502;
static const int serviceUnavailable = 503;
static const int gatewayTimeout = 504;
static const int httpVersionNotSupported = 505;
static const int variantAlsoNegotiates = 506;
static const int insufficientStorage = 507;
static const int loopDetected = 508;
static const int notExtended = 510;
static const int networkAuthenticationRequired = 511;
static const int networkConnectTimeoutError = 599;
}
''';
}
3 changes: 3 additions & 0 deletions lib/src/eval/shared/types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,9 @@ class IoTypes {
/// Bridge type spec for [$HttpClientResponse]
static const httpClientResponse =
BridgeTypeSpec('dart:io', 'HttpClientResponse');

/// Bridge type spec for [$HttpStatus]
static const httpStatus = BridgeTypeSpec('dart:io', 'HttpStatus');
}

class TypedDataTypes {
Expand Down
1 change: 1 addition & 0 deletions lib/stdlib/io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export '../src/eval/shared/stdlib/io/http.dart';
export '../src/eval/shared/stdlib/io/io_sink.dart';
export '../src/eval/shared/stdlib/io/string_sink.dart';
export '../src/eval/shared/stdlib/io/socket.dart';
export '../src/eval/shared/stdlib/io/http_status.dart';

0 comments on commit f08ac04

Please sign in to comment.