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
66161f47
Commit
66161f47
authored
Jul 14, 2013
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1377 from suzukaze/add-comments-in-variable.c
Add comments in variable.c
parents
5b0907b4
6bab0c65
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
2 deletions
+43
-2
src/variable.c
src/variable.c
+43
-2
No files found.
src/variable.c
View file @
66161f47
...
@@ -27,12 +27,21 @@ typedef struct segment {
...
@@ -27,12 +27,21 @@ typedef struct segment {
struct
segment
*
next
;
struct
segment
*
next
;
}
segment
;
}
segment
;
/* Instance variable table structure */
typedef
struct
iv_tbl
{
typedef
struct
iv_tbl
{
segment
*
rootseg
;
segment
*
rootseg
;
size_t
size
;
size_t
size
;
size_t
last_len
;
size_t
last_len
;
}
iv_tbl
;
}
iv_tbl
;
/*
* Creates instance variable table.
*
* Parameters
* mrb
* Returns
* the instance variable table.
*/
static
iv_tbl
*
static
iv_tbl
*
iv_new
(
mrb_state
*
mrb
)
iv_new
(
mrb_state
*
mrb
)
{
{
...
@@ -47,6 +56,15 @@ iv_new(mrb_state *mrb)
...
@@ -47,6 +56,15 @@ iv_new(mrb_state *mrb)
return
t
;
return
t
;
}
}
/*
* Set the value for the symbol in the instance variable table.
*
* Parameters
* mrb
* t the instance variable table to be set in.
* sym the symbol to be used as the key.
* val the value to be set.
*/
static
void
static
void
iv_put
(
mrb_state
*
mrb
,
iv_tbl
*
t
,
mrb_sym
sym
,
mrb_value
val
)
iv_put
(
mrb_state
*
mrb
,
iv_tbl
*
t
,
mrb_sym
sym
,
mrb_value
val
)
{
{
...
@@ -59,7 +77,7 @@ iv_put(mrb_state *mrb, iv_tbl *t, mrb_sym sym, mrb_value val)
...
@@ -59,7 +77,7 @@ iv_put(mrb_state *mrb, iv_tbl *t, mrb_sym sym, mrb_value val)
while
(
seg
)
{
while
(
seg
)
{
for
(
i
=
0
;
i
<
MRB_SEGMENT_SIZE
;
i
++
)
{
for
(
i
=
0
;
i
<
MRB_SEGMENT_SIZE
;
i
++
)
{
mrb_sym
key
=
seg
->
key
[
i
];
mrb_sym
key
=
seg
->
key
[
i
];
/*
f
ound room in last segment after last_len */
/*
F
ound room in last segment after last_len */
if
(
!
seg
->
next
&&
i
>=
t
->
last_len
)
{
if
(
!
seg
->
next
&&
i
>=
t
->
last_len
)
{
seg
->
key
[
i
]
=
sym
;
seg
->
key
[
i
]
=
sym
;
seg
->
val
[
i
]
=
val
;
seg
->
val
[
i
]
=
val
;
...
@@ -80,7 +98,7 @@ iv_put(mrb_state *mrb, iv_tbl *t, mrb_sym sym, mrb_value val)
...
@@ -80,7 +98,7 @@ iv_put(mrb_state *mrb, iv_tbl *t, mrb_sym sym, mrb_value val)
seg
=
seg
->
next
;
seg
=
seg
->
next
;
}
}
/*
n
ot found */
/*
N
ot found */
t
->
size
++
;
t
->
size
++
;
if
(
matched_seg
)
{
if
(
matched_seg
)
{
matched_seg
->
key
[
matched_idx
]
=
sym
;
matched_seg
->
key
[
matched_idx
]
=
sym
;
...
@@ -103,6 +121,18 @@ iv_put(mrb_state *mrb, iv_tbl *t, mrb_sym sym, mrb_value val)
...
@@ -103,6 +121,18 @@ iv_put(mrb_state *mrb, iv_tbl *t, mrb_sym sym, mrb_value val)
return
;
return
;
}
}
/*
* Get a value for a symbol from the instance the variable table.
*
* Parameters
* mrb
* t the variable table to be searched.
* sym the symbol to be used as the key.
* vp the value pointer. Recieves the value if if the specified symbol contains
* in the instance variable table.
* Returns
* true if the specfiyed symbol contains in the instance variable table.
*/
static
mrb_bool
static
mrb_bool
iv_get
(
mrb_state
*
mrb
,
iv_tbl
*
t
,
mrb_sym
sym
,
mrb_value
*
vp
)
iv_get
(
mrb_state
*
mrb
,
iv_tbl
*
t
,
mrb_sym
sym
,
mrb_value
*
vp
)
{
{
...
@@ -127,6 +157,17 @@ iv_get(mrb_state *mrb, iv_tbl *t, mrb_sym sym, mrb_value *vp)
...
@@ -127,6 +157,17 @@ iv_get(mrb_state *mrb, iv_tbl *t, mrb_sym sym, mrb_value *vp)
return
FALSE
;
return
FALSE
;
}
}
/*
* Deletes the value for the symbol from the instance variable table.
*
* Parameters
* t the variable table to be searched.
* sym the symbol to be used as the key.
* vp the value pointer. Recieve the deleted value if the symbol contans
* in the instance varible table.
* Returns
* true if the specfied symbol contains in the instance variable table.
*/
static
mrb_bool
static
mrb_bool
iv_del
(
mrb_state
*
mrb
,
iv_tbl
*
t
,
mrb_sym
sym
,
mrb_value
*
vp
)
iv_del
(
mrb_state
*
mrb
,
iv_tbl
*
t
,
mrb_sym
sym
,
mrb_value
*
vp
)
{
{
...
...
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