[svn:parrot] r37670 - in trunk: compilers/imcc include/parrot src src/ops
allison at svn.parrot.org
allison at svn.parrot.org
Tue Mar 24 07:48:03 UTC 2009
Author: allison
Date: Tue Mar 24 07:48:03 2009
New Revision: 37670
URL: https://trac.parrot.org/parrot/changeset/37670
Log:
[hll] Merging in the 'load_language' branch. Implements an opcode
'load_language' that loads the primary compiler libraries for a language
and sets up its search paths.
Modified:
trunk/compilers/imcc/main.c
trunk/include/parrot/library.h
trunk/include/parrot/packfile.h
trunk/src/library.c
trunk/src/ops/core.ops
trunk/src/ops/ops.num
trunk/src/packfile.c
Modified: trunk/compilers/imcc/main.c
==============================================================================
--- trunk/compilers/imcc/main.c Tue Mar 24 07:20:45 2009 (r37669)
+++ trunk/compilers/imcc/main.c Tue Mar 24 07:48:03 2009 (r37670)
@@ -532,11 +532,11 @@
SET_FLAG(PARROT_DESTROY_FLAG);
break;
case 'I':
- Parrot_add_library_path(interp, opt.opt_arg,
+ Parrot_add_library_path_from_cstring(interp, opt.opt_arg,
PARROT_LIB_PATH_INCLUDE);
break;
case 'L':
- Parrot_add_library_path(interp, opt.opt_arg,
+ Parrot_add_library_path_from_cstring(interp, opt.opt_arg,
PARROT_LIB_PATH_LIBRARY);
break;
default:
Modified: trunk/include/parrot/library.h
==============================================================================
--- trunk/include/parrot/library.h Tue Mar 24 07:20:45 2009 (r37669)
+++ trunk/include/parrot/library.h Tue Mar 24 07:48:03 2009 (r37670)
@@ -17,7 +17,8 @@
PARROT_RUNTIME_FT_LIBRARY = 0x0001,
PARROT_RUNTIME_FT_INCLUDE = 0x0002,
PARROT_RUNTIME_FT_DYNEXT = 0x0004,
- PARROT_RUNTIME_FT_PBC = 0x0010,
+ PARROT_RUNTIME_FT_LANG = 0x0010,
+ PARROT_RUNTIME_FT_PBC = 0x0020,
PARROT_RUNTIME_FT_PASM = 0x0100,
PARROT_RUNTIME_FT_PIR = 0x0200,
PARROT_RUNTIME_FT_PAST = 0x0400,
@@ -28,6 +29,7 @@
PARROT_LIB_PATH_INCLUDE, /* .include "foo" */
PARROT_LIB_PATH_LIBRARY, /* load_bytecode "bar" */
PARROT_LIB_PATH_DYNEXT, /* loadlib "baz" */
+ PARROT_LIB_PATH_LANG, /* load_language "buz" */
PARROT_LIB_DYN_EXTS, /* ".so", ".dylib" .. */
/* must be last: */
PARROT_LIB_PATH_SIZE
@@ -38,6 +40,13 @@
PARROT_EXPORT
void Parrot_add_library_path(PARROT_INTERP,
+ ARGIN(STRING *path),
+ enum_lib_paths which)
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2);
+
+PARROT_EXPORT
+void Parrot_add_library_path_from_cstring(PARROT_INTERP,
ARGIN(const char *path),
enum_lib_paths which)
__attribute__nonnull__(1)
@@ -94,6 +103,10 @@
#define ASSERT_ARGS_Parrot_add_library_path __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(path)
+#define ASSERT_ARGS_Parrot_add_library_path_from_cstring \
+ __attribute__unused__ int _ASSERT_ARGS_CHECK = \
+ PARROT_ASSERT_ARG(interp) \
+ || PARROT_ASSERT_ARG(path)
#define ASSERT_ARGS_Parrot_get_runtime_path __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp)
#define ASSERT_ARGS_Parrot_get_runtime_prefix __attribute__unused__ int _ASSERT_ARGS_CHECK = \
Modified: trunk/include/parrot/packfile.h
==============================================================================
--- trunk/include/parrot/packfile.h Tue Mar 24 07:20:45 2009 (r37669)
+++ trunk/include/parrot/packfile.h Tue Mar 24 07:48:03 2009 (r37670)
@@ -677,6 +677,10 @@
FUNC_MODIFIES(*dir);
PARROT_EXPORT
+void Parrot_load_language(PARROT_INTERP, ARGIN_NULLOK(STRING *lang_name))
+ __attribute__nonnull__(1);
+
+PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
opcode_t * PackFile_Segment_pack(PARROT_INTERP,
@@ -935,6 +939,8 @@
PARROT_ASSERT_ARG(interp)
#define ASSERT_ARGS_Parrot_load_bytecode __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp)
+#define ASSERT_ARGS_Parrot_load_language __attribute__unused__ int _ASSERT_ARGS_CHECK = \
+ PARROT_ASSERT_ARG(interp)
#define ASSERT_ARGS_Parrot_new_debug_seg __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(cs)
Modified: trunk/src/library.c
==============================================================================
--- trunk/src/library.c Tue Mar 24 07:20:45 2009 (r37669)
+++ trunk/src/library.c Tue Mar 24 07:48:03 2009 (r37670)
@@ -136,6 +136,7 @@
[ "runtime/parrot/include", ... ], # paths for .include 'file'
[ "runtime/parrot/library", ... ], # paths for load_bytecode
[ "runtime/parrot/dynext", ... ], # paths for loadlib
+ [ "languages", ... ], # paths for languages
[ ".so", ... ] # list of shared extensions
]
@@ -143,7 +144,7 @@
#define PARROT_PLATFORM_LIB_PATH_INIT_HOOK the_init_hook
-if will be called as a function with this prototype:
+it will be called as a function with this prototype:
void the_init_hook(PARROT_INTERP, PMC *lib_paths);
@@ -209,6 +210,19 @@
VTABLE_push_string(interp, paths, entry);
}
+ /* define languages paths */
+ paths = pmc_new(interp, enum_class_ResizableStringArray);
+ VTABLE_set_pmc_keyed_int(interp, lib_paths,
+ PARROT_LIB_PATH_LANG, paths);
+ entry = CONST_STRING(interp, "runtime/parrot/languages/");
+ VTABLE_push_string(interp, paths, entry);
+ entry = CONST_STRING(interp, "./");
+ VTABLE_push_string(interp, paths, entry);
+ if (!STRING_IS_NULL(versionlib)) {
+ entry = Parrot_str_concat(interp, versionlib, CONST_STRING(interp, "/languages/"), 0);
+ VTABLE_push_string(interp, paths, entry);
+ }
+
/* define dynext paths */
paths = pmc_new(interp, enum_class_ResizableStringArray);
VTABLE_set_pmc_keyed_int(interp, lib_paths,
@@ -252,6 +266,7 @@
[ "runtime/parrot/include", ... ], # paths for .include 'file'
[ "runtime/parrot/library", ... ], # paths for load_bytecode
[ "runtime/parrot/dynext", ... ], # paths for loadlib
+ [ "languages", ... ], # paths for languages
[ ".so", ... ] # list of shared extensions
]
@@ -580,9 +595,6 @@
Add a path to the library searchpath of the given type.
-TODO:
- - allow path to be a list of paths.
-
=cut
*/
@@ -590,7 +602,7 @@
PARROT_EXPORT
void
Parrot_add_library_path(PARROT_INTERP,
- ARGIN(const char *path),
+ ARGIN(STRING *path),
enum_lib_paths which)
{
ASSERT_ARGS(Parrot_add_library_path)
@@ -598,8 +610,31 @@
PMC * const lib_paths = VTABLE_get_pmc_keyed_int(interp, iglobals,
IGLOBALS_LIB_PATHS);
PMC * const paths = VTABLE_get_pmc_keyed_int(interp, lib_paths, which);
+ VTABLE_push_string(interp, paths, path);
+}
+
+/*
+
+=item C<void Parrot_add_library_path_from_cstring>
+
+Add a path to the library searchpath of the given type (passing in a C string).
+
+This function is just an interface to C<Parrot_add_library_path> for low-level
+code.
+
+=cut
+
+*/
+
+PARROT_EXPORT
+void
+Parrot_add_library_path_from_cstring(PARROT_INTERP,
+ ARGIN(const char *path),
+ enum_lib_paths which)
+{
+ ASSERT_ARGS(Parrot_add_library_path)
STRING * const path_str = Parrot_str_new(interp, path, 0);
- VTABLE_push_string(interp, paths, path_str);
+ Parrot_add_library_path(interp, path_str, which);
}
/*
@@ -612,10 +647,15 @@
=item C<STRING* Parrot_locate_runtime_file_str>
-Like above but use and return STRINGs. If successful, the returned STRING
-is 0-terminated so that C<result-E<gt>strstart> is usable as B<const char*>
-c-string for C library functions like fopen(3).
-This is the preferred API function.
+Like above but use and return STRINGs.
+
+Locate the full path for C<file_name> and the given file type(s). If
+successful, returns a C-string allocated with C<Parrot_str_to_cstring> or
+NULL otherwise.
+
+If successful, the returned STRING is 0-terminated so that
+C<result-E<gt>strstart> is usable as B<const char*> c-string for C library
+functions like fopen(3). This is the preferred API function.
The C<enum_runtime_ft type> is one or more of the types defined in
F<include/parrot/library.h>.
@@ -641,7 +681,9 @@
if (is_abs_path(file))
return file;
- if (type & PARROT_RUNTIME_FT_DYNEXT)
+ if (type & PARROT_RUNTIME_FT_LANG)
+ paths = get_search_paths(interp, PARROT_LIB_PATH_LANG);
+ else if (type & PARROT_RUNTIME_FT_DYNEXT)
paths = get_search_paths(interp, PARROT_LIB_PATH_DYNEXT);
else if (type & (PARROT_RUNTIME_FT_PBC | PARROT_RUNTIME_FT_SOURCE))
paths = get_search_paths(interp, PARROT_LIB_PATH_LIBRARY);
Modified: trunk/src/ops/core.ops
==============================================================================
--- trunk/src/ops/core.ops Tue Mar 24 07:20:45 2009 (r37669)
+++ trunk/src/ops/core.ops Tue Mar 24 07:48:03 2009 (r37670)
@@ -165,6 +165,18 @@
Parrot_load_bytecode(interp, $1);
}
+=item B<load_language>(in STR)
+
+Load the compiler libraries for a language $1. Search the library path to
+locate the main compiler file in the standard locations.
+
+inline op load_language(in STR) :load_file {
+ Parrot_load_language(interp, $1);
+}
+
+
+=cut
+
=back
=cut
Modified: trunk/src/ops/ops.num
==============================================================================
--- trunk/src/ops/ops.num Tue Mar 24 07:20:45 2009 (r37669)
+++ trunk/src/ops/ops.num Tue Mar 24 07:48:03 2009 (r37670)
@@ -1266,3 +1266,5 @@
find_name_p_sc 1242
find_sub_not_null_p_s 1243
find_sub_not_null_p_sc 1244
+load_language_s 1245
+load_language_sc 1246
Modified: trunk/src/packfile.c
==============================================================================
--- trunk/src/packfile.c Tue Mar 24 07:20:45 2009 (r37669)
+++ trunk/src/packfile.c Tue Mar 24 07:48:03 2009 (r37670)
@@ -56,6 +56,12 @@
__attribute__nonnull__(1)
__attribute__nonnull__(2);
+static void compile_or_load_file(PARROT_INTERP,
+ ARGIN(STRING *path),
+ enum_runtime_ft file_type)
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2);
+
static void const_destroy(PARROT_INTERP, ARGMOD(PackFile_Segment *self))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
@@ -333,6 +339,9 @@
#define ASSERT_ARGS_clone_constant __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(old_const)
+#define ASSERT_ARGS_compile_or_load_file __attribute__unused__ int _ASSERT_ARGS_CHECK = \
+ PARROT_ASSERT_ARG(interp) \
+ || PARROT_ASSERT_ARG(path)
#define ASSERT_ARGS_const_destroy __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(self)
@@ -4510,6 +4519,10 @@
for (i = 0; i < self->num_groups; i++)
if (offset < self->groups[i]->bytecode_offset)
break;
+
+
+ /* Check if the found file was actually bytecode (.pbc extension), or a
+ * source file (.pir or .pasm extension). */
else
start_entry = self->groups[i]->entries_offset;
@@ -4568,6 +4581,116 @@
return result;
}
+/*
+
+=item C<static void compile_or_load_file>
+
+Either load a bytecode file and append it to the current packfile directory, or
+compile a PIR or PASM file from source.
+
+=cut
+
+*/
+
+static void
+compile_or_load_file(PARROT_INTERP, ARGIN(STRING *path),
+ enum_runtime_ft file_type)
+{
+ char *filename = Parrot_str_to_cstring(interp, path);
+
+ if (file_type == PARROT_RUNTIME_FT_PBC) {
+ PackFile *pf = PackFile_append_pbc(interp, filename);
+ Parrot_str_free_cstring(filename);
+
+ if (!pf)
+ Parrot_ex_throw_from_c_args(interp, NULL, 1,
+ "Unable to append PBC to the current directory");
+ }
+ else {
+ STRING *err;
+ PackFile_ByteCode * const cs =
+ (PackFile_ByteCode *)IMCC_compile_file_s(interp,
+ filename, &err);
+ Parrot_str_free_cstring(filename);
+
+ if (cs)
+ do_sub_pragmas(interp, cs, PBC_LOADED, NULL);
+ else
+ Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_LIBRARY_ERROR,
+ "compiler returned NULL ByteCode '%Ss' - %Ss", path, err);
+ }
+}
+
+/*
+
+=item C<void Parrot_load_language>
+
+Load the compiler libraries for a given high-level language into the
+interpreter.
+
+=cut
+
+*/
+
+PARROT_EXPORT
+void
+Parrot_load_language(PARROT_INTERP, ARGIN_NULLOK(STRING *lang_name))
+{
+ ASSERT_ARGS(Parrot_load_language)
+ STRING *wo_ext, *file_str, *path, *pbc;
+ STRING *found_path, *found_ext;
+ INTVAL name_length;
+ 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");
+
+ /* Full path to language library is "abc/abc.pbc". */
+ pbc = CONST_STRING(interp, "pbc");
+ wo_ext = Parrot_str_concat(interp, lang_name, CONST_STRING(interp, "/"), 0);
+ wo_ext = Parrot_str_append(interp, wo_ext, lang_name);
+ file_str = Parrot_str_concat(interp, wo_ext, CONST_STRING(interp, "."), 0);
+ file_str = Parrot_str_append(interp, file_str, pbc);
+
+ /* 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;
+
+ 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 */
+ parrot_split_path_ext(interp, path, &found_path, &found_ext);
+ name_length = Parrot_str_length(interp, lang_name);
+ found_path = Parrot_str_substr(interp, found_path, -name_length, name_length, NULL, 0);
+ Parrot_add_library_path(interp, Parrot_str_append(interp, found_path, CONST_STRING(interp, "include/")),
+ PARROT_LIB_PATH_INCLUDE);
+ Parrot_add_library_path(interp, Parrot_str_append(interp, found_path, CONST_STRING(interp, "dynext/")),
+ PARROT_LIB_PATH_DYNEXT);
+
+
+ /* Check if the file found was actually a bytecode file (.pbc extension) or
+ * a source file (.pir or .pasm extension. */
+
+ if (Parrot_str_equal(interp, found_ext, pbc))
+ file_type = PARROT_RUNTIME_FT_PBC;
+ else
+ file_type = PARROT_RUNTIME_FT_SOURCE;
+
+ compile_or_load_file(interp, path, file_type);
+}
/*
@@ -4603,8 +4726,7 @@
=item C<void Parrot_load_bytecode>
-Loads and append a bytecode, PIR, or PASM file into interpreter in the current
-directory.
+Load a bytecode, PIR, or PASM file into the interpreter.
=cut
@@ -4649,28 +4771,7 @@
/* remember wo_ext => full_path mapping */
VTABLE_set_string_keyed_str(interp, is_loaded_hash, wo_ext, path);
- filename = Parrot_str_to_cstring(interp, path);
-
- if (file_type == PARROT_RUNTIME_FT_PBC) {
- PackFile *pf = PackFile_append_pbc(interp, filename);
- Parrot_str_free_cstring(filename);
-
- if (!pf)
- Parrot_ex_throw_from_c_args(interp, NULL, 1,
- "Unable to append PBC to the current directory");
- }
- else {
- STRING *err;
- PackFile_ByteCode * const cs =
- (PackFile_ByteCode *)IMCC_compile_file_s(interp, filename, &err);
- Parrot_str_free_cstring(filename);
-
- if (cs)
- do_sub_pragmas(interp, cs, PBC_LOADED, NULL);
- else
- Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_LIBRARY_ERROR,
- "compiler returned NULL ByteCode '%Ss' - %Ss", file_str, err);
- }
+ compile_or_load_file(interp, path, file_type);
}
More information about the parrot-commits
mailing list