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
04a2c58e
Commit
04a2c58e
authored
Nov 15, 2013
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add new function mrb_load_irep_file_cxt() and simplifies mruby.c
parent
d8f9a30e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
39 additions
and
34 deletions
+39
-34
include/mruby/dump.h
include/mruby/dump.h
+1
-0
include/mruby/irep.h
include/mruby/irep.h
+3
-0
mrbgems/mruby-bin-mruby/tools/mruby/mruby.c
mrbgems/mruby-bin-mruby/tools/mruby/mruby.c
+17
-30
src/load.c
src/load.c
+18
-4
No files found.
include/mruby/dump.h
View file @
04a2c58e
...
...
@@ -19,6 +19,7 @@ int mrb_dump_irep_binary(mrb_state*, mrb_irep*, int, FILE*);
int
mrb_dump_irep_cfunc
(
mrb_state
*
mrb
,
mrb_irep
*
,
int
,
FILE
*
f
,
const
char
*
initname
);
mrb_irep
*
mrb_read_irep_file
(
mrb_state
*
,
FILE
*
);
mrb_value
mrb_load_irep_file
(
mrb_state
*
,
FILE
*
);
mrb_value
mrb_load_irep_file_cxt
(
mrb_state
*
,
FILE
*
,
mrbc_context
*
);
#endif
mrb_irep
*
mrb_read_irep
(
mrb_state
*
,
const
uint8_t
*
);
...
...
include/mruby/irep.h
View file @
04a2c58e
...
...
@@ -11,6 +11,8 @@
extern
"C"
{
#endif
#include "mruby/compile.h"
enum
irep_pool_type
{
IREP_TT_STRING
,
IREP_TT_FIXNUM
,
...
...
@@ -50,6 +52,7 @@ typedef struct mrb_irep {
mrb_irep
*
mrb_add_irep
(
mrb_state
*
mrb
);
mrb_value
mrb_load_irep
(
mrb_state
*
,
const
uint8_t
*
);
mrb_value
mrb_load_irep_cxt
(
mrb_state
*
,
const
uint8_t
*
,
mrbc_context
*
);
void
mrb_irep_free
(
mrb_state
*
,
struct
mrb_irep
*
);
void
mrb_irep_incref
(
mrb_state
*
,
struct
mrb_irep
*
);
void
mrb_irep_decref
(
mrb_state
*
,
struct
mrb_irep
*
);
...
...
mrbgems/mruby-bin-mruby/tools/mruby/mruby.c
View file @
04a2c58e
...
...
@@ -178,6 +178,8 @@ main(int argc, char **argv)
int
i
;
struct
_args
args
;
mrb_value
ARGV
;
mrbc_context
*
c
;
mrb_value
v
;
if
(
mrb
==
NULL
)
{
fputs
(
"Invalid mrb_state, exiting mruby
\n
"
,
stderr
);
...
...
@@ -197,30 +199,16 @@ main(int argc, char **argv)
}
mrb_define_global_const
(
mrb
,
"ARGV"
,
ARGV
);
c
=
mrbc_context_new
(
mrb
);
if
(
args
.
verbose
)
c
->
dump_result
=
1
;
if
(
args
.
check_syntax
)
c
->
no_exec
=
1
;
if
(
args
.
mrbfile
)
{
mrb_irep
*
irep
=
mrb_read_irep_file
(
mrb
,
args
.
rfp
);
if
(
!
irep
)
{
fprintf
(
stderr
,
"failed to load mrb file: %s
\n
"
,
args
.
cmdline
);
}
else
if
(
!
args
.
check_syntax
)
{
mrb_context_run
(
mrb
,
mrb_proc_new
(
mrb
,
irep
),
mrb_top_self
(
mrb
),
0
);
mrb_irep_decref
(
mrb
,
irep
);
n
=
0
;
if
(
mrb
->
exc
)
{
mrb_print_error
(
mrb
);
n
=
-
1
;
}
}
v
=
mrb_load_irep_file_cxt
(
mrb
,
args
.
rfp
,
c
);
}
else
{
mrbc_context
*
c
=
mrbc_context_new
(
mrb
);
mrb_sym
zero_sym
=
mrb_intern2
(
mrb
,
"$0"
,
2
);
mrb_value
v
;
if
(
args
.
verbose
)
c
->
dump_result
=
1
;
if
(
args
.
check_syntax
)
c
->
no_exec
=
1
;
if
(
args
.
rfp
)
{
char
*
cmdline
;
...
...
@@ -234,17 +222,16 @@ main(int argc, char **argv)
mrb_gv_set
(
mrb
,
zero_sym
,
mrb_str_new
(
mrb
,
"-e"
,
2
));
v
=
mrb_load_string_cxt
(
mrb
,
args
.
cmdline
,
c
);
}
mrbc_context_free
(
mrb
,
c
);
if
(
mrb
->
exc
)
{
if
(
!
mrb_undef_p
(
v
))
{
mrb_print_error
(
mrb
);
}
n
=
-
1
;
}
else
if
(
args
.
check_syntax
)
{
printf
(
"Syntax OK
\n
"
);
}
mrbc_context_free
(
mrb
,
c
);
if
(
mrb
->
exc
)
{
if
(
!
mrb_undef_p
(
v
))
{
mrb_print_error
(
mrb
);
}
n
=
-
1
;
}
else
if
(
args
.
check_syntax
)
{
printf
(
"Syntax OK
\n
"
);
}
cleanup
(
mrb
,
&
args
);
...
...
src/load.c
View file @
04a2c58e
...
...
@@ -477,7 +477,7 @@ irep_error(mrb_state *mrb)
}
mrb_value
mrb_load_irep
(
mrb_state
*
mrb
,
const
uint8_t
*
bin
)
mrb_load_irep
_cxt
(
mrb_state
*
mrb
,
const
uint8_t
*
bin
,
mrbc_context
*
c
)
{
mrb_irep
*
irep
=
mrb_read_irep
(
mrb
,
bin
);
mrb_value
val
;
...
...
@@ -488,11 +488,18 @@ mrb_load_irep(mrb_state *mrb, const uint8_t *bin)
return
mrb_nil_value
();
}
proc
=
mrb_proc_new
(
mrb
,
irep
);
val
=
mrb_context_run
(
mrb
,
proc
,
mrb_top_self
(
mrb
),
0
);
mrb_irep_decref
(
mrb
,
irep
);
if
(
c
&&
c
->
no_exec
)
return
mrb_obj_value
(
proc
);
val
=
mrb_context_run
(
mrb
,
proc
,
mrb_top_self
(
mrb
),
0
);
return
val
;
}
mrb_value
mrb_load_irep
(
mrb_state
*
mrb
,
const
uint8_t
*
bin
)
{
return
mrb_load_irep_cxt
(
mrb
,
bin
,
NULL
);
}
#ifdef ENABLE_STDIO
static
int
...
...
@@ -691,7 +698,7 @@ mrb_read_irep_file(mrb_state *mrb, FILE* fp)
}
mrb_value
mrb_load_irep_file
(
mrb_state
*
mrb
,
FILE
*
fp
)
mrb_load_irep_file
_cxt
(
mrb_state
*
mrb
,
FILE
*
fp
,
mrbc_context
*
c
)
{
mrb_irep
*
irep
=
mrb_read_irep_file
(
mrb
,
fp
);
mrb_value
val
;
...
...
@@ -702,8 +709,15 @@ mrb_load_irep_file(mrb_state *mrb, FILE* fp)
return
mrb_nil_value
();
}
proc
=
mrb_proc_new
(
mrb
,
irep
);
val
=
mrb_context_run
(
mrb
,
proc
,
mrb_top_self
(
mrb
),
0
);
mrb_irep_decref
(
mrb
,
irep
);
if
(
c
&&
c
->
no_exec
)
return
mrb_obj_value
(
proc
);
val
=
mrb_context_run
(
mrb
,
proc
,
mrb_top_self
(
mrb
),
0
);
return
val
;
}
mrb_value
mrb_load_irep_file
(
mrb_state
*
mrb
,
FILE
*
fp
)
{
return
mrb_load_irep_file_cxt
(
mrb
,
fp
,
NULL
);
}
#endif
/* ENABLE_STDIO */
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