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
4004e122
Commit
4004e122
authored
May 20, 2014
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2296 from take-cheeze/core_local_vars
Move `Kernel.local_variables` to core.
parents
c4268f67
d8d07a23
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
61 additions
and
61 deletions
+61
-61
mrbgems/mruby-bin-strip/mrbgem.rake
mrbgems/mruby-bin-strip/mrbgem.rake
+0
-1
mrbgems/mruby-proc-ext/src/proc.c
mrbgems/mruby-proc-ext/src/proc.c
+0
-46
mrbgems/mruby-proc-ext/test/proc.rb
mrbgems/mruby-proc-ext/test/proc.rb
+0
-14
src/kernel.c
src/kernel.c
+47
-0
test/t/kernel.rb
test/t/kernel.rb
+14
-0
No files found.
mrbgems/mruby-bin-strip/mrbgem.rake
View file @
4004e122
...
@@ -3,5 +3,4 @@ MRuby::Gem::Specification.new('mruby-bin-strip') do |spec|
...
@@ -3,5 +3,4 @@ MRuby::Gem::Specification.new('mruby-bin-strip') do |spec|
spec
.
author
=
'mruby developers'
spec
.
author
=
'mruby developers'
spec
.
summary
=
'irep dump debug section remover command'
spec
.
summary
=
'irep dump debug section remover command'
spec
.
bins
=
%w(mruby-strip)
spec
.
bins
=
%w(mruby-strip)
spec
.
add_dependency
'mruby-proc-ext'
,
:core
=>
'mruby-proc-ext'
end
end
mrbgems/mruby-proc-ext/src/proc.c
View file @
4004e122
...
@@ -122,51 +122,6 @@ mrb_kernel_proc(mrb_state *mrb, mrb_value self)
...
@@ -122,51 +122,6 @@ mrb_kernel_proc(mrb_state *mrb, mrb_value self)
return
blk
;
return
blk
;
}
}
static
mrb_value
mrb_local_variables
(
mrb_state
*
mrb
,
mrb_value
self
)
{
mrb_value
ret
;
struct
RProc
*
proc
;
struct
mrb_irep
*
irep
;
size_t
i
;
proc
=
mrb
->
c
->
ci
[
-
1
].
proc
;
if
(
MRB_PROC_CFUNC_P
(
proc
))
{
return
mrb_ary_new
(
mrb
);
}
irep
=
proc
->
body
.
irep
;
if
(
!
irep
->
lv
)
{
return
mrb_ary_new
(
mrb
);
}
ret
=
mrb_ary_new_capa
(
mrb
,
irep
->
nlocals
-
1
);
for
(
i
=
0
;
i
+
1
<
irep
->
nlocals
;
++
i
)
{
if
(
irep
->
lv
[
i
].
name
)
{
mrb_ary_push
(
mrb
,
ret
,
mrb_symbol_value
(
irep
->
lv
[
i
].
name
));
}
}
if
(
proc
->
env
)
{
struct
REnv
*
e
=
proc
->
env
;
while
(
e
)
{
if
(
!
MRB_PROC_CFUNC_P
(
mrb
->
c
->
cibase
[
e
->
cioff
].
proc
))
{
irep
=
mrb
->
c
->
cibase
[
e
->
cioff
].
proc
->
body
.
irep
;
if
(
irep
->
lv
)
{
for
(
i
=
0
;
i
+
1
<
irep
->
nlocals
;
++
i
)
{
if
(
irep
->
lv
[
i
].
name
)
{
mrb_ary_push
(
mrb
,
ret
,
mrb_symbol_value
(
irep
->
lv
[
i
].
name
));
}
}
}
}
e
=
(
struct
REnv
*
)
e
->
c
;
}
}
return
ret
;
}
void
void
mrb_mruby_proc_ext_gem_init
(
mrb_state
*
mrb
)
mrb_mruby_proc_ext_gem_init
(
mrb_state
*
mrb
)
{
{
...
@@ -178,7 +133,6 @@ mrb_mruby_proc_ext_gem_init(mrb_state* mrb)
...
@@ -178,7 +133,6 @@ mrb_mruby_proc_ext_gem_init(mrb_state* mrb)
mrb_define_class_method
(
mrb
,
mrb
->
kernel_module
,
"proc"
,
mrb_kernel_proc
,
MRB_ARGS_NONE
());
mrb_define_class_method
(
mrb
,
mrb
->
kernel_module
,
"proc"
,
mrb_kernel_proc
,
MRB_ARGS_NONE
());
mrb_define_method
(
mrb
,
mrb
->
kernel_module
,
"proc"
,
mrb_kernel_proc
,
MRB_ARGS_NONE
());
mrb_define_method
(
mrb
,
mrb
->
kernel_module
,
"proc"
,
mrb_kernel_proc
,
MRB_ARGS_NONE
());
mrb_define_module_function
(
mrb
,
mrb
->
kernel_module
,
"local_variables"
,
mrb_local_variables
,
MRB_ARGS_NONE
());
}
}
void
void
...
...
mrbgems/mruby-proc-ext/test/proc.rb
View file @
4004e122
...
@@ -74,17 +74,3 @@ assert('mrb_cfunc_env_get') do
...
@@ -74,17 +74,3 @@ assert('mrb_cfunc_env_get') do
assert_equal
1
,
t
.
get_int
(
1
)
assert_equal
1
,
t
.
get_int
(
1
)
end
end
assert
(
'Kernel.local_variables'
,
'15.3.1.2.7'
)
do
a
,
b
=
0
,
1
a
+=
b
vars
=
Kernel
.
local_variables
.
sort
assert_equal
[
:a
,
:b
,
:vars
],
vars
proc
{
c
=
2
vars
=
Kernel
.
local_variables
.
sort
assert_equal
[
:a
,
:b
,
:c
,
:vars
],
vars
}.
call
end
src/kernel.c
View file @
4004e122
...
@@ -1101,6 +1101,51 @@ mrb_obj_ceqq(mrb_state *mrb, mrb_value self)
...
@@ -1101,6 +1101,51 @@ mrb_obj_ceqq(mrb_state *mrb, mrb_value self)
return
mrb_false_value
();
return
mrb_false_value
();
}
}
static
mrb_value
mrb_local_variables
(
mrb_state
*
mrb
,
mrb_value
self
)
{
mrb_value
ret
;
struct
RProc
*
proc
;
struct
mrb_irep
*
irep
;
size_t
i
;
proc
=
mrb
->
c
->
ci
[
-
1
].
proc
;
if
(
MRB_PROC_CFUNC_P
(
proc
))
{
return
mrb_ary_new
(
mrb
);
}
irep
=
proc
->
body
.
irep
;
if
(
!
irep
->
lv
)
{
return
mrb_ary_new
(
mrb
);
}
ret
=
mrb_ary_new_capa
(
mrb
,
irep
->
nlocals
-
1
);
for
(
i
=
0
;
i
+
1
<
irep
->
nlocals
;
++
i
)
{
if
(
irep
->
lv
[
i
].
name
)
{
mrb_ary_push
(
mrb
,
ret
,
mrb_symbol_value
(
irep
->
lv
[
i
].
name
));
}
}
if
(
proc
->
env
)
{
struct
REnv
*
e
=
proc
->
env
;
while
(
e
)
{
if
(
!
MRB_PROC_CFUNC_P
(
mrb
->
c
->
cibase
[
e
->
cioff
].
proc
))
{
irep
=
mrb
->
c
->
cibase
[
e
->
cioff
].
proc
->
body
.
irep
;
if
(
irep
->
lv
)
{
for
(
i
=
0
;
i
+
1
<
irep
->
nlocals
;
++
i
)
{
if
(
irep
->
lv
[
i
].
name
)
{
mrb_ary_push
(
mrb
,
ret
,
mrb_symbol_value
(
irep
->
lv
[
i
].
name
));
}
}
}
}
e
=
(
struct
REnv
*
)
e
->
c
;
}
}
return
ret
;
}
void
void
mrb_init_kernel
(
mrb_state
*
mrb
)
mrb_init_kernel
(
mrb_state
*
mrb
)
{
{
...
@@ -1110,6 +1155,7 @@ mrb_init_kernel(mrb_state *mrb)
...
@@ -1110,6 +1155,7 @@ mrb_init_kernel(mrb_state *mrb)
mrb_define_class_method
(
mrb
,
krn
,
"block_given?"
,
mrb_f_block_given_p_m
,
MRB_ARGS_NONE
());
/* 15.3.1.2.2 */
mrb_define_class_method
(
mrb
,
krn
,
"block_given?"
,
mrb_f_block_given_p_m
,
MRB_ARGS_NONE
());
/* 15.3.1.2.2 */
mrb_define_class_method
(
mrb
,
krn
,
"global_variables"
,
mrb_f_global_variables
,
MRB_ARGS_NONE
());
/* 15.3.1.2.4 */
mrb_define_class_method
(
mrb
,
krn
,
"global_variables"
,
mrb_f_global_variables
,
MRB_ARGS_NONE
());
/* 15.3.1.2.4 */
mrb_define_class_method
(
mrb
,
krn
,
"iterator?"
,
mrb_f_block_given_p_m
,
MRB_ARGS_NONE
());
/* 15.3.1.2.5 */
mrb_define_class_method
(
mrb
,
krn
,
"iterator?"
,
mrb_f_block_given_p_m
,
MRB_ARGS_NONE
());
/* 15.3.1.2.5 */
mrb_define_class_method
(
mrb
,
krn
,
"local_variables"
,
mrb_local_variables
,
MRB_ARGS_NONE
());
/* 15.3.1.2.7 */
;
/* 15.3.1.2.11 */
;
/* 15.3.1.2.11 */
mrb_define_class_method
(
mrb
,
krn
,
"raise"
,
mrb_f_raise
,
MRB_ARGS_ANY
());
/* 15.3.1.2.12 */
mrb_define_class_method
(
mrb
,
krn
,
"raise"
,
mrb_f_raise
,
MRB_ARGS_ANY
());
/* 15.3.1.2.12 */
...
@@ -1140,6 +1186,7 @@ mrb_init_kernel(mrb_state *mrb)
...
@@ -1140,6 +1186,7 @@ mrb_init_kernel(mrb_state *mrb)
mrb_define_method
(
mrb
,
krn
,
"is_a?"
,
mrb_obj_is_kind_of_m
,
MRB_ARGS_REQ
(
1
));
/* 15.3.1.3.24 */
mrb_define_method
(
mrb
,
krn
,
"is_a?"
,
mrb_obj_is_kind_of_m
,
MRB_ARGS_REQ
(
1
));
/* 15.3.1.3.24 */
mrb_define_method
(
mrb
,
krn
,
"iterator?"
,
mrb_f_block_given_p_m
,
MRB_ARGS_NONE
());
/* 15.3.1.3.25 */
mrb_define_method
(
mrb
,
krn
,
"iterator?"
,
mrb_f_block_given_p_m
,
MRB_ARGS_NONE
());
/* 15.3.1.3.25 */
mrb_define_method
(
mrb
,
krn
,
"kind_of?"
,
mrb_obj_is_kind_of_m
,
MRB_ARGS_REQ
(
1
));
/* 15.3.1.3.26 */
mrb_define_method
(
mrb
,
krn
,
"kind_of?"
,
mrb_obj_is_kind_of_m
,
MRB_ARGS_REQ
(
1
));
/* 15.3.1.3.26 */
mrb_define_method
(
mrb
,
krn
,
"local_variables"
,
mrb_local_variables
,
MRB_ARGS_NONE
());
/* 15.3.1.3.28 */
mrb_define_method
(
mrb
,
krn
,
"methods"
,
mrb_obj_methods_m
,
MRB_ARGS_OPT
(
1
));
/* 15.3.1.3.31 */
mrb_define_method
(
mrb
,
krn
,
"methods"
,
mrb_obj_methods_m
,
MRB_ARGS_OPT
(
1
));
/* 15.3.1.3.31 */
mrb_define_method
(
mrb
,
krn
,
"nil?"
,
mrb_false
,
MRB_ARGS_NONE
());
/* 15.3.1.3.32 */
mrb_define_method
(
mrb
,
krn
,
"nil?"
,
mrb_false
,
MRB_ARGS_NONE
());
/* 15.3.1.3.32 */
mrb_define_method
(
mrb
,
krn
,
"object_id"
,
mrb_obj_id_m
,
MRB_ARGS_NONE
());
/* 15.3.1.3.33 */
mrb_define_method
(
mrb
,
krn
,
"object_id"
,
mrb_obj_id_m
,
MRB_ARGS_NONE
());
/* 15.3.1.3.33 */
...
...
test/t/kernel.rb
View file @
4004e122
...
@@ -507,6 +507,20 @@ assert('Kernel#to_s', '15.3.1.3.46') do
...
@@ -507,6 +507,20 @@ assert('Kernel#to_s', '15.3.1.3.46') do
assert_equal
to_s
.
class
,
String
assert_equal
to_s
.
class
,
String
end
end
assert
(
'Kernel.local_variables'
,
'15.3.1.2.7'
)
do
a
,
b
=
0
,
1
a
+=
b
vars
=
Kernel
.
local_variables
.
sort
assert_equal
[
:a
,
:b
,
:vars
],
vars
Proc
.
new
{
c
=
2
vars
=
Kernel
.
local_variables
.
sort
assert_equal
[
:a
,
:b
,
:c
,
:vars
],
vars
}.
call
end
assert
(
'Kernel#!='
)
do
assert
(
'Kernel#!='
)
do
str1
=
"hello"
str1
=
"hello"
str2
=
str1
str2
=
str1
...
...
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