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

Side by Side Diff: src/ia32/fast-codegen-ia32.cc

Issue 368005: Add support for all declarations in the top-level compiler: ... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/fast-codegen.cc ('k') | src/x64/fast-codegen-x64.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2009 the V8 project authors. All rights reserved. 1 // Copyright 2009 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 // Call the stub for all other cases. 283 // Call the stub for all other cases.
284 __ push(source); 284 __ push(source);
285 ToBooleanStub stub; 285 ToBooleanStub stub;
286 __ CallStub(&stub); 286 __ CallStub(&stub);
287 __ test(eax, Operand(eax)); // The stub returns nonzero for true. 287 __ test(eax, Operand(eax)); // The stub returns nonzero for true.
288 __ j(not_zero, true_label); 288 __ j(not_zero, true_label);
289 __ jmp(false_label); 289 __ jmp(false_label);
290 } 290 }
291 291
292 292
293 void FastCodeGenerator::VisitDeclaration(Declaration* decl) {
294 Variable* var = decl->proxy()->var();
295 ASSERT(var != NULL); // Must have been resolved.
296 Slot* slot = var->slot();
297 ASSERT(slot != NULL); // No global declarations here.
298
299 // We have 3 cases for slots: LOOKUP, LOCAL, CONTEXT.
300 switch (slot->type()) {
301 case Slot::LOOKUP: {
302 __ push(esi);
303 __ push(Immediate(var->name()));
304 // Declaration nodes are always introduced in one of two modes.
305 ASSERT(decl->mode() == Variable::VAR || decl->mode() == Variable::CONST);
306 PropertyAttributes attr =
307 (decl->mode() == Variable::VAR) ? NONE : READ_ONLY;
308 __ push(Immediate(Smi::FromInt(attr)));
309 // Push initial value, if any.
310 // Note: For variables we must not push an initial value (such as
311 // 'undefined') because we may have a (legal) redeclaration and we
312 // must not destroy the current value.
313 if (decl->mode() == Variable::CONST) {
314 __ push(Immediate(Factory::the_hole_value()));
315 } else if (decl->fun() != NULL) {
316 Visit(decl->fun());
317 } else {
318 __ push(Immediate(Smi::FromInt(0))); // No initial value!
319 }
320 __ CallRuntime(Runtime::kDeclareContextSlot, 4);
321 break;
322 }
323 case Slot::LOCAL:
324 if (decl->mode() == Variable::CONST) {
325 __ mov(Operand(ebp, SlotOffset(var->slot())),
326 Immediate(Factory::the_hole_value()));
327 } else if (decl->fun() != NULL) {
328 Visit(decl->fun());
329 __ pop(Operand(ebp, SlotOffset(var->slot())));
330 }
331 break;
332 case Slot::CONTEXT:
333 // The variable in the decl always resides in the current context.
334 ASSERT(function_->scope()->ContextChainLength(slot->var()->scope()) == 0);
335 if (decl->mode() == Variable::CONST) {
336 __ mov(eax, Immediate(Factory::the_hole_value()));
337 if (FLAG_debug_code) {
338 // Check if we have the correct context pointer.
339 __ mov(ebx,
340 CodeGenerator::ContextOperand(esi, Context::FCONTEXT_INDEX));
341 __ cmp(ebx, Operand(esi));
342 __ Check(equal, "Unexpected declaration in current context.");
343 }
344 __ mov(CodeGenerator::ContextOperand(esi, slot->index()), eax);
345 // No write barrier since the_hole_value is in old space.
346 } else if (decl->fun() != NULL) {
347 Visit(decl->fun());
348 __ pop(eax);
349 if (FLAG_debug_code) {
350 // Check if we have the correct context pointer.
351 __ mov(ebx,
352 CodeGenerator::ContextOperand(esi, Context::FCONTEXT_INDEX));
353 __ cmp(ebx, Operand(esi));
354 __ Check(equal, "Unexpected declaration in current context.");
355 }
356 __ mov(CodeGenerator::ContextOperand(esi, slot->index()), eax);
357 int offset = FixedArray::kHeaderSize + slot->index() * kPointerSize;
358 __ RecordWrite(esi, offset, eax, ecx);
359 }
360 break;
361 default:
362 UNREACHABLE();
363 }
364 }
365
366
293 void FastCodeGenerator::DeclareGlobals(Handle<FixedArray> pairs) { 367 void FastCodeGenerator::DeclareGlobals(Handle<FixedArray> pairs) {
294 // Call the runtime to declare the globals. 368 // Call the runtime to declare the globals.
295 __ push(esi); // The context is the first argument. 369 __ push(esi); // The context is the first argument.
296 __ push(Immediate(pairs)); 370 __ push(Immediate(pairs));
297 __ push(Immediate(Smi::FromInt(is_eval_ ? 1 : 0))); 371 __ push(Immediate(Smi::FromInt(is_eval_ ? 1 : 0)));
298 __ CallRuntime(Runtime::kDeclareGlobals, 3); 372 __ CallRuntime(Runtime::kDeclareGlobals, 3);
299 // Return value is ignored. 373 // Return value is ignored.
300 } 374 }
301 375
302 376
(...skipping 1032 matching lines...) Expand 10 before | Expand all | Expand 10 after
1335 true_label_ = saved_true; 1409 true_label_ = saved_true;
1336 false_label_ = saved_false; 1410 false_label_ = saved_false;
1337 // Convert current context to test context: End post-test code. 1411 // Convert current context to test context: End post-test code.
1338 } 1412 }
1339 1413
1340 1414
1341 #undef __ 1415 #undef __
1342 1416
1343 1417
1344 } } // namespace v8::internal 1418 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/fast-codegen.cc ('k') | src/x64/fast-codegen-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698