+usertype support; *polished code; *polished document

This commit is contained in:
tony 2015-04-15 22:27:19 +08:00
parent 34b50f77b8
commit 538ee44708
8 changed files with 234 additions and 520 deletions

11
HISTORY
View File

@ -1,12 +1,17 @@
Apr. 15 2015
Added mb_pop_usertype, mb_push_usertype to support user defined type
Polished code
Polished document
Apr. 13 2015 Apr. 13 2015
Added mixed integer/float array support Added mixed integer/float array support
Added warning prompt when passing strings to maths functions Added warning prompt when passing strings to maths functions
Fixed a memory leak when storing strings in an array Fixed a memory leak when storing strings in an array
Polisned the interpreter commands Polished the interpreter commands
Apr. 11 2015 Apr. 11 2015
Moved struct mb_interpreter_t from my_basic.h to my_basic.c Moved struct mb_interpreter_t from my_basic.h to my_basic.c
Added an mb_has_argument interface to tell whether there is any more argument Added an mb_has_arg interface to tell whether there is any more argument
Added an MB_ENABLE_SOURCE_TRACE macro to enable or disable source tracing Added an MB_ENABLE_SOURCE_TRACE macro to enable or disable source tracing
Disposed parsing context at runtime to reduce memory occupation Disposed parsing context at runtime to reduce memory occupation
@ -18,7 +23,7 @@ Fixed a crash bug when a script begins with a meaningless negtive number
Mar. 25 2015 Mar. 25 2015
Changed _strupr macro to mb_strupr function Changed _strupr macro to mb_strupr function
Added an mb_strdup function Added an mb_memdup function
Fixed an intermediate value disposing more than once bug Fixed an intermediate value disposing more than once bug
Dec. 17 2014 Dec. 17 2014

BIN
MY-BASIC Quick Reference.pdf Normal file → Executable file

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -34,14 +34,22 @@ extern "C" {
# define MBAPI # define MBAPI
#endif /* MBAPI */ #endif /* MBAPI */
#ifndef MB_ENABLE_SOURCE_TRACE
# define MB_ENABLE_SOURCE_TRACE
#endif /* MB_ENABLE_SOURCE_TRACE */
#ifndef MB_SIMPLE_ARRAY #ifndef MB_SIMPLE_ARRAY
# define MB_SIMPLE_ARRAY # define MB_SIMPLE_ARRAY
#endif /* MB_SIMPLE_ARRAY */ #endif /* MB_SIMPLE_ARRAY */
#ifndef MB_MAX_DIMENSION_COUNT
# define MB_MAX_DIMENSION_COUNT 4
#endif /* MB_MAX_DIMENSION_COUNT */
#ifndef MB_ENABLE_ALLOC_STAT
# define MB_ENABLE_ALLOC_STAT
#endif /* MB_ENABLE_ALLOC_STAT */
#ifndef MB_ENABLE_SOURCE_TRACE
# define MB_ENABLE_SOURCE_TRACE
#endif /* MB_ENABLE_SOURCE_TRACE */
#ifndef MB_COMPACT_MODE #ifndef MB_COMPACT_MODE
# define MB_COMPACT_MODE # define MB_COMPACT_MODE
#endif /* MB_COMPACT_MODE */ #endif /* MB_COMPACT_MODE */
@ -76,9 +84,9 @@ extern "C" {
# define _strcmpi stricmp # define _strcmpi stricmp
# elif defined __POCC__ # elif defined __POCC__
# define _strcmpi _stricmp # define _strcmpi _stricmp
# else /* __BORLANDC__*/ # else
# define _strcmpi strcasecmp # define _strcmpi strcasecmp
# endif /* __BORLANDC__ */ # endif
# endif /* _strcmpi */ # endif /* _strcmpi */
#endif /* _MSC_VER */ #endif /* _MSC_VER */
@ -188,13 +196,15 @@ typedef enum mb_data_e {
MB_DT_NIL = -1, MB_DT_NIL = -1,
MB_DT_INT = 0, MB_DT_INT = 0,
MB_DT_REAL, MB_DT_REAL,
MB_DT_STRING MB_DT_STRING,
MB_DT_USERTYPE
} mb_data_e; } mb_data_e;
typedef union mb_value_u { typedef union mb_value_u {
int_t integer; int_t integer;
real_t float_point; real_t float_point;
char* string; char* string;
void* usertype;
} mb_value_u; } mb_value_u;
typedef struct mb_value_t { typedef struct mb_value_t {
@ -228,10 +238,12 @@ MBAPI int mb_has_arg(struct mb_interpreter_t* s, void** l);
MBAPI int mb_pop_int(struct mb_interpreter_t* s, void** l, int_t* val); MBAPI int mb_pop_int(struct mb_interpreter_t* s, void** l, int_t* val);
MBAPI int mb_pop_real(struct mb_interpreter_t* s, void** l, real_t* val); MBAPI int mb_pop_real(struct mb_interpreter_t* s, void** l, real_t* val);
MBAPI int mb_pop_string(struct mb_interpreter_t* s, void** l, char** val); MBAPI int mb_pop_string(struct mb_interpreter_t* s, void** l, char** val);
MBAPI int mb_pop_usertype(struct mb_interpreter_t* s, void** l, void** val);
MBAPI int mb_pop_value(struct mb_interpreter_t* s, void** l, mb_value_t* val); MBAPI int mb_pop_value(struct mb_interpreter_t* s, void** l, mb_value_t* val);
MBAPI int mb_push_int(struct mb_interpreter_t* s, void** l, int_t val); MBAPI int mb_push_int(struct mb_interpreter_t* s, void** l, int_t val);
MBAPI int mb_push_real(struct mb_interpreter_t* s, void** l, real_t val); MBAPI int mb_push_real(struct mb_interpreter_t* s, void** l, real_t val);
MBAPI int mb_push_string(struct mb_interpreter_t* s, void** l, char* val); MBAPI int mb_push_string(struct mb_interpreter_t* s, void** l, char* val);
MBAPI int mb_push_usertype(struct mb_interpreter_t* s, void** l, void* val);
MBAPI int mb_push_value(struct mb_interpreter_t* s, void** l, mb_value_t val); MBAPI int mb_push_value(struct mb_interpreter_t* s, void** l, mb_value_t val);
MBAPI int mb_load_string(struct mb_interpreter_t* s, const char* l); MBAPI int mb_load_string(struct mb_interpreter_t* s, const char* l);
@ -247,7 +259,7 @@ MBAPI int mb_set_inputer(struct mb_interpreter_t* s, mb_input_func_t p);
MBAPI int mb_gets(char* buf, int s); MBAPI int mb_gets(char* buf, int s);
MBAPI char* mb_strdup(char* val, unsigned size); MBAPI char* mb_memdup(char* val, unsigned size);
#ifdef MB_COMPACT_MODE #ifdef MB_COMPACT_MODE
# pragma pack() # pragma pack()

Binary file not shown.

Binary file not shown.

View File

@ -62,8 +62,8 @@ IDI_ICON_MAIN ICON "icon.ico"
// //
VS_VERSION_INFO VERSIONINFO VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,0,0,49 FILEVERSION 1,0,0,50
PRODUCTVERSION 1,0,0,49 PRODUCTVERSION 1,0,0,50
FILEFLAGSMASK 0x17L FILEFLAGSMASK 0x17L
#ifdef _DEBUG #ifdef _DEBUG
FILEFLAGS 0x1L FILEFLAGS 0x1L
@ -81,13 +81,13 @@ BEGIN
VALUE "Comments", "MY-BASIC" VALUE "Comments", "MY-BASIC"
VALUE "CompanyName", "W. Renxin" VALUE "CompanyName", "W. Renxin"
VALUE "FileDescription", "MY-BASIC interpreter" VALUE "FileDescription", "MY-BASIC interpreter"
VALUE "FileVersion", "1, 0, 0, 49" VALUE "FileVersion", "1, 0, 0, 50"
VALUE "InternalName", "my_basic" VALUE "InternalName", "my_basic"
VALUE "LegalCopyright", "Copyright (C) 2011 - 2015 W. Renxin" VALUE "LegalCopyright", "Copyright (C) 2011 - 2015 W. Renxin"
VALUE "LegalTrademarks", "MY-BASIC" VALUE "LegalTrademarks", "MY-BASIC"
VALUE "OriginalFilename", "my_basic.exe" VALUE "OriginalFilename", "my_basic.exe"
VALUE "ProductName", "MY-BASIC" VALUE "ProductName", "MY-BASIC"
VALUE "ProductVersion", "1, 0, 0, 49" VALUE "ProductVersion", "1, 0, 0, 50"
END END
END END
BLOCK "VarFileInfo" BLOCK "VarFileInfo"

View File

@ -119,9 +119,8 @@ static char* _get_code(_code_line_t* code) {
result[0] = '\0'; result[0] = '\0';
for(i = 0; i < code->count; ++i) { for(i = 0; i < code->count; ++i) {
result = strcat(result, code->lines[i]); result = strcat(result, code->lines[i]);
if(i != code->count - 1) { if(i != code->count - 1)
result = strcat(result, "\n"); result = strcat(result, "\n");
}
} }
return result; return result;
@ -131,18 +130,17 @@ static void _set_code(_code_line_t* code, char* txt) {
char* cursor = 0; char* cursor = 0;
char _c = '\0'; char _c = '\0';
mb_assert(code); mb_assert(code);
if(!txt) { if(!txt)
return; return;
}
_clear_code(code); _clear_code(code);
cursor = txt; cursor = txt;
do { do {
_c = *cursor; _c = *cursor;
if(_c == '\r' || _c == '\n' || _c == '\0') { if(_c == '\r' || _c == '\n' || _c == '\0') {
cursor[0] = '\0'; cursor[0] = '\0';
if(_c == '\r' && *(cursor + 1) == '\n') { if(_c == '\r' && *(cursor + 1) == '\n')
++cursor; ++cursor;
}
_append_line(code, txt); _append_line(code, txt);
txt = cursor + 1; txt = cursor + 1;
} }
@ -272,9 +270,9 @@ static void _list_program(const char* sn, const char* cn) {
--lsn; --lsn;
e = lcn ? lsn + lcn : c->count; e = lcn ? lsn + lcn : c->count;
for(i = lsn; i < e; ++i) { for(i = lsn; i < e; ++i) {
if(i >= c->count) { if(i >= c->count)
break; break;
}
printf("%d]%s\n", i + 1, c->lines[i]); printf("%d]%s\n", i + 1, c->lines[i]);
} }
} }
@ -434,9 +432,8 @@ int main(int argc, char* argv[]) {
status = _do_line(); status = _do_line();
} while(_NO_END(status)); } while(_NO_END(status));
} else if(argc == 2) { } else if(argc == 2) {
if(mb_load_file(bas, argv[1]) == MB_FUNC_OK) { if(mb_load_file(bas, argv[1]) == MB_FUNC_OK)
mb_run(bas); mb_run(bas);
}
} else { } else {
printf("Unknown arguments\n"); printf("Unknown arguments\n");
_show_tip(); _show_tip();