From 103ef78e59348d5aef4775759cfb651ae1b340ee Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Thu, 17 May 2012 13:21:01 +0900 Subject: no SEGV for nth_ref & back_ref; close #152 --- src/codegen.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'src/codegen.c') diff --git a/src/codegen.c b/src/codegen.c index a943c607a..ae5eafdf7 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -1477,11 +1477,27 @@ codegen(codegen_scope *s, node *tree, int val) break; case NODE_BACK_REF: - codegen(s, tree, VAL); + { + char buf[4]; + int sym; + + snprintf(buf, 3, "$%c", (intptr_t)tree); + sym = new_sym(s, mrb_intern(s->mrb, buf)); + genop(s, MKOP_ABx(OP_GETGLOBAL, cursp(), sym)); + push(); + } break; case NODE_NTH_REF: - codegen(s, tree, VAL); + { + char buf[4]; + int sym; + + snprintf(buf, 3, "$%d", (intptr_t)tree); + sym = new_sym(s, mrb_intern(s->mrb, buf)); + genop(s, MKOP_ABx(OP_GETGLOBAL, cursp(), sym)); + push(); + } break; case NODE_ARG: -- cgit v1.2.3