Skip to content

Commit

Permalink
v0.7.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanblake4 committed Oct 29, 2023
1 parent 12f5f2a commit 979e1b5
Show file tree
Hide file tree
Showing 54 changed files with 175 additions and 177 deletions.
24 changes: 1 addition & 23 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1 @@
include: package:lints/recommended.yaml

analyzer:
language:
# would be good to turn these on in future
strict-inference: false
strict-casts: false
strict-raw-types: false
errors:
todo: ignore

linter:
rules:
camel_case_types: false
non_constant_identifier_names: false
always_put_control_body_on_new_line: false
curly_braces_in_flow_control_structures: false
prefer_final_locals: false
constant_identifier_names: false
avoid_renaming_method_parameters: false
prefer_function_declarations_over_variables: false
avoid_function_literals_in_foreach_calls: false
no_leading_underscores_for_local_identifiers: false
include: package:lints/core.yaml
12 changes: 10 additions & 2 deletions bin/dart_eval.dart
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,14 @@ void main(List<String> args) {

stdout.write('${package.name} ');

final pkgDir = Directory(package.packageUriRoot.toFilePath());
String filepath;
try {
filepath = package.packageUriRoot.toFilePath();
} catch (e) {
filepath = package.packageUriRoot.toString();
}

final pkgDir = Directory(filepath);
addFiles(package.name, pkgDir, pkgDir.path);
}

Expand Down Expand Up @@ -203,8 +210,9 @@ void main(List<String> args) {
print('Usage:');
print(
' dart_eval run <file> [-l, --library <library>] [-f, --function <function>] [-h, --help]');
if (command['help'])
if (command['help']) {
print('\nNote that bindings are not supported in the run command.');
}
exit(command['help'] ? 0 : 1);
}
if (command['library'] == null) {
Expand Down
1 change: 1 addition & 0 deletions lib/dart_eval_bridge.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
library dart_eval.bridge;

export 'package:pub_semver/pub_semver.dart' show Version;
export 'src/eval/runtime/class.dart' hide $InstanceImpl;
export 'src/eval/runtime/declaration.dart' hide EvalClassClass;
export 'src/eval/bridge/declaration/class.dart';
Expand Down
2 changes: 2 additions & 0 deletions lib/src/eval/bridge/runtime_bridge.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore_for_file: non_constant_identifier_names

import 'package:dart_eval/dart_eval_bridge.dart';
import 'package:dart_eval/src/eval/runtime/runtime.dart';

Expand Down
15 changes: 5 additions & 10 deletions lib/src/eval/compiler/builtins.dart
Original file line number Diff line number Diff line change
Expand Up @@ -241,15 +241,13 @@ Map<TypeRef, Map<String, KnownMethod>> getKnownMethods(ctx) {
[KnownMethodArg('other', CoreTypes.string.ref(ctx), false)], {}),
'endsWith': KnownMethod(AlwaysReturnType(CoreTypes.bool.ref(ctx), false),
[KnownMethodArg('other', CoreTypes.string.ref(ctx), false)], {}),
//TODO: needs to be fixed to not use stringType but instead EvalTypes.patternType once its available
'indexOf': KnownMethod(AlwaysReturnType(CoreTypes.int.ref(ctx), false), [
KnownMethodArg('pattern', CoreTypes.string.ref(ctx), false),
KnownMethodArg('pattern', CoreTypes.pattern.ref(ctx), false),
KnownMethodArg('start', CoreTypes.int.ref(ctx), true),
], {}),
//TODO: needs to be fixed to not use stringType but instead EvalTypes.patternType once its available
'lastIndexOf':
KnownMethod(AlwaysReturnType(CoreTypes.int.ref(ctx), false), [
KnownMethodArg('pattern', CoreTypes.string.ref(ctx), false),
KnownMethodArg('pattern', CoreTypes.pattern.ref(ctx), false),
KnownMethodArg('start', CoreTypes.int.ref(ctx), true),
], {}),
'padLeft':
Expand All @@ -262,17 +260,15 @@ Map<TypeRef, Map<String, KnownMethod>> getKnownMethods(ctx) {
KnownMethodArg('width', CoreTypes.int.ref(ctx), false),
KnownMethodArg('padding', CoreTypes.string.ref(ctx), true),
], {}),
//TODO: needs to be fixed to not use stringType but instead EvalTypes.patternType once its available
'replaceAll':
KnownMethod(AlwaysReturnType(CoreTypes.string.ref(ctx), false), [
KnownMethodArg('pattern', CoreTypes.string.ref(ctx), false),
KnownMethodArg('replace', CoreTypes.string.ref(ctx), false),
], {}),
//TODO: needs to be fixed to not use stringType but instead EvalTypes.patternType once its available
'replaceFirst':
KnownMethod(AlwaysReturnType(CoreTypes.string.ref(ctx), false), [
KnownMethodArg('from', CoreTypes.string.ref(ctx), false),
KnownMethodArg('to', CoreTypes.string.ref(ctx), false),
KnownMethodArg('from', CoreTypes.pattern.ref(ctx), false),
KnownMethodArg('to', CoreTypes.pattern.ref(ctx), false),
KnownMethodArg('startIndex', CoreTypes.int.ref(ctx), true),
], {}),
'replaceRange':
Expand All @@ -282,10 +278,9 @@ Map<TypeRef, Map<String, KnownMethod>> getKnownMethods(ctx) {
'end', CoreTypes.int.ref(ctx).copyWith(nullable: true), false),
KnownMethodArg('replacement', CoreTypes.string.ref(ctx), false),
], {}),
//TODO: needs to be fixed to not use stringType but instead EvalTypes.patternType once its available
'startsWith':
KnownMethod(AlwaysReturnType(CoreTypes.bool.ref(ctx), false), [
KnownMethodArg('pattern', CoreTypes.string.ref(ctx), false),
KnownMethodArg('pattern', CoreTypes.pattern.ref(ctx), false),
KnownMethodArg('index', CoreTypes.int.ref(ctx), true),
], {}),
'substring':
Expand Down
32 changes: 16 additions & 16 deletions lib/src/eval/compiler/declaration/constructor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void compileConstructorDeclaration(
for (final param in resolvedParams) {
final p = param.parameter;
final V = param.V;
Variable Vrep;
Variable vrep;
if (p is FieldFormalParameter) {
TypeRef? _type;
if (p.type != null) {
Expand All @@ -80,15 +80,15 @@ void compileConstructorDeclaration(
_type ??= V?.type;
_type ??= CoreTypes.dynamic.ref(ctx);

Vrep = Variable(i,
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(
vrep = Variable(
i, type.copyWith(boxed: !type.isUnboxedAcrossFunctionBoundaries))
.boxIfNeeded(ctx)
..name = p.name.lexeme;
Expand All @@ -101,10 +101,10 @@ void compileConstructorDeclaration(
}
type =
type.copyWith(boxed: !unboxedAcrossFunctionBoundaries.contains(type));
Vrep = Variable(i, type)..name = p.name!.lexeme;
vrep = Variable(i, type)..name = p.name!.lexeme;
}

ctx.setLocal(Vrep.name!, Vrep);
ctx.setLocal(vrep.name!, vrep);

i++;
}
Expand Down Expand Up @@ -163,7 +163,7 @@ void compileConstructorDeclaration(
final decl = extendsWhat.declaration!;

if (decl.isBridge) {
ctx.pushOp(PushBridgeSuperShim.make(), PushBridgeSuperShim.LEN);
ctx.pushOp(PushBridgeSuperShim.make(), PushBridgeSuperShim.length);
$super = Variable.alloc(ctx, CoreTypes.dynamic.ref(ctx));
} else {
final extendsType = TypeRef.lookupDeclaration(
Expand Down Expand Up @@ -201,7 +201,7 @@ void compileConstructorDeclaration(
}

final offset = method.methodOffset!;
final loc = ctx.pushOp(Call.make(offset.offset ?? -1), Call.LEN);
final loc = ctx.pushOp(Call.make(offset.offset ?? -1), Call.length);
if (offset.offset == null) {
ctx.offsetTracker.setOffset(loc, offset);
}
Expand Down Expand Up @@ -232,16 +232,16 @@ void compileConstructorDeclaration(

if (parent is EnumDeclaration) {
ctx.pushOp(SetObjectPropertyImpl.make(instOffset, 0, 0),
SetObjectPropertyImpl.LEN);
SetObjectPropertyImpl.length);
ctx.pushOp(SetObjectPropertyImpl.make(instOffset, 1, 1),
SetObjectPropertyImpl.LEN);
SetObjectPropertyImpl.length);
}

for (final fieldFormal in fieldFormalNames) {
ctx.pushOp(
SetObjectPropertyImpl.make(instOffset, fieldIndices[fieldFormal]!,
ctx.lookupLocal(fieldFormal)!.scopeFrameOffset),
SetObjectPropertyImpl.LEN);
SetObjectPropertyImpl.length);
}

final usedNames = {...fieldFormalNames};
Expand All @@ -252,7 +252,7 @@ void compileConstructorDeclaration(
ctx.pushOp(
SetObjectPropertyImpl.make(instOffset,
fieldIndices[init.fieldName.name]!, V.scopeFrameOffset),
SetObjectPropertyImpl.LEN);
SetObjectPropertyImpl.length);
usedNames.add(init.fieldName.name);
} else {
throw CompileError('${init.runtimeType} initializer is not supported');
Expand Down Expand Up @@ -336,7 +336,7 @@ void compileDefaultConstructor(CompilerContext ctx,
final decl = extendsWhat.declaration!;

if (decl.isBridge) {
ctx.pushOp(PushBridgeSuperShim.make(), PushBridgeSuperShim.LEN);
ctx.pushOp(PushBridgeSuperShim.make(), PushBridgeSuperShim.length);
$super = Variable.alloc(ctx, CoreTypes.dynamic.ref(ctx));
} else {
final extendsType = TypeRef.lookupDeclaration(
Expand All @@ -353,7 +353,7 @@ void compileDefaultConstructor(CompilerContext ctx,
}

final offset = method.methodOffset!;
final loc = ctx.pushOp(Call.make(offset.offset ?? -1), Call.LEN);
final loc = ctx.pushOp(Call.make(offset.offset ?? -1), Call.length);
if (offset.offset == null) {
ctx.offsetTracker.setOffset(loc, offset);
}
Expand Down Expand Up @@ -384,9 +384,9 @@ void compileDefaultConstructor(CompilerContext ctx,

if (parent is EnumDeclaration) {
ctx.pushOp(SetObjectPropertyImpl.make(instOffset, 0, 0),
SetObjectPropertyImpl.LEN);
SetObjectPropertyImpl.length);
ctx.pushOp(SetObjectPropertyImpl.make(instOffset, 1, 1),
SetObjectPropertyImpl.LEN);
SetObjectPropertyImpl.length);
}

_compileUnusedFields(
Expand Down Expand Up @@ -452,7 +452,7 @@ void _compileUnusedFields(CompilerContext ctx, List<FieldDeclaration> fields,
ctx.pushOp(
SetObjectPropertyImpl.make(
instOffset, _fieldIdx, V.scopeFrameOffset),
SetObjectPropertyImpl.LEN);
SetObjectPropertyImpl.length);
}
_fieldIdx++;
}
Expand Down
12 changes: 6 additions & 6 deletions lib/src/eval/compiler/declaration/enum.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void compileEnumDeclaration(CompilerContext ctx, EnumDeclaration d,

ctx.resetStack(position: 0);
final pos = beginMethod(ctx, d, d.offset, '$clsName.index (get)');
ctx.pushOp(PushObjectPropertyImpl.make(0, 0), PushObjectPropertyImpl.LEN);
ctx.pushOp(PushObjectPropertyImpl.make(0, 0), PushObjectPropertyImpl.length);
ctx.pushOp(Return.make(1), Return.LEN);
ctx.instanceDeclarationPositions[ctx.library]![clsName]![0]['index'] = pos;
i++;
Expand Down Expand Up @@ -80,11 +80,11 @@ void compileEnumDeclaration(CompilerContext ctx, EnumDeclaration d,
final cstr =
ctx.topLevelDeclarationsMap[offset.file]![offset.name ?? '$clsName.'];

final Vindex = BuiltinValue(intval: idx).push(ctx).boxIfNeeded(ctx);
final Vname = BuiltinValue(stringval: cName).push(ctx);
final vIndex = BuiltinValue(intval: idx).push(ctx).boxIfNeeded(ctx);
final vName = BuiltinValue(stringval: cName).push(ctx);

ctx.pushOp(PushArg.make(Vindex.scopeFrameOffset), PushArg.LEN);
ctx.pushOp(PushArg.make(Vname.scopeFrameOffset), PushArg.LEN);
ctx.pushOp(PushArg.make(vIndex.scopeFrameOffset), PushArg.LEN);
ctx.pushOp(PushArg.make(vName.scopeFrameOffset), PushArg.LEN);

final dec = cstr?.declaration;
if (constant.arguments != null && dec != null) {
Expand All @@ -94,7 +94,7 @@ void compileEnumDeclaration(CompilerContext ctx, EnumDeclaration d,
source: constant);
}

final loc = ctx.pushOp(Call.make(offset.offset ?? -1), Call.LEN);
final loc = ctx.pushOp(Call.make(offset.offset ?? -1), Call.length);
if (offset.offset == null) {
ctx.offsetTracker.setOffset(loc, offset);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/src/eval/compiler/declaration/field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void compileFieldDeclaration(int fieldIndex, FieldDeclaration d,
} else {
final pos = beginMethod(ctx, d, d.offset, '$parentName.$fieldName (get)');
ctx.pushOp(PushObjectPropertyImpl.make(0, _fieldIndex),
PushObjectPropertyImpl.LEN);
PushObjectPropertyImpl.length);
ctx.pushOp(Return.make(1), Return.LEN);
ctx.instanceDeclarationPositions[ctx.library]![parentName]![0]
[fieldName] = pos;
Expand All @@ -62,7 +62,7 @@ void compileFieldDeclaration(int fieldIndex, FieldDeclaration d,
final setterPos =
beginMethod(ctx, d, d.offset, '$parentName.$fieldName (set)');
ctx.pushOp(SetObjectPropertyImpl.make(0, _fieldIndex, 1),
SetObjectPropertyImpl.LEN);
SetObjectPropertyImpl.length);
ctx.pushOp(Return.make(1), Return.LEN);
ctx.instanceDeclarationPositions[ctx.library]![parentName]![1]
[fieldName] = setterPos;
Expand Down
6 changes: 3 additions & 3 deletions lib/src/eval/compiler/declaration/function.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,18 @@ void compileFunctionDeclaration(FunctionDeclaration d, CompilerContext ctx) {

for (final param in resolvedParams) {
final p = param.parameter;
Variable Vrep;
Variable vRep;

p as SimpleFormalParameter;
var type = CoreTypes.dynamic.ref(ctx);
if (p.type != null) {
type = TypeRef.fromAnnotation(ctx, ctx.library, p.type!);
}
Vrep = Variable(
vRep = Variable(
i, type.copyWith(boxed: !type.isUnboxedAcrossFunctionBoundaries))
..name = p.name!.lexeme;

ctx.setLocal(Vrep.name!, Vrep);
ctx.setLocal(vRep.name!, vRep);

i++;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/src/eval/compiler/declaration/method.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ int compileMethodDeclaration(MethodDeclaration d, CompilerContext ctx,

for (final param in resolvedParams) {
final p = param.parameter;
Variable Vrep;
Variable vRep;

p as SimpleFormalParameter;
var type = CoreTypes.dynamic.ref(ctx);
if (p.type != null) {
type = TypeRef.fromAnnotation(ctx, ctx.library, p.type!)
.copyWith(boxed: true);
}
Vrep = Variable(i, type)..name = p.name!.lexeme;
vRep = Variable(i, type)..name = p.name!.lexeme;

ctx.setLocal(Vrep.name!, Vrep);
ctx.setLocal(vRep.name!, vRep);

i++;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/eval/compiler/errors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class CompileError implements Exception {
}

class NotReferencableError extends CompileError {
const NotReferencableError(String message) : super(message);
const NotReferencableError(super.message);

@override
String toString() {
Expand Down
8 changes: 4 additions & 4 deletions lib/src/eval/compiler/expression/as.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ Variable compileAsExpression(AsExpression e, CompilerContext ctx) {

// Otherwise type-test
ctx.pushOp(IsType.make(V.scopeFrameOffset, ctx.typeRefIndexMap[slot]!, false),
IsType.LEN);
final Vis =
IsType.length);
final vIs =
Variable.alloc(ctx, CoreTypes.bool.ref(ctx).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);
Assert.make(vIs.scopeFrameOffset, errMsg.scopeFrameOffset), Assert.LEN);

// If the type changes between num and int/double, unbox/box
if (slot == CoreTypes.num.ref(ctx)) {
Expand All @@ -39,6 +39,6 @@ Variable compileAsExpression(AsExpression e, CompilerContext ctx) {
}

// For all other types, just inform the compiler
// TODO: mixins may need different behavior
// (todo) Mixins may need different behavior
return V.copyWithUpdate(ctx, type: slot.copyWith(boxed: V.type.boxed));
}
6 changes: 3 additions & 3 deletions lib/src/eval/compiler/expression/assignment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ Reference compileAssignmentExpressionAsReference(
final R = compileExpression(e.rightHandSide, ctx);

if (e.operator.type == TokenType.EQ) {
final Ltype = L.resolveType(ctx).resolveTypeChain(ctx);
if (!R.type.resolveTypeChain(ctx).isAssignableTo(ctx, Ltype)) {
final lType = L.resolveType(ctx).resolveTypeChain(ctx);
if (!R.type.resolveTypeChain(ctx).isAssignableTo(ctx, lType)) {
throw CompileError(
'Syntax error: cannot assign value of type ${R.type} to $Ltype');
'Syntax error: cannot assign value of type ${R.type} to $lType');
}
L.setValue(ctx, R);
} else if (e.operator.type.binaryOperatorOfCompoundAssignment ==
Expand Down
Loading

0 comments on commit 979e1b5

Please sign in to comment.