summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-compiler/core/codegen.c
diff options
context:
space:
mode:
Diffstat (limited to 'mrbgems/mruby-compiler/core/codegen.c')
-rw-r--r--mrbgems/mruby-compiler/core/codegen.c55
1 files changed, 39 insertions, 16 deletions
diff --git a/mrbgems/mruby-compiler/core/codegen.c b/mrbgems/mruby-compiler/core/codegen.c
index 3853814ec..c56c1550c 100644
--- a/mrbgems/mruby-compiler/core/codegen.c
+++ b/mrbgems/mruby-compiler/core/codegen.c
@@ -8,16 +8,16 @@
#include <limits.h>
#include <stdlib.h>
#include <string.h>
-#include "mruby.h"
-#include "mruby/compile.h"
-#include "mruby/proc.h"
-#include "mruby/numeric.h"
-#include "mruby/string.h"
-#include "mruby/debug.h"
+#include <mruby.h>
+#include <mruby/compile.h>
+#include <mruby/proc.h>
+#include <mruby/numeric.h>
+#include <mruby/string.h>
+#include <mruby/debug.h>
#include "node.h"
-#include "mruby/opcode.h"
-#include "mruby/re.h"
-#include "mruby/throw.h"
+#include <mruby/opcode.h>
+#include <mruby/re.h>
+#include <mruby/throw.h>
typedef mrb_ast_node node;
typedef struct mrb_parser_state parser_state;
@@ -96,7 +96,7 @@ codegen_error(codegen_scope *s, const char *message)
mrb_pool_close(s->mpool);
s = tmp;
}
-#ifdef ENABLE_STDIO
+#ifndef MRB_DISABLE_STDIO
if (s->filename && s->lineno) {
fprintf(stderr, "codegen error:%s:%d: %s\n", s->filename, s->lineno, message);
}
@@ -375,7 +375,7 @@ dispatch(codegen_scope *s, int pc)
case OP_ONERR:
break;
default:
-#ifdef ENABLE_STDIO
+#ifndef MRB_DISABLE_STDIO
fprintf(stderr, "bug: dispatch on non JMP op\n");
#endif
scope_error(s);
@@ -978,7 +978,7 @@ gen_assignment(codegen_scope *s, node *tree, int sp, int val)
break;
default:
-#ifdef ENABLE_STDIO
+#ifndef MRB_DISABLE_STDIO
printf("unknown lhs %d\n", type);
#endif
break;
@@ -1330,6 +1330,17 @@ codegen(codegen_scope *s, node *tree, int val)
int pos1, pos2;
node *e = tree->cdr->cdr->car;
+ switch ((intptr_t)tree->car->car) {
+ case NODE_TRUE:
+ case NODE_INT:
+ case NODE_STR:
+ codegen(s, tree->cdr->car, val);
+ return;
+ case NODE_FALSE:
+ case NODE_NIL:
+ codegen(s, e, val);
+ return;
+ }
codegen(s, tree->car, VAL);
pop();
pos1 = genop_peep(s, MKOP_AsBx(OP_JMPNOT, cursp(), 0), NOVAL);
@@ -2216,7 +2227,8 @@ codegen(codegen_scope *s, node *tree, int val)
case NODE_REGX:
if (val) {
char *p1 = (char*)tree->car;
- char *p2 = (char*)tree->cdr;
+ char *p2 = (char*)tree->cdr->car;
+ char *p3 = (char*)tree->cdr->cdr;
int ai = mrb_gc_arena_save(s->mrb);
int sym = new_sym(s, mrb_intern_lit(s->mrb, REGEXP_CLASS));
int off = new_lit(s, mrb_str_new_cstr(s->mrb, p1));
@@ -2226,11 +2238,22 @@ codegen(codegen_scope *s, node *tree, int val)
genop(s, MKOP_ABx(OP_GETMCNST, cursp(), sym));
push();
genop(s, MKOP_ABx(OP_STRING, cursp(), off));
- if (p2) {
+ if (p2 || p3) {
push();
- off = new_lit(s, mrb_str_new_cstr(s->mrb, p2));
- genop(s, MKOP_ABx(OP_STRING, cursp(), off));
+ if (p2) {
+ off = new_lit(s, mrb_str_new_cstr(s->mrb, p2));
+ genop(s, MKOP_ABx(OP_STRING, cursp(), off));
+ } else {
+ genop(s, MKOP_A(OP_LOADNIL, cursp()));
+ }
argc++;
+ if (p3) {
+ push();
+ off = new_lit(s, mrb_str_new(s->mrb, p3, 1));
+ genop(s, MKOP_ABx(OP_STRING, cursp(), off));
+ argc++;
+ pop();
+ }
pop();
}
pop();