Anarres-Mud-Driver
view release on metacpan or search on metacpan
Compiler/parser.y view on Meta::CPAN
node = POPs;
PUTBACK;
SvREFCNT_inc(node);
FREETMPS;
LEAVE;
// sv_2mortal(node); /* This segfaults it at the moment. */
return node;
}
/* We have to make sure that 'type' coming into here is PV not RV */
static SV *
yyparse_type(const char *type, SV *stars)
{
static SV *class = NULL;
SV *sv;
dSP;
int count;
SV *node;
if (!class) {
class = newSVpv(_AMD "::Compiler::Type", 0);
}
// fprintf(stderr, "Type is %s, stars is %s\n", type, SvPV_nolen(stars));
/* XXX It's quite likely that we own the only ref to 'stars' here.
*/
sv = newSVsv(stars);
sv_catpv(sv, type);
ENTER;
SAVETMPS;
PUSHMARK(SP);
XPUSHs(class);
XPUSHs(sv); /* Does this get freed? */
PUTBACK;
count = call_method("new", G_SCALAR);
SPAGAIN;
if (count != 1)
croak("Didn't get a return value from constructing Type\n");
node = POPs;
PUTBACK;
SvREFCNT_inc(node);
FREETMPS;
LEAVE;
/* In the outer scope. Let's hope this doesn't get dested. */
sv_2mortal(node);
return node;
#if 0
return sv_bless(newRV_noinc(stars),
gv_stashpv(_AMD "::Compiler::Type", TRUE));
#endif
}
/* Can I pass mods as a primitive integer, and not bother if they
* are zero? This applies to functions as well. */
static SV *
yyparse_variable(SV *name, const char *type, SV *stars, SV *mods)
{
static SV *class = NULL;
static SV *k_type = NULL;
static SV *k_name = NULL;
static SV *k_flags = NULL;
SV *newtype;
dSP;
int count;
SV *node;
if (!class) {
class = newSVpv(_AMD "::Program::Variable", 0);
k_type = newSVpv("Type", 0);
k_name = newSVpv("Name", 0);
k_flags = newSVpv("Flags", 0);
}
newtype = yyparse_type(type, stars);
ENTER;
SAVETMPS;
PUSHMARK(SP);
XPUSHs(class);
XPUSHs(k_type);
XPUSHs(newtype);
XPUSHs(k_name);
XPUSHs(name);
XPUSHs(k_flags);
XPUSHs(mods);
PUTBACK;
count = call_method("new", G_SCALAR);
SPAGAIN;
if (count != 1)
croak("Didn't get a return value from constructing Variable\n");
node = POPs;
PUTBACK;
SvREFCNT_inc(node);
FREETMPS;
LEAVE;
return node;
}
static SV *
yyparse_method(SV *name, const char *type, SV *stars,
SV *args, SV *mods)
{
static SV *class = NULL;
Compiler/parser.y view on Meta::CPAN
SvREFCNT_inc(node);
PUTBACK;
FREETMPS;
LEAVE;
return node;
}
%}
%token L_BREAK L_CASE L_CATCH L_CLASS L_CONTINUE L_DEFAULT L_DO
%token L_EFUN L_ELSE L_FOR L_FOREACH L_IF L_IN L_INHERIT L_NEW
%token L_NIL L_RETURN L_RLIMITS L_SWITCH L_SSCANF L_TRY L_WHILE
%token L_MAP_START L_MAP_END
%token L_ARRAY_START L_ARRAY_END
%token L_FUNCTION_START L_FUNCTION_END
%token L_PARAMETER L_IDENTIFIER L_NIL L_STRING L_CHARACTER
%token L_INTEGER L_HEXINTEGER
%token L_BASIC_TYPE L_TYPE_MODIFIER L_STATIC
%token L_INHERIT L_COLONCOLON
%token L_IF L_DO L_WHILE L_FOR L_FOREACH L_IN L_RLIMITS
%token L_TRY L_CATCH
%token L_SWITCH L_CASE L_BREAK
%token L_CONTINUE L_RETURN L_ELSE
%token L_VOID L_ELLIPSIS
%token L_ARROW L_RANGE
%nonassoc LOWER_THAN_ELSE
%nonassoc L_ELSE
/* Strictly these can be %token */
%nonassoc L_PLUS_EQ L_MINUS_EQ L_DIV_EQ L_TIMES_EQ
%nonassoc L_MOD_EQ L_AND_EQ L_OR_EQ L_XOR_EQ L_DOT_EQ
/* Is this the right place? */
%nonassoc L_LOR_EQ L_LAND_EQ
/* %left CONST */
%right '?'
%left L_LOR
%left L_LAND
%left '|'
%left '^'
%left '&'
%left L_EQ L_NE
%left L_GE L_LE '<' '>'
%left L_LSH L_RSH
%left '.'
%left '+' '-'
%left '*' '%' '/'
%right '!' '~'
%nonassoc L_INC L_DEC
/* These aren't strictly necessary, but they help debugging. */
%token '{' '}' ',' ';' ':' '(' ')' '[' ']' '=' '$'
/* I should have a new type 'node' in here for blessed objects
* which are specifically parse nodes. */
/* It is very very tempting to expand this to say 12 bytes
* to save on the use of AVs for type declarators. */
%union {
int number;
const char *str;
SV *sv;
SV *obj;
AV *av;
struct _assoc_t {
SV *key;
SV *value;
} assoc;
}
%{
/* This declares either yylex or yylex_verbose, according to
* the macros above. This is a bit obscure and occasionally
* highly fucked up. */
int yylex(YYSTYPE *yylval, amd_parse_param_t *param);
%}
/* %TYPES */
%type <av> function_declarator
%type <av> argument_list arguments
%type <sv> argument
%type <sv> function_prologue
%type <av> variable_declarator variable_declarator_list
%type <av> variable_declarator_init variable_declarator_list_init
%type <str> L_VOID L_BASIC_TYPE
/* This might point into an SvPV in the type cache. */
%type <str> type_specifier
/* An SvPV. */
%type <sv> star_list
%type <number> opt_endrange
%type <number> type_modifier_list L_TYPE_MODIFIER
%type <av> class_member_list class_member
%type <number> L_PARAMETER
%type <number> integer L_INTEGER L_HEXINTEGER L_CHARACTER
%type <sv> L_STRING string string_const
%type <sv> L_IDENTIFIER identifier
%type <obj> function_name
%type <assoc> assoc_exp
%type <av> arg_list opt_arg_list opt_arg_list_comma
%type <av> assoc_arg_list opt_assoc_arg_list_comma
%type <av> array mapping
%type <obj> lvalue
%type <av> lvalue_list
%type <obj> block
%type <av> local_decls local_decl
%type <obj> statement
( run in 0.539 second using v1.01-cache-2.11-cpan-5c0b1e786e0 )