| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/runtime_entry.h" | 5 #include "vm/runtime_entry.h" |
| 6 | 6 |
| 7 #include "vm/code_index_table.h" | |
| 8 #include "vm/object.h" | 7 #include "vm/object.h" |
| 9 #include "vm/verifier.h" | 8 #include "vm/verifier.h" |
| 10 | 9 |
| 11 namespace dart { | 10 namespace dart { |
| 12 | 11 |
| 13 // Add function to a class and that class to the class dictionary so that | 12 // Add function to a class and that class to the class dictionary so that |
| 14 // frame walking can be used. | 13 // frame walking can be used. |
| 15 const Function& RegisterFakeFunction(const char* name, const Code& code) { | 14 const Function& RegisterFakeFunction(const char* name, const Code& code) { |
| 16 const String& function_name = String::ZoneHandle(String::NewSymbol(name)); | 15 const String& function_name = String::ZoneHandle(String::NewSymbol(name)); |
| 17 const Function& function = Function::ZoneHandle( | 16 const Function& function = Function::ZoneHandle( |
| 18 Function::New(function_name, RawFunction::kFunction, true, false, 0)); | 17 Function::New(function_name, RawFunction::kFunction, true, false, 0)); |
| 19 Class& cls = Class::ZoneHandle(); | 18 Class& cls = Class::ZoneHandle(); |
| 20 const Script& script = Script::Handle(); | 19 const Script& script = Script::Handle(); |
| 21 cls = Class::New(function_name, script, Scanner::kDummyTokenIndex); | 20 cls = Class::New(function_name, script, Scanner::kDummyTokenIndex); |
| 22 const Array& functions = Array::Handle(Array::New(1)); | 21 const Array& functions = Array::Handle(Array::New(1)); |
| 23 functions.SetAt(0, function); | 22 functions.SetAt(0, function); |
| 24 cls.SetFunctions(functions); | 23 cls.SetFunctions(functions); |
| 25 Library& lib = Library::Handle(Library::CoreLibrary()); | 24 Library& lib = Library::Handle(Library::CoreLibrary()); |
| 26 lib.AddClass(cls); | 25 lib.AddClass(cls); |
| 27 function.SetCode(code); | 26 function.SetCode(code); |
| 28 CodeIndexTable* code_index_table = Isolate::Current()->code_index_table(); | |
| 29 ASSERT(code_index_table != NULL); | |
| 30 code_index_table->AddCode(code); | |
| 31 return function; | 27 return function; |
| 32 } | 28 } |
| 33 | 29 |
| 34 | 30 |
| 35 // A runtime call for test purposes. | 31 // A runtime call for test purposes. |
| 36 // Arg0: a smi. | 32 // Arg0: a smi. |
| 37 // Arg1: a smi. | 33 // Arg1: a smi. |
| 38 // Result: a smi representing arg0 - arg1. | 34 // Result: a smi representing arg0 - arg1. |
| 39 DEFINE_RUNTIME_ENTRY(TestSmiSub, 2) { | 35 DEFINE_RUNTIME_ENTRY(TestSmiSub, 2) { |
| 40 ASSERT(arguments.Count() == kTestSmiSubRuntimeEntry.argument_count()); | 36 ASSERT(arguments.Count() == kTestSmiSubRuntimeEntry.argument_count()); |
| 41 const Smi& left = Smi::CheckedHandle(arguments.At(0)); | 37 const Smi& left = Smi::CheckedHandle(arguments.At(0)); |
| 42 const Smi& right = Smi::CheckedHandle(arguments.At(1)); | 38 const Smi& right = Smi::CheckedHandle(arguments.At(1)); |
| 43 // Ignoring overflow in the calculation below. | 39 // Ignoring overflow in the calculation below. |
| 44 intptr_t result = left.Value() - right.Value(); | 40 intptr_t result = left.Value() - right.Value(); |
| 45 arguments.SetReturn(Smi::Handle(Smi::New(result))); | 41 arguments.SetReturn(Smi::Handle(Smi::New(result))); |
| 46 } | 42 } |
| 47 | 43 |
| 48 } // namespace dart | 44 } // namespace dart |
| OLD | NEW |