Permalink
Browse files

first prototype of a new mechanism for setting the configuration hash…

… as a PMC
  • Loading branch information...
1 parent 98cd26c commit c4ccd134064a7d1af321d63fb7c3277becc6cc2f @Whiteknight Whiteknight committed Nov 22, 2010
View
@@ -148,6 +148,58 @@ is_all_hex_digits(ARGIN(const char *s))
/*
+=item C<static const struct longopt_opt_decl * Parrot_cmd_options(void)>
+
+Set up the const struct declaration for cmd_options
+
+=cut
+
+*/
+
+// TODO: Weed out the options that IMCC doesn't use, and rename this function
+// to something more imcc-ish
+static const struct longopt_opt_decl *
+Parrot_cmd_options(void)
+{
+ //ASSERT_ARGS(Parrot_cmd_options)
+ static const struct longopt_opt_decl cmd_options[] = {
+ { '.', '.', (OPTION_flags)0, { "--wait" } },
+ { 'D', 'D', OPTION_optional_FLAG, { "--parrot-debug" } },
+ { 'E', 'E', (OPTION_flags)0, { "--pre-process-only" } },
+ { 'G', 'G', (OPTION_flags)0, { "--no-gc" } },
+ { '\0', OPT_HASH_SEED, OPTION_required_FLAG, { "--hash-seed" } },
+ { 'I', 'I', OPTION_required_FLAG, { "--include" } },
+ { 'L', 'L', OPTION_required_FLAG, { "--library" } },
+ { 'O', 'O', OPTION_optional_FLAG, { "--optimize" } },
+ { 'R', 'R', OPTION_required_FLAG, { "--runcore" } },
+ { 'g', 'g', OPTION_required_FLAG, { "--gc" } },
+ { '\0', OPT_GC_THRESHOLD, OPTION_required_FLAG, { "--gc-threshold" } },
+ { 'V', 'V', (OPTION_flags)0, { "--version" } },
+ { 'X', 'X', OPTION_required_FLAG, { "--dynext" } },
+ { '\0', OPT_DESTROY_FLAG, (OPTION_flags)0,
+ { "--leak-test", "--destroy-at-end" } },
+ { '\0', OPT_GC_DEBUG, (OPTION_flags)0, { "--gc-debug" } },
+ { 'a', 'a', (OPTION_flags)0, { "--pasm" } },
+ { 'c', 'c', (OPTION_flags)0, { "--pbc" } },
+ { 'd', 'd', OPTION_optional_FLAG, { "--imcc-debug" } },
+ { '\0', OPT_HELP_DEBUG, (OPTION_flags)0, { "--help-debug" } },
+ { 'h', 'h', (OPTION_flags)0, { "--help" } },
+ { 'o', 'o', OPTION_required_FLAG, { "--output" } },
+ { '\0', OPT_PBC_OUTPUT, (OPTION_flags)0, { "--output-pbc" } },
+ { 'r', 'r', (OPTION_flags)0, { "--run-pbc" } },
+ { '\0', OPT_RUNTIME_PREFIX, (OPTION_flags)0, { "--runtime-prefix" } },
+ { 't', 't', OPTION_optional_FLAG, { "--trace" } },
+ { 'v', 'v', (OPTION_flags)0, { "--verbose" } },
+ { 'w', 'w', (OPTION_flags)0, { "--warnings" } },
+ { 'y', 'y', (OPTION_flags)0, { "--yydebug" } },
+ { 0, 0, (OPTION_flags)0, { NULL } }
+ };
+ return cmd_options;
+}
+
+
+/*
+
=item C<static void imcc_parseflags(PARROT_INTERP, int argc, const char **argv)>
Parse flags ans set approptiate state(s)
@@ -243,57 +295,6 @@ imcc_parseflags(PARROT_INTERP, int argc, ARGIN(const char **argv))
/*
-=item C<const struct longopt_opt_decl * Parrot_cmd_options(void)>
-
-Set up the const struct declaration for cmd_options
-
-=cut
-
-*/
-
-// TODO: Weed out the options that IMCC doesn't use, and rename this function
-// to something more imcc-ish
-const struct longopt_opt_decl *
-Parrot_cmd_options(void)
-{
- ASSERT_ARGS(Parrot_cmd_options)
- static const struct longopt_opt_decl cmd_options[] = {
- { '.', '.', (OPTION_flags)0, { "--wait" } },
- { 'D', 'D', OPTION_optional_FLAG, { "--parrot-debug" } },
- { 'E', 'E', (OPTION_flags)0, { "--pre-process-only" } },
- { 'G', 'G', (OPTION_flags)0, { "--no-gc" } },
- { '\0', OPT_HASH_SEED, OPTION_required_FLAG, { "--hash-seed" } },
- { 'I', 'I', OPTION_required_FLAG, { "--include" } },
- { 'L', 'L', OPTION_required_FLAG, { "--library" } },
- { 'O', 'O', OPTION_optional_FLAG, { "--optimize" } },
- { 'R', 'R', OPTION_required_FLAG, { "--runcore" } },
- { 'g', 'g', OPTION_required_FLAG, { "--gc" } },
- { '\0', OPT_GC_THRESHOLD, OPTION_required_FLAG, { "--gc-threshold" } },
- { 'V', 'V', (OPTION_flags)0, { "--version" } },
- { 'X', 'X', OPTION_required_FLAG, { "--dynext" } },
- { '\0', OPT_DESTROY_FLAG, (OPTION_flags)0,
- { "--leak-test", "--destroy-at-end" } },
- { '\0', OPT_GC_DEBUG, (OPTION_flags)0, { "--gc-debug" } },
- { 'a', 'a', (OPTION_flags)0, { "--pasm" } },
- { 'c', 'c', (OPTION_flags)0, { "--pbc" } },
- { 'd', 'd', OPTION_optional_FLAG, { "--imcc-debug" } },
- { '\0', OPT_HELP_DEBUG, (OPTION_flags)0, { "--help-debug" } },
- { 'h', 'h', (OPTION_flags)0, { "--help" } },
- { 'o', 'o', OPTION_required_FLAG, { "--output" } },
- { '\0', OPT_PBC_OUTPUT, (OPTION_flags)0, { "--output-pbc" } },
- { 'r', 'r', (OPTION_flags)0, { "--run-pbc" } },
- { '\0', OPT_RUNTIME_PREFIX, (OPTION_flags)0, { "--runtime-prefix" } },
- { 't', 't', OPTION_optional_FLAG, { "--trace" } },
- { 'v', 'v', (OPTION_flags)0, { "--verbose" } },
- { 'w', 'w', (OPTION_flags)0, { "--warnings" } },
- { 'y', 'y', (OPTION_flags)0, { "--yydebug" } },
- { 0, 0, (OPTION_flags)0, { NULL } }
- };
- return cmd_options;
-}
-
-/*
-
=item C<static void do_pre_process(PARROT_INTERP, yyscan_t yyscanner)>
Pre-processor step. Turn parser's output codes into Parrot instructions.
View
@@ -156,6 +156,11 @@ Parrot_Int Parrot_api_run_bytecode(
FUNC_MODIFIES(*interp_pmc);
PARROT_API
+Parrot_Int Parrot_api_set_configuration_hash(
+ Parrot_PMC interp_pmc,
+ Parrot_PMC confighash);
+
+PARROT_API
Parrot_Int Parrot_api_set_executable_name(
ARGMOD(PMC *interp_pmc),
ARGIN(const char * name))
@@ -230,6 +235,8 @@ Parrot_Int Parrot_api_set_warnings(
PARROT_ASSERT_ARG(interp_pmc) \
, PARROT_ASSERT_ARG(pbc) \
, PARROT_ASSERT_ARG(mainargs))
+#define ASSERT_ARGS_Parrot_api_set_configuration_hash \
+ __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
#define ASSERT_ARGS_Parrot_api_set_executable_name \
__attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp_pmc) \
@@ -272,6 +279,16 @@ Parrot_Int Parrot_api_string_import_ascii(
__attribute__nonnull__(3)
FUNC_MODIFIES(* out);
+PARROT_API
+Parrot_Int Parrot_api_string_import_binary(
+ Parrot_PMC interp_pmc,
+ ARGIN(const unsigned char *bytes),
+ Parrot_Int length,
+ ARGOUT(Parrot_String *out))
+ __attribute__nonnull__(2)
+ __attribute__nonnull__(4)
+ FUNC_MODIFIES(*out);
+
#define ASSERT_ARGS_Parrot_api_string_export_ascii \
__attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(string) \
@@ -283,6 +300,10 @@ Parrot_Int Parrot_api_string_import_ascii(
__attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(str) \
, PARROT_ASSERT_ARG(out))
+#define ASSERT_ARGS_Parrot_api_string_import_binary \
+ __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(bytes) \
+ , PARROT_ASSERT_ARG(out))
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
/* HEADERIZER END: src/embed/strings.c */
@@ -23,11 +23,6 @@ typedef enum {
enum_DIS_HEADER = 2
} Parrot_disassemble_options;
-/* Parrot_set_config_hash exists in *_config.o (e.g install_config.o),
- so if you make this call then you will need to link with it in
- addition to libparrot */
-void Parrot_set_config_hash(void);
-
PARROT_EXPORT
PARROT_DOES_NOT_RETURN
PARROT_COLD
@@ -25,25 +25,32 @@ void Parrot_initialize_core_pmcs(PARROT_INTERP, int pass)
/* HEADERIZER BEGIN: src/global_setup.c */
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
-PARROT_EXPORT
-void Parrot_set_config_hash_internal(
- ARGIN(const unsigned char* parrot_config),
- unsigned int parrot_config_size)
- __attribute__nonnull__(1);
-
void init_world(PARROT_INTERP)
__attribute__nonnull__(1);
void init_world_once(PARROT_INTERP)
__attribute__nonnull__(1);
-#define ASSERT_ARGS_Parrot_set_config_hash_internal \
- __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(parrot_config))
+void Parrot_set_config_hash_internal(
+ ARGIN(const unsigned char* parrot_config),
+ unsigned int parrot_config_size)
+ __attribute__nonnull__(1);
+
+void Parrot_set_config_hash_pmc(PARROT_INTERP, ARGMOD(PMC * config))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2)
+ FUNC_MODIFIES(* config);
+
#define ASSERT_ARGS_init_world __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
#define ASSERT_ARGS_init_world_once __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
+#define ASSERT_ARGS_Parrot_set_config_hash_internal \
+ __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(parrot_config))
+#define ASSERT_ARGS_Parrot_set_config_hash_pmc __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp) \
+ , PARROT_ASSERT_ARG(config))
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
/* HEADERIZER END: src/global_setup.c */
@@ -61,12 +61,10 @@ int longopt_get(
__attribute__nonnull__(4)
FUNC_MODIFIES(* info_buf);
-const struct longopt_opt_decl * Parrot_cmd_options(void);
#define ASSERT_ARGS_longopt_get __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(argv) \
, PARROT_ASSERT_ARG(options) \
, PARROT_ASSERT_ARG(info_buf))
-#define ASSERT_ARGS_Parrot_cmd_options __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
/* HEADERIZER END: src/longopt.c */
View
@@ -291,3 +291,13 @@ Parrot_api_get_runtime_path(Parrot_PMC interp_pmc, ARGOUT(Parrot_String *runtime
EMBED_API_CALLOUT(interp_pmc, interp);
}
+PARROT_API
+Parrot_Int
+Parrot_api_set_configuration_hash(Parrot_PMC interp_pmc, Parrot_PMC confighash)
+{
+ EMBED_API_CALLIN(interp_pmc, interp);
+ Parrot_set_config_hash_pmc(interp, confighash);
+ EMBED_API_CALLOUT(interp_pmc, interp);
+}
+
+
View
@@ -34,4 +34,13 @@ Parrot_api_string_import_ascii(Parrot_PMC interp_pmc, ARGIN(const char * str), A
EMBED_API_CALLOUT(interp_pmc, interp);
}
+PARROT_API
+Parrot_Int
+Parrot_api_string_import_binary(Parrot_PMC interp_pmc, ARGIN(const unsigned char *bytes), Parrot_Int length, ARGOUT(Parrot_String *out))
+{
+ EMBED_API_CALLIN(interp_pmc, interp);
+ *out = Parrot_str_new(interp, bytes, length);
+ EMBED_API_CALLOUT(interp_pmc, interp);
+}
+
/* TODO: wchar_t variants */
View
@@ -32,6 +32,7 @@ void Parrot_register_core_pmcs(PARROT_INTERP, PMC* registry);
static const unsigned char* parrot_config_stored = NULL;
static unsigned int parrot_config_size_stored = 0;
+static PMC * parrot_config_hash_global = NULL;
/* HEADERIZER HFILE: include/parrot/global_setup.h */
@@ -65,7 +66,6 @@ will be used in subsequently created Interpreters.
*/
-PARROT_EXPORT
void
Parrot_set_config_hash_internal(ARGIN(const unsigned char* parrot_config),
unsigned int parrot_config_size)
@@ -77,6 +77,15 @@ Parrot_set_config_hash_internal(ARGIN(const unsigned char* parrot_config),
}
}
+void
+Parrot_set_config_hash_pmc(PARROT_INTERP, ARGMOD(PMC * config))
+{
+ ASSERT_ARGS(Parrot_set_config_hash_pmc)
+ parrot_config_hash_global = config;
+ if (!PMC_IS_NULL(config))
+ parrot_set_config_hash_interpreter(interp);
+}
+
/*
=item C<static void parrot_set_config_hash_interpreter(PARROT_INTERP)>
@@ -94,19 +103,14 @@ parrot_set_config_hash_interpreter(PARROT_INTERP)
ASSERT_ARGS(parrot_set_config_hash_interpreter)
PMC *iglobals = interp->iglobals;
- PMC *config_hash = NULL;
-
- if (parrot_config_size_stored > 1) {
- STRING * const config_string =
- Parrot_str_new_init(interp,
- (const char *)parrot_config_stored, parrot_config_size_stored,
- Parrot_default_encoding_ptr,
- PObj_external_FLAG|PObj_constant_FLAG);
-
- config_hash = Parrot_thaw(interp, config_string);
- }
- else {
+ PMC *config_hash = parrot_config_hash_global;
+ if (config_hash == NULL)
config_hash = Parrot_pmc_new(interp, enum_class_Hash);
+ else {
+ /* On initialization, we probably set up an empty hash for our first
+ interpreter. We should use this branch here to insert some sane
+ defaults so that things do not go crazy if the user forgets to set
+ the config hash later */
}
VTABLE_set_pmc_keyed_int(interp, iglobals,
View
@@ -132,9 +132,8 @@ main(int argc, const char *argv[])
/* Parse minimal subset of flags */
parseflags_minimal(initargs, argc, argv);
- Parrot_set_config_hash();
-
if (!(Parrot_api_make_interpreter(NULL, 0, initargs, &interp) &&
+ Parrot_set_config_hash(interp) &&
Parrot_api_set_executable_name(interp, argv[0]))) {
fprintf(stderr, "PARROT VM: Could not initialize new interpreter");
get_last_error(interp);
@@ -351,10 +350,11 @@ Set up the const struct declaration for cmd_options
*/
// TODO: Weed out the options that are not used by this executable
+static
const struct longopt_opt_decl *
Parrot_cmd_options(void)
{
- ASSERT_ARGS(Parrot_cmd_options)
+ //ASSERT_ARGS(Parrot_cmd_options)
static const struct longopt_opt_decl cmd_options[] = {
{ '.', '.', (OPTION_flags)0, { "--wait" } },
{ 'D', 'D', OPTION_optional_FLAG, { "--parrot-debug" } },
@@ -41,12 +41,7 @@ =head1 DESCRIPTION
*
*/
-#include "parrot/parrot.h"
-
-/* proto is in embed.h, but we don't include anything here, which
- * could pull in some globals
- */
-void Parrot_set_config_hash(void);
+#include "parrot/api.h"
void
Parrot_set_config_hash_internal (const unsigned char* parrot_config,
@@ -86,10 +81,12 @@ =head1 DESCRIPTION
print << "EOF";
}; /* parrot_config */
-void
-Parrot_set_config_hash(void)
+int
+Parrot_set_config_hash(Parrot_PMC interp_pmc)
{
- Parrot_set_config_hash_internal(parrot_config, sizeof(parrot_config));
+ Parrot_String strhash;
+ return Parrot_api_string_import_binary(interp_pmc, parrot_config, sizeof(parrot_config), &strhash) &&
+ Parrot_api_set_configuration_hash(interp_pmc, strhash);
}
EOF

0 comments on commit c4ccd13

Please sign in to comment.