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
a165fce1
Commit
a165fce1
authored
Mar 04, 2013
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #937 from monaka/pr-remove-snprintf-from-localjump_error
Reduce a snprintf() call in localjump_error().
parents
ec70b2ab
15ac0e03
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
10 deletions
+19
-10
src/vm.c
src/vm.c
+19
-10
No files found.
src/vm.c
View file @
a165fce1
...
@@ -453,15 +453,24 @@ mrb_yield(mrb_state *mrb, mrb_value b, mrb_value v)
...
@@ -453,15 +453,24 @@ mrb_yield(mrb_state *mrb, mrb_value b, mrb_value v)
return
mrb_yield_internal
(
mrb
,
b
,
1
,
&
v
,
mrb
->
stack
[
0
],
p
->
target_class
);
return
mrb_yield_internal
(
mrb
,
b
,
1
,
&
v
,
mrb
->
stack
[
0
],
p
->
target_class
);
}
}
typedef
enum
{
LOCALJUMP_ERROR_RETURN
=
0
,
LOCALJUMP_ERROR_BREAK
=
1
,
LOCALJUMP_ERROR_YIELD
=
2
}
localjump_error_kind
;
static
void
static
void
localjump_error
(
mrb_state
*
mrb
,
const
char
*
kind
)
localjump_error
(
mrb_state
*
mrb
,
localjump_error_kind
kind
)
{
{
char
buf
[
256
];
char
kind_str
[
3
][
7
]
=
{
"return"
,
"break"
,
"yield"
};
int
len
;
char
kind_str_len
[]
=
{
6
,
5
,
5
};
static
const
char
lead
[]
=
"unexpected "
;
mrb_value
msg
;
mrb_value
exc
;
mrb_value
exc
;
len
=
snprintf
(
buf
,
sizeof
(
buf
),
"unexpected %s"
,
kind
);
msg
=
mrb_str_new
(
mrb
,
lead
,
sizeof
(
lead
)
-
1
);
exc
=
mrb_exc_new
(
mrb
,
E_LOCALJUMP_ERROR
,
buf
,
len
);
mrb_str_buf_cat
(
mrb
,
msg
,
kind_str
[
kind
],
kind_str_len
[
kind
]);
exc
=
mrb_exc_new3
(
mrb
,
E_LOCALJUMP_ERROR
,
msg
);
mrb
->
exc
=
(
struct
RObject
*
)
mrb_object
(
exc
);
mrb
->
exc
=
(
struct
RObject
*
)
mrb_object
(
exc
);
}
}
...
@@ -1218,12 +1227,12 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
...
@@ -1218,12 +1227,12 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
struct
REnv
*
e
=
top_env
(
mrb
,
proc
);
struct
REnv
*
e
=
top_env
(
mrb
,
proc
);
if
(
e
->
cioff
<
0
)
{
if
(
e
->
cioff
<
0
)
{
localjump_error
(
mrb
,
"return"
);
localjump_error
(
mrb
,
LOCALJUMP_ERROR_RETURN
);
goto
L_RAISE
;
goto
L_RAISE
;
}
}
ci
=
mrb
->
cibase
+
e
->
cioff
;
ci
=
mrb
->
cibase
+
e
->
cioff
;
if
(
ci
==
mrb
->
cibase
)
{
if
(
ci
==
mrb
->
cibase
)
{
localjump_error
(
mrb
,
"return"
);
localjump_error
(
mrb
,
LOCALJUMP_ERROR_RETURN
);
goto
L_RAISE
;
goto
L_RAISE
;
}
}
mrb
->
ci
=
ci
;
mrb
->
ci
=
ci
;
...
@@ -1231,14 +1240,14 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
...
@@ -1231,14 +1240,14 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
}
}
case
OP_R_NORMAL
:
case
OP_R_NORMAL
:
if
(
ci
==
mrb
->
cibase
)
{
if
(
ci
==
mrb
->
cibase
)
{
localjump_error
(
mrb
,
"return"
);
localjump_error
(
mrb
,
LOCALJUMP_ERROR_RETURN
);
goto
L_RAISE
;
goto
L_RAISE
;
}
}
ci
=
mrb
->
ci
;
ci
=
mrb
->
ci
;
break
;
break
;
case
OP_R_BREAK
:
case
OP_R_BREAK
:
if
(
proc
->
env
->
cioff
<
0
)
{
if
(
proc
->
env
->
cioff
<
0
)
{
localjump_error
(
mrb
,
"break"
);
localjump_error
(
mrb
,
LOCALJUMP_ERROR_BREAK
);
goto
L_RAISE
;
goto
L_RAISE
;
}
}
ci
=
mrb
->
ci
=
mrb
->
cibase
+
proc
->
env
->
cioff
+
1
;
ci
=
mrb
->
ci
=
mrb
->
cibase
+
proc
->
env
->
cioff
+
1
;
...
@@ -1350,7 +1359,7 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
...
@@ -1350,7 +1359,7 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
else
{
else
{
struct
REnv
*
e
=
uvenv
(
mrb
,
lv
-
1
);
struct
REnv
*
e
=
uvenv
(
mrb
,
lv
-
1
);
if
(
!
e
)
{
if
(
!
e
)
{
localjump_error
(
mrb
,
"yield"
);
localjump_error
(
mrb
,
LOCALJUMP_ERROR_YIELD
);
goto
L_RAISE
;
goto
L_RAISE
;
}
}
stack
=
e
->
stack
+
1
;
stack
=
e
->
stack
+
1
;
...
...
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