Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
e7082a50
Commit
e7082a50
authored
Sep 19, 2013
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1505 from ktaobo/return-breaks-self
Fixed self value in a block is changed with return value
parents
f65a39f4
c4e5a8b1
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
8 deletions
+42
-8
src/codegen.c
src/codegen.c
+5
-8
test/t/proc.rb
test/t/proc.rb
+37
-0
No files found.
src/codegen.c
View file @
e7082a50
...
@@ -278,16 +278,14 @@ genop_peep(codegen_scope *s, mrb_code i, int val)
...
@@ -278,16 +278,14 @@ genop_peep(codegen_scope *s, mrb_code i, int val)
s
->
iseq
[
s
->
pc
-
1
]
=
MKOP_AB
(
OP_RETURN
,
GETARG_B
(
i0
),
OP_R_NORMAL
);
s
->
iseq
[
s
->
pc
-
1
]
=
MKOP_AB
(
OP_RETURN
,
GETARG_B
(
i0
),
OP_R_NORMAL
);
return
;
return
;
case
OP_LOADI
:
case
OP_LOADI
:
s
->
iseq
[
s
->
pc
-
1
]
=
MKOP_AsBx
(
OP_LOADI
,
0
,
GETARG_sBx
(
i0
));
genop
(
s
,
MKOP_AB
(
OP_RETURN
,
GETARG_A
(
i0
),
OP_R_NORMAL
));
genop
(
s
,
MKOP_AB
(
OP_RETURN
,
0
,
OP_R_NORMAL
));
return
;
return
;
case
OP_ARRAY
:
case
OP_ARRAY
:
case
OP_HASH
:
case
OP_HASH
:
case
OP_RANGE
:
case
OP_RANGE
:
case
OP_AREF
:
case
OP_AREF
:
case
OP_GETUPVAR
:
case
OP_GETUPVAR
:
s
->
iseq
[
s
->
pc
-
1
]
=
MKOP_ABC
(
c0
,
0
,
GETARG_B
(
i0
),
GETARG_C
(
i0
));
genop
(
s
,
MKOP_AB
(
OP_RETURN
,
GETARG_A
(
i0
),
OP_R_NORMAL
));
genop
(
s
,
MKOP_AB
(
OP_RETURN
,
0
,
OP_R_NORMAL
));
return
;
return
;
case
OP_SETIV
:
case
OP_SETIV
:
case
OP_SETCV
:
case
OP_SETCV
:
...
@@ -308,8 +306,8 @@ genop_peep(codegen_scope *s, mrb_code i, int val)
...
@@ -308,8 +306,8 @@ genop_peep(codegen_scope *s, mrb_code i, int val)
case
OP_GETSPECIAL
:
case
OP_GETSPECIAL
:
case
OP_LOADL
:
case
OP_LOADL
:
case
OP_STRING
:
case
OP_STRING
:
s
->
iseq
[
s
->
pc
-
1
]
=
MKOP_ABx
(
c0
,
0
,
GETARG_Bx
(
i0
));
s
->
iseq
[
s
->
pc
-
1
]
=
MKOP_ABx
(
c0
,
GETARG_A
(
i0
)
,
GETARG_Bx
(
i0
));
genop
(
s
,
MKOP_AB
(
OP_RETURN
,
0
,
OP_R_NORMAL
));
genop
(
s
,
MKOP_AB
(
OP_RETURN
,
GETARG_A
(
i0
)
,
OP_R_NORMAL
));
return
;
return
;
case
OP_SCLASS
:
case
OP_SCLASS
:
s
->
iseq
[
s
->
pc
-
1
]
=
MKOP_AB
(
c0
,
GETARG_A
(
i
),
GETARG_B
(
i0
));
s
->
iseq
[
s
->
pc
-
1
]
=
MKOP_AB
(
c0
,
GETARG_A
(
i
),
GETARG_B
(
i0
));
...
@@ -320,8 +318,7 @@ genop_peep(codegen_scope *s, mrb_code i, int val)
...
@@ -320,8 +318,7 @@ genop_peep(codegen_scope *s, mrb_code i, int val)
case
OP_LOADT
:
case
OP_LOADT
:
case
OP_LOADF
:
case
OP_LOADF
:
case
OP_OCLASS
:
case
OP_OCLASS
:
s
->
iseq
[
s
->
pc
-
1
]
=
MKOP_A
(
c0
,
0
);
genop
(
s
,
MKOP_AB
(
OP_RETURN
,
GETARG_A
(
i0
),
OP_R_NORMAL
));
genop
(
s
,
MKOP_AB
(
OP_RETURN
,
0
,
OP_R_NORMAL
));
return
;
return
;
#if 0
#if 0
case OP_SEND:
case OP_SEND:
...
...
test/t/proc.rb
View file @
e7082a50
...
@@ -54,3 +54,40 @@ assert('Proc#call', '15.2.17.4.3') do
...
@@ -54,3 +54,40 @@ assert('Proc#call', '15.2.17.4.3') do
assert_equal
1
,
a
assert_equal
1
,
a
assert_equal
5
,
a2
assert_equal
5
,
a2
end
end
assert
(
'Proc#return_does_not_break_self'
)
do
class
TestClass
attr_accessor
:block
def
initialize
end
def
return_array
@block
=
Proc
.
new
{
self
}
return
[]
end
def
return_instance_variable
@block
=
Proc
.
new
{
self
}
return
@block
end
def
return_const_fixnum
@block
=
Proc
.
new
{
self
}
return
123
end
def
return_nil
@block
=
Proc
.
new
{
self
}
return
nil
end
end
c
=
TestClass
.
new
assert_equal
[],
c
.
return_array
assert_equal
c
,
c
.
block
.
call
c
.
return_instance_variable
assert_equal
c
,
c
.
block
.
call
assert_equal
123
,
c
.
return_const_fixnum
assert_equal
c
,
c
.
block
.
call
assert_equal
nil
,
c
.
return_nil
assert_equal
c
,
c
.
block
.
call
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment