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
74da7240
Commit
74da7240
authored
May 21, 2014
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
direct invocation of module_eval; ref #2298
parent
a6f26514
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
23 deletions
+44
-23
src/class.c
src/class.c
+2
-23
src/vm.c
src/vm.c
+42
-0
No files found.
src/class.c
View file @
74da7240
...
...
@@ -941,29 +941,8 @@ mrb_mod_instance_methods(mrb_state *mrb, mrb_value mod)
return
mrb_class_instance_method_list
(
mrb
,
recur
,
c
,
0
);
}
/* 15.2.2.4.35 */
/*
* call-seq:
* mod.class_eval {| | block } -> obj
* mod.module_eval {| | block } -> obj
*
* Evaluates block in the context of _mod_. This can
* be used to add methods to a class. <code>module_eval</code> returns
* the result of evaluating its argument.
*/
static
mrb_value
mrb_mod_module_eval
(
mrb_state
*
mrb
,
mrb_value
mod
)
{
mrb_value
a
,
b
;
struct
RClass
*
c
;
if
(
mrb_get_args
(
mrb
,
"|S&"
,
&
a
,
&
b
)
==
1
)
{
mrb_raise
(
mrb
,
E_NOTIMP_ERROR
,
"module_eval/class_eval with string not implemented"
);
}
c
=
mrb_class_ptr
(
mod
);
return
mrb_yield_with_class
(
mrb
,
b
,
0
,
0
,
mod
,
c
);
}
/* implementation of module_eval/class_eval */
mrb_value
mrb_mod_module_eval
(
mrb_state
*
,
mrb_value
);
static
mrb_value
mrb_mod_dummy_visibility
(
mrb_state
*
mrb
,
mrb_value
mod
)
...
...
src/vm.c
View file @
74da7240
...
...
@@ -507,6 +507,48 @@ mrb_f_send(mrb_state *mrb, mrb_value self)
return
self
;
}
/* 15.2.2.4.35 */
/*
* call-seq:
* mod.class_eval {| | block } -> obj
* mod.module_eval {| | block } -> obj
*
* Evaluates block in the context of _mod_. This can
* be used to add methods to a class. <code>module_eval</code> returns
* the result of evaluating its argument.
*/
mrb_value
mrb_mod_module_eval
(
mrb_state
*
mrb
,
mrb_value
mod
)
{
mrb_value
a
,
b
;
struct
RClass
*
c
;
struct
RProc
*
p
;
mrb_callinfo
*
ci
;
if
(
mrb_get_args
(
mrb
,
"|S&"
,
&
a
,
&
b
)
==
1
)
{
mrb_raise
(
mrb
,
E_NOTIMP_ERROR
,
"module_eval/class_eval with string not implemented"
);
}
c
=
mrb_class_ptr
(
mod
);
ci
=
mrb
->
c
->
ci
;
if
(
ci
->
acc
==
CI_ACC_DIRECT
)
{
return
mrb_yield_with_class
(
mrb
,
b
,
0
,
0
,
mod
,
c
);
}
ci
->
target_class
=
c
;
p
=
mrb_proc_ptr
(
b
);
ci
->
proc
=
p
;
if
(
MRB_PROC_CFUNC_P
(
p
))
{
return
p
->
body
.
func
(
mrb
,
mod
);
}
ci
->
nregs
=
p
->
body
.
irep
->
nregs
;
ci
=
cipush
(
mrb
);
ci
->
target_class
=
0
;
ci
->
pc
=
p
->
body
.
irep
->
iseq
;
ci
->
stackent
=
mrb
->
c
->
stack
;
ci
->
acc
=
0
;
return
mod
;
}
mrb_value
mrb_yield_with_class
(
mrb_state
*
mrb
,
mrb_value
b
,
mrb_int
argc
,
const
mrb_value
*
argv
,
mrb_value
self
,
struct
RClass
*
c
)
{
...
...
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