diff --git a/HISTORY b/HISTORY index 0618bc5..dd87b4f 100755 --- a/HISTORY +++ b/HISTORY @@ -1,3 +1,7 @@ +Dec. 7 2015 +Improved TICKS function +Initialized random number seed on start up + Dec. 4 2015 Updated icon Added structures for class development diff --git a/core/my_basic.c b/core/my_basic.c index e71ed84..c8c36cc 100755 --- a/core/my_basic.c +++ b/core/my_basic.c @@ -3612,7 +3612,7 @@ _end_import: goto _exit; } - if(_IS_FUNC(context->last_symbol, _core_def)) { + if(_IS_FUNC(context->last_symbol, _core_class)) { if(context->routine_state > 1) { _handle_error_now(s, SE_RN_INVALID_CLASS, 0, MB_FUNC_ERR); diff --git a/output/my_basic.exe b/output/my_basic.exe index 2099e22..ff7412b 100755 Binary files a/output/my_basic.exe and b/output/my_basic.exe differ diff --git a/shell/main.c b/shell/main.c index b04de1d..ca2fb0b 100755 --- a/shell/main.c +++ b/shell/main.c @@ -852,6 +852,49 @@ static void _process_parameters(int argc, char* argv[]) { ** Scripting interfaces */ +#define _HAS_TICKS +#if defined _MSC_VER +static int_t _ticks(void) { + LARGE_INTEGER li; + double freq = 0.0; + int_t ret = 0; + + QueryPerformanceFrequency(&li); + freq = (double)li.QuadPart / 1000.0; + QueryPerformanceCounter(&li); + ret = (int_t)((double)li.QuadPart / freq); + + return ret; +} +#elif defined __GNUC__ || defined __clang__ /* _MSC_VER */ +static int_t _ticks(void) { + struct timespec ts; + int_t ret = 0; + + clock_gettime(CLOCK_MONOTONIC, &ts); + ret = (ts.tv_sec * 1000 + ts.tv_nsec / 1000000); + + return ret; +} +#else /* _MSC_VER */ +# undef _HAS_TICKS +#endif /* _MSC_VER */ + +#ifdef _HAS_TICKS +static int ticks(struct mb_interpreter_t* s, void** l) { + int result = MB_FUNC_OK; + + mb_assert(s && l); + + mb_check(mb_attempt_open_bracket(s, l)); + mb_check(mb_attempt_close_bracket(s, l)); + + mb_check(mb_push_int(s, l, _ticks())); + + return result; +} +#endif /* _HAS_TICKS */ + static int beep(struct mb_interpreter_t* s, void** l) { int result = MB_FUNC_OK; @@ -865,21 +908,6 @@ static int beep(struct mb_interpreter_t* s, void** l) { return result; } -#ifdef _MSC_VER -static int ticks(struct mb_interpreter_t* s, void** l) { - int result = MB_FUNC_OK; - - mb_assert(s && l); - - mb_check(mb_attempt_open_bracket(s, l)); - mb_check(mb_attempt_close_bracket(s, l)); - - mb_check(mb_push_int(s, l, (int_t)GetTickCount())); - - return result; -} -#endif /* _MSC_VER */ - /* ========================================================} */ /* @@ -919,6 +947,10 @@ static void _on_startup(void) { c = _create_code(); +#ifdef _HAS_TICKS + srand((unsigned)_ticks()); +#endif /* _HAS_TICKS */ + mb_init(); mb_open(&bas); @@ -926,10 +958,10 @@ static void _on_startup(void) { mb_debug_set_stepped_handler(bas, _on_stepped); mb_set_error_handler(bas, _on_error); - mb_reg_fun(bas, beep); -#ifdef _MSC_VER +#ifdef _HAS_TICKS mb_reg_fun(bas, ticks); -#endif /* _MSC_VER */ +#endif /* _HAS_TICKS */ + mb_reg_fun(bas, beep); } static void _on_exit(void) {