Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

implement the test for Parrot_api_serialize_bytecode_pmc. Fix some AR…

…G modifiers to allow nulls, since we have logic in there to handle nulls
  • Loading branch information...
commit ca855f2ca1ae58f90c3d6336e0b18fda13ecd200 1 parent 29c4a7f
@Whiteknight Whiteknight authored
View
20 compilers/imcc/main.c
@@ -75,17 +75,15 @@ static void imcc_get_optimization_description(
static char * imcc_parseflags(PARROT_INTERP,
int argc,
- ARGIN(const char **argv))
- __attribute__nonnull__(1)
- __attribute__nonnull__(3);
+ ARGIN_NULLOK(const char **argv))
+ __attribute__nonnull__(1);
static int imcc_run(PARROT_INTERP,
ARGIN(const char *sourcefile),
- ARGIN(const char *output_file),
+ ARGIN_NULLOK(const char *output_file),
ARGOUT(PMC **pbcpmc))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
- __attribute__nonnull__(3)
__attribute__nonnull__(4)
FUNC_MODIFIES(*pbcpmc);
@@ -118,12 +116,10 @@ static const struct longopt_opt_decl * Parrot_cmd_options(void);
__attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(opt_desc))
#define ASSERT_ARGS_imcc_parseflags __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(interp) \
- , PARROT_ASSERT_ARG(argv))
+ PARROT_ASSERT_ARG(interp))
#define ASSERT_ARGS_imcc_run __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(sourcefile) \
- , PARROT_ASSERT_ARG(output_file) \
, PARROT_ASSERT_ARG(pbcpmc))
#define ASSERT_ARGS_imcc_write_pbc __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
@@ -232,7 +228,7 @@ Parse flags ans set approptiate state(s)
*/
static char *
-imcc_parseflags(PARROT_INTERP, int argc, ARGIN(const char **argv))
+imcc_parseflags(PARROT_INTERP, int argc, ARGIN_NULLOK(const char **argv))
{
ASSERT_ARGS(imcc_parseflags)
struct longopt_opt_info opt = LONGOPT_OPT_INFO_INIT;
@@ -240,6 +236,8 @@ imcc_parseflags(PARROT_INTERP, int argc, ARGIN(const char **argv))
/* default state: run pbc */
SET_STATE_RUN_PBC(interp);
+ if (!argv)
+ return NULL;
while (longopt_get(argc, argv, Parrot_cmd_options(), &opt) > 0) {
switch (opt.opt_id) {
@@ -631,7 +629,7 @@ PMC interpreter.
PARROT_API
int
imcc_run_api(ARGMOD(PMC * interp_pmc), ARGIN(const char *sourcefile), int argc,
- ARGIN(const char **argv), ARGOUT(PMC **pbcpmc))
+ ARGIN_NULLOK(const char **argv), ARGOUT(PMC **pbcpmc))
{
Interp * interp = (Interp *)VTABLE_get_pointer(NULL, interp_pmc);
const char * output_file = imcc_parseflags(interp, argc, argv);
@@ -653,7 +651,7 @@ and run. This function always returns 0.
static int
imcc_run(PARROT_INTERP, ARGIN(const char *sourcefile),
- ARGIN(const char *output_file), ARGOUT(PMC **pbcpmc))
+ ARGIN_NULLOK(const char *output_file), ARGOUT(PMC **pbcpmc))
{
yyscan_t yyscanner;
PackFile * pf_raw = NULL;
View
4 include/parrot/api.h
@@ -229,12 +229,11 @@ Parrot_Int Parrot_api_wrap_imcc_hack(
Parrot_PMC interp_pmc,
ARGIN(const char * sourcefile),
int argc,
- ARGIN(const char **argv),
+ ARGIN_NULLOK(const char **argv),
ARGMOD(Parrot_PMC* bytecodepmc),
ARGOUT(int *result),
imcc_hack_func_t func)
__attribute__nonnull__(2)
- __attribute__nonnull__(4)
__attribute__nonnull__(5)
__attribute__nonnull__(6)
FUNC_MODIFIES(* bytecodepmc)
@@ -294,7 +293,6 @@ Parrot_Int Parrot_api_wrap_imcc_hack(
#define ASSERT_ARGS_Parrot_api_set_warnings __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
#define ASSERT_ARGS_Parrot_api_wrap_imcc_hack __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(sourcefile) \
- , PARROT_ASSERT_ARG(argv) \
, PARROT_ASSERT_ARG(bytecodepmc) \
, PARROT_ASSERT_ARG(result))
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
View
2  src/embed/api.c
@@ -732,7 +732,7 @@ otherwise.
PARROT_API
Parrot_Int
Parrot_api_wrap_imcc_hack(Parrot_PMC interp_pmc, ARGIN(const char * sourcefile),
- int argc, ARGIN(const char **argv), ARGMOD(Parrot_PMC* bytecodepmc),
+ int argc, ARGIN_NULLOK(const char **argv), ARGMOD(Parrot_PMC* bytecodepmc),
ARGOUT(int *result), imcc_hack_func_t func)
{
ASSERT_ARGS(Parrot_api_wrap_imcc_hack)
View
59 t/src/embed/api.t
@@ -11,7 +11,7 @@ use Parrot::Test::Util 'create_tempfile';
plan skip_all => 'src/parrot_config.o does not exist' unless -e catfile(qw/src parrot_config.o/);
-plan tests => 1;
+plan tests => 2;
=head1 NAME
@@ -93,14 +93,6 @@ c_output_is(linedirective(__LINE__) . <<'CODE', <<'OUTPUT', "get set compiler" )
#include "parrot/api.h"
-void fail(const char *msg);
-
-void fail(const char *msg)
-{
- fprintf(stderr, "failed: %s\n", msg);
- exit(EXIT_FAILURE);
-}
-
int main(int argc, const char **argv)
{
char * c_outstr = NULL;
@@ -130,11 +122,12 @@ True
Done
OUTPUT
-my (undef, $temp_pir) = create_tempfile( SUFFIX => '.pir', UNLINK => 1 );
-my (undef, $temp_pbc) = create_tempfile( SUFFIX => '.pir', UNLINK => 1 );
-open PIR_FILE, $temp_pir, ">";
+my (undef, $temp_pir) = create_tempfile( SUFFIX => '.pir', UNLINK => 0 );
+my (undef, $temp_pbc) = create_tempfile( SUFFIX => '.pir', UNLINK => 0 );
+open PIR_FILE, ">", $temp_pir;
print PIR_FILE <<'PIR_CODE';
-.sub main :mainargv
+.sub main :main
+ .param pmc args
say "executed"
.end
PIR_CODE
@@ -145,27 +138,33 @@ c_output_is( <<"CODE", << 'OUTPUT', "Parrot_api_serialize_bytecode_pmc" );
#include "parrot/api.h"
-void fail(const char *msg);
-
-void fail(const char *msg)
-{
- fprintf(stderr, "failed: %s\n", msg);
- exit(EXIT_FAILURE);
-}
-
int main(void) {
Parrot_PMC interp;
- Parrot_PMC bytecode
+ Parrot_PMC bytecode;
Parrot_Int run_pbc;
- Parrot_String pbc;
-
- const char *argv[] = {"$temp_pir"};
- Parrot_api_make_interpreter(NULL, 0, initargs, &inter);
-
- Parrot_api_wrap_imcc_hack(interp, sourcefile, 1, argv, &bytecode, &run_pbc, imcc_run_api);
- Parrot_api_serialize_bytecode_pmc(interp, bytecode, &pbc);
- // TODO: Write out to a file
+ Parrot_String pbc_s;
+ Parrot_Int length;
+ char * pbc_c;
+ FILE * file;
+
+ Parrot_api_make_interpreter(NULL, 0, NULL, &interp);
+
+ /* Step 1: Take the PIR, and compile it to PBC. Write to file */
+ Parrot_api_wrap_imcc_hack(interp, "$temp_pir", 0, NULL, &bytecode, &run_pbc, imcc_run_api);
+ Parrot_api_serialize_bytecode_pmc(interp, bytecode, &pbc_s);
+ Parrot_api_string_export_ascii(interp, pbc_s, &pbc_c);
+ Parrot_api_string_byte_length(interp, pbc_s, &length);
+ file = fopen("$temp_pbc", "w");
+ fwrite(pbc_c, length, 1, file);
+ fclose(file);
+
+ /* Step 2: Now load in the PIR and execute it */
+ Parrot_api_load_bytecode_file(interp, "$temp_pbc", &bytecode);
+ Parrot_api_run_bytecode(interp, bytecode, NULL);
}
+CODE
+executed
+OUTPUT
# Local Variables:
# mode: cperl
Please sign in to comment.
Something went wrong with that request. Please try again.