Permalink
Browse files

Add profiling flags to makefile. Enter parameters in chunk's symbol t…

…able.
  • Loading branch information...
1 parent e3a093b commit 16126dea3e0b82594904b0746d58ae102c51d3d3 @kjs kjs committed Jun 12, 2012
Showing with 42 additions and 11 deletions.
  1. +15 −8 src/ast.c
  2. +3 −1 src/ast.h
  3. +14 −2 src/m1.y
  4. +10 −0 src/semcheck.c
View
@@ -474,18 +474,25 @@ Parameters are also represented by m1_var nodes.
m1_var *
parameter(M1_compiler *comp, char *paramtype, char *paramname) {
m1_var *p = (m1_var *)m1_malloc(sizeof(m1_var));
-
- p->sym = sym_new_symbol(comp,
- comp->currentsymtab, /* enter in current chunk's symbol table */
- paramname, /* name of this parameter being declared */
- paramtype,
- 1); /* just 1 element, not an array.
- XXX this is possible though! */
-
+ p->type = paramtype;
p->name = paramname;
+ /* cannot enter into a symbol table, as there is not yet an active symbol table. */
return p;
}
+void
+enter_param(M1_compiler *comp, m1_var *parameter) {
+ fprintf(stderr, "Entering param '%s'\n", parameter->name);
+ assert(parameter->type != NULL);
+ assert(parameter->name != NULL);
+ parameter->sym = sym_new_symbol(comp,
+ comp->currentsymtab,
+ parameter->name,
+ parameter->type,
+ 1);
+ assert(parameter->sym != NULL);
+}
+
m1_var *
array(M1_compiler *comp, char *varname, unsigned num_elems, m1_expression *init) {
m1_var *v = make_var(comp, varname, init, num_elems);
View
@@ -21,7 +21,8 @@ typedef struct m1_chunk {
struct m1_block *block; /* list of statements. */
struct m1_var *parameters; /* list of parameters */
-
+
+ unsigned line; /* line of function declaration. */
struct m1_symboltable constants; /* constants used in this chunk */
} m1_chunk;
@@ -383,6 +384,7 @@ extern void block_set_stat(m1_expression *block, m1_expression *stat);
extern struct m1_expression *open_scope(M1_compiler *comp);
extern void close_scope(M1_compiler *comp);
+extern void enter_param(M1_compiler *comp, m1_var *parameter);
#endif
View
@@ -476,9 +476,21 @@ opt_vtable : /* empty */
| "vtable"
;
-function_definition : function_init '(' parameters ')' block
+function_definition : function_init '(' parameters ')' open_block statements '}'
{
- $1->block = $5->expr.blck;
+ M1_compiler *comp = (M1_compiler *)yyget_extra(yyscanner);
+ $1->block = $5->expr.blck;
+ block_set_stat($5, $6);
+
+ /* add parameters here. */
+ m1_var *paramiter = $3;
+ while (paramiter != NULL) {
+
+ enter_param(comp, paramiter);
+ paramiter = paramiter->next;
+ }
+ /* now close the scope. */
+ close_scope(comp);
$$ = $1;
}
;
View
@@ -584,6 +584,15 @@ check_block(M1_compiler *comp, m1_block *block) {
comp->currentsymtab = block->locals.parentscope;
}
+static void
+check_parameters(M1_compiler *comp, m1_var *parameters, unsigned line) {
+ m1_var *paramiter = parameters;
+ while (paramiter != NULL) {
+ check_vardecl(comp, paramiter, line);
+ paramiter = paramiter->next;
+ }
+}
+
static void
check_chunk(M1_compiler *comp, m1_chunk *c) {
/* We're in a block, but not a block to break out of.
@@ -594,6 +603,7 @@ check_chunk(M1_compiler *comp, m1_chunk *c) {
*/
push(comp->breakstack, 0);
+ check_parameters(comp, c->parameters, c->line);
check_block(comp, c->block);
(void)pop(comp->breakstack);

0 comments on commit 16126de

Please sign in to comment.