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
72d57ad0
Commit
72d57ad0
authored
Aug 31, 2019
by
Ukrainskiy Sergey
Committed by
Yukihiro "Matz" Matsumoto
Dec 09, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement numbered parameters
parent
82679939
Changes
5
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
143 additions
and
4 deletions
+143
-4
include/mruby/compile.h
include/mruby/compile.h
+1
-0
mrbgems/mruby-compiler/core/codegen.c
mrbgems/mruby-compiler/core/codegen.c
+15
-0
mrbgems/mruby-compiler/core/node.h
mrbgems/mruby-compiler/core/node.h
+1
-0
mrbgems/mruby-compiler/core/parse.y
mrbgems/mruby-compiler/core/parse.y
+117
-4
test/t/syntax.rb
test/t/syntax.rb
+9
-0
No files found.
include/mruby/compile.h
View file @
72d57ad0
...
@@ -161,6 +161,7 @@ struct mrb_parser_state {
...
@@ -161,6 +161,7 @@ struct mrb_parser_state {
uint16_t
current_filename_index
;
uint16_t
current_filename_index
;
struct
mrb_jmpbuf
*
jmp
;
struct
mrb_jmpbuf
*
jmp
;
mrb_ast_node
*
nvars
;
};
};
MRB_API
struct
mrb_parser_state
*
mrb_parser_new
(
mrb_state
*
);
MRB_API
struct
mrb_parser_state
*
mrb_parser_new
(
mrb_state
*
);
...
...
mrbgems/mruby-compiler/core/codegen.c
View file @
72d57ad0
...
@@ -1122,6 +1122,10 @@ gen_assignment(codegen_scope *s, node *tree, int sp, int val)
...
@@ -1122,6 +1122,10 @@ gen_assignment(codegen_scope *s, node *tree, int sp, int val)
}
}
}
}
break
;
break
;
case
NODE_NVAR
:
idx
=
nint
(
tree
);
codegen_error
(
s
,
"Can't assign to numbered parameter"
);
break
;
case
NODE_IVAR
:
case
NODE_IVAR
:
idx
=
new_sym
(
s
,
nsym
(
tree
));
idx
=
new_sym
(
s
,
nsym
(
tree
));
genop_2
(
s
,
OP_SETIV
,
sp
,
idx
);
genop_2
(
s
,
OP_SETIV
,
sp
,
idx
);
...
@@ -2340,6 +2344,17 @@ codegen(codegen_scope *s, node *tree, int val)
...
@@ -2340,6 +2344,17 @@ codegen(codegen_scope *s, node *tree, int val)
}
}
break
;
break
;
case
NODE_NVAR
:
if
(
val
)
{
int
idx
=
nint
(
tree
);
gen_move
(
s
,
cursp
(),
idx
,
val
);
if
(
val
&&
on_eval
(
s
))
genop_0
(
s
,
OP_NOP
);
push
();
}
break
;
case
NODE_GVAR
:
case
NODE_GVAR
:
{
{
int
sym
=
new_sym
(
s
,
nsym
(
tree
));
int
sym
=
new_sym
(
s
,
nsym
(
tree
));
...
...
mrbgems/mruby-compiler/core/node.h
View file @
72d57ad0
...
@@ -51,6 +51,7 @@ enum node_type {
...
@@ -51,6 +51,7 @@ enum node_type {
NODE_IVAR
,
NODE_IVAR
,
NODE_CONST
,
NODE_CONST
,
NODE_CVAR
,
NODE_CVAR
,
NODE_NVAR
,
NODE_NTH_REF
,
NODE_NTH_REF
,
NODE_BACK_REF
,
NODE_BACK_REF
,
NODE_MATCH
,
NODE_MATCH
,
...
...
mrbgems/mruby-compiler/core/parse.y
View file @
72d57ad0
This diff is collapsed.
Click to expand it.
test/t/syntax.rb
View file @
72d57ad0
...
@@ -671,3 +671,12 @@ assert 'keyword arguments' do
...
@@ -671,3 +671,12 @@ assert 'keyword arguments' do
assert_equal
([
1
,
1
,
:c
],
m
(
c: :c
))
assert_equal
([
1
,
1
,
:c
],
m
(
c: :c
))
assert_equal
([
:a
,
nil
,
:c
],
m
(
a: :a
,
c: :c
))
assert_equal
([
:a
,
nil
,
:c
],
m
(
a: :a
,
c: :c
))
end
end
assert
(
'numbered parameters'
)
do
assert_equal
(
15
,
[
1
,
2
,
3
,
4
,
5
].
reduce
{
@
1
+
@
2
})
assert_equal
(
3
,
->
{
@
1
+
@
2
}.
call
(
1
,
2
))
assert_equal
(
4
,
->
(
a
=->
{
@
1
}){
a
}.
call
.
call
(
4
))
assert_equal
(
5
,
->
a:
->
{
@
1
}
{
a
}.
call
.
call
(
5
))
assert_equal
(
55
,
Proc
.
new
do
@
1
+
@
2
+
@
3
+
@
4
+
@
5
+
@
6
+
@
7
+
@
8
+
@
9
+
@
10
end
.
call
(
*
[
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
]))
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