Permalink
Browse files

Pluggable Regexp

  • Loading branch information...
1 parent 8578cd6 commit b1a5146ea8f8665df5edf2b26dcadc028d7929f7 @mattn mattn committed Feb 14, 2013
Showing with 147 additions and 22,517 deletions.
  1. +1 −1 include/mrbconf.h
  2. +1 −3 include/mruby/class.h
  3. +1 −0 include/mruby/compile.h
  4. +0 −4 include/mruby/string.h
  5. +17 −0 src/codegen.c
  6. +0 −27 src/dump.c
  7. +0 −345 src/encoding.h
  8. +0 −1 src/etc.c
  9. +0 −35 src/gc.c
  10. +1 −3 src/init.c
  11. +0 −10 src/load.c
  12. +1 −0 src/node.h
  13. +0 −771 src/oniguruma.h
  14. +74 −4 src/parse.y
  15. +1 −2,562 src/re.c
  16. +2 −51 src/re.h
  17. +0 −6,288 src/regcomp.c
  18. +0 −901 src/regenc.c
  19. +0 −203 src/regenc.h
  20. +0 −375 src/regerror.c
  21. +0 −26 src/regex.h
  22. +0 −3,757 src/regexec.c
  23. +0 −838 src/regint.h
  24. +0 −5,600 src/regparse.c
  25. +0 −354 src/regparse.h
  26. +0 −1 src/sprintf.c
  27. +48 −349 src/string.c
  28. +0 −4 src/struct.c
  29. +0 −4 src/variable.c
View
@@ -44,7 +44,7 @@
//#define POOL_PAGE_SIZE 16000
/* -DDISABLE_XXXX to drop the feature */
-#define DISABLE_REGEXP /* regular expression classes */
+//#define DISABLE_REGEXP /* regular expression classes */
//#define DISABLE_SPRINTF /* Kernel.sprintf method */
//#define DISABLE_MATH /* Math functions */
//#define DISABLE_TIME /* Time class */
View
@@ -42,13 +42,11 @@ mrb_class(mrb_state *mrb, mrb_value v)
case MRB_TT_MAIN:
return mrb->object_class;
-#ifdef ENABLE_REGEXP
case MRB_TT_REGEX:
case MRB_TT_MATCH:
- mrb_raise(mrb, E_TYPE_ERROR, "type mismatch: %s given",
+ mrb_raisef(mrb, E_TYPE_ERROR, "type mismatch: %s given",
mrb_obj_classname(mrb, v));
return mrb->nil_class; /* not reach */
-#endif
default:
return mrb_object(v)->c;
}
View
@@ -72,6 +72,7 @@ struct mrb_parser_state {
enum mrb_lex_state_enum lstate;
int sterm;
+ int regexp;
unsigned int cond_stack;
unsigned int cmdarg_stack;
View
@@ -11,10 +11,6 @@
extern "C" {
#endif
-#ifdef INCLUDE_ENCODING
-#include "encoding.h"
-#endif
-
#ifndef RB_GC_GUARD
#define RB_GC_GUARD(v) v
#endif
View
@@ -1910,6 +1910,23 @@ codegen(codegen_scope *s, node *tree, int val)
}
break;
+ case NODE_REGX:
+ if (val) {
+ char *p = (char*)tree->car;
+ size_t len = (intptr_t)tree->cdr;
+ int ai = mrb_gc_arena_save(s->mrb);
+ struct RClass* c = mrb_class_get(s->mrb, "Regexp");
+ mrb_value args[1];
+ args[0] = mrb_str_new(s->mrb, p, len);
+ int off = new_lit(s,
+ mrb_class_new_instance(s->mrb, 1, args, c));
+
+ mrb_gc_arena_restore(s->mrb, ai);
+ genop(s, MKOP_ABx(OP_STRING, cursp(), off));
+ push();
+ }
+ break;
+
case NODE_SYM:
if (val) {
int sym = new_sym(s, sym(tree));
View
@@ -9,9 +9,6 @@
#include <ctype.h>
#include "mruby/string.h"
-#ifdef ENABLE_REGEXP
-#include "re.h"
-#endif
#include "mruby/irep.h"
static const unsigned char def_rite_binary_header[] =
@@ -256,13 +253,6 @@ get_pool_block_size(mrb_state *mrb, mrb_irep *irep, int type)
nlen = str_dump_len(RSTRING_PTR(str), RSTRING_LEN(str), type);
size += nlen;
break;
-#ifdef ENABLE_REGEXP
- case MRB_TT_REGEX:
- str = mrb_reg_to_s(mrb, irep->pool[pool_no]);
- nlen = str_dump_len(RSTRING_PTR(str), RSTRING_LEN(str), type);
- size += nlen;
- break;
-#endif
default:
break;
}
@@ -390,23 +380,6 @@ write_pool_block(mrb_state *mrb, mrb_irep *irep, char *buf, int type)
str_dump(RSTRING_PTR(str), char_buf, RSTRING_LEN(str), type);
break;
-#ifdef ENABLE_REGEXP
- case MRB_TT_REGEX:
- str = mrb_reg_to_s(mrb, irep->pool[pool_no]);
- len = str_dump_len(RSTRING_PTR(str), RSTRING_LEN(str), type);
- if ( len > buf_size - 1) {
- buf_size = len + 1;
- char_buf = mrb_realloc(mrb, char_buf, buf_size);
- if (char_buf == NULL) {
- result = MRB_DUMP_GENERAL_FAILURE;
- goto error_exit;
- }
- memset(char_buf, 0, buf_size);
- }
- str_dump(RSTRING_PTR(str), char_buf, RSTRING_LEN(str), type);
- break;
-#endif
-
default:
buf += uint16_dump(0, buf, type); /* data length = 0 */
continue;
Oops, something went wrong.

0 comments on commit b1a5146

Please sign in to comment.