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

Side by Side Diff: test/cctest/test-regexp.cc

Issue 9690: Rename codegen to macro-assembler.... (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/regexp2000/
Patch Set: Created 12 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
« src/interpreter-re2k.cc ('K') | « src/regexp-macro-assembler-re2k.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 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 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 __ Bind(&advance); 488 __ Bind(&advance);
489 __ AdvanceCP(); 489 __ AdvanceCP();
490 __ Bind(&look_for_foo); 490 __ Bind(&look_for_foo);
491 __ FailIfWithin(3); 491 __ FailIfWithin(3);
492 __ LoadCurrentChar(0); 492 __ LoadCurrentChar(0);
493 __ CheckChar('f', &advance); 493 __ CheckChar('f', &advance);
494 __ LoadCurrentChar(1); 494 __ LoadCurrentChar(1);
495 __ CheckChar('o', &advance); 495 __ CheckChar('o', &advance);
496 __ LoadCurrentChar(2); 496 __ LoadCurrentChar(2);
497 __ CheckChar('o', &advance); 497 __ CheckChar('o', &advance);
498 __ SetRegister(0); 498 __ SetRegisterToCurrentPosition(0);
499 __ SetRegister(1, 2); 499 __ SetRegisterToCurrentPosition(1, 2);
500 __ Succeed(); 500 __ Succeed();
501 501
502 v8::HandleScope scope; 502 v8::HandleScope scope;
503 Handle<ByteArray> array = Factory::NewByteArray(assembler.length()); 503 Handle<ByteArray> array = Factory::NewByteArray(assembler.length());
504 assembler.Copy(array->GetDataStartAddress()); 504 assembler.Copy(array->GetDataStartAddress());
505 int captures[2]; 505 int captures[2];
506 506
507 Handle<String> f1 = 507 Handle<String> f1 =
508 Factory::NewStringFromAscii(CStrVector("Now is the time")); 508 Factory::NewStringFromAscii(CStrVector("Now is the time"));
509 CHECK(!Re2kInterpreter::Match(*array, *f1, captures, 0)); 509 CHECK(!Re2kInterpreter::Match(*array, *f1, captures, 0));
510 510
511 Handle<String> f2 = Factory::NewStringFromAscii(CStrVector("foo bar baz")); 511 Handle<String> f2 = Factory::NewStringFromAscii(CStrVector("foo bar baz"));
512 CHECK(Re2kInterpreter::Match(*array, *f2, captures, 0)); 512 CHECK(Re2kInterpreter::Match(*array, *f2, captures, 0));
513 CHECK_EQ(0, captures[0]); 513 CHECK_EQ(0, captures[0]);
514 CHECK_EQ(2, captures[1]); 514 CHECK_EQ(2, captures[1]);
515 515
516 Handle<String> f3 = Factory::NewStringFromAscii(CStrVector("tomfoolery")); 516 Handle<String> f3 = Factory::NewStringFromAscii(CStrVector("tomfoolery"));
517 CHECK(Re2kInterpreter::Match(*array, *f3, captures, 0)); 517 CHECK(Re2kInterpreter::Match(*array, *f3, captures, 0));
518 CHECK_EQ(3, captures[0]); 518 CHECK_EQ(3, captures[0]);
519 CHECK_EQ(5, captures[1]); 519 CHECK_EQ(5, captures[1]);
520 } 520 }
521
522
523 TEST(Assembler2) {
524 V8::Initialize(NULL);
525 byte codes[1024];
526 Re2kAssembler assembler(Vector<byte>(codes, 1024));
527 #define __ assembler.
528 // /^.*foo/
529 Label more_dots;
530 Label unwind_dot;
531 Label failure;
532 Label foo;
533 Label foo_failed;
534 Label dot_match;
535 // ^
536 __ PushCurrentPosition();
537 __ PushRegister(0);
538 __ SetRegisterToCurrentPosition(0);
539 __ PushBacktrack(&failure);
540 __ GoTo(&dot_match);
541 // .*
542 __ Bind(&more_dots);
543 __ AdvanceCP();
544 __ Bind(&dot_match);
545 __ PushCurrentPosition();
546 __ PushBacktrack(&unwind_dot);
547 __ LoadCurrentChar();
548 __ CheckNotEnd(&foo);
549 __ CheckChar('\n', &more_dots);
550 // foo
551 __ Bind(&foo);
552 __ CheckChar('f', &foo_failed);
553 __ LoadCurrentChar(1);
554 __ CheckChar('o', &foo_failed);
555 __ LoadCurrentChar(2);
556 __ CheckChar('o', &foo_failed);
557 __ SetRegisterToCurrentPosition(1, 2);
558 __ Succeed();
559 __ Break();
560
561 __ Bind(&foo_failed);
562 __ PopBacktrack();
563 __ Break();
564
565 __ Bind(&unwind_dot);
566 __ PopCurrentPosition();
567 __ LoadCurrentChar();
568 __ GoTo(&foo);
569
570 __ Bind(&failure);
571 __ PopRegister(0);
572 __ PopCurrentPosition();
573 __ Fail();
574
575 v8::HandleScope scope;
576 Handle<ByteArray> array = Factory::NewByteArray(assembler.length());
577 assembler.Copy(array->GetDataStartAddress());
578 int captures[2];
579
580 Handle<String> f1 =
581 Factory::NewStringFromAscii(CStrVector("Now is the time"));
582 CHECK(!Re2kInterpreter::Match(*array, *f1, captures, 0));
583
584 Handle<String> f2 = Factory::NewStringFromAscii(CStrVector("foo bar baz"));
585 CHECK(Re2kInterpreter::Match(*array, *f2, captures, 0));
586 CHECK_EQ(0, captures[0]);
587 CHECK_EQ(2, captures[1]);
588
589 Handle<String> f3 = Factory::NewStringFromAscii(CStrVector("tomfoolery"));
590 CHECK(Re2kInterpreter::Match(*array, *f3, captures, 0));
591 CHECK_EQ(0, captures[0]);
592 CHECK_EQ(5, captures[1]);
593
594 Handle<String> f4 = Factory::NewStringFromAscii(CStrVector("football buffooner y"));
595 CHECK(Re2kInterpreter::Match(*array, *f4, captures, 0));
596 CHECK_EQ(0, captures[0]);
597 CHECK_EQ(14, captures[1]);
598
599 Handle<String> f5 = Factory::NewStringFromAscii(CStrVector("walking\nbarefoot" ));
600 CHECK(!Re2kInterpreter::Match(*array, *f5, captures, 0));
601 }
OLDNEW
« src/interpreter-re2k.cc ('K') | « src/regexp-macro-assembler-re2k.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698