From 74f6f054b44a4565a20e8e63e84d15f21af3386c Mon Sep 17 00:00:00 2001 From: Wang Renxin Date: Sat, 16 Jan 2016 14:01:02 +0800 Subject: [PATCH] +added a range of integer syntax. +Added a range of integer syntax for the LIST statement, eg. LIST(m TO n). --- HISTORY | 3 +++ README.md | 2 +- core/my_basic.c | 31 +++++++++++++++++++++++++++++-- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/HISTORY b/HISTORY index f58f86f..cb4cb5b 100755 --- a/HISTORY +++ b/HISTORY @@ -1,3 +1,6 @@ +Jan. 16 2016 +Added a range of integer syntax for the LIST statement, eg. LIST(m TO n) + Jan. 15 2016 Added a REFLECT statement Added an MB_ENABLE_USERTYPE_REF macro diff --git a/README.md b/README.md index 659f597..51c95b9 100755 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ MY-BASIC is a dynamic typed programming language with BASIC syntax and has a ver * Collection implementation and manipulation functions for **`LIST`** and **`DICT`** * Automatic releasing of referenced objects (list, dictionary, referenced usertype, prototype, lambda, etc.) benefited from **Reference Counting** and **Garbage Collection** * Multiple file support by `IMPORT` statement -* Structured user customizable **sub routine** definition by **`DEF/ENDDEF`** support, including tail recursion optimization +* Structured user customizable **sub routine** definition by **`DEF-ENDDEF`** support, including tail recursion optimization * Structured `IF-THEN-ELSEIF-ELSE-ENDIF` support * Structured `FOR-TO-STEP-NEXT/WHILE-WEND/DO-UNTIL` support * Reserved retro `GOTO/GOSUB-RETURN` support diff --git a/core/my_basic.c b/core/my_basic.c index 9e917e0..1a88efc 100755 --- a/core/my_basic.c +++ b/core/my_basic.c @@ -13511,10 +13511,37 @@ int _coll_list(mb_interpreter_t* s, void** l) { coll = _create_list(s); - while(mb_has_arg(s, l)) { + if(mb_has_arg(s, l)) { + _ls_node_t* ast = 0; + _object_t* obj = 0; mb_make_nil(arg); _mb_check_mark(mb_pop_value(s, l, &arg), result, _error); - _push_list(coll, &arg, 0); + ast = (_ls_node_t*)*l; + if(ast) obj = (_object_t*)ast->data; + if(arg.type == MB_DT_INT && obj && _IS_FUNC(obj, _core_to)) { + /* Push a range of integer */ + int_t begin = arg.value.integer; + int_t end = 0; + int_t step = 0; + ast = ast->next; + _mb_check_mark(mb_pop_int(s, (void**)&ast, &end), result, _error); + step = sgn(end - begin); + end += step; + do { + mb_make_int(arg, begin); + _push_list(coll, &arg, 0); + begin += step; + } while(begin != end); + *l = ast; + } else { + /* Push arguments */ + _push_list(coll, &arg, 0); + while(mb_has_arg(s, l)) { + mb_make_nil(arg); + _mb_check_mark(mb_pop_value(s, l, &arg), result, _error); + _push_list(coll, &arg, 0); + } + } } _mb_check_mark(mb_attempt_close_bracket(s, l), result, _error);