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
cdfeb538
Commit
cdfeb538
authored
Apr 16, 2019
by
Shokuji
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into fix_mruby-io_test
parents
16498588
4e3e4260
Changes
11
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
174 additions
and
303 deletions
+174
-303
mrbgems/mruby-compiler/core/codegen.c
mrbgems/mruby-compiler/core/codegen.c
+5
-2
mrbgems/mruby-compiler/core/parse.y
mrbgems/mruby-compiler/core/parse.y
+19
-15
mrbgems/mruby-random/test/random.rb
mrbgems/mruby-random/test/random.rb
+45
-25
src/etc.c
src/etc.c
+0
-1
src/gc.c
src/gc.c
+4
-1
src/hash.c
src/hash.c
+1
-1
src/numeric.c
src/numeric.c
+4
-4
src/symbol.c
src/symbol.c
+1
-1
src/variable.c
src/variable.c
+2
-2
src/vm.c
src/vm.c
+90
-248
test/assert.rb
test/assert.rb
+3
-3
No files found.
mrbgems/mruby-compiler/core/codegen.c
View file @
cdfeb538
...
...
@@ -102,6 +102,7 @@ codegen_error(codegen_scope *s, const char *message)
while
(
s
->
prev
)
{
codegen_scope
*
tmp
=
s
->
prev
;
mrb_free
(
s
->
mrb
,
s
->
iseq
);
mrb_free
(
s
->
mrb
,
s
->
lines
);
mrb_pool_close
(
s
->
mpool
);
s
=
tmp
;
}
...
...
@@ -272,8 +273,7 @@ genop_W(codegen_scope *s, mrb_code i, uint32_t a)
#define NOVAL 0
#define VAL 1
//static
mrb_bool
static
mrb_bool
no_optimize
(
codegen_scope
*
s
)
{
if
(
s
&&
s
->
parser
&&
s
->
parser
->
no_optimize
)
...
...
@@ -3020,6 +3020,9 @@ scope_finish(codegen_scope *s)
mrb_state
*
mrb
=
s
->
mrb
;
mrb_irep
*
irep
=
s
->
irep
;
if
(
s
->
nlocals
>=
0x3ff
)
{
codegen_error
(
s
,
"too many local variables"
);
}
irep
->
flags
=
0
;
if
(
s
->
iseq
)
{
irep
->
iseq
=
(
mrb_code
*
)
codegen_realloc
(
s
,
s
->
iseq
,
sizeof
(
mrb_code
)
*
s
->
pc
);
...
...
mrbgems/mruby-compiler/core/parse.y
View file @
cdfeb538
...
...
@@ -3716,8 +3716,9 @@ yyerror_c(parser_state *p, const char *msg, char c)
{
char buf[256];
strcpy(buf, msg);
strcat(buf, &c);
strncpy(buf, msg, sizeof(buf) - 2);
buf[sizeof(buf) - 2] = '\0';
strncat(buf, &c, 1);
yyerror(p, buf);
}
...
...
@@ -3760,9 +3761,10 @@ yywarning_s(parser_state *p, const char *msg, const char *s)
{
char buf[256];
strcpy(buf, msg);
strcat(buf, ": ");
strcat(buf, s);
strncpy(buf, msg, sizeof(buf) - 1);
buf[sizeof(buf) - 1] = '\0';
strncat(buf, ": ", sizeof(buf) - strlen(buf) - 1);
strncat(buf, s, sizeof(buf) - strlen(buf) - 1);
yywarning(p, buf);
}
...
...
@@ -4326,11 +4328,12 @@ parse_string(parser_state *p)
if (sizeof(s1)+sizeof(s2)+strlen(hinf->term)+1 >= sizeof(buf)) {
yyerror(p, "can't find heredoc delimiter anywhere before EOF");
} else {
strcpy(buf, s1);
strcat(buf, hinf->term);
strcat(buf, s2);
yyerror(p, buf);
}
strcpy(buf, s1);
strcat(buf, hinf->term);
strcat(buf, s2);
yyerror(p, buf);
return 0;
}
pylval.nd = new_str(p, tok(p), toklen(p));
...
...
@@ -4487,7 +4490,7 @@ parse_string(parser_state *p)
strcat(msg, "s");
}
strcat(msg, " - ");
str
cat(msg, tok(p)
);
str
ncat(msg, tok(p), sizeof(msg) - strlen(msg) - 1
);
yyerror(p, msg);
}
if (f != 0) {
...
...
@@ -4918,7 +4921,7 @@ parser_yylex(parser_state *p)
char cc = (char)c2;
strcpy(buf, "invalid character syntax; use ?\\");
str
cat(buf, &cc
);
str
ncat(buf, &cc, 1
);
yyerror(p, buf);
}
}
...
...
@@ -5709,11 +5712,12 @@ parser_yylex(parser_state *p)
if (!identchar(c)) {
char buf[36];
const char s[] = "Invalid char in expression: 0x";
const char hexdigits[] = "0123456789ABCDEF";
strcpy(buf, s);
buf[sizeof(s)
] = (c & 0xff00) >> 8
;
buf[sizeof(s)
+1] = (c & 0xff)
;
buf[sizeof(s)+
2
] = 0;
buf[sizeof(s)
-1] = hexdigits[(c & 0xf0) >> 4]
;
buf[sizeof(s)
] = hexdigits[(c & 0x0f)]
;
buf[sizeof(s)+
1
] = 0;
yyerror(p, buf);
goto retry;
}
...
...
@@ -6147,7 +6151,7 @@ mrb_load_exec(mrb_state *mrb, struct mrb_parser_state *p, mrbc_context *c)
strcpy(buf, "line ");
dump_int(p->error_buffer[0].lineno, buf+5);
strcat(buf, ": ");
str
cat(buf, p->error_buffer[0].message
);
str
ncat(buf, p->error_buffer[0].message, sizeof(buf) - strlen(buf) - 1
);
mrb->exc = mrb_obj_ptr(mrb_exc_new(mrb, E_SYNTAX_ERROR, buf, strlen(buf)));
mrb_parser_free(p);
return mrb_undef_value();
...
...
mrbgems/mruby-random/test/random.rb
View file @
cdfeb538
##
# Random Test
assert
(
"Random
#srand
"
)
do
assert
(
"Random
.new
"
)
do
r1
=
Random
.
new
(
123
)
r2
=
Random
.
new
(
123
)
r1
.
rand
==
r2
.
rand
r3
=
Random
.
new
(
124
)
assert_equal
(
r1
.
rand
,
r2
.
rand
)
assert_not_equal
(
r1
.
rand
,
r3
.
rand
)
end
assert
(
"Kernel
::
srand"
)
do
assert
(
"Kernel
.
srand"
)
do
srand
(
234
)
r1
=
rand
srand
(
234
)
r2
=
rand
r1
==
r2
srand
(
235
)
r3
=
rand
assert_equal
(
r1
,
r2
)
assert_not_equal
(
r1
,
r3
)
end
assert
(
"Random
::
srand"
)
do
assert
(
"Random
.
srand"
)
do
Random
.
srand
(
345
)
r1
=
rand
srand
(
345
)
r2
=
Random
.
rand
r1
==
r2
Random
.
srand
(
346
)
r3
=
rand
assert_equal
(
r1
,
r2
)
assert_not_equal
(
r1
,
r3
)
end
assert
(
"fixnum"
)
do
rand
(
3
).
class
==
Fixnum
end
assert
(
"float"
)
do
rand
.
class
==
Float
assert
(
"return class of Kernel.rand"
)
do
assert_kind_of
(
Fixnum
,
rand
(
3
))
assert_kind_of
(
Fixnum
,
rand
(
1.5
))
assert_kind_of
(
Float
,
rand
)
assert_kind_of
(
Float
,
rand
(
0.5
))
end
assert
(
"Array#shuffle"
)
do
ary
=
[
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
]
orig
=
ary
.
dup
shuffled
=
ary
.
shuffle
ary
==
[
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
]
and
shuffled
!=
ary
and
10
.
times
{
|
x
|
ary
.
include?
x
}
assert_equal
(
orig
,
ary
)
assert_not_equal
(
ary
,
shuffled
)
assert_equal
(
ary
.
size
,
shuffled
.
size
)
shuffled
.
each
do
|
x
|
assert_include
(
ary
,
x
)
ary
.
delete
(
x
)
end
end
assert
(
'Array#shuffle!'
)
do
ary
=
[
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
]
ary
.
shuffle!
ary
!=
[
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
]
and
10
.
times
{
|
x
|
ary
.
include?
x
}
orig
=
ary
.
dup
assert_same
(
ary
,
ary
.
shuffle!
)
assert_not_equal
(
orig
,
ary
)
assert_equal
(
orig
.
size
,
ary
.
size
)
ary
.
each
do
|
x
|
assert_include
(
orig
,
x
)
orig
.
delete
(
x
)
end
end
assert
(
"Array#shuffle(random)"
)
do
...
...
@@ -52,12 +70,12 @@ assert("Array#shuffle(random)") do
end
# verify that the same seed causes the same results
ary
1
=
[
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
]
shuffle
1
=
ary1
.
shuffle
Random
.
new
345
ary2
=
[
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
]
shuffle
2
=
ary2
.
shuffle
Random
.
new
345
a
ry1
!=
shuffle1
and
10
.
times
{
|
x
|
shuffle1
.
include?
x
}
and
shuffle1
==
shuffle2
ary
=
[
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
]
shuffle
d1
=
ary
.
shuffle
Random
.
new
345
shuffled2
=
ary
.
shuffle
Random
.
new
345
shuffle
d3
=
ary
.
shuffle
Random
.
new
346
assert_equal
(
shuffled1
,
shuffled2
)
a
ssert_not_equal
(
shuffled1
,
shuffled3
)
end
assert
(
'Array#shuffle!(random)'
)
do
...
...
@@ -71,6 +89,8 @@ assert('Array#shuffle!(random)') do
ary1
.
shuffle!
Random
.
new
345
ary2
=
[
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
]
ary2
.
shuffle!
Random
.
new
345
ary1
!=
[
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
]
and
10
.
times
{
|
x
|
ary1
.
include?
x
}
and
ary1
==
ary2
ary3
=
[
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
]
ary3
.
shuffle!
Random
.
new
346
assert_equal
(
ary1
,
ary2
)
assert_not_equal
(
ary1
,
ary3
)
end
src/etc.c
View file @
cdfeb538
...
...
@@ -205,7 +205,6 @@ mrb_regexp_p(mrb_state *mrb, mrb_value v)
return
mrb_obj_is_kind_of
(
mrb
,
v
,
mrb_class_get
(
mrb
,
REGEXP_CLASS
));
}
else
{
mrb
->
flags
|=
MRB_STATE_REGEXP
;
mrb
->
flags
|=
MRB_STATE_NO_REGEXP
;
}
return
FALSE
;
...
...
src/gc.c
View file @
cdfeb538
...
...
@@ -10,6 +10,7 @@
#include <mruby/array.h>
#include <mruby/class.h>
#include <mruby/data.h>
#include <mruby/istruct.h>
#include <mruby/hash.h>
#include <mruby/proc.h>
#include <mruby/range.h>
...
...
@@ -109,8 +110,10 @@ typedef struct {
struct
RHash
hash
;
struct
RRange
range
;
struct
RData
data
;
struct
RIstruct
istruct
;
struct
RProc
proc
;
struct
REnv
env
;
struct
RFiber
fiber
;
struct
RException
exc
;
struct
RBreak
brk
;
#ifdef MRB_WORD_BOXING
...
...
@@ -396,7 +399,7 @@ mrb_gc_init(mrb_state *mrb, mrb_gc *gc)
static
void
obj_free
(
mrb_state
*
mrb
,
struct
RBasic
*
obj
,
int
end
);
void
static
void
free_heap
(
mrb_state
*
mrb
,
mrb_gc
*
gc
)
{
mrb_heap_page
*
page
=
gc
->
heaps
;
...
...
src/hash.c
View file @
cdfeb538
...
...
@@ -182,7 +182,7 @@ ht_index(mrb_state *mrb, htable *t)
if
(
!
index
||
index
->
capa
<
size
)
{
index
=
(
segindex
*
)
mrb_realloc_simple
(
mrb
,
index
,
sizeof
(
segindex
)
+
sizeof
(
struct
segkv
*
)
*
size
);
if
(
index
==
NULL
)
{
mrb_free
(
mrb
,
index
);
mrb_free
(
mrb
,
t
->
index
);
t
->
index
=
NULL
;
return
;
}
...
...
src/numeric.c
View file @
cdfeb538
...
...
@@ -510,7 +510,7 @@ flo_shift(mrb_state *mrb, mrb_value x, mrb_int width)
}
static
mrb_value
flo_
l
shift
(
mrb_state
*
mrb
,
mrb_value
x
)
flo_
r
shift
(
mrb_state
*
mrb
,
mrb_value
x
)
{
mrb_int
width
;
...
...
@@ -519,7 +519,7 @@ flo_lshift(mrb_state *mrb, mrb_value x)
}
static
mrb_value
flo_
r
shift
(
mrb_state
*
mrb
,
mrb_value
x
)
flo_
l
shift
(
mrb_state
*
mrb
,
mrb_value
x
)
{
mrb_int
width
;
...
...
@@ -1608,8 +1608,8 @@ mrb_init_numeric(mrb_state *mrb)
mrb_define_method
(
mrb
,
fl
,
"&"
,
flo_and
,
MRB_ARGS_REQ
(
1
));
mrb_define_method
(
mrb
,
fl
,
"|"
,
flo_or
,
MRB_ARGS_REQ
(
1
));
mrb_define_method
(
mrb
,
fl
,
"^"
,
flo_xor
,
MRB_ARGS_REQ
(
1
));
mrb_define_method
(
mrb
,
fl
,
">>"
,
flo_
l
shift
,
MRB_ARGS_REQ
(
1
));
mrb_define_method
(
mrb
,
fl
,
"<<"
,
flo_
r
shift
,
MRB_ARGS_REQ
(
1
));
mrb_define_method
(
mrb
,
fl
,
">>"
,
flo_
r
shift
,
MRB_ARGS_REQ
(
1
));
mrb_define_method
(
mrb
,
fl
,
"<<"
,
flo_
l
shift
,
MRB_ARGS_REQ
(
1
));
mrb_define_method
(
mrb
,
fl
,
"ceil"
,
flo_ceil
,
MRB_ARGS_NONE
());
/* 15.2.9.3.8 */
mrb_define_method
(
mrb
,
fl
,
"finite?"
,
flo_finite_p
,
MRB_ARGS_NONE
());
/* 15.2.9.3.9 */
mrb_define_method
(
mrb
,
fl
,
"floor"
,
flo_floor
,
MRB_ARGS_NONE
());
/* 15.2.9.3.10 */
...
...
src/symbol.c
View file @
cdfeb538
...
...
@@ -91,7 +91,7 @@ sym_inline_unpack(mrb_sym sym, char *buf, mrb_int *lenp)
}
#endif
uint8_t
static
uint8_t
symhash
(
const
char
*
key
,
size_t
len
)
{
uint32_t
hash
,
i
;
...
...
src/variable.c
View file @
cdfeb538
...
...
@@ -79,19 +79,19 @@ iv_put(mrb_state *mrb, iv_tbl *t, mrb_sym sym, mrb_value val)
}
/* Not found */
t
->
size
++
;
if
(
matched_seg
)
{
matched_seg
->
key
[
matched_idx
]
=
sym
;
matched_seg
->
val
[
matched_idx
]
=
val
;
t
->
size
++
;
return
;
}
seg
=
(
segment
*
)
mrb_malloc
(
mrb
,
sizeof
(
segment
));
if
(
!
seg
)
return
;
seg
->
next
=
NULL
;
seg
->
key
[
0
]
=
sym
;
seg
->
val
[
0
]
=
val
;
t
->
last_len
=
1
;
t
->
size
++
;
if
(
prev
)
{
prev
->
next
=
seg
;
}
...
...
src/vm.c
View file @
cdfeb538
This diff is collapsed.
Click to expand it.
test/assert.rb
View file @
cdfeb538
...
...
@@ -149,11 +149,11 @@ end
# Fails unless +exp+ is equal to +act+ in terms of a Float
def
assert_float
(
exp
,
act
,
msg
=
nil
)
e
,
a
=
exp
.
to_f
,
act
.
to_f
if
(
e
.
infinite?
||
a
.
infinite?
)
&&
e
!=
a
||
if
e
.
finite?
&&
a
.
finite?
&&
(
n
=
(
e
-
a
).
abs
)
>
Mrbtest
::
FLOAT_TOLERANCE
flunk
(
msg
,
" Expected |
#{
exp
}
-
#{
act
}
| (
#{
n
}
) to be <=
#{
Mrbtest
::
FLOAT_TOLERANCE
}
."
)
elsif
(
e
.
infinite?
||
a
.
infinite?
)
&&
e
!=
a
||
e
.
nan?
&&
!
a
.
nan?
||
!
e
.
nan?
&&
a
.
nan?
flunk
(
msg
,
" Expected
#{
act
}
to be
#{
exp
}
."
)
elsif
(
n
=
(
e
-
a
).
abs
)
>
Mrbtest
::
FLOAT_TOLERANCE
flunk
(
msg
,
" Expected |
#{
exp
}
-
#{
act
}
| (
#{
n
}
) to be <=
#{
Mrbtest
::
FLOAT_TOLERANCE
}
."
)
else
pass
end
...
...
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