/
main.c
87 lines (59 loc) · 1.58 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
Copyright (C) 2007, The Perl Foundation
$Id$
=head1 NAME
src/main.c - the Entry Point to Parrot Programs
=head1 DESCRIPTION
Start Parrot
=head2 Functions
=over 4
=cut
*/
#include <stdio.h>
#include <string.h>
#include "parrot/parrot.h"
#include "parrot/embed.h"
#include "parrot/imcc.h"
/*
=item C<int main(int argc, char * argv[])>
The entry point from the command line into Parrot.
*/
int
main(int argc, char * argv[])
{
char *sourcefile;
Interp *interp;
STRING *executable_name;
PMC *executable_name_pmc;
int status;
Parrot_set_config_hash();
interp = Parrot_new(NULL);
if (!imcc_initialize(interp))
internal_exception(1, "Could not initialize IMCC\n");
/* We parse the arguments, but first store away the name of the Parrot
executable, since parsing destroys that and we want to make it
available. */
executable_name = string_from_cstring(interp, argv[0], 0);
executable_name_pmc = pmc_new(interp, enum_class_String);
VTABLE_set_string_native(interp, executable_name_pmc, executable_name);
VTABLE_set_pmc_keyed_int(interp, interp->iglobals, IGLOBALS_EXECUTABLE,
executable_name_pmc);
sourcefile = parseflags(interp, &argc, &argv);
status = imcc_run(interp, sourcefile, argc, argv);
/* Clean-up after ourselves */
Parrot_destroy(interp);
Parrot_exit(interp, 0);
return status;
}
/*
=back
=head1 SEE ALSO
F<compilers/imcc/main.c>, unfortunately.
=cut
*/
/*
* Local variables:
* c-file-style: "parrot"
* End:
* vim: expandtab shiftwidth=4:
*/