Alien-LibJIT
view release on metacpan or search on metacpan
libjit/dpas/dpas-main.c view on Meta::CPAN
}
else if((file = fopen(filename, "r")) != NULL)
{
dpas_load_file(filename, file);
fclose(file);
}
else
{
perror(filename);
return 1;
}
/* Bail out if we had errors during the compilation phase */
if(dpas_error_reported)
{
return 1;
}
/* Execute the program that we just compiled */
if(!dpas_dump_functions)
{
if(!dpas_run_main_functions())
{
return 1;
}
}
/* Done */
return 0;
}
static void version(void)
{
printf("Dynamic Pascal Version " VERSION "\n");
printf("Copyright (c) 2004 Southern Storm Software, Pty Ltd.\n");
exit(0);
}
static void usage(void)
{
printf("Dynamic Pascal Version " VERSION "\n");
printf("Copyright (c) 2004 Southern Storm Software, Pty Ltd.\n");
printf("\n");
printf("Usage: %s [-Idir] file.pas [args]\n", progname);
exit(1);
}
static void add_include_dir(char *dir)
{
include_dirs = (char **)jit_realloc
(include_dirs, (num_include_dirs + 1) * sizeof(char *));
if(!include_dirs)
{
dpas_out_of_memory();
}
include_dirs[num_include_dirs++] = dir;
}
void dpas_out_of_memory(void)
{
fputs(progname, stderr);
fputs(": virtual memory exhausted\n", stderr);
exit(1);
}
void dpas_import(const char *name)
{
int posn;
char *pathname;
FILE *file;
/* Bail out if we've already included this name before */
for(posn = 0; posn < num_using_seen; ++posn)
{
if(!jit_strcmp(using_seen[posn], name))
{
return;
}
}
/* Add the name to the "seen" list */
using_seen = (char **)jit_realloc
(using_seen, (num_using_seen + 1) * sizeof(char *));
if(!using_seen)
{
dpas_out_of_memory();
}
using_seen[num_using_seen] = jit_strdup(name);
if(!(using_seen[num_using_seen]))
{
dpas_out_of_memory();
}
++num_using_seen;
/* Look in the same directory as the including source file first */
posn = jit_strlen(dpas_filename);
while(posn > 0 && dpas_filename[posn - 1] != '/' &&
dpas_filename[posn - 1] != '\\')
{
--posn;
}
if(posn > 0)
{
pathname = (char *)jit_malloc(posn + jit_strlen(name) + 5);
if(!pathname)
{
dpas_out_of_memory();
}
jit_strncpy(pathname, dpas_filename, posn);
jit_strcpy(pathname + posn, name);
jit_strcat(pathname, ".pas");
}
else
{
pathname = (char *)jit_malloc(jit_strlen(name) + 5);
if(!pathname)
{
dpas_out_of_memory();
}
jit_strcpy(pathname, name);
jit_strcat(pathname, ".pas");
}
if((file = fopen(pathname, "r")) != NULL)
{
dpas_load_file(pathname, file);
fclose(file);
jit_free(pathname);
return;
}
jit_free(pathname);
/* Scan the include directories looking for the name */
for(posn = 0; posn < num_include_dirs; ++posn)
{
pathname = (char *)jit_malloc(jit_strlen(include_dirs[posn]) +
jit_strlen(name) + 6);
if(!pathname)
{
dpas_out_of_memory();
}
jit_strcpy(pathname, include_dirs[posn]);
jit_strcat(pathname, "/");
jit_strcat(pathname, name);
jit_strcat(pathname, ".pas");
if((file = fopen(pathname, "r")) != NULL)
{
dpas_load_file(pathname, file);
fclose(file);
jit_free(pathname);
return;
}
jit_free(pathname);
}
/* If we get here, then we could not find the specified module */
fprintf(stderr, "%s:%ld: could not locate the module `%s'\n",
dpas_filename, dpas_linenum, name);
dpas_error_reported = 1;
}
/*
* Initialize the system.
*/
static void initialize(void)
{
jit_init();
dpas_init_types();
if(dont_fold)
{
jit_context_set_meta_numeric
(dpas_current_context(), JIT_OPTION_DONT_FOLD, 1);
}
}
( run in 1.887 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )