Chromium Code Reviews| Index: pkg/fletchc/lib/src/codegen_visitor.dart |
| diff --git a/pkg/fletchc/lib/src/codegen_visitor.dart b/pkg/fletchc/lib/src/codegen_visitor.dart |
| index e2e0b6a70a83711eaba778b8e2ff17d4ed9b2145..0195e866e391dabacb4c9ab96fcfdd02db85e003 100644 |
| --- a/pkg/fletchc/lib/src/codegen_visitor.dart |
| +++ b/pkg/fletchc/lib/src/codegen_visitor.dart |
| @@ -37,7 +37,8 @@ import 'fletch_backend.dart'; |
| import 'fletch_constants.dart' show |
| CompiledFunctionConstant, |
| - FletchClassConstant; |
| + FletchClassConstant, |
| + FletchClassInstanceConstant; |
| import '../bytecodes.dart' show |
| Bytecode; |
| @@ -189,6 +190,12 @@ abstract class CodegenVisitor |
| return compiledFunction.allocateConstant(expression.value); |
| } |
| + int allocateConstantClassInstance(int classId) { |
| + var constant = new FletchClassInstanceConstant(classId); |
| + context.markConstantUsed(constant); |
|
ahe
2015/04/07 15:00:11
Why isn't this called for other constants?
Anders Johnsen
2015/04/08 06:32:14
It is, through "compileConstant".
|
| + return compiledFunction.allocateConstant(constant); |
| + } |
| + |
| int allocateStringConstant(String string) { |
| return compiledFunction.allocateConstant( |
| context.backend.constantSystem.createString( |
| @@ -715,9 +722,14 @@ abstract class CodegenVisitor |
| context.backend.createCompiledFunction(function, null, null); |
| CompiledClass compiledClass = context.backend.createTearoffClass( |
| compiledFunctionTarget); |
| - int classConstant = compiledFunction.allocateConstantFromClass( |
| - compiledClass.id); |
| - builder.allocate(classConstant, compiledClass.fields); |
| + if (compiledClass.fields == 0) { |
|
ahe
2015/04/08 08:04:18
Why is it the number of fields that determine if y
Anders Johnsen
2015/04/08 08:37:57
Because the field is not a constant - it can only
|
| + int constId = allocateConstantClassInstance(compiledClass.id); |
| + builder.loadConst(constId); |
| + } else { |
| + int classConstant = compiledFunction.allocateConstantFromClass( |
| + compiledClass.id); |
| + builder.allocate(classConstant, compiledClass.fields); |
| + } |
| } |
| void visitTopLevelFunctionGet( |
| @@ -1088,6 +1100,20 @@ abstract class CodegenVisitor |
| } |
| } |
| + void visitLiteralInt(LiteralInt node) { |
| + if (visitState == VisitState.Value) { |
| + int value = node.value; |
| + if (value >= 0x3FFFFFFF) { |
|
ahe
2015/04/07 15:03:30
0x3FFFFFFF should probably be a named constant wit
Anders Johnsen
2015/04/08 06:32:13
literal ints are never negative.
ahe
2015/04/08 08:04:18
Assert that?
Anders Johnsen
2015/04/08 08:37:57
Done.
|
| + int constId = allocateConstantFromNode(node); |
| + builder.loadConst(constId); |
| + } else { |
| + builder.loadLiteral(value); |
| + } |
| + } else if (visitState == VisitState.Test) { |
| + builder.branch(falseLabel); |
| + } |
| + } |
| + |
| void visitLiteral(Literal node) { |
| if (visitState == VisitState.Value) { |
| builder.loadConst(allocateConstantFromNode(node)); |