-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3c869be
commit 4f6b69f
Showing
19 changed files
with
301 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import 'package:analyzer/dart/ast/ast.dart'; | ||
import 'package:dart_eval/dart_eval_bridge.dart'; | ||
import 'package:dart_eval/source_node_wrapper.dart'; | ||
import 'package:dart_eval/src/eval/compiler/context.dart'; | ||
import 'package:dart_eval/src/eval/compiler/expression/expression.dart'; | ||
import 'package:dart_eval/src/eval/compiler/type.dart'; | ||
import 'package:dart_eval/src/eval/compiler/variable.dart'; | ||
import 'package:dart_eval/src/eval/runtime/runtime.dart'; | ||
import 'package:dart_eval/src/eval/shared/types.dart'; | ||
|
||
Variable compileAsExpression(AsExpression e, CompilerContext ctx) { | ||
var V = compileExpression(e.expression, ctx); | ||
final slot = TypeRef.fromAnnotation(ctx, ctx.library, e.type); | ||
|
||
/// If the type is the slot, we can just return | ||
if (V.type == slot) { | ||
return V; | ||
} | ||
|
||
// Otherwise type-test | ||
ctx.pushOp(IsType.make(V.scopeFrameOffset, runtimeTypeMap[slot] ?? ctx.typeRefIndexMap[slot]!, false), IsType.LEN); | ||
final Vis = Variable.alloc(ctx, EvalTypes.boolType.copyWith(boxed: false)); | ||
|
||
// And assert | ||
final errMsg = BuiltinValue(stringval: "TypeError: Not a subtype of type TYPE").push(ctx); | ||
ctx.pushOp(Assert.make(Vis.scopeFrameOffset, errMsg.scopeFrameOffset), Assert.LEN); | ||
|
||
// If the type changes between num and int/double, unbox/box | ||
if (slot == EvalTypes.numType) { | ||
V = V.boxIfNeeded(ctx); | ||
} else if (slot == EvalTypes.intType || slot == EvalTypes.doubleType) { | ||
V = V.unboxIfNeeded(ctx); | ||
} | ||
|
||
// For all other types, just inform the compiler | ||
// TODO: mixins may need different behavior | ||
return V.copyWithUpdate(ctx, type: slot.copyWith(boxed: V.type.boxed)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import 'package:analyzer/dart/ast/ast.dart'; | ||
import 'package:dart_eval/dart_eval_bridge.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/expression/expression.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/compiler/variable.dart'; | ||
import 'package:dart_eval/src/eval/runtime/runtime.dart'; | ||
|
||
StatementInfo compileAssertStatement(AssertStatement s, CompilerContext ctx, AlwaysReturnType? expectedReturnType) { | ||
final cond = compileExpression(s.condition, ctx); | ||
final msg = s.message != null ? compileExpression(s.message!, ctx) : BuiltinValue().push(ctx); | ||
|
||
msg.pushArg(ctx); | ||
ctx.pushOp(InvokeExternal.make(ctx.bridgeStaticFunctionIndices[ctx.libraryMap['dart:core']]!['AssertionError.']!), | ||
InvokeExternal.LEN); | ||
ctx.pushOp(PushReturnValue.make(), PushReturnValue.LEN); | ||
final assertionErr = Variable.alloc(ctx, TypeRef.fromBridgeTypeRef(ctx, BridgeTypeRef(CoreTypes.assertionError))); | ||
|
||
ctx.pushOp(Assert.make(cond.scopeFrameOffset, assertionErr.scopeFrameOffset), Assert.LEN); | ||
|
||
return StatementInfo(-1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import 'package:dart_eval/dart_eval.dart'; | ||
import 'package:dart_eval/dart_eval_bridge.dart'; | ||
import 'package:dart_eval/src/eval/shared/stdlib/core/base.dart'; | ||
|
||
/// dart_eval wrapper for [AssertionError] | ||
class $AssertionError implements AssertionError, $Instance { | ||
/// Compile-time class definition for [$Iterable] | ||
static const $declaration = BridgeClassDef(BridgeClassType(BridgeTypeRef(CoreTypes.assertionError)), | ||
constructors: { | ||
'': BridgeConstructorDef(BridgeFunctionDef( | ||
returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.assertionError)), | ||
params: [ | ||
BridgeParameter( | ||
'message', BridgeTypeAnnotation(BridgeTypeRef.type(RuntimeTypes.objectType), nullable: true), true) | ||
])) | ||
}, | ||
methods: {}, | ||
getters: { | ||
'message': BridgeMethodDef( | ||
BridgeFunctionDef( | ||
params: [], returns: BridgeTypeAnnotation(BridgeTypeRef.type(RuntimeTypes.objectType), nullable: true)), | ||
isStatic: false), | ||
}, | ||
setters: {}, | ||
fields: {}, | ||
wrap: true); | ||
|
||
final $Instance _superclass; | ||
|
||
/// Wrap a [AssertionError] in a [$AssertionError] | ||
$AssertionError.wrap(this.$value) : _superclass = $Object($value); | ||
|
||
static $AssertionError $new(Runtime runtime, $Value? target, List<$Value?> args) { | ||
return $AssertionError.wrap(AssertionError(args[0]?.$value)); | ||
} | ||
|
||
@override | ||
final AssertionError $value; | ||
|
||
@override | ||
AssertionError get $reified => $value; | ||
|
||
@override | ||
int $getRuntimeType(Runtime runtime) => runtime.lookupType(CoreTypes.assertionError); | ||
|
||
@override | ||
$Value? $getProperty(Runtime runtime, String identifier) { | ||
if (identifier == 'message') { | ||
return $value.message == null ? $null() : $Object($value.message!); | ||
} | ||
return _superclass.$getProperty(runtime, identifier); | ||
} | ||
|
||
@override | ||
void $setProperty(Runtime runtime, String identifier, $Value value) { | ||
return _superclass.$setProperty(runtime, identifier, value); | ||
} | ||
|
||
@override | ||
Object? get message => $value.message; | ||
|
||
@override | ||
StackTrace? get stackTrace => $value.stackTrace; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.