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
261e4d3f
Commit
261e4d3f
authored
Jun 13, 2012
by
Yukihiro Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
handle number literal overflow
parent
38d2b7f8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
14 deletions
+54
-14
src/codegen.c
src/codegen.c
+54
-14
No files found.
src/codegen.c
View file @
261e4d3f
...
@@ -16,6 +16,9 @@
...
@@ -16,6 +16,9 @@
#include "node.h"
#include "node.h"
#include <string.h>
#include <string.h>
#include <stdlib.h>
#include <stdlib.h>
#include <errno.h>
#include <limits.h>
#include <ctype.h>
typedef
mrb_ast_node
node
;
typedef
mrb_ast_node
node
;
typedef
struct
mrb_parser_state
parser_state
;
typedef
struct
mrb_parser_state
parser_state
;
...
@@ -800,6 +803,27 @@ raise_error(codegen_scope *s, const char *msg)
...
@@ -800,6 +803,27 @@ raise_error(codegen_scope *s, const char *msg)
genop
(
s
,
MKOP_ABx
(
OP_ERR
,
0
,
idx
));
genop
(
s
,
MKOP_ABx
(
OP_ERR
,
0
,
idx
));
}
}
static
mrb_float
readint_float
(
codegen_scope
*
s
,
const
char
*
p
,
int
base
)
{
const
char
*
e
=
p
+
strlen
(
p
);
mrb_float
f
=
0
;
int
n
;
while
(
p
<=
e
)
{
char
c
=
tolower
(
*
p
);
for
(
n
=
0
;
n
<
base
;
n
++
)
{
if
(
mrb_digitmap
[
n
]
==
c
)
{
f
*=
base
;
f
+=
n
;
break
;
}
}
p
++
;
}
return
f
;
}
static
void
static
void
codegen
(
codegen_scope
*
s
,
node
*
tree
,
int
val
)
codegen
(
codegen_scope
*
s
,
node
*
tree
,
int
val
)
{
{
...
@@ -1553,14 +1577,22 @@ codegen(codegen_scope *s, node *tree, int val)
...
@@ -1553,14 +1577,22 @@ codegen(codegen_scope *s, node *tree, int val)
int
i
=
readint
(
p
,
base
);
int
i
=
readint
(
p
,
base
);
mrb_code
co
;
mrb_code
co
;
if
(
i
<
MAXARG_sBx
&&
i
>
-
MAXARG_sBx
)
{
if
(
i
==
LONG_MAX
&&
errno
==
ERANGE
)
{
co
=
MKOP_AsBx
(
OP_LOADI
,
cursp
(),
i
);
mrb_float
f
=
readint_float
(
s
,
p
,
base
);
int
off
=
new_lit
(
s
,
mrb_float_value
(
f
));
genop
(
s
,
MKOP_ABx
(
OP_LOADL
,
cursp
(),
off
));
}
}
else
{
else
{
int
off
=
new_lit
(
s
,
mrb_fixnum_value
(
i
));
if
(
i
<
MAXARG_sBx
&&
i
>
-
MAXARG_sBx
)
{
co
=
MKOP_ABx
(
OP_LOADL
,
cursp
(),
off
);
co
=
MKOP_AsBx
(
OP_LOADI
,
cursp
(),
i
);
}
else
{
int
off
=
new_lit
(
s
,
mrb_fixnum_value
(
i
));
co
=
MKOP_ABx
(
OP_LOADL
,
cursp
(),
off
);
}
genop
(
s
,
co
);
}
}
genop
(
s
,
co
);
push
();
push
();
}
}
break
;
break
;
...
@@ -1599,15 +1631,23 @@ codegen(codegen_scope *s, node *tree, int val)
...
@@ -1599,15 +1631,23 @@ codegen(codegen_scope *s, node *tree, int val)
int
i
=
readint
(
p
,
base
);
int
i
=
readint
(
p
,
base
);
mrb_code
co
;
mrb_code
co
;
i
=
-
i
;
if
(
i
==
LONG_MAX
&&
errno
==
ERANGE
)
{
if
(
i
<
MAXARG_sBx
&&
i
>
-
MAXARG_sBx
)
{
mrb_float
f
=
readint_float
(
s
,
p
,
base
);
co
=
MKOP_AsBx
(
OP_LOADI
,
cursp
(),
i
);
int
off
=
new_lit
(
s
,
mrb_float_value
(
-
f
));
}
else
{
genop
(
s
,
MKOP_ABx
(
OP_LOADL
,
cursp
(),
off
));
int
off
=
new_lit
(
s
,
mrb_fixnum_value
(
i
));
}
co
=
MKOP_ABx
(
OP_LOADL
,
cursp
(),
off
);
else
{
}
i
=
-
i
;
genop
(
s
,
co
);
if
(
i
<
MAXARG_sBx
&&
i
>
-
MAXARG_sBx
)
{
co
=
MKOP_AsBx
(
OP_LOADI
,
cursp
(),
i
);
}
else
{
int
off
=
new_lit
(
s
,
mrb_fixnum_value
(
i
));
co
=
MKOP_ABx
(
OP_LOADL
,
cursp
(),
off
);
}
genop
(
s
,
co
);
}
push
();
push
();
}
}
break
;
break
;
...
...
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