*developing lambda, improved error handling.

This commit is contained in:
Wang Renxin 2016-01-09 14:29:51 +08:00
parent 71ab22d995
commit 5338eb47f3
4 changed files with 20 additions and 0 deletions

View File

@ -1,4 +1,5 @@
Jan. 9 2016
Developing lambda, improved error handling
Developing lambda, fixed an issue with only a PRINT statement
Jan. 8 2016

View File

@ -259,6 +259,7 @@ static const char* _ERR_DESC[] = {
"Class expected",
"Duplicate class",
"Wrong meta class",
"Invalid lambda",
"Collection expected",
"Iterator expected",
"Collection or iterator expected",
@ -1410,6 +1411,7 @@ static int _remove_filled_upvalue(void* data, void* extra, void* u);
static int _fill_outer_scope(void* data, void* extra, void* t);
static _running_context_t* _link_lambda_scope_chain(mb_interpreter_t* s, _lambda_t* lambda, bool_t weak);
static _running_context_t* _unlink_lambda_scope_chain(mb_interpreter_t* s, _lambda_t* lambda, bool_t weak);
static bool_t _is_valid_lambda_body_node(mb_interpreter_t* s, _lambda_t* lambda, _object_t* obj);
#endif /* MB_ENABLE_LAMBDA */
#ifdef MB_ENABLE_CLASS
static _running_context_t* _reference_scope_by_class(mb_interpreter_t* s, _running_context_t* p, _class_t* c);
@ -6407,6 +6409,15 @@ _running_context_t* _unlink_lambda_scope_chain(mb_interpreter_t* s, _lambda_t* l
return lambda->scope;
}
bool_t _is_valid_lambda_body_node(mb_interpreter_t* s, _lambda_t* lambda, _object_t* obj) {
/* Check whether an object is a valid lambda body node */
return
!_IS_FUNC(obj, _core_def) &&
!_IS_FUNC(obj, _core_enddef) &&
!_IS_FUNC(obj, _core_class) &&
!_IS_FUNC(obj, _core_endclass);
}
#endif /* MB_ENABLE_LAMBDA */
#ifdef MB_ENABLE_CLASS
@ -11936,6 +11947,9 @@ int _core_lambda(mb_interpreter_t* s, void** l) {
if(!routine->func.lambda.parameters)
routine->func.lambda.parameters = _ls_create();
if(!v || ((_object_t*)v)->type != _DT_VAR) {
_handle_error_on_obj(s, SE_RN_INVALID_LAMBDA, 0, TON(l), MB_FUNC_ERR, _error, result);
}
var = ((_object_t*)v)->data.variable;
/* Add lambda parameters */
@ -11979,6 +11993,10 @@ int _core_lambda(mb_interpreter_t* s, void** l) {
else if(_IS_FUNC(ast->data, _core_close_bracket))
brackets--;
if(ast && !_is_valid_lambda_body_node(s, &routine->func.lambda, (_object_t*)ast->data)) {
_handle_error_on_obj(s, SE_RN_INVALID_LAMBDA, 0, TON(l), MB_FUNC_ERR, _error, result);
}
/* Mark upvalues */
if(ast)
_try_mark_upvalue(s, routine, (_object_t*)ast->data);

View File

@ -329,6 +329,7 @@ typedef enum mb_error_e {
SE_RN_CLASS_EXPECTED,
SE_RN_DUPLICATE_CLASS,
SE_RN_WRONG_META_CLASS,
SE_RN_INVALID_LAMBDA,
SE_RN_COLLECTION_EXPECTED,
SE_RN_ITERATOR_EXPECTED,
SE_RN_COLLECTION_OR_ITERATOR_EXPECTED,

Binary file not shown.