static inline void *psi_do_let(let_stmt *let)
{
decl_arg *darg = let->var->arg;
- impl_arg *iarg = darg->let->arg;
impl_val *arg_val = darg->ptr;
- if (!iarg) {
- /* let foo = calloc(1, long);
- * let foo = NULL;
- * let foo;
- */
- if (darg->let->val->func && darg->let->val->func->type == PSI_T_CALLOC) {
- arg_val->ptr = psi_do_calloc(darg->let->val->func->alloc);
- darg->mem = arg_val->ptr;
- } else if (darg->var->array_size) {
+ if (!let->val) {
+ if (darg->var->array_size) {
arg_val->ptr = ecalloc(darg->var->array_size, sizeof(*arg_val));
darg->mem = arg_val->ptr;
} else {
memset(arg_val, 0, sizeof(*arg_val));
}
+ } else if (let->val->num) {
+ arg_val->zend.lval = psi_long_num_exp(darg->let->val->num, NULL);
} else {
+ impl_arg *iarg = darg->let->arg;
- switch (darg->let->val->func->type) {
+ switch (let->val->func->type) {
+ case PSI_T_CALLOC:
+ arg_val->ptr = psi_do_calloc(let->val->func->alloc);
+ darg->mem = arg_val->ptr;
+ break;
case PSI_T_BOOLVAL:
if (iarg->type->type == PSI_T_BOOL) {
arg_val->cval = iarg->val.zend.bval;
ret->set->func->handler(return_value, ret->set, ret->set->vars->vars[0]->arg->ptr);
}
-static inline void psi_do_return2(zval *return_value, return_stmt *ret, impl_val *ret_val)
-{
- ret->set->func->handler(return_value, ret->set, ret_val);
-}
-
static inline void psi_do_free(free_stmt *fre)
{
size_t i, j;
stmt = init_impl_stmt(PSI_T_FREE, free);
}
+%token_class num_exp_token NUMBER NSNAME.
+%token_class num_exp_op_token PLUS MINUS ASTERISK SLASH.
+%type num_exp {num_exp*}
+%destructor num_exp {free_num_exp($$);}
+num_exp(exp) ::= num_exp_token(tok). {
+ exp = init_num_exp(tok->type, tok->text);
+ free(tok);
+}
+num_exp(exp) ::= decl_var(var). {
+ exp = init_num_exp(PSI_T_NAME, var);
+}
+num_exp(exp) ::= num_exp(exp_) num_exp_op_token(operator_) num_exp(operand_). {
+ exp_->operator = operator_->type;
+ exp_->operand = operand_;
+ exp = exp_;
+ free(operator_);
+}
+
%type let_stmt {let_stmt*}
%destructor let_stmt {free_let_stmt($$);}
let_stmt(let) ::= LET decl_var(var) EOS. {
let_stmt(let) ::= LET decl_var(var) EQUALS let_value(val) EOS. {
let = init_let_stmt(var, val);
}
+let_stmt(let) ::= decl_arg(arg) EQUALS decl_var(var_) EOS. {
+ let = init_let_stmt(arg->var, NULL);
+}
%type let_value {let_value*}
%destructor let_value {free_let_value($$);}
-let_value(val) ::= CALLOC(F) LPAREN let_calloc(alloc) RPAREN. {
- val = init_let_value(init_let_func(F->type, F->text, alloc), NULL, 0);
+let_value(val) ::= reference(r) CALLOC(F) LPAREN let_calloc(alloc) RPAREN. {
+ val = init_let_value(init_let_func(F->type, F->text, alloc), NULL, r);
free(F);
}
-
%type let_calloc {let_calloc*}
%destructor let_calloc {free_let_calloc($$);}
let_calloc(alloc) ::= num_exp(nmemb) COMMA num_exp(size). {
alloc = init_let_calloc(nmemb, size);
}
-%token_class num_exp_token NUMBER NSNAME.
-%token_class num_exp_op_token PLUS MINUS ASTERISK SLASH.
-%type num_exp {num_exp*}
-%destructor num_exp {free_num_exp($$);}
-num_exp(exp) ::= num_exp_token(tok). {
- exp = init_num_exp(tok->type, tok->text);
- free(tok);
-}
-num_exp(exp) ::= decl_var(var). {
- exp = init_num_exp(PSI_T_NAME, var);
-}
-num_exp(exp) ::= num_exp(exp_) num_exp_op_token(operator_) num_exp(operand_). {
- exp_->operator = operator_->type;
- exp_->operand = operand_;
- exp = exp_;
- free(operator_);
+let_value(val) ::= reference(r) num_exp(exp). {
+ val = init_let_value(NULL, NULL, r);
+ val->num = exp;
}
-
let_value(val) ::= reference(r) let_func(func) LPAREN impl_var(var) RPAREN. {
val = init_let_value(func, var, r);
}