static bool parser_variable(parser_t *parser, ast_block *localblock)
{
bool isfunc = false;
- ast_function *func = NULL;
lex_ctx ctx;
ast_value *var;
varentry_t varent;
{
hadproto = false;
olddecl = NULL;
- func = NULL;
isparam = false;
ctx = parser_ctx(parser);
* as return type
*/
fval = ast_value_new(ctx, var->name, TYPE_FUNCTION);
- func = ast_function_new(ctx, var->name, fval);
- if (!fval || !func) {
+ if (!fval) {
ast_value_delete(var);
if (fval) ast_value_delete(fval);
- if (func) ast_function_delete(func);
return false;
}
parseerror(parser, "conflicting types for `%s`, previous declaration was here: %s:%i",
proto->name,
ast_ctx(proto).file, ast_ctx(proto).line);
- ast_function_delete(func);
ast_value_delete(fval);
return false;
}
ast_ctx(proto) = ast_ctx(fval);
/* now ditch the rest of the new data */
- ast_function_delete(func);
ast_value_delete(fval);
fval = proto;
- func = proto->constval.vfunc;
hadproto = true;
}
- else
- {
- if (!parser_t_functions_add(parser, func)) {
- ast_function_delete(func);
- ast_value_delete(fval);
- return false;
- }
- }
var = fval;
}
}
if (parser->tok == '#') {
+ ast_function *func;
+
if (localblock) {
parseerror(parser, "cannot declare builtins within functions");
ast_value_delete(typevar);
return false;
}
- if (!isfunc || !func) {
+ if (!isfunc) {
parseerror(parser, "unexpected builtin number, '%s' is not a function", var->name);
ast_value_delete(typevar);
return false;
return false;
}
+ func = ast_function_new(ast_ctx(var), var->name, var);
+ if (!func) {
+ parseerror(parser, "failed to allocate function for `%s`", var->name);
+ ast_value_delete(typevar);
+ return false;
+ }
+ if (!parser_t_functions_add(parser, func)) {
+ parseerror(parser, "failed to allocate slot for function `%s`", var->name);
+ ast_function_delete(func);
+ var->constval.vfunc = NULL;
+ ast_value_delete(typevar);
+ return false;
+ }
+
func->builtin = -parser_token(parser)->constval.i;
if (!parser_next(parser)) {
}
} else if (parser->tok == '{' || parser->tok == '[') {
/* function body */
+ ast_function *func;
ast_function *old;
ast_block *block;
size_t parami;
}
}
+ func = ast_function_new(ast_ctx(var), var->name, var);
+ if (!func) {
+ parseerror(parser, "failed to allocate function for `%s`", var->name);
+ ast_block_delete(block);
+ parser->function = old;
+ ast_value_delete(typevar);
+ return false;
+ }
+ if (!parser_t_functions_add(parser, func)) {
+ parseerror(parser, "failed to allocate slot for function `%s`", var->name);
+ ast_function_delete(func);
+ var->constval.vfunc = NULL;
+ ast_value_delete(typevar);
+ ast_block_delete(block);
+ parser->function = old;
+ return false;
+ }
+
parser->function = func;
if (!parser_parse_block_into(parser, block, true)) {
ast_block_delete(block);