diff --git a/HISTORY b/HISTORY index 55f0a9d..e7af3c9 100755 --- a/HISTORY +++ b/HISTORY @@ -1,3 +1,7 @@ +Mar. 1 2016 +Added an OS statement +Refactored platform dependent macros + Feb. 29 2016 Added multi-line comment support Fixed a crash bug with an invalid expression diff --git a/core/my_basic.c b/core/my_basic.c index 1612213..93cd77a 100755 --- a/core/my_basic.c +++ b/core/my_basic.c @@ -30,15 +30,15 @@ #endif /* _MSC_VER */ #include "my_basic.h" -#ifdef _MSC_VER +#ifdef MB_CP_VC # include # include -#else /* _MSC_VER */ +#else /* MB_CP_VC */ # include -#endif /* _MSC_VER */ -#ifndef ARDUINO +#endif /* MB_CP_VC */ +#ifndef MB_CP_ARDUINO # include -#endif /* ARDUINO */ +#endif /* MB_CP_ARDUINO */ #include #include #include @@ -51,26 +51,26 @@ extern "C" { #endif /* __cplusplus */ -#ifdef _MSC_VER +#ifdef MB_CP_VC # pragma warning(push) # pragma warning(disable : 4127) # pragma warning(disable : 4305) # pragma warning(disable : 4309) # pragma warning(disable : 4805) # pragma warning(disable : 4996) -#endif /* _MSC_VER */ +#endif /* MB_CP_VC */ -#ifdef __APPLE__ +#ifdef MB_CP_CLANG # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wunused-function" # pragma clang diagnostic ignored "-Wunused-variable" -#endif /* __APPLE__ */ +#endif /* MB_CP_CLANG */ -#ifdef __BORLANDC__ +#ifdef MB_CP_BORLANDC # pragma warn -8004 # pragma warn -8008 # pragma warn -8012 -#endif /* __BORLANDC__ */ +#endif /* MB_CP_BORLANDC */ #ifdef MB_COMPACT_MODE # pragma pack(1) @@ -1684,22 +1684,22 @@ static int _close_coll_lib(mb_interpreter_t* s); */ /** Macro */ -#ifdef _MSC_VER -# if _MSC_VER < 1300 +#ifdef MB_CP_VC +# if MB_CP_VC < 1300 # define MB_FUNC 0 -# else /* _MSC_VER < 1300 */ +# else /* MB_CP_VC < 1300 */ # define MB_FUNC __FUNCTION__ -# endif /* _MSC_VER < 1300 */ -#elif defined __BORLANDC__ +# endif /* MB_CP_VC < 1300 */ +#elif defined MB_CP_BORLANDC # define MB_FUNC __FUNC__ -#elif defined __POCC__ +#elif defined MB_CP_PELLESC # define MB_FUNC __func__ -#else /* _MSC_VER */ +#else /* MB_CP_VC */ # define MB_FUNC __FUNCTION__ -#endif /* _MSC_VER */ +#endif /* MB_CP_VC */ -#ifdef _MSC_VER -# if _MSC_VER < 1300 +#ifdef MB_CP_VC +# if MB_CP_VC < 1300 # define _do_nothing(__s, __l, __exit, __result) \ do { \ _ls_node_t* ast = 0; static int i = 0; ++i; \ @@ -1707,8 +1707,8 @@ static int _close_coll_lib(mb_interpreter_t* s); ast = (_ls_node_t*)(*(__l)); \ _handle_error_on_obj((__s), SE_RN_WRONG_FUNCTION_REACHED, (__s)->source_file, DON(ast), MB_FUNC_ERR, __exit, __result); \ } while(0) -# endif /* _MSC_VER < 1300 */ -#endif /* _MSC_VER */ +# endif /* MB_CP_VC < 1300 */ +#endif /* MB_CP_VC */ #ifndef _do_nothing # define _do_nothing(__s, __l, __exit, __result) \ do { \ @@ -4145,7 +4145,7 @@ static mb_input_func_t _get_inputer(mb_interpreter_t* s) { static char* _load_file(mb_interpreter_t* s, const char* f, const char* prefix) { /* Read all content of a file into a buffer */ -#ifndef ARDUINO +#ifndef MB_CP_ARDUINO FILE* fp = 0; char* buf = 0; long curpos = 0; @@ -4186,9 +4186,9 @@ static char* _load_file(mb_interpreter_t* s, const char* f, const char* prefix) } return buf; -#else /* ARDUINO */ +#else /* MB_CP_ARDUINO */ return 0; -#endif /* ARDUINO */ +#endif /* MB_CP_ARDUINO */ } static void _end_of_file(_parsing_context_t* context) { @@ -15093,11 +15093,11 @@ static int _std_input(mb_interpreter_t* s, void** l) { obj = (_object_t*)ast->data; if(!obj || obj->type == _DT_EOS) { -#ifdef _MSC_VER +#ifdef MB_CP_VC getch(); -#else /* _MSC_VER */ +#else /* MB_CP_VC */ _get_inputer(s)(line, sizeof(line)); -#endif /* _MSC_VER */ +#endif /* MB_CP_VC */ goto _exit; } @@ -15906,19 +15906,19 @@ _exit: # pragma pack() #endif /* MB_COMPACT_MODE */ -#ifdef __BORLANDC__ +#ifdef MB_CP_BORLANDC # pragma warn .8004 # pragma warn .8008 # pragma warn .8012 -#endif /* __BORLANDC__ */ +#endif /* MB_CP_BORLANDC */ -#ifdef __APPLE__ +#ifdef MB_CP_CLANG # pragma clang diagnostic pop -#endif /* __APPLE__ */ +#endif /* MB_CP_CLANG */ -#ifdef _MSC_VER +#ifdef MB_CP_VC # pragma warning(pop) -#endif /* _MSC_VER */ +#endif /* MB_CP_VC */ #ifdef __cplusplus } diff --git a/core/my_basic.h b/core/my_basic.h index 68750b4..98e701d 100755 --- a/core/my_basic.h +++ b/core/my_basic.h @@ -30,6 +30,60 @@ extern "C" { #endif /* __cplusplus */ +#if defined _MSC_VER +# define MB_CP_VC _MSC_VER +#elif defined __clang__ +# define MB_CP_CLANG +#elif defined __CYGWIN__ +# define MB_CP_CYGWIN +#elif defined __MINGW32__ +# define MB_CP_MINGW32 +#elif defined __BORLANDC__ +# define MB_CP_BORLANDC +#elif defined __POCC__ +# define MB_CP_PELLESC +#elif defined __TINYC__ +# define MB_CP_TCC +#elif defined __GNUC__ || defined __GNUG__ +# define MB_CP_GCC +#elif defined __ICC || defined __INTEL_COMPILER +# define MB_CP_ICC +#elif defined __HP_cc || defined __HP_aCC +# define MB_CP_HPC +#elif defined __IBMC__ || defined __IBMCPP__ +# define MB_CP_IBMC +#elif defined __PGI +# define MB_CP_PGCC +#elif defined __SUNPRO_C || defined__SUNPRO_CC +# define MB_CP_SOLARISC +#elif defined ARDUINO +# define MB_CP_ARDUINO +#else +# define MB_CP_UNKNOWN +#endif /* Compiler dependent macro */ + +#if defined _WIN32 || defined _WIN64 +# define MB_OS_WIN +#elif defined __APPLE__ +# include +# define MB_OS_APPLE +# ifdef TARGET_OS_IPHONE +# define MB_OS_IOS +# elif defined TARGET_IPHONE_SIMULATOR +# define MB_OS_IOS_SIM +# elif defined TARGET_OS_MAC +# define MB_OS_MAC +# endif +#elif defined __unix__ +# define MB_OS_UNIX +#elif defined __linux__ +# define MB_OS_LINUX +#elif defined __ANDROID__ +# define MB_OS_ANDROID +#else +# define MB_OS_UNKNOWN +#endif /* OS dependent macro */ + #ifndef MBAPI # define MBAPI #endif /* MBAPI */ @@ -156,17 +210,17 @@ extern "C" { #endif /* MB_NULL_STRING */ #ifndef mb_stricmp -# ifdef _MSC_VER +# ifdef MB_CP_VC # define mb_stricmp _strcmpi -# else /* _MSC_VER */ -# ifdef __BORLANDC__ +# else /* MB_CP_VC */ +# ifdef MB_CP_BORLANDC # define mb_stricmp stricmp -# elif defined __POCC__ +# elif defined MB_CP_PELLESC # define mb_stricmp _stricmp # else # define mb_stricmp strcasecmp # endif -# endif /* _MSC_VER */ +# endif /* MB_CP_VC */ #endif /* mb_stricmp */ #ifndef mb_assert diff --git a/output/my_basic.exe b/output/my_basic.exe index f5df4eb..e9175d2 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 90639c1..bd72d71 100755 --- a/shell/main.c +++ b/shell/main.c @@ -30,59 +30,59 @@ #endif /* _MSC_VER */ #include "../core/my_basic.h" -#ifdef _MSC_VER +#ifdef MB_CP_VC # include # include # include -#elif !defined __BORLANDC__ && !defined __TINYC__ +#elif !defined MB_CP_BORLANDC && !defined MB_CP_TCC # include -#endif /* _MSC_VER */ -#ifndef _MSC_VER +#endif /* MB_CP_VC */ +#ifndef MB_CP_VC # include -#endif /* _MSC_VER */ +#endif /* MB_CP_VC */ +#ifdef MB_CP_CLANG +# include +#endif /* MB_CP_CLANG */ #include #include #include #include #include #include -#ifdef __APPLE__ -# include -#endif /* __APPLE__ */ #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ -#ifdef _MSC_VER +#ifdef MB_CP_VC # pragma warning(disable : 4127) # pragma warning(disable : 4706) # pragma warning(disable : 4996) -#endif /* _MSC_VER */ +#endif /* MB_CP_VC */ -#ifdef __BORLANDC__ +#ifdef MB_CP_BORLANDC # pragma warn -8004 # pragma warn -8008 # pragma warn -8066 -#endif /* __BORLANDC__ */ +#endif /* MB_CP_BORLANDC */ -#ifdef __POCC__ +#ifdef MB_CP_PELLESC # define strdup _strdup # define unlink _unlink -#endif /* __POCC__ */ +#endif /* MB_CP_PELLESC */ /* ** {======================================================== ** Common declarations */ -#ifdef _MSC_VER +#ifdef MB_OS_WIN # define _BIN_FILE_NAME "my_basic" -#elif defined __APPLE__ +#elif defined MB_OS_MAC # define _BIN_FILE_NAME "my_basic_mac" -#else /* _MSC_VER */ +#else # define _BIN_FILE_NAME "my_basic_bin" -#endif /* _MSC_VER */ +#endif /* Define as 1 to use memory pool, 0 to disable */ #define _USE_MEM_POOL 1 @@ -646,11 +646,11 @@ static bool_t _try_import(struct mb_interpreter_t* s, const char* p) { */ static void _clear_screen(void) { -#ifdef _MSC_VER +#ifdef MB_OS_WIN system("cls"); -#else /* _MSC_VER */ +#else /* MB_OS_WIN */ system("clear"); -#endif /* _MSC_VER */ +#endif /* MB_OS_WIN */ } static int _new_program(void) { @@ -821,13 +821,13 @@ static void _kill_program(const char* path) { static void _list_directory(const char* path) { char line[_MAX_LINE_LENGTH]; -#ifdef _MSC_VER +#ifdef MB_OS_WIN if(path && *path) sprintf(line, "dir %s", path); else sprintf(line, "dir"); -#else /* _MSC_VER */ +#else /* MB_OS_WIN */ if(path && *path) sprintf(line, "ls %s", path); else sprintf(line, "ls"); -#endif /* _MSC_VER */ +#endif /* MB_OS_WIN */ system(line); } @@ -1065,8 +1065,24 @@ static bool_t _process_parameters(int argc, char* argv[]) { ** Scripting interfaces */ +#ifdef MB_OS_WIN +# define _OS "WIN" +#elif defined MB_OS_IOS || MB_OS_IOS_SIM +# define _OS "IOS" +#elif defined MB_OS_MAC +# define _OS "MAC" +#elif defined MB_OS_UNIX +# define _OS "UNIX" +#elif defined MB_OS_LINUX +# define _OS "LINUX" +#elif defined MB_OS_ANDROID +# define _OS "ANDROID" +#else +# define _OS "UNKNOWN" +#endif /* MB_OS_WIN */ + #define _HAS_TICKS -#if defined _MSC_VER +#if defined MB_CP_VC static int_t _ticks(void) { LARGE_INTEGER li; double freq = 0.0; @@ -1079,7 +1095,7 @@ static int_t _ticks(void) { return ret; } -#elif defined __APPLE__ +#elif defined MB_CP_CLANG static int_t _ticks(void) { struct timespec ts; struct timeval now; @@ -1092,7 +1108,7 @@ static int_t _ticks(void) { return (int_t)(ts.tv_sec * 1000 + ts.tv_nsec / 1000000); } -#elif defined __GNUC__ +#elif defined MB_CP_GCC static int_t _ticks(void) { struct timespec ts; @@ -1100,9 +1116,9 @@ static int_t _ticks(void) { return (int_t)(ts.tv_sec * 1000 + ts.tv_nsec / 1000000); } -#else /* _MSC_VER */ +#else /* MB_CP_VC */ # undef _HAS_TICKS -#endif /* _MSC_VER */ +#endif /* MB_CP_VC */ #ifdef _HAS_TICKS static int ticks(struct mb_interpreter_t* s, void** l) { @@ -1167,6 +1183,20 @@ static int set_importing_dirs(struct mb_interpreter_t* s, void** l) { return result; } +static int os(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_string(s, l, mb_memdup(_OS, (unsigned)(strlen(_OS) + 1)))); + + return result; +} + static int sys(struct mb_interpreter_t* s, void** l) { int result = MB_FUNC_OK; char* arg = 0; @@ -1345,6 +1375,7 @@ static void _on_startup(void) { #endif /* _HAS_TICKS */ mb_reg_fun(bas, now); mb_reg_fun(bas, set_importing_dirs); + mb_reg_fun(bas, os); mb_reg_fun(bas, sys); mb_reg_fun(bas, trace); mb_reg_fun(bas, raise); @@ -1365,11 +1396,11 @@ static void _on_exit(void) { _close_mem_pool(); #endif /* _USE_MEM_POOL */ -#if defined _MSC_VER && !defined _WIN64 +#if defined MB_CP_VC && !defined _WIN64 if(!!_CrtDumpMemoryLeaks()) { _asm { int 3 } } #elif _USE_MEM_POOL if(alloc_count > 0 || alloc_bytes > 0) { mb_assert(0 && "Memory leak."); } -#endif /* _MSC_VER && !_WIN64 */ +#endif /* MB_CP_VC && !_WIN64 */ } /* ========================================================} */ @@ -1382,9 +1413,9 @@ static void _on_exit(void) { int main(int argc, char* argv[]) { int status = 0; -#if defined _MSC_VER && !defined _WIN64 +#if defined MB_CP_VC && !defined _WIN64 _CrtSetBreakAlloc(0); -#endif /* _MSC_VER && !_WIN64 */ +#endif /* MB_CP_VC && !_WIN64 */ atexit(_on_exit);