Skip to content

Commit

Permalink
many changes to the new IMCC API. We're building again and doing abou…
Browse files Browse the repository at this point in the history
…t as well on the test suite as we were
  • Loading branch information
Whiteknight committed Feb 9, 2011
1 parent 83b1708 commit db1fa87
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 79 deletions.
3 changes: 2 additions & 1 deletion compilers/imcc/Defines.mak
Expand Up @@ -13,4 +13,5 @@ IMCC_O_FILES = \
compilers/imcc/optimizer$(O) \
compilers/imcc/pbc$(O) \
compilers/imcc/parser_util$(O) \
compilers/imcc/pcc$(O)
compilers/imcc/pcc$(O) \
compilers/imcc/api$(O)
5 changes: 5 additions & 0 deletions compilers/imcc/Rules.in
@@ -1,3 +1,8 @@
compilers/imcc/api$(O) : \
compilers/imcc/api.c \
include/imcc/api.h \
$(PARROT_H_HEADERS)

compilers/imcc/pcc$(O) : \
compilers/imcc/pcc.c \
compilers/imcc/cfg.h \
Expand Down
102 changes: 69 additions & 33 deletions compilers/imcc/api.c
Expand Up @@ -23,114 +23,149 @@ IMCC call-in routines for use with the Parrot embedding API
*/

#include "imc.h"
#include "parrot.h"
#include "parrot/parrot.h"
#include "parrot/extend.h"

/* HEADERIZER HFILE: compilers/imcc/imc.h */

/* HEADERIZER BEGIN: static */
/* HEADERIZER END: static */
#include "imcc/api.h"
#include "imc.h"

struct _get_compreg_data {
int is_pasm;
int add_compreg;
PMC * compiler;
PMC * error;
}
};

struct _compile_file_data {
PMC * compiler;
STRING * file;
PMC * pbc;
PMC * error;
};

/* HEADERIZER HFILE: include/imcc/api.h */

/* HEADERIZER BEGIN: static */
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */

static void compile_file(PARROT_INTERP, struct _compile_file_data * data)
__attribute__nonnull__(1);

static void compile_file_handler(PARROT_INTERP,
PMC * ex,
struct _compile_file_data * data)
__attribute__nonnull__(1);

static void get_compreg_handler(PARROT_INTERP,
PMC * ex,
struct _get_compreg_data * data)
__attribute__nonnull__(1);

static void get_compreg_pmc(PARROT_INTERP, struct _get_compreg_data * data)
__attribute__nonnull__(1);

#define ASSERT_ARGS_compile_file __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
#define ASSERT_ARGS_compile_file_handler __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
#define ASSERT_ARGS_get_compreg_handler __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
#define ASSERT_ARGS_get_compreg_pmc __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
/* HEADERIZER END: static */



PARROT_EXPORT
PARROT_CANNOT_RETURN_NULL
PMC *
imcc_get_pir_compreg_api(PMC * interp_pmc, int add_compreg, PMC **err)
imcc_get_pir_compreg_api(Parrot_PMC interp_pmc, int add_compreg, Parrot_PMC *err)
{
Interp * const interp = (Interp *) VTABLE_get_pointer(NULL, interp_pmc);
PMC * compiler = PMCNULL;
_get_compreg_data * const data =
(_get_compreg_data *)Parrot_gc_allocate_fixed_size_storage(interp, sizeof(_get_compreg_data))
struct _get_compreg_data * const data = (struct _get_compreg_data *)
Parrot_gc_allocate_fixed_size_storage(interp, sizeof(struct _get_compreg_data));
data->is_pasm = 0;
data->add_compreg = add_compreg;
Parrot_ext_try(interp, get_compreg_pmc, get_compreg_handler, data);
compiler = data->compiler;
if (PMC_IS_NULL(compiler))
*err = data->error;
Parrot_gc_free_fixed_size_storage(interp, sizeof(_get_compreg_data), data);
Parrot_gc_free_fixed_size_storage(interp, sizeof(struct _get_compreg_data), data);
return compiler;
}

PARROT_EXPORT
PARROT_CANNOT_RETURN_NULL
PMC *
imcc_get_pasm_compreg_api(PMC * interp_pmc, int add_compreg, PMC **err)
imcc_get_pasm_compreg_api(Parrot_PMC interp_pmc, int add_compreg,
Parrot_PMC *err)
{
Interp * const interp = (Interp *) VTABLE_get_pointer(NULL, interp_pmc);
PMC * compiler = PMCNULL;
_get_compreg_data * const data =
(_get_compreg_data *)Parrot_gc_allocate_fixed_size_storage(interp, sizeof(_get_compreg_data))
struct _get_compreg_data * const data = (struct _get_compreg_data *)
Parrot_gc_allocate_fixed_size_storage(interp, sizeof(struct _get_compreg_data));
data->is_pasm = 1;
data->add_compreg = add_compreg;
Parrot_ext_try(interp, get_compreg_pmc, get_compreg_handler, data);
compiler = data->compiler;
if (PMC_IS_NULL(compiler))
*err = data->error;
Parrot_gc_free_fixed_size_storage(interp, sizeof(_get_compreg_data), data);
Parrot_gc_free_fixed_size_storage(interp, sizeof(struct _get_compreg_data), data);
return compiler;
}

static void
get_compreg_pmc(PARROT_INTERP, _get_compreg_data * data)
get_compreg_pmc(PARROT_INTERP, struct _get_compreg_data * data)
{
data->compiler = Parrot_pmc_new_init_int(interp, enum_class_IMCCompiler, is_pasm);
data->compiler = Parrot_pmc_new_init_int(interp, enum_class_IMCCompiler, data->is_pasm);
if (data->add_compreg) {
STRING * const name = VTABLE_get_string(interp, data->compiler);
Parrot_set_compiler(interp, name, data->compiler);
}
}

static void
get_compreg_handler(PARROT_INTERP, PMC * ex, _get_compreg_data * data)
get_compreg_handler(PARROT_INTERP, PMC * ex, struct _get_compreg_data * data)
{
data->error = ex;
data->compiler = PMCNULL;
}

struct _compile_file_data {
PMC * compiler;
STRING * file;
PMC * pbc;
PMC * error;
}


PARROT_EXPORT
PARROT_CANNOT_RETURN_NULL
PMC *
imcc_compile_file_api(PMC *interp_pmc, PMC *compiler, STRING *file, PMC **error)
imcc_compile_file_api(Parrot_PMC interp_pmc, Parrot_PMC compiler,
Parrot_String file, Parrot_PMC *error)
{
Interp * const interp = (Interp *) VTABLE_get_pointer(NULL, interp_pmc);
PMC * pbc = PMCNULL;
_compile_file_data * const data =
(_compile_file_data *)Parrot_gc_allocate_fixed_size_storage(interp, sizeof(_compile_file_data));
struct _compile_file_data * const data = (struct _compile_file_data *)
Parrot_gc_allocate_fixed_size_storage(interp, sizeof(struct _compile_file_data));
data->compiler = compiler;
data->file = file;
Parrot_ext_try(interp, compile_file, compile_file_handler, data);
pbc = data->pbc;
if (PMC_IS_NULL(pbc))
*error = data->error;
Parrot_gc_free_fixed_size_storage(interp, sizeof(struct _compile_file_data), data);
return pbc;
}

static void
compile_file(PARROT_INTERP, _compile_file_data * data)
compile_file(PARROT_INTERP, struct _compile_file_data * data)
{
PMC * result = PMCNULL;
STRING * const meth_name = Parrot_str_new(interp, "compile_file", 0);
Parrot_pcc_invoke_method_from_c_args(interp, compiler, meth_name,
"S->P", file, &result);
Parrot_pcc_invoke_method_from_c_args(interp, data->compiler, meth_name,
"S->P", data->file, &result);
data->pbc = result;
}

static void
compile_file_handler(PARROT_INTERP, PMC * ex, _compile_file_data * data)
compile_file_handler(PARROT_INTERP, PMC * ex, struct _compile_file_data * data)
{
data->error = ex;
data->pbc = PMCNULL;
Expand All @@ -139,7 +174,8 @@ compile_file_handler(PARROT_INTERP, PMC * ex, _compile_file_data * data)
PARROT_EXPORT
PARROT_CANNOT_RETURN_NULL
void
imcc_preprocess_file_api(PMC *interp_pmc, PMC *compiler, STRING *file)
imcc_preprocess_file_api(Parrot_PMC interp_pmc, Parrot_PMC compiler,
Parrot_String file)
{
/* TODO: Error handling with Parrot_ext_try */
Interp * const interp = (Interp *) VTABLE_get_pointer(NULL, interp_pmc);
Expand Down
5 changes: 0 additions & 5 deletions compilers/imcc/imc.h
Expand Up @@ -95,10 +95,6 @@ PARROT_CANNOT_RETURN_NULL
imc_info_t * imcc_new(PARROT_INTERP)
__attribute__nonnull__(1);

PARROT_EXPORT
PARROT_CANNOT_RETURN_NULL
imc_info_t * imcc_new_pmc(PMC * interp_pmc);

PARROT_EXPORT
void imcc_preprocess(
ARGMOD(imc_info_t *imcc),
Expand Down Expand Up @@ -177,7 +173,6 @@ yyscan_t imcc_get_scanner(ARGMOD(imc_info_t *imcc))
PARROT_ASSERT_ARG(imcc))
#define ASSERT_ARGS_imcc_new __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
#define ASSERT_ARGS_imcc_new_pmc __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
#define ASSERT_ARGS_imcc_preprocess __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(imcc) \
, PARROT_ASSERT_ARG(sourcefile))
Expand Down
51 changes: 11 additions & 40 deletions frontend/parrot/main.c
Expand Up @@ -23,6 +23,7 @@ Start Parrot
#include <ctype.h>
#include "parrot/longopt.h"
#include "parrot/api.h"
#include "imcc/api.h"

struct init_args_t {
const char *run_core_name;
Expand All @@ -44,26 +45,6 @@ extern int Parrot_set_config_hash(Parrot_PMC interp_pmc);
/* HEADERIZER BEGIN: static */
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */

PARROT_CANNOT_RETURN_NULL
static PMC * compile_file(
Parrot_PMC interp,
Parrot_PMC compiler,
Parrot_String file);

PARROT_CANNOT_RETURN_NULL
static PMC * get_class_pmc(Parrot_PMC interp, ARGIN(const char *name))
__attribute__nonnull__(2);

PARROT_CANNOT_RETURN_NULL
static PMC * get_imcc_compiler_pmc(
Parrot_PMC interp,
Parrot_PMC class_pmc,
Parrot_Int is_pasm);

PARROT_CANNOT_RETURN_NULL
static PMC * get_signature_pmc(Parrot_PMC interp, ARGIN(const char *sig))
__attribute__nonnull__(2);

static void help(void);
static void help_debug(void);
PARROT_WARN_UNUSED_RESULT
Expand Down Expand Up @@ -114,12 +95,6 @@ static void parseflags_minimal(
__attribute__nonnull__(3)
FUNC_MODIFIES(* initargs);

PARROT_CANNOT_RETURN_NULL
static void preprocess_file(
Parrot_PMC interp,
Parrot_PMC compiler,
Parrot_String file);

static void print_parrot_string(
Parrot_PMC interp,
ARGMOD(FILE *vector),
Expand Down Expand Up @@ -149,12 +124,6 @@ static void write_bytecode_file(
Parrot_String filename,
Parrot_PMC pbc);

#define ASSERT_ARGS_compile_file __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
#define ASSERT_ARGS_get_class_pmc __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(name))
#define ASSERT_ARGS_get_imcc_compiler_pmc __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
#define ASSERT_ARGS_get_signature_pmc __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(sig))
#define ASSERT_ARGS_help __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
#define ASSERT_ARGS_help_debug __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
#define ASSERT_ARGS_is_all_digits __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
Expand All @@ -175,7 +144,6 @@ static void write_bytecode_file(
#define ASSERT_ARGS_parseflags_minimal __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(initargs) \
, PARROT_ASSERT_ARG(argv))
#define ASSERT_ARGS_preprocess_file __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
#define ASSERT_ARGS_print_parrot_string __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(vector))
#define ASSERT_ARGS_run_imcc __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
Expand Down Expand Up @@ -252,7 +220,7 @@ main(int argc, const char *argv[])

/* -o outputs the file. -r outputs it and reads it in again from .pbc */
if (parsed_flags.write_packfile) {
if (!Parrot_api_write_bytecode_to_file(interp, bytecodepmc, output_str));
if (!Parrot_api_write_bytecode_to_file(interp, bytecodepmc, output_str))
show_last_error_and_exit(interp);
if (parsed_flags.execute_packfile)
bytecodepmc = load_bytecode_file(interp, output_str);
Expand Down Expand Up @@ -284,8 +252,10 @@ static PMC *
run_imcc(Parrot_PMC interp, Parrot_String sourcefile, ARGIN(struct init_args_t *flags))
{
ASSERT_ARGS(run_imcc)
Parrot_PMC pir_compiler = imcc_get_pir_compreg_api(interp, 1);
Parrot_PMC pasm_compiler = imcc_get_pasm_compreg_api(interp, 1);
/* TODO: Handle the error condition */
Parrot_PMC error = NULL;
Parrot_PMC pir_compiler = imcc_get_pir_compreg_api(interp, 1, &error);
Parrot_PMC pasm_compiler = imcc_get_pasm_compreg_api(interp, 1, &error);

if (flags->preprocess_only) {
imcc_preprocess_file_api(interp, pir_compiler, sourcefile);
Expand All @@ -294,7 +264,7 @@ run_imcc(Parrot_PMC interp, Parrot_String sourcefile, ARGIN(struct init_args_t *
else {
const Parrot_Int pasm_mode = flags->have_pasm_file;
Parrot_PMC compiler = pasm_mode ? pasm_compiler : pir_compiler;
return imcc_compile_file_api(interp, compiler, sourcefile);
return imcc_compile_file_api(interp, compiler, sourcefile, &error);
}
}

Expand All @@ -314,11 +284,12 @@ static PMC *
load_bytecode_file(Parrot_PMC interp, Parrot_String filename)
{
ASSERT_ARGS(load_bytecode_file)
PMC * bytecode = NULL;
Parrot_PMC bytecode = NULL;
Parrot_PMC error = NULL;

/* set up all the compregs */
Parrot_PMC pir_compiler = imcc_get_pir_compreg_api(interp, 1);
Parrot_PMC pasm_compiler = imcc_get_pasm_compreg_api(interp, 1);
Parrot_PMC pir_compiler = imcc_get_pir_compreg_api(interp, 1, &error);
Parrot_PMC pasm_compiler = imcc_get_pasm_compreg_api(interp, 1, &error);

if (!Parrot_api_load_bytecode_file(interp, filename, &bytecode))
show_last_error_and_exit(interp);
Expand Down
46 changes: 46 additions & 0 deletions include/imcc/api.h
@@ -0,0 +1,46 @@

#ifndef PARROT_IMCC_API_H_GUARD
#define PARROT_IMCC_API_H_GUARD

#include "parrot/api.h"

/* HEADERIZER BEGIN: compilers/imcc/api.c */
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */

PARROT_EXPORT
PARROT_CANNOT_RETURN_NULL
PMC * imcc_compile_file_api(
Parrot_PMC interp_pmc,
Parrot_PMC compiler,
Parrot_String file,
Parrot_PMC *error);

PARROT_EXPORT
PARROT_CANNOT_RETURN_NULL
PMC * imcc_get_pasm_compreg_api(
Parrot_PMC interp_pmc,
int add_compreg,
Parrot_PMC *err);

PARROT_EXPORT
PARROT_CANNOT_RETURN_NULL
PMC * imcc_get_pir_compreg_api(
Parrot_PMC interp_pmc,
int add_compreg,
Parrot_PMC *err);

PARROT_EXPORT
PARROT_CANNOT_RETURN_NULL
void imcc_preprocess_file_api(
Parrot_PMC interp_pmc,
Parrot_PMC compiler,
Parrot_String file);

#define ASSERT_ARGS_imcc_compile_file_api __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
#define ASSERT_ARGS_imcc_get_pasm_compreg_api __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
#define ASSERT_ARGS_imcc_get_pir_compreg_api __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
#define ASSERT_ARGS_imcc_preprocess_file_api __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
/* HEADERIZER END: compilers/imcc/api.c */

#endif /* PARROT_IMCC_API_H_GUARD */

0 comments on commit db1fa87

Please sign in to comment.