Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(182)

Unified Diff: pkg/fletchc/lib/src/fletch_function_builder.dart

Issue 1659163007: Rename fletch -> dartino (Closed) Base URL: https://github.com/dartino/sdk.git@master
Patch Set: address comments Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/fletchc/lib/src/fletch_enqueuer.dart ('k') | pkg/fletchc/lib/src/fletch_native_descriptor.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/fletchc/lib/src/fletch_function_builder.dart
diff --git a/pkg/fletchc/lib/src/fletch_function_builder.dart b/pkg/fletchc/lib/src/fletch_function_builder.dart
deleted file mode 100644
index 57b570aeef513da2c4218890f9352c8693b29431..0000000000000000000000000000000000000000
--- a/pkg/fletchc/lib/src/fletch_function_builder.dart
+++ /dev/null
@@ -1,174 +0,0 @@
-// Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE.md file.
-
-library fletchc.compiled_function;
-
-import 'package:compiler/src/constants/values.dart' show
- ConstantValue;
-
-import 'package:compiler/src/elements/elements.dart';
-
-import 'fletch_constants.dart' show
- FletchFunctionConstant,
- FletchClassConstant;
-
-import '../bytecodes.dart' show
- Bytecode,
- Opcode;
-
-import 'fletch_context.dart';
-import 'bytecode_assembler.dart';
-
-import '../fletch_system.dart';
-import '../vm_commands.dart';
-
-class FletchFunctionBuilder extends FletchFunctionBase {
- final BytecodeAssembler assembler;
-
- /**
- * If the functions is an instance member, [memberOf] is set to the id of the
- * class.
- *
- * If [memberOf] is set, the compiled function takes an 'this' argument in
- * addition to that of [signature].
- */
- final Map<ConstantValue, int> constants = <ConstantValue, int>{};
- final Map<int, ConstantValue> functionConstantValues = <int, ConstantValue>{};
- final Map<int, ConstantValue> classConstantValues = <int, ConstantValue>{};
-
- FletchFunctionBuilder.fromFletchFunction(FletchFunction function)
- : this(
- function.functionId,
- function.kind,
- function.arity,
- name: function.name,
- element: function.element,
- memberOf: function.memberOf);
-
- FletchFunctionBuilder(
- int functionId,
- FletchFunctionKind kind,
- int arity,
- {String name,
- Element element,
- FunctionSignature signature,
- int memberOf})
- : super(functionId, kind, arity, name, element, signature, memberOf),
- assembler = new BytecodeAssembler(arity) {
- assert(signature == null ||
- arity == (signature.parameterCount + (isInstanceMember ? 1 : 0)));
- }
-
- void reuse() {
- assembler.reuse();
- constants.clear();
- functionConstantValues.clear();
- classConstantValues.clear();
- }
-
- int allocateConstant(ConstantValue constant) {
- if (constant == null) throw "bad constant";
- return constants.putIfAbsent(constant, () => constants.length);
- }
-
- int allocateConstantFromFunction(int functionId) {
- FletchFunctionConstant constant =
- functionConstantValues.putIfAbsent(
- functionId, () => new FletchFunctionConstant(functionId));
- return allocateConstant(constant);
- }
-
- int allocateConstantFromClass(int classId) {
- FletchClassConstant constant =
- classConstantValues.putIfAbsent(
- classId, () => new FletchClassConstant(classId));
- return allocateConstant(constant);
- }
-
- // TODO(ajohnsen): Remove this function when usage is avoided in
- // FletchBackend.
- void copyFrom(FletchFunctionBuilder function) {
- assembler.bytecodes.addAll(function.assembler.bytecodes);
- assembler.catchRanges.addAll(function.assembler.catchRanges);
- constants.addAll(function.constants);
- functionConstantValues.addAll(function.functionConstantValues);
- classConstantValues.addAll(function.classConstantValues);
- }
-
- FletchFunction finalizeFunction(
- FletchContext context,
- List<VmCommand> commands) {
- int constantCount = constants.length;
- for (int i = 0; i < constantCount; i++) {
- commands.add(const PushNull());
- }
-
- assert(assembler.bytecodes.last.opcode == Opcode.MethodEnd);
-
- commands.add(
- new PushNewFunction(
- assembler.functionArity,
- constantCount,
- assembler.bytecodes,
- assembler.catchRanges));
-
- commands.add(new PopToMap(MapId.methods, functionId));
-
- return new FletchFunction(
- functionId,
- kind,
- arity,
- name,
- element,
- signature,
- assembler.bytecodes,
- createFletchConstants(context),
- memberOf);
- }
-
- List<FletchConstant> createFletchConstants(FletchContext context) {
- List<FletchConstant> fletchConstants = <FletchConstant>[];
-
- constants.forEach((constant, int index) {
- if (constant is ConstantValue) {
- if (constant is FletchFunctionConstant) {
- fletchConstants.add(
- new FletchConstant(constant.functionId, MapId.methods));
- } else if (constant is FletchClassConstant) {
- fletchConstants.add(
- new FletchConstant(constant.classId, MapId.classes));
- } else {
- int id = context.lookupConstantIdByValue(constant);
- if (id == null) {
- throw "Unsupported constant: ${constant.toStructuredString()}";
- }
- fletchConstants.add(
- new FletchConstant(id, MapId.constants));
- }
- } else {
- throw "Unsupported constant: ${constant.runtimeType}";
- }
- });
-
- return fletchConstants;
- }
-
- String verboseToString() {
- StringBuffer sb = new StringBuffer();
-
- sb.writeln("Function $functionId, Arity=${assembler.functionArity}");
- sb.writeln("Constants:");
- constants.forEach((constant, int index) {
- if (constant is ConstantValue) {
- constant = constant.toStructuredString();
- }
- sb.writeln(" #$index: $constant");
- });
-
- sb.writeln("Bytecodes (${assembler.byteSize} bytes):");
- Bytecode.prettyPrint(sb, assembler.bytecodes);
-
- return '$sb';
- }
-}
« no previous file with comments | « pkg/fletchc/lib/src/fletch_enqueuer.dart ('k') | pkg/fletchc/lib/src/fletch_native_descriptor.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698