+usertype support; *polished code; *polished document
This commit is contained in:
parent
34b50f77b8
commit
538ee44708
11
HISTORY
11
HISTORY
@ -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
|
||||
Added mixed integer/float array support
|
||||
Added warning prompt when passing strings to maths functions
|
||||
Fixed a memory leak when storing strings in an array
|
||||
Polisned the interpreter commands
|
||||
Polished the interpreter commands
|
||||
|
||||
Apr. 11 2015
|
||||
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
|
||||
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
|
||||
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
|
||||
|
||||
Dec. 17 2014
|
||||
|
BIN
MY-BASIC Quick Reference.pdf
Normal file → Executable file
BIN
MY-BASIC Quick Reference.pdf
Normal file → Executable file
Binary file not shown.
688
core/my_basic.c
688
core/my_basic.c
File diff suppressed because it is too large
Load Diff
@ -34,14 +34,22 @@ extern "C" {
|
||||
# define MBAPI
|
||||
#endif /* MBAPI */
|
||||
|
||||
#ifndef MB_ENABLE_SOURCE_TRACE
|
||||
# define MB_ENABLE_SOURCE_TRACE
|
||||
#endif /* MB_ENABLE_SOURCE_TRACE */
|
||||
|
||||
#ifndef MB_SIMPLE_ARRAY
|
||||
# define 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
|
||||
# define MB_COMPACT_MODE
|
||||
#endif /* MB_COMPACT_MODE */
|
||||
@ -76,9 +84,9 @@ extern "C" {
|
||||
# define _strcmpi stricmp
|
||||
# elif defined __POCC__
|
||||
# define _strcmpi _stricmp
|
||||
# else /* __BORLANDC__*/
|
||||
# else
|
||||
# define _strcmpi strcasecmp
|
||||
# endif /* __BORLANDC__ */
|
||||
# endif
|
||||
# endif /* _strcmpi */
|
||||
#endif /* _MSC_VER */
|
||||
|
||||
@ -188,13 +196,15 @@ typedef enum mb_data_e {
|
||||
MB_DT_NIL = -1,
|
||||
MB_DT_INT = 0,
|
||||
MB_DT_REAL,
|
||||
MB_DT_STRING
|
||||
MB_DT_STRING,
|
||||
MB_DT_USERTYPE
|
||||
} mb_data_e;
|
||||
|
||||
typedef union mb_value_u {
|
||||
int_t integer;
|
||||
real_t float_point;
|
||||
char* string;
|
||||
void* usertype;
|
||||
} mb_value_u;
|
||||
|
||||
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_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_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_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_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_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 char* mb_strdup(char* val, unsigned size);
|
||||
MBAPI char* mb_memdup(char* val, unsigned size);
|
||||
|
||||
#ifdef MB_COMPACT_MODE
|
||||
# pragma pack()
|
||||
|
Binary file not shown.
Binary file not shown.
@ -62,8 +62,8 @@ IDI_ICON_MAIN ICON "icon.ico"
|
||||
//
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 1,0,0,49
|
||||
PRODUCTVERSION 1,0,0,49
|
||||
FILEVERSION 1,0,0,50
|
||||
PRODUCTVERSION 1,0,0,50
|
||||
FILEFLAGSMASK 0x17L
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
@ -81,13 +81,13 @@ BEGIN
|
||||
VALUE "Comments", "MY-BASIC"
|
||||
VALUE "CompanyName", "W. Renxin"
|
||||
VALUE "FileDescription", "MY-BASIC interpreter"
|
||||
VALUE "FileVersion", "1, 0, 0, 49"
|
||||
VALUE "FileVersion", "1, 0, 0, 50"
|
||||
VALUE "InternalName", "my_basic"
|
||||
VALUE "LegalCopyright", "Copyright (C) 2011 - 2015 W. Renxin"
|
||||
VALUE "LegalTrademarks", "MY-BASIC"
|
||||
VALUE "OriginalFilename", "my_basic.exe"
|
||||
VALUE "ProductName", "MY-BASIC"
|
||||
VALUE "ProductVersion", "1, 0, 0, 49"
|
||||
VALUE "ProductVersion", "1, 0, 0, 50"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
|
17
shell/main.c
17
shell/main.c
@ -119,10 +119,9 @@ static char* _get_code(_code_line_t* code) {
|
||||
result[0] = '\0';
|
||||
for(i = 0; i < code->count; ++i) {
|
||||
result = strcat(result, code->lines[i]);
|
||||
if(i != code->count - 1) {
|
||||
if(i != code->count - 1)
|
||||
result = strcat(result, "\n");
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -131,18 +130,17 @@ static void _set_code(_code_line_t* code, char* txt) {
|
||||
char* cursor = 0;
|
||||
char _c = '\0';
|
||||
mb_assert(code);
|
||||
if(!txt) {
|
||||
if(!txt)
|
||||
return;
|
||||
}
|
||||
|
||||
_clear_code(code);
|
||||
cursor = txt;
|
||||
do {
|
||||
_c = *cursor;
|
||||
if(_c == '\r' || _c == '\n' || _c == '\0') {
|
||||
cursor[0] = '\0';
|
||||
if(_c == '\r' && *(cursor + 1) == '\n') {
|
||||
if(_c == '\r' && *(cursor + 1) == '\n')
|
||||
++cursor;
|
||||
}
|
||||
_append_line(code, txt);
|
||||
txt = cursor + 1;
|
||||
}
|
||||
@ -272,9 +270,9 @@ static void _list_program(const char* sn, const char* cn) {
|
||||
--lsn;
|
||||
e = lcn ? lsn + lcn : c->count;
|
||||
for(i = lsn; i < e; ++i) {
|
||||
if(i >= c->count) {
|
||||
if(i >= c->count)
|
||||
break;
|
||||
}
|
||||
|
||||
printf("%d]%s\n", i + 1, c->lines[i]);
|
||||
}
|
||||
}
|
||||
@ -434,9 +432,8 @@ int main(int argc, char* argv[]) {
|
||||
status = _do_line();
|
||||
} while(_NO_END(status));
|
||||
} 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);
|
||||
}
|
||||
} else {
|
||||
printf("Unknown arguments\n");
|
||||
_show_tip();
|
||||
|
Loading…
x
Reference in New Issue
Block a user