Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/Alekssasho/parrot into load…
Browse files Browse the repository at this point in the history
…_language_refactor
  • Loading branch information
Whiteknight committed Dec 2, 2011
2 parents 9a764f7 + bf40847 commit 910982f
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 87 deletions.
2 changes: 1 addition & 1 deletion docs/embed.pod
Expand Up @@ -908,7 +908,7 @@ The list may also be augmented if additional functionality is required.

=item C<Parrot_load_encoding>

=item C<Parrot_load_language>
=item C<Parrot_pf_load_language>

=item C<Parrot_dyn_load_lib>

Expand Down
2 changes: 1 addition & 1 deletion src/embed/api.c
Expand Up @@ -533,7 +533,7 @@ Parrot_api_load_language(Parrot_PMC interp_pmc, ARGIN(Parrot_String lang))
{
ASSERT_ARGS(Parrot_api_load_language)
EMBED_API_CALLIN(interp_pmc, interp)
Parrot_load_language(interp, lang);
Parrot_pf_load_language(interp, lang);
EMBED_API_CALLOUT(interp_pmc, interp);
}

Expand Down
2 changes: 1 addition & 1 deletion src/ops/core.ops
Expand Up @@ -132,7 +132,7 @@ locate the main compiler file in the standard locations.
=cut

inline op load_language(in STR) :load_file {
Parrot_load_language(interp, $1);
Parrot_pf_load_language(interp, $1);
}

=back
Expand Down
4 changes: 2 additions & 2 deletions src/ops/core_ops.c
Expand Up @@ -13384,13 +13384,13 @@ Parrot_load_bytecode_p_sc(opcode_t *cur_opcode, PARROT_INTERP) {

opcode_t *
Parrot_load_language_s(opcode_t *cur_opcode, PARROT_INTERP) {
Parrot_load_language(interp, SREG(1));
Parrot_pf_load_language(interp, SREG(1));
return (opcode_t *)cur_opcode + 2;
}

opcode_t *
Parrot_load_language_sc(opcode_t *cur_opcode, PARROT_INTERP) {
Parrot_load_language(interp, SCONST(1));
Parrot_pf_load_language(interp, SCONST(1));
return (opcode_t *)cur_opcode + 2;
}

Expand Down
149 changes: 67 additions & 82 deletions src/packfile/api.c
Expand Up @@ -37,9 +37,9 @@ format of bytecode.
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */

static void base_path_module(PARROT_INTERP,
ARGIN(STRING *found_ext),
ARGIN(STRING *lang_name),
ARGIN(STRING *path))
ARGIN(STRING *path),
ARGIN(STRING *pbc))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(3)
Expand All @@ -54,13 +54,16 @@ static void check_bytecode_or_source_file(PARROT_INTERP,
__attribute__nonnull__(3)
__attribute__nonnull__(4);

PARROT_WARN_UNUSED_RESULT
static int check_lang_load(PARROT_INTERP,
ARGIN(PMC *is_loaded_hash),
ARGIN(STRING *wo_ext))
static void check_lang_load(PARROT_INTERP,
ARGIN(STRING *wo_ext),
ARGIN(STRING *file_str),
ARGIN(STRING *lang_name),
ARGIN(STRING *pbc))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(3);
__attribute__nonnull__(3)
__attribute__nonnull__(4)
__attribute__nonnull__(5);

static void compile_file(PARROT_INTERP, ARGIN(STRING *path), INTVAL is_pasm)
__attribute__nonnull__(1)
Expand Down Expand Up @@ -105,16 +108,9 @@ static INTVAL find_pf_ann_idx(
__attribute__nonnull__(1)
__attribute__nonnull__(2);

static void full_path_name(PARROT_INTERP,
ARGIN(STRING *wo_ext),
ARGIN(STRING *file_str),
ARGIN(STRING *pbc),
ARGIN(STRING *lang_name))
static void full_path_name(PARROT_INTERP, ARGIN(STRING *lang_name))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(3)
__attribute__nonnull__(4)
__attribute__nonnull__(5);
__attribute__nonnull__(2);

static void load_file(PARROT_INTERP, ARGIN(STRING *path))
__attribute__nonnull__(1)
Expand Down Expand Up @@ -200,18 +196,20 @@ static int sub_pragma(PARROT_INTERP,

#define ASSERT_ARGS_base_path_module __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(found_ext) \
, PARROT_ASSERT_ARG(lang_name) \
, PARROT_ASSERT_ARG(path))
, PARROT_ASSERT_ARG(path) \
, PARROT_ASSERT_ARG(pbc))
#define ASSERT_ARGS_check_bytecode_or_source_file __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(found_ext) \
, PARROT_ASSERT_ARG(pbc) \
, PARROT_ASSERT_ARG(path))
#define ASSERT_ARGS_check_lang_load __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(is_loaded_hash) \
, PARROT_ASSERT_ARG(wo_ext))
, PARROT_ASSERT_ARG(wo_ext) \
, PARROT_ASSERT_ARG(file_str) \
, PARROT_ASSERT_ARG(lang_name) \
, PARROT_ASSERT_ARG(pbc))
#define ASSERT_ARGS_compile_file __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(path))
Expand All @@ -231,9 +229,6 @@ static int sub_pragma(PARROT_INTERP,
, PARROT_ASSERT_ARG(key))
#define ASSERT_ARGS_full_path_name __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(wo_ext) \
, PARROT_ASSERT_ARG(file_str) \
, PARROT_ASSERT_ARG(pbc) \
, PARROT_ASSERT_ARG(lang_name))
#define ASSERT_ARGS_load_file __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
Expand Down Expand Up @@ -2120,57 +2115,80 @@ load_file(PARROT_INTERP, ARGIN(STRING *path))

/*
=item C<static void full_path_name(PARROT_INTERP, STRING *wo_ext, STRING
*file_str, STRING *pbc, STRING *lang_name)>
=item C<static void full_path_name(PARROT_INTERP, STRING *lang_name)>
This function is only for local use of Parrot_pf_load_language();
=cut
*/
static void
full_path_name(PARROT_INTERP, ARGIN(STRING *wo_ext), ARGIN(STRING *file_str),
ARGIN(STRING *pbc), ARGIN(STRING *lang_name))
full_path_name(PARROT_INTERP, ARGIN(STRING *lang_name))
{
ASSERT_ARGS(full_path_name)
//ASSERT_ARGS(full_path_name)
STRING *wo_ext, *file_str, *pbc;

pbc = CONST_STRING(interp, "pbc");

/* Full path to language library is "abc/abc.pbc". */
wo_ext = Parrot_str_concat(interp, lang_name, CONST_STRING(interp, "/"));
wo_ext = Parrot_str_concat(interp, wo_ext, lang_name);
file_str = Parrot_str_concat(interp, wo_ext, CONST_STRING(interp, "."));
file_str = Parrot_str_concat(interp, file_str, pbc);

/* Check if the language is already loaded */
check_lang_load(interp, wo_ext, file_str, lang_name, pbc);
}

/*
=item C<static int check_lang_load(PARROT_INTERP, PMC *is_loaded_hash, STRING
*wo_ext)>
=item C<static void check_lang_load(PARROT_INTERP, STRING *wo_ext, STRING
*file_str, STRING *lang_name, STRING *pbc)>
This function is only for local use of Parrot_pf_load_language();
=cut
*/

PARROT_WARN_UNUSED_RESULT
static int
check_lang_load(PARROT_INTERP, ARGIN(PMC *is_loaded_hash), ARGIN(STRING *wo_ext))
static void
check_lang_load(PARROT_INTERP, ARGIN(STRING *wo_ext), ARGIN(STRING *file_str),
ARGIN(STRING *lang_name), ARGIN(STRING *pbc))
{
ASSERT_ARGS(check_lang_load)
//ASSERT_ARGS(check_lang_load)

enum_runtime_ft file_type;
PMC *is_loaded_hash;
STRING *path;

/* Check if the language is already loaded */
is_loaded_hash = VTABLE_get_pmc_keyed_int(interp,
interp->iglobals, IGLOBALS_PBC_LIBS);
if (VTABLE_exists_keyed_str(interp, is_loaded_hash, wo_ext))
return 1;
return 0;
return;

file_type = PARROT_RUNTIME_FT_LANG;

path = Parrot_locate_runtime_file_str(interp, file_str, file_type);
if (!path)
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_LIBRARY_ERROR,
"\"load_language\" couldn't find a compiler module for the language '%Ss'", lang_name);

/* remember wo_ext => full_path mapping */

VTABLE_set_string_keyed_str(interp, is_loaded_hash,
wo_ext, path);

/* Add the include and dynext paths to the global search */

base_path_module(interp, lang_name, path, pbc);
}


/*
=item C<static void base_path_module(PARROT_INTERP, STRING *found_ext, STRING
*lang_name, STRING *path)>
=item C<static void base_path_module(PARROT_INTERP, STRING *lang_name, STRING
*path, STRING *pbc)>
This function is only for local use of Parrot_pf_load_language();
Expand All @@ -2179,14 +2197,14 @@ This function is only for local use of Parrot_pf_load_language();
*/

static void
base_path_module(PARROT_INTERP, ARGIN(STRING *found_ext), ARGIN(STRING *lang_name),
ARGIN(STRING *path))
base_path_module(PARROT_INTERP, ARGIN(STRING *lang_name), ARGIN(STRING *path),
ARGIN(STRING *pbc))
{
ASSERT_ARGS(base_path_module)
//ASSERT_ARGS(base_path_module)

/* Get the base path of the located module */
/* Get the base path of the located module */
INTVAL name_length;
STRING *found_path;
STRING *found_ext, *found_path;

parrot_split_path_ext(interp, path, &found_path, &found_ext);
name_length = Parrot_str_length(interp, lang_name);
Expand All @@ -2199,6 +2217,10 @@ base_path_module(PARROT_INTERP, ARGIN(STRING *found_ext), ARGIN(STRING *lang_nam
PARROT_LIB_PATH_DYNEXT);
Parrot_lib_add_path(interp, Parrot_str_concat(interp, found_path, CONST_STRING(interp, "library/")),
PARROT_LIB_PATH_LIBRARY);

/* Check if the file found was actually a bytecode file (.pbc extension) or
* a source file (.pir or .pasm extension. */
check_bytecode_or_source_file(interp, found_ext, pbc, path);
}
/*
Expand All @@ -2215,7 +2237,7 @@ static void
check_bytecode_or_source_file(PARROT_INTERP, ARGIN(STRING *found_ext),
ARGIN(STRING *pbc), ARGIN(STRING *path))
{
ASSERT_ARGS(check_bytecode_or_source_file)
//ASSERT_ARGS(check_bytecode_or_source_file)

push_context(interp);

Expand Down Expand Up @@ -2246,50 +2268,13 @@ void
Parrot_pf_load_language(PARROT_INTERP, ARGIN_NULLOK(STRING *lang_name))
{
ASSERT_ARGS(Parrot_pf_load_language)
STRING *wo_ext, *file_str, *path, *pbc;
STRING *found_ext;

enum_runtime_ft file_type;
PMC *is_loaded_hash;

if (STRING_IS_NULL(lang_name))
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_LIBRARY_ERROR,
"\"load_language\" no language name");

pbc = CONST_STRING(interp, "pbc");

/* Full path to language library is "abc/abc.pbc". */

full_path_name(interp, wo_ext, file_str, pbc, lang_name);

/* Check if the language is already loaded */

if (check_lang_load(interp, is_loaded_hash, wo_ext) == 1)
return;

file_type = PARROT_RUNTIME_FT_LANG;

path = Parrot_locate_runtime_file_str(interp, file_str, file_type);
if (!path)
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_LIBRARY_ERROR,
"\"load_language\" couldn't find a compiler module for the language '%Ss'", lang_name);

/* remember wo_ext => full_path mapping */

VTABLE_set_string_keyed_str(interp, is_loaded_hash,
wo_ext, path);

/* Add the include and dynext paths to the global search */

/* Get the base path of the located module */

base_path_module (interp, found_ext, lang_name, path);


/* Check if the file found was actually a bytecode file (.pbc extension) or
* a source file (.pir or .pasm extension. */
full_path_name(interp, lang_name);

check_bytecode_or_source_file (interp, found_ext, pbc, path);
}

/*
Expand Down

0 comments on commit 910982f

Please sign in to comment.