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
20875263
Commit
20875263
authored
Feb 03, 2013
by
Masamitsu MURASE
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Modify handling of integer literal.
Do not assume that significand of `double` is larger than `mrb_int`.
parent
dfff7323
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
9 deletions
+51
-9
src/codegen.c
src/codegen.c
+51
-9
No files found.
src/codegen.c
View file @
20875263
...
...
@@ -959,6 +959,48 @@ readint_float(codegen_scope *s, const char *p, int base)
return
f
;
}
static
mrb_int
readint_mrb_int
(
codegen_scope
*
s
,
const
char
*
p
,
int
base
,
int
neg
,
int
*
overflow
)
{
const
char
*
e
=
p
+
strlen
(
p
);
mrb_int
result
=
0
;
int
n
;
if
(
*
p
==
'+'
)
p
++
;
while
(
p
<
e
)
{
char
c
=
*
p
;
c
=
tolower
((
unsigned
char
)
c
);
for
(
n
=
0
;
n
<
base
;
n
++
)
{
if
(
mrb_digitmap
[
n
]
==
c
)
{
break
;
}
}
if
(
n
==
base
)
{
codegen_error
(
s
,
"malformed readint input"
);
}
if
(
neg
)
{
if
((
MRB_INT_MIN
+
n
)
/
base
>
result
)
{
*
overflow
=
TRUE
;
return
0
;
}
result
*=
base
;
result
-=
n
;
}
else
{
if
((
MRB_INT_MAX
-
n
)
/
base
<
result
)
{
*
overflow
=
TRUE
;
return
0
;
}
result
*=
base
;
result
+=
n
;
}
p
++
;
}
*
overflow
=
FALSE
;
return
result
;
}
static
void
codegen
(
codegen_scope
*
s
,
node
*
tree
,
int
val
)
{
...
...
@@ -1733,18 +1775,18 @@ codegen(codegen_scope *s, node *tree, int val)
if
(
val
)
{
char
*
p
=
(
char
*
)
tree
->
car
;
int
base
=
(
intptr_t
)
tree
->
cdr
->
car
;
double
f
;
mrb_int
i
;
mrb_code
co
;
int
overflow
;
f
=
readint_float
(
s
,
p
,
base
);
if
(
!
FIXABLE
(
f
))
{
i
=
readint_mrb_int
(
s
,
p
,
base
,
FALSE
,
&
overflow
);
if
(
overflow
)
{
double
f
=
readint_float
(
s
,
p
,
base
);
int
off
=
new_lit
(
s
,
mrb_float_value
(
f
));
genop
(
s
,
MKOP_ABx
(
OP_LOADL
,
cursp
(),
off
));
}
else
{
i
=
(
mrb_int
)
f
;
if
(
i
<
MAXARG_sBx
&&
i
>
-
MAXARG_sBx
)
{
co
=
MKOP_AsBx
(
OP_LOADI
,
cursp
(),
i
);
}
...
...
@@ -1789,18 +1831,18 @@ codegen(codegen_scope *s, node *tree, int val)
{
char
*
p
=
(
char
*
)
tree
->
car
;
int
base
=
(
intptr_t
)
tree
->
cdr
->
car
;
mrb_float
f
;
mrb_int
i
;
mrb_code
co
;
int
overflow
;
f
=
readint_float
(
s
,
p
,
base
);
if
(
!
FIXABLE
(
f
))
{
i
=
readint_mrb_int
(
s
,
p
,
base
,
TRUE
,
&
overflow
);
if
(
overflow
)
{
double
f
=
readint_float
(
s
,
p
,
base
);
int
off
=
new_lit
(
s
,
mrb_float_value
(
-
f
));
genop
(
s
,
MKOP_ABx
(
OP_LOADL
,
cursp
(),
off
));
}
else
{
i
=
(
mrb_int
)
-
f
;
if
(
i
<
MAXARG_sBx
&&
i
>
-
MAXARG_sBx
)
{
co
=
MKOP_AsBx
(
OP_LOADI
,
cursp
(),
i
);
}
...
...
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