Skip to content

Commit

Permalink
load_bytecode and load_language now properly handle .pasm file again
Browse files Browse the repository at this point in the history
  • Loading branch information
Whiteknight committed Feb 11, 2011
1 parent 0b177f4 commit a4626d5
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 18 deletions.
17 changes: 14 additions & 3 deletions compilers/imcc/pbc.c
Expand Up @@ -1346,6 +1346,7 @@ find_outer(ARGMOD(imc_info_t * imcc), ARGIN(const IMC_Unit *unit))
Parrot_Sub_attributes *sub;
size_t len;


if (!unit->outer)
return NULL;

Expand All @@ -1367,12 +1368,22 @@ find_outer(ARGMOD(imc_info_t * imcc), ARGIN(const IMC_Unit *unit))
}
}

/* could be eval too; check if :outer is the current sub */
/* could be eval too; check if :outer is the current sub. If not, look
in the current namespace */
current = Parrot_pcc_get_sub(imcc->interp, CURRENT_CONTEXT(imcc->interp));
if (PMC_IS_NULL(current))
{
PMC * const ns = Parrot_pcc_get_namespace(imcc->interp, CURRENT_CONTEXT(imcc->interp));
STRING * const invokable_s = Parrot_str_new(imcc->interp, "invokable", 0);
STRING * const unit_name_s = Parrot_str_new(imcc->interp, unit->outer->name, 0);
current = VTABLE_get_pmc_keyed_str(imcc->interp, ns, unit_name_s);
if (current->vtable->base_type != enum_class_Sub &&
!VTABLE_does(imcc->interp, current, invokable_s))
current = PMCNULL;
}

if (PMC_IS_NULL(current))
IMCC_fatal(imcc, 1, "Undefined :outer sub '%s'.\n",
unit->outer->name);
IMCC_fatal(imcc, 1, "Undefined :outer sub '%s'.\n", unit->outer->name);

PMC_get_sub(imcc->interp, current, sub);

Expand Down
3 changes: 2 additions & 1 deletion include/parrot/interpreter.h
Expand Up @@ -467,10 +467,11 @@ PARROT_EXPORT
PARROT_CANNOT_RETURN_NULL
PackFile_ByteCode * Parrot_compile_file(PARROT_INTERP,
ARGIN(STRING *fullname),
INTVAL is_pasm,
ARGOUT(STRING **error))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(3)
__attribute__nonnull__(4)
FUNC_MODIFIES(*error);

PARROT_EXPORT
Expand Down
12 changes: 7 additions & 5 deletions src/interp/inter_misc.c
Expand Up @@ -212,7 +212,7 @@ Parrot_set_compiler(PARROT_INTERP, ARGIN(STRING *type), ARGIN(PMC *compiler))
/*
=item C<PackFile_ByteCode * Parrot_compile_file(PARROT_INTERP, STRING *fullname,
STRING **error)>
INTVAL is_pasm, STRING **error)>
Compile code file.
Expand All @@ -223,21 +223,23 @@ Compile code file.
PARROT_EXPORT
PARROT_CANNOT_RETURN_NULL
PackFile_ByteCode *
Parrot_compile_file(PARROT_INTERP, ARGIN(STRING *fullname), ARGOUT(STRING **error))
Parrot_compile_file(PARROT_INTERP, ARGIN(STRING *fullname), INTVAL is_pasm,
ARGOUT(STRING **error))
{
ASSERT_ARGS(Parrot_compile_file)
PMC *result = NULL;
UINTVAL regs_used[4] = {3, 3, 3, 3};
PMC * const newcontext = Parrot_push_context(interp, regs_used);
PMC * pir_compiler = Parrot_get_compiler(interp, CONST_STRING(interp, "PIR"));
imc_info_t *imcc = (imc_info_t *) VTABLE_get_pointer(interp, pir_compiler);
STRING * compiler_s = is_pasm ? CONST_STRING(interp, "PASM") : CONST_STRING(interp, "PIR");
PMC * compiler = Parrot_get_compiler(interp, compiler_s);
imc_info_t *imcc = (imc_info_t *) VTABLE_get_pointer(interp, compiler);
PackFile * pf = NULL;

Parrot_block_GC_mark(interp);
Parrot_pcc_set_HLL(interp, newcontext, 0);
Parrot_pcc_set_sub(interp, newcontext, 0);

result = imcc_compile_file(imcc, fullname, 0);
result = imcc_compile_file(imcc, fullname, is_pasm);
if (PMC_IS_NULL(result)) {
STRING * const msg = imcc_last_error_message(imcc);
INTVAL code = imcc_last_error_code(imcc);
Expand Down
22 changes: 14 additions & 8 deletions src/packfile/api.c
Expand Up @@ -85,7 +85,7 @@ static void clone_constant(PARROT_INTERP, ARGIN(PMC **c))
__attribute__nonnull__(1)
__attribute__nonnull__(2);

static void compile_file(PARROT_INTERP, ARGIN(STRING *path))
static void compile_file(PARROT_INTERP, ARGIN(STRING *path), INTVAL is_pasm)
__attribute__nonnull__(1)
__attribute__nonnull__(2);

Expand Down Expand Up @@ -4047,7 +4047,7 @@ push_context(PARROT_INTERP)

/*
=item C<static void compile_file(PARROT_INTERP, STRING *path)>
=item C<static void compile_file(PARROT_INTERP, STRING *path, INTVAL is_pasm)>
Compile a PIR or PASM file from source.
Expand All @@ -4056,14 +4056,14 @@ Compile a PIR or PASM file from source.
*/

static void
compile_file(PARROT_INTERP, ARGIN(STRING *path))
compile_file(PARROT_INTERP, ARGIN(STRING *path), INTVAL is_pasm)
{
ASSERT_ARGS(compile_file)

STRING *err;
PackFile_ByteCode * const cur_code = interp->code;
PackFile_ByteCode * const cs =
(PackFile_ByteCode *)Parrot_compile_file(interp, path, &err);
(PackFile_ByteCode *)Parrot_compile_file(interp, path, is_pasm, &err);

if (cs) {
interp->code = cur_code;
Expand Down Expand Up @@ -4182,8 +4182,11 @@ Parrot_load_language(PARROT_INTERP, ARGIN_NULLOK(STRING *lang_name))

if (STRING_equal(interp, found_ext, pbc))
load_file(interp, path);
else
compile_file(interp, path);
else {
const STRING * pasm_s = CONST_STRING(interp, "pasm");
const INTVAL is_pasm = STRING_equal(interp, found_ext, pasm_s);
compile_file(interp, path, is_pasm);
}

Parrot_pop_context(interp);
}
Expand Down Expand Up @@ -4287,8 +4290,11 @@ Parrot_load_bytecode(PARROT_INTERP, ARGIN_NULLOK(Parrot_String file_str))

if (STRING_equal(interp, found_ext, pbc))
load_file(interp, path);
else
compile_file(interp, path);
else {
const STRING * pasm_s = CONST_STRING(interp, "pasm");
const INTVAL is_pasm = STRING_equal(interp, ext, pasm_s);
compile_file(interp, path, is_pasm);
}

Parrot_pop_context(interp);

Expand Down
2 changes: 1 addition & 1 deletion src/pmc/imccompiler.pmc
Expand Up @@ -4,7 +4,7 @@

/* HEADERIZER HFILE: none */

pmclass IMCCompiler auto_attrs provides HLLCompiler {
pmclass IMCCompiler auto_attrs provides HLLCompiler provide invokable {
ATTR void *imcc_info;
ATTR INTVAL is_pasm; /* 0 = PIR, 1 = PASM */

Expand Down

0 comments on commit a4626d5

Please sign in to comment.