Skip to content

Commit

Permalink
refactored pmc attribute AST nodes. Added handling of extends clause …
Browse files Browse the repository at this point in the history
…of PMCs, AST only.
  • Loading branch information
kjs committed Jun 16, 2012
1 parent e780f6c commit db023f4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 26 deletions.
10 changes: 9 additions & 1 deletion src/ast.c
Expand Up @@ -378,10 +378,11 @@ newstruct(M1_compiler *comp, char *name)
}

m1_pmc *
newpmc(M1_compiler *comp, char *name)
newpmc(M1_compiler *comp, char *name, m1_ident *idlist)
{
m1_pmc *pmc = (m1_pmc *)m1_malloc(sizeof(m1_pmc));
pmc->name = name;
pmc->parents = idlist;

init_symtab(&pmc->sfields);

Expand Down Expand Up @@ -649,3 +650,10 @@ array_dimension(int ival) {
return d;
}

m1_ident *
identlist(m1_ident *next, char *newnode) {
m1_ident *id = (m1_ident *)m1_malloc(sizeof(m1_ident));
id->next = next;
id->name = newnode;
return id;
}
17 changes: 13 additions & 4 deletions src/ast.h
Expand Up @@ -8,6 +8,13 @@

#include "ann.h"

typedef struct m1_ident {
char *name;
struct m1_ident *next;

} m1_ident;


/* for array dimensions. */
typedef struct m1_dimension {
int intval;
Expand Down Expand Up @@ -50,9 +57,9 @@ typedef struct m1_struct {
} m1_struct;

typedef struct m1_pmc {
char *name;
unsigned size;

char *name;
unsigned size;
struct m1_ident *parents;
struct m1_chunk *methods;
struct m1_symboltable sfields;

Expand Down Expand Up @@ -337,7 +344,7 @@ extern void obj_set_ident(m1_object *node, char *ident);

extern m1_struct *newstruct(M1_compiler *comp, char *name);

extern m1_pmc *newpmc(M1_compiler *comp, char *name);
extern m1_pmc *newpmc(M1_compiler *comp, char *name, m1_ident *parents);

extern m1_expression *ifexpr(M1_compiler *comp, m1_expression *cond, m1_expression *ifblock, m1_expression *elseblock);
extern m1_expression *whileexpr(M1_compiler *comp, m1_expression *cond, m1_expression *block);
Expand Down Expand Up @@ -392,5 +399,7 @@ extern void enter_param(M1_compiler *comp, m1_var *parameter);

extern m1_dimension *array_dimension(int ival);

extern m1_ident *identlist(m1_ident *next, char *newnode);

#endif

34 changes: 13 additions & 21 deletions src/m1.y
Expand Up @@ -61,6 +61,7 @@ yyerror(yyscan_t yyscanner, M1_compiler *comp, char *str) {
struct m1_block *blck;
struct m1_dimension *dim;
struct m1_symbol *sym;
struct m1_ident *ident;
}


Expand Down Expand Up @@ -232,8 +233,6 @@ yyerror(yyscan_t yyscanner, M1_compiler *comp, char *str) {

%type <sym> struct_members
struct_member
pmc_attributes
pmc_attr


%type <strct> struct_definition
Expand All @@ -249,6 +248,8 @@ yyerror(yyscan_t yyscanner, M1_compiler *comp, char *str) {
%type <cse> case
cases

%type <ident> id_list
extends_clause

%token KW_M0 "M0"
TK_NL
Expand Down Expand Up @@ -380,8 +381,9 @@ chunk : function_definition

enum_definition : "enum" TK_IDENT '{' enum_constants '}'
{
$$ = newenum(comp, $2, $4);
type_enter_enum((M1_compiler *)yyget_extra(yyscanner), $2, $$);
M1_compiler *comp = (M1_compiler *)yyget_extra(yyscanner);
$$ = newenum(comp, $2, $4 );
type_enter_enum(comp, $2, $$);
}
;

Expand All @@ -396,9 +398,7 @@ enum_constants : enum_const
;

enum_const : TK_IDENT opt_enum_val
{
$$ = enumconst((M1_compiler *)yyget_extra(yyscanner), $1, $2);
}
{ $$ = enumconst((M1_compiler *)yyget_extra(yyscanner), $1, $2); }
;

opt_enum_val : /* empty */
Expand Down Expand Up @@ -427,40 +427,32 @@ namespace_definition: "namespace" TK_IDENT ';'
}
;

pmc_definition : pmc_init '{' pmc_attributes pmc_methods '}'
{

}
pmc_definition : pmc_init '{' struct_members pmc_methods '}'
;

pmc_init : "pmc" TK_IDENT extends_clause
{
M1_compiler *comp = (M1_compiler *)yyget_extra(yyscanner);
$$ = newpmc(comp, $2);
$$ = newpmc(comp, $2, $3);
type_enter_pmc(comp, $2, $$);
/* point to this PMC's symbol table. */
comp->currentsymtab = &$$->sfields;
}
;

extends_clause : /* empty */
{ $$ = NULL; }
| "extends" id_list
{ $$ = $2; }
;

id_list : TK_IDENT
{ $$ = identlist(NULL, $1); }
| id_list ',' TK_IDENT
{ $$ = identlist($1, $3); }
;

pmc_attributes : pmc_attr
| pmc_attributes pmc_attr
{
$2->next = $1;
$$ = $2;
}
;

pmc_attr : struct_member
;

pmc_methods : /* empty */
{ $$ = NULL; }
Expand Down

0 comments on commit db023f4

Please sign in to comment.