2001-06-12 19:44:26 +00:00
|
|
|
%{
|
2001-06-12 20:24:02 +00:00
|
|
|
#include "qfcc.h"
|
2001-06-15 19:38:43 +00:00
|
|
|
|
2001-06-13 07:16:39 +00:00
|
|
|
#define YYDEBUG 1
|
|
|
|
#define YYERROR_VERBOSE 1
|
2001-06-18 22:51:49 +00:00
|
|
|
|
|
|
|
extern char *yytext;
|
2001-06-25 23:38:32 +00:00
|
|
|
extern int pr_source_line;
|
2001-06-18 22:51:49 +00:00
|
|
|
|
2001-06-12 20:24:02 +00:00
|
|
|
void
|
2001-06-18 22:51:49 +00:00
|
|
|
yyerror (const char *s)
|
2001-06-12 20:24:02 +00:00
|
|
|
{
|
2001-06-25 23:42:49 +00:00
|
|
|
fprintf (stderr, "%s:%d, %s %s\n", strings + s_file, pr_source_line, yytext, s);
|
2001-06-12 20:24:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int yylex (void);
|
2001-06-14 21:49:47 +00:00
|
|
|
type_t *PR_FindType (type_t *new);
|
2001-06-21 07:08:34 +00:00
|
|
|
void PR_PrintType(type_t*);
|
|
|
|
|
2001-06-18 22:51:49 +00:00
|
|
|
type_t *parse_params (def_t *parms);
|
2001-06-21 07:08:34 +00:00
|
|
|
function_t *new_function (void);
|
2001-06-25 18:23:29 +00:00
|
|
|
void build_function (function_t *f);
|
2001-06-25 20:52:04 +00:00
|
|
|
void emit_function (function_t *f, expr_t *e);
|
2001-06-25 18:23:29 +00:00
|
|
|
void build_scope (function_t *f, def_t *func);
|
2001-06-18 22:51:49 +00:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
type_t *type;
|
|
|
|
def_t *scope;
|
|
|
|
def_t *pscope;
|
|
|
|
} scope_t;
|
2001-06-12 20:24:02 +00:00
|
|
|
|
2001-06-12 19:44:26 +00:00
|
|
|
%}
|
|
|
|
|
2001-06-12 20:24:02 +00:00
|
|
|
%union {
|
2001-06-19 07:28:50 +00:00
|
|
|
scope_t scope;
|
2001-06-12 20:24:02 +00:00
|
|
|
def_t *def;
|
2001-06-13 07:16:39 +00:00
|
|
|
type_t *type;
|
2001-06-15 19:38:43 +00:00
|
|
|
expr_t *expr;
|
2001-06-13 07:16:39 +00:00
|
|
|
int int_val;
|
|
|
|
float float_val;
|
|
|
|
char *string_val;
|
|
|
|
float vector_val[3];
|
|
|
|
float quaternion_val[4];
|
2001-06-25 18:23:29 +00:00
|
|
|
function_t *function;
|
2001-06-12 20:24:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
%left OR AND
|
2001-06-12 19:44:26 +00:00
|
|
|
%right '='
|
2001-06-12 20:24:02 +00:00
|
|
|
%left EQ NE LE GE LT GT
|
2001-06-12 19:44:26 +00:00
|
|
|
%left '+' '-'
|
|
|
|
%left '*' '/' '&' '|'
|
2001-06-25 17:15:56 +00:00
|
|
|
%left '!'
|
2001-06-20 21:18:04 +00:00
|
|
|
%right '('
|
2001-06-25 17:15:56 +00:00
|
|
|
%left '.'
|
2001-06-12 19:44:26 +00:00
|
|
|
|
2001-06-15 07:16:18 +00:00
|
|
|
%token <string_val> NAME STRING_VAL
|
|
|
|
%token <int_val> INT_VAL
|
|
|
|
%token <float_val> FLOAT_VAL
|
|
|
|
%token <vector_val> VECTOR_VAL
|
|
|
|
%token <quaternion_val> QUATERNION_VAL
|
2001-06-12 19:44:26 +00:00
|
|
|
|
2001-06-14 21:49:47 +00:00
|
|
|
%token LOCAL RETURN WHILE DO IF ELSE FOR ELIPSIS
|
|
|
|
%token <type> TYPE
|
|
|
|
|
2001-06-20 23:32:13 +00:00
|
|
|
%type <type> type maybe_func
|
2001-06-15 19:38:43 +00:00
|
|
|
%type <def> param param_list def_item def_list def_name
|
2001-06-21 07:08:34 +00:00
|
|
|
%type <expr> const expr arg_list
|
2001-06-25 20:52:04 +00:00
|
|
|
%type <expr> statement statements statement_block
|
2001-06-25 18:23:29 +00:00
|
|
|
%type <function> begin_function
|
2001-06-12 19:44:26 +00:00
|
|
|
|
|
|
|
%expect 1
|
|
|
|
|
2001-06-15 07:16:18 +00:00
|
|
|
%{
|
|
|
|
|
2001-06-15 19:38:43 +00:00
|
|
|
type_t *current_type;
|
|
|
|
def_t *current_def;
|
2001-06-15 20:38:57 +00:00
|
|
|
def_t param_scope;
|
2001-06-25 22:11:20 +00:00
|
|
|
function_t *current_func;
|
2001-06-15 07:16:18 +00:00
|
|
|
|
|
|
|
%}
|
|
|
|
|
2001-06-12 19:44:26 +00:00
|
|
|
%%
|
|
|
|
|
|
|
|
defs
|
|
|
|
: /* empty */
|
|
|
|
| defs def ';'
|
|
|
|
;
|
|
|
|
|
|
|
|
def
|
2001-06-19 23:35:09 +00:00
|
|
|
: type
|
|
|
|
{
|
|
|
|
current_type = $1;
|
|
|
|
}
|
|
|
|
def_list
|
|
|
|
{
|
|
|
|
}
|
2001-06-13 07:16:39 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
type
|
|
|
|
: TYPE
|
2001-06-20 23:32:13 +00:00
|
|
|
{
|
|
|
|
current_type = $1;
|
|
|
|
}
|
|
|
|
maybe_func
|
|
|
|
{
|
|
|
|
$$ = $3 ? $3 : $1;
|
|
|
|
}
|
2001-06-13 07:16:39 +00:00
|
|
|
| '.' TYPE
|
2001-06-20 23:32:13 +00:00
|
|
|
{
|
|
|
|
current_type = $2;
|
|
|
|
}
|
|
|
|
maybe_func
|
2001-06-14 21:49:47 +00:00
|
|
|
{
|
|
|
|
type_t new;
|
|
|
|
memset (&new, 0, sizeof (new));
|
|
|
|
new.type = ev_field;
|
2001-06-20 23:32:13 +00:00
|
|
|
new.aux_type = $4 ? $4 : $2;
|
2001-06-14 21:49:47 +00:00
|
|
|
$$ = PR_FindType (&new);
|
|
|
|
}
|
2001-06-12 19:44:26 +00:00
|
|
|
;
|
|
|
|
|
2001-06-20 23:32:13 +00:00
|
|
|
maybe_func
|
|
|
|
: /* empty */
|
2001-06-20 07:02:36 +00:00
|
|
|
{
|
2001-06-20 23:32:13 +00:00
|
|
|
$$ = 0;
|
2001-06-20 07:02:36 +00:00
|
|
|
}
|
2001-06-15 20:38:57 +00:00
|
|
|
| '('
|
|
|
|
{
|
2001-06-19 07:28:50 +00:00
|
|
|
$<scope>$.scope = pr_scope;
|
|
|
|
$<scope>$.type = current_type;
|
|
|
|
$<scope>$.pscope = param_scope.scope_next;
|
|
|
|
param_scope.scope_next = 0;
|
2001-06-15 20:38:57 +00:00
|
|
|
pr_scope = ¶m_scope;
|
|
|
|
}
|
|
|
|
param_list
|
|
|
|
{
|
2001-06-20 23:32:13 +00:00
|
|
|
PR_FlushScope (¶m_scope);
|
2001-06-19 07:28:50 +00:00
|
|
|
current_type = $<scope>2.type;
|
|
|
|
param_scope.scope_next = $<scope>2.pscope;
|
|
|
|
pr_scope = $<scope>2.scope;
|
2001-06-15 20:38:57 +00:00
|
|
|
}
|
2001-06-19 23:35:09 +00:00
|
|
|
')'
|
|
|
|
{
|
2001-06-25 17:15:56 +00:00
|
|
|
$$ = parse_params ($3);
|
2001-06-15 20:38:57 +00:00
|
|
|
}
|
2001-06-19 23:35:09 +00:00
|
|
|
| '(' ')'
|
|
|
|
{
|
2001-06-20 23:32:13 +00:00
|
|
|
$$ = parse_params (0);
|
2001-06-19 23:35:09 +00:00
|
|
|
}
|
|
|
|
| '(' ELIPSIS ')'
|
|
|
|
{
|
2001-06-20 23:32:13 +00:00
|
|
|
$$ = parse_params ((def_t*)1);
|
2001-06-19 23:35:09 +00:00
|
|
|
}
|
2001-06-20 23:32:13 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
|
|
|
|
def_list
|
|
|
|
: def_list ',' def_item
|
|
|
|
| def_item
|
|
|
|
;
|
|
|
|
|
|
|
|
def_item
|
|
|
|
: def_name opt_initializer
|
2001-06-19 23:35:09 +00:00
|
|
|
{
|
2001-06-20 23:32:13 +00:00
|
|
|
$$ = $1;
|
2001-06-19 23:35:09 +00:00
|
|
|
}
|
2001-06-15 19:38:43 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
def_name
|
2001-06-15 07:16:18 +00:00
|
|
|
: NAME
|
|
|
|
{
|
|
|
|
$$ = PR_GetDef (current_type, $1, pr_scope, pr_scope ? &pr_scope->num_locals : &numpr_globals);
|
2001-06-15 19:38:43 +00:00
|
|
|
current_def = $$;
|
2001-06-15 07:16:18 +00:00
|
|
|
}
|
2001-06-12 19:44:26 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
param_list
|
2001-06-13 07:16:39 +00:00
|
|
|
: param
|
2001-06-12 19:44:26 +00:00
|
|
|
| param_list ',' param
|
2001-06-14 21:49:47 +00:00
|
|
|
{
|
2001-06-18 22:51:49 +00:00
|
|
|
if ($3->next) {
|
|
|
|
yyerror ("parameter redeclared");
|
|
|
|
yyerror ($3->name);
|
|
|
|
$$ = $1;
|
|
|
|
} else {
|
|
|
|
$3->next = $1;
|
|
|
|
$$ = $3;
|
|
|
|
}
|
2001-06-14 21:49:47 +00:00
|
|
|
}
|
2001-06-12 19:44:26 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
param
|
2001-06-18 22:51:49 +00:00
|
|
|
: type {current_type = $1;} def_item
|
2001-06-14 21:49:47 +00:00
|
|
|
{
|
2001-06-18 22:51:49 +00:00
|
|
|
$3->type = $1;
|
|
|
|
$$ = $3;
|
2001-06-14 21:49:47 +00:00
|
|
|
}
|
2001-06-12 19:44:26 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
opt_initializer
|
|
|
|
: /*empty*/
|
2001-06-13 07:16:39 +00:00
|
|
|
| '=' const
|
2001-06-20 07:02:36 +00:00
|
|
|
{
|
2001-06-26 22:43:28 +00:00
|
|
|
if (pr_scope) {
|
|
|
|
def_t *imm = PR_ReuseConstant ($2, 0);
|
|
|
|
opcode_t *op = PR_Opcode_Find ("=", 5, imm, imm, current_def);
|
|
|
|
emit_statement (op, imm, current_def, 0);
|
|
|
|
} else {
|
|
|
|
current_def = PR_ReuseConstant ($2, current_def);
|
|
|
|
}
|
2001-06-20 07:02:36 +00:00
|
|
|
}
|
2001-06-15 19:38:43 +00:00
|
|
|
| '=' '#' const
|
|
|
|
{
|
2001-06-21 07:08:34 +00:00
|
|
|
if (current_type->type != ev_func) {
|
|
|
|
yyerror ("note a function");
|
2001-06-20 07:02:36 +00:00
|
|
|
} else {
|
2001-06-21 07:08:34 +00:00
|
|
|
if ($3->type != ex_int && $3->type != ex_float) {
|
|
|
|
yyerror ("invalid constant for = #");
|
|
|
|
} else {
|
|
|
|
function_t *f;
|
|
|
|
|
|
|
|
f = new_function ();
|
|
|
|
f->builtin = $3->type == ex_int
|
|
|
|
? $3->e.int_val : (int)$3->e.float_val;
|
|
|
|
f->def = current_def;
|
2001-06-25 18:23:29 +00:00
|
|
|
build_function (f);
|
2001-06-21 07:08:34 +00:00
|
|
|
}
|
2001-06-15 19:38:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
| '=' begin_function statement_block end_function
|
2001-06-20 07:02:36 +00:00
|
|
|
{
|
2001-06-25 18:23:29 +00:00
|
|
|
build_function ($2);
|
2001-06-25 20:52:04 +00:00
|
|
|
emit_function ($2, $3);
|
2001-06-20 07:02:36 +00:00
|
|
|
}
|
2001-06-25 20:52:04 +00:00
|
|
|
| '=' '[' const ','
|
2001-06-20 07:02:36 +00:00
|
|
|
{
|
2001-06-25 20:52:04 +00:00
|
|
|
$<def>$ = current_def;
|
|
|
|
}
|
|
|
|
def_name
|
|
|
|
{
|
|
|
|
current_def = $<def>5;
|
|
|
|
}
|
|
|
|
']' begin_function statement_block end_function
|
|
|
|
{
|
|
|
|
expr_t *e = new_expr ();
|
|
|
|
build_function ($9);
|
|
|
|
e->type = ex_expr;
|
|
|
|
e->e.expr.op = 's';
|
|
|
|
e->e.expr.e1 = $3;
|
|
|
|
e->e.expr.e2 = new_expr ();
|
|
|
|
e->e.expr.e2->type = ex_def;
|
|
|
|
e->e.expr.e2->e.def = $6;
|
|
|
|
e->next = $10;
|
|
|
|
|
|
|
|
emit_function ($9, e);
|
2001-06-20 07:02:36 +00:00
|
|
|
}
|
2001-06-15 19:38:43 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
begin_function
|
|
|
|
: /*empty*/
|
|
|
|
{
|
2001-06-25 22:11:20 +00:00
|
|
|
$$ = current_func = new_function ();
|
2001-06-25 18:23:29 +00:00
|
|
|
$$->def = current_def;
|
|
|
|
$$->code = numstatements;
|
2001-06-15 19:38:43 +00:00
|
|
|
pr_scope = current_def;
|
2001-06-25 18:23:29 +00:00
|
|
|
build_scope ($$, current_def);
|
2001-06-15 19:38:43 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
end_function
|
|
|
|
: /*empty*/
|
|
|
|
{
|
|
|
|
pr_scope = 0;
|
|
|
|
}
|
2001-06-12 19:44:26 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
statement_block
|
|
|
|
: '{' statements '}'
|
2001-06-20 07:02:36 +00:00
|
|
|
{
|
|
|
|
$$ = $2;
|
|
|
|
}
|
2001-06-12 19:44:26 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
statements
|
|
|
|
: /*empty*/
|
2001-06-20 07:02:36 +00:00
|
|
|
{
|
2001-06-26 03:33:01 +00:00
|
|
|
//printf("statements: /* empty */\n");
|
|
|
|
$$ = new_block_expr ();
|
2001-06-20 07:02:36 +00:00
|
|
|
}
|
2001-06-13 07:16:39 +00:00
|
|
|
| statements statement
|
2001-06-20 07:02:36 +00:00
|
|
|
{
|
2001-06-26 03:33:01 +00:00
|
|
|
//printf("statements: statements statement\n");
|
|
|
|
$$ = append_expr ($1, $2);
|
2001-06-20 07:02:36 +00:00
|
|
|
}
|
2001-06-12 19:44:26 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
statement
|
2001-06-25 20:52:04 +00:00
|
|
|
: ';' { $$ = 0; }
|
2001-06-20 07:02:36 +00:00
|
|
|
| statement_block { $$ = $1; }
|
2001-06-25 20:52:04 +00:00
|
|
|
| RETURN expr ';'
|
|
|
|
{
|
2001-06-26 02:46:02 +00:00
|
|
|
$$ = new_unary_expr ('r', $2);
|
2001-06-25 20:52:04 +00:00
|
|
|
}
|
|
|
|
| RETURN ';'
|
|
|
|
{
|
2001-06-26 02:46:02 +00:00
|
|
|
$$ = new_unary_expr ('r', 0);
|
2001-06-25 20:52:04 +00:00
|
|
|
}
|
|
|
|
| WHILE '(' expr ')' statement
|
|
|
|
{
|
2001-06-26 02:46:02 +00:00
|
|
|
expr_t *l1 = new_label_expr ();
|
|
|
|
expr_t *l2 = new_label_expr ();
|
2001-06-25 20:52:04 +00:00
|
|
|
|
2001-06-26 03:33:01 +00:00
|
|
|
$$ = new_block_expr ();
|
2001-06-25 20:52:04 +00:00
|
|
|
|
2001-06-26 03:33:01 +00:00
|
|
|
append_expr ($$, new_binary_expr ('n', $3, l2));
|
|
|
|
append_expr ($$, l1);
|
|
|
|
append_expr ($$, $5);
|
|
|
|
append_expr ($$, new_binary_expr ('i', $3, l1));
|
|
|
|
append_expr ($$, l2);
|
2001-06-25 20:52:04 +00:00
|
|
|
}
|
|
|
|
| DO statement WHILE '(' expr ')' ';'
|
|
|
|
{
|
2001-06-26 02:46:02 +00:00
|
|
|
expr_t *l1 = new_label_expr ();
|
2001-06-25 20:52:04 +00:00
|
|
|
|
2001-06-26 03:33:01 +00:00
|
|
|
$$ = new_block_expr ();
|
2001-06-25 20:52:04 +00:00
|
|
|
|
2001-06-26 03:33:01 +00:00
|
|
|
append_expr ($$, l1);
|
|
|
|
append_expr ($$, $2);
|
|
|
|
append_expr ($$, new_binary_expr ('i', $5, l1));
|
2001-06-25 20:52:04 +00:00
|
|
|
}
|
2001-06-20 21:18:04 +00:00
|
|
|
| LOCAL type
|
|
|
|
{
|
|
|
|
current_type = $2;
|
|
|
|
}
|
2001-06-25 20:52:04 +00:00
|
|
|
def_list ';' { $$ = 0; }
|
|
|
|
| IF '(' expr ')' statement
|
|
|
|
{
|
2001-06-26 02:46:02 +00:00
|
|
|
expr_t *l1 = new_label_expr ();
|
2001-06-25 20:52:04 +00:00
|
|
|
|
2001-06-26 03:33:01 +00:00
|
|
|
$$ = new_block_expr ();
|
2001-06-25 20:52:04 +00:00
|
|
|
|
2001-06-26 03:33:01 +00:00
|
|
|
append_expr ($$, new_binary_expr ('n', $3, l1));
|
|
|
|
append_expr ($$, $5);
|
|
|
|
append_expr ($$, l1);
|
2001-06-25 20:52:04 +00:00
|
|
|
}
|
|
|
|
| IF '(' expr ')' statement ELSE statement
|
|
|
|
{
|
2001-06-26 02:46:02 +00:00
|
|
|
expr_t *l1 = new_label_expr ();
|
|
|
|
expr_t *l2 = new_label_expr ();
|
2001-06-25 20:52:04 +00:00
|
|
|
|
2001-06-26 03:33:01 +00:00
|
|
|
$$ = new_block_expr ();
|
2001-06-25 20:52:04 +00:00
|
|
|
|
2001-06-26 03:33:01 +00:00
|
|
|
append_expr ($$, new_binary_expr ('n', $3, l1));
|
|
|
|
append_expr ($$, $5);
|
|
|
|
append_expr ($$, new_unary_expr ('g', l2));
|
|
|
|
append_expr ($$, l1);
|
|
|
|
append_expr ($$, $7);
|
|
|
|
append_expr ($$, l2);
|
2001-06-25 20:52:04 +00:00
|
|
|
}
|
|
|
|
| FOR '(' expr ';' expr ';' expr ')' statement
|
|
|
|
{
|
2001-06-26 02:46:02 +00:00
|
|
|
expr_t *l1 = new_label_expr ();
|
|
|
|
expr_t *l2 = new_label_expr ();
|
2001-06-25 20:52:04 +00:00
|
|
|
|
2001-06-26 03:33:01 +00:00
|
|
|
$$ = new_block_expr ();
|
2001-06-25 20:52:04 +00:00
|
|
|
|
2001-06-26 03:33:01 +00:00
|
|
|
append_expr ($$, $3);
|
|
|
|
append_expr ($$, new_binary_expr ('n', $5, l2));
|
|
|
|
append_expr ($$, l1);
|
|
|
|
append_expr ($$, $9);
|
|
|
|
append_expr ($$, $7);
|
|
|
|
append_expr ($$, new_binary_expr ('i', $5, l1));
|
|
|
|
append_expr ($$, l2);
|
2001-06-25 20:52:04 +00:00
|
|
|
}
|
|
|
|
| expr ';'
|
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
}
|
2001-06-12 19:44:26 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
expr
|
2001-06-20 07:02:36 +00:00
|
|
|
: expr AND expr { $$ = binary_expr (AND, $1, $3); }
|
|
|
|
| expr OR expr { $$ = binary_expr (OR, $1, $3); }
|
2001-06-20 21:18:04 +00:00
|
|
|
| expr '=' expr { $$ = binary_expr ('=', $1, $3); }
|
2001-06-20 07:02:36 +00:00
|
|
|
| expr EQ expr { $$ = binary_expr (EQ, $1, $3); }
|
|
|
|
| expr NE expr { $$ = binary_expr (NE, $1, $3); }
|
|
|
|
| expr LE expr { $$ = binary_expr (LE, $1, $3); }
|
|
|
|
| expr GE expr { $$ = binary_expr (GE, $1, $3); }
|
|
|
|
| expr LT expr { $$ = binary_expr (LT, $1, $3); }
|
|
|
|
| expr GT expr { $$ = binary_expr (GT, $1, $3); }
|
|
|
|
| expr '+' expr { $$ = binary_expr ('+', $1, $3); }
|
|
|
|
| expr '-' expr { $$ = binary_expr ('-', $1, $3); }
|
|
|
|
| expr '*' expr { $$ = binary_expr ('*', $1, $3); }
|
|
|
|
| expr '/' expr { $$ = binary_expr ('/', $1, $3); }
|
|
|
|
| expr '&' expr { $$ = binary_expr ('&', $1, $3); }
|
2001-06-20 21:18:04 +00:00
|
|
|
| expr '|' expr { $$ = binary_expr ('|', $1, $3); }
|
|
|
|
| expr '(' arg_list ')' { $$ = function_expr ($1, $3); }
|
|
|
|
| expr '(' ')' { $$ = function_expr ($1, 0); }
|
2001-06-25 17:15:56 +00:00
|
|
|
| expr '.' expr { $$ = binary_expr ('.', $1, $3); }
|
2001-06-20 07:02:36 +00:00
|
|
|
| '-' expr { $$ = unary_expr ('-', $2); }
|
|
|
|
| '!' expr { $$ = unary_expr ('!', $2); }
|
2001-06-12 19:44:26 +00:00
|
|
|
| NAME
|
2001-06-15 07:16:18 +00:00
|
|
|
{
|
2001-06-15 19:38:43 +00:00
|
|
|
$$ = new_expr ();
|
|
|
|
$$->type = ex_def;
|
|
|
|
$$->e.def = PR_GetDef (NULL, $1, pr_scope, false);
|
2001-06-15 07:16:18 +00:00
|
|
|
}
|
2001-06-20 07:02:36 +00:00
|
|
|
| const { $$ = $1; }
|
|
|
|
| '(' expr ')' { $$ = $2; }
|
2001-06-12 19:44:26 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
arg_list
|
2001-06-13 07:16:39 +00:00
|
|
|
: expr
|
2001-06-12 19:44:26 +00:00
|
|
|
| arg_list ',' expr
|
2001-06-20 21:18:04 +00:00
|
|
|
{
|
|
|
|
$3->next = $1;
|
|
|
|
$$ = $3;
|
|
|
|
}
|
2001-06-12 19:44:26 +00:00
|
|
|
;
|
|
|
|
|
2001-06-13 07:16:39 +00:00
|
|
|
const
|
2001-06-15 19:38:43 +00:00
|
|
|
: FLOAT_VAL
|
|
|
|
{
|
|
|
|
$$ = new_expr ();
|
|
|
|
$$->type = ex_float;
|
|
|
|
$$->e.float_val = $1;
|
|
|
|
}
|
2001-06-15 07:16:18 +00:00
|
|
|
| STRING_VAL {}
|
2001-06-15 19:38:43 +00:00
|
|
|
{
|
|
|
|
$$ = new_expr ();
|
|
|
|
$$->type = ex_string;
|
2001-06-25 22:53:15 +00:00
|
|
|
$$->e.string_val = $1;
|
2001-06-15 19:38:43 +00:00
|
|
|
}
|
2001-06-15 07:16:18 +00:00
|
|
|
| VECTOR_VAL {}
|
2001-06-15 19:38:43 +00:00
|
|
|
{
|
|
|
|
$$ = new_expr ();
|
|
|
|
$$->type = ex_vector;
|
|
|
|
memcpy ($$->e.vector_val, $1, sizeof ($$->e.vector_val));
|
|
|
|
}
|
2001-06-15 07:16:18 +00:00
|
|
|
| QUATERNION_VAL {}
|
2001-06-15 19:38:43 +00:00
|
|
|
{
|
|
|
|
$$ = new_expr ();
|
|
|
|
$$->type = ex_quaternion;
|
|
|
|
memcpy ($$->e.quaternion_val, $1, sizeof ($$->e.quaternion_val));
|
|
|
|
}
|
2001-06-15 07:16:18 +00:00
|
|
|
| INT_VAL {}
|
2001-06-15 19:38:43 +00:00
|
|
|
{
|
|
|
|
$$ = new_expr ();
|
|
|
|
$$->type = ex_int;
|
|
|
|
$$->e.int_val = $1;
|
|
|
|
}
|
2001-06-13 07:16:39 +00:00
|
|
|
;
|
|
|
|
|
2001-06-12 19:44:26 +00:00
|
|
|
%%
|
2001-06-18 22:51:49 +00:00
|
|
|
|
|
|
|
type_t *
|
|
|
|
parse_params (def_t *parms)
|
|
|
|
{
|
|
|
|
type_t new;
|
|
|
|
def_t *p;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
memset (&new, 0, sizeof (new));
|
|
|
|
new.type = ev_func;
|
|
|
|
new.aux_type = current_type;
|
|
|
|
new.num_parms = 0;
|
|
|
|
|
|
|
|
if (!parms) {
|
|
|
|
} else if (parms == (def_t*)1) {
|
|
|
|
new.num_parms = -1; // variable args
|
|
|
|
} else {
|
|
|
|
for (p = parms; p; p = p->next, new.num_parms++)
|
|
|
|
;
|
|
|
|
if (new.num_parms > MAX_PARMS) {
|
|
|
|
yyerror ("too many params");
|
|
|
|
return current_type;
|
|
|
|
}
|
|
|
|
i = 1;
|
|
|
|
do {
|
|
|
|
//puts (parms->name);
|
2001-06-19 07:28:50 +00:00
|
|
|
strcpy (pr_parm_names[new.num_parms - i], parms->name);
|
|
|
|
new.parm_types[new.num_parms - i] = parms->type;
|
2001-06-18 22:51:49 +00:00
|
|
|
i++;
|
|
|
|
parms = parms->next;
|
|
|
|
} while (parms);
|
|
|
|
}
|
|
|
|
return PR_FindType (&new);
|
|
|
|
}
|
2001-06-21 07:08:34 +00:00
|
|
|
|
|
|
|
void
|
2001-06-25 18:23:29 +00:00
|
|
|
build_scope (function_t *f, def_t *func)
|
2001-06-21 07:08:34 +00:00
|
|
|
{
|
2001-06-25 17:15:56 +00:00
|
|
|
int i;
|
|
|
|
def_t *def;
|
|
|
|
type_t *ftype = func->type;
|
|
|
|
|
|
|
|
for (i = 0; i < ftype->num_parms; i++) {
|
|
|
|
def = PR_GetDef (ftype->parm_types[i], pr_parm_names[i], func, &func->num_locals);
|
2001-06-25 18:23:29 +00:00
|
|
|
f->parm_ofs[i] = def->ofs;
|
|
|
|
if (i > 0 && f->parm_ofs[i] < f->parm_ofs[i - 1])
|
|
|
|
Error ("bad parm order");
|
2001-06-25 17:15:56 +00:00
|
|
|
}
|
2001-06-21 07:08:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function_t *
|
|
|
|
new_function (void)
|
|
|
|
{
|
|
|
|
function_t *f;
|
|
|
|
|
|
|
|
f = calloc (1, sizeof (function_t));
|
|
|
|
f->next = pr_functions;
|
|
|
|
pr_functions = f;
|
|
|
|
|
|
|
|
return f;
|
|
|
|
}
|
2001-06-25 18:23:29 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
build_function (function_t *f)
|
|
|
|
{
|
|
|
|
dfunction_t *df;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
f->def->initialized = 1;
|
|
|
|
G_FUNCTION (f->def->ofs) = numfunctions;
|
|
|
|
// fill in the dfunction
|
|
|
|
df = &functions[numfunctions];
|
|
|
|
numfunctions++;
|
|
|
|
f->dfunc = df;
|
|
|
|
|
|
|
|
if (f->builtin)
|
|
|
|
df->first_statement = -f->builtin;
|
|
|
|
else
|
|
|
|
df->first_statement = f->code;
|
|
|
|
|
|
|
|
df->s_name = ReuseString (f->def->name);
|
|
|
|
df->s_file = s_file;
|
|
|
|
df->numparms = f->def->type->num_parms;
|
|
|
|
df->locals = f->def->num_locals;
|
|
|
|
df->parm_start = 0;
|
|
|
|
for (i = 0; i < df->numparms; i++)
|
|
|
|
df->parm_size[i] = type_size[f->def->type->parm_types[i]->type];
|
|
|
|
}
|
2001-06-25 20:52:04 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
emit_function (function_t *f, expr_t *e)
|
|
|
|
{
|
2001-06-26 07:21:20 +00:00
|
|
|
pr_scope = f->def;
|
|
|
|
while (e) {
|
|
|
|
emit_expr (e);
|
|
|
|
e = e->next;
|
|
|
|
}
|
2001-06-26 16:12:01 +00:00
|
|
|
PR_FlushScope (pr_scope);
|
|
|
|
pr_scope = 0;
|
2001-06-26 03:33:01 +00:00
|
|
|
/*PR_PrintType (f->def->type);
|
|
|
|
printf (" %s =\n", f->def->name);
|
2001-06-25 20:52:04 +00:00
|
|
|
while (e) {
|
|
|
|
print_expr (e);
|
|
|
|
puts("");
|
|
|
|
e = e->next;
|
|
|
|
}
|
2001-06-26 03:33:01 +00:00
|
|
|
puts ("");*/
|
2001-06-25 20:52:04 +00:00
|
|
|
}
|