Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
92f5c4f2
提交
92f5c4f2
authored
4月 05, 2014
作者:
Travis Cross
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Pull in new upstream my-basic
ref:
http://my-basic.googlecode.com/svn/trunk@57
上级
a49f4d3d
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
42 行增加
和
10 行删除
+42
-10
my_basic.c
my_basic.c
+36
-9
my_basic.h
my_basic.h
+6
-1
没有找到文件。
my_basic.c
浏览文件 @
92f5c4f2
...
...
@@ -3,7 +3,7 @@
**
** For the latest info, see http://code.google.com/p/my-basic/
**
** Copyright (c) 2011 - 201
3 Tony & Tony's Toy Game Development Team
** Copyright (c) 2011 - 201
4 paladin_t
**
** Permission is hereby granted, free of charge, to any person obtaining a copy of
** this software and associated documentation files (the "Software"), to deal in
...
...
@@ -66,9 +66,9 @@ extern "C" {
/** Macros */
#define _VER_MAJOR 1
#define _VER_MINOR 0
#define _VER_REVISION
37
#define _VER_REVISION
40
#define _MB_VERSION ((_VER_MAJOR * 0x01000000) + (_VER_MINOR * 0x00010000) + (_VER_REVISION))
#define _MB_VERSION_STRING "1.0.00
37
"
#define _MB_VERSION_STRING "1.0.00
40
"
/* Uncomment this line to treat warnings as error */
/*#define _WARING_AS_ERROR*/
...
...
@@ -198,12 +198,15 @@ static const char* _ERR_DESC[] = {
"Integer expected"
,
"ELSE statement expected"
,
"TO statement expected"
,
"NEXT statement expected"
,
"UNTIL statement expected"
,
"Loop variable expected"
,
"Jump label expected"
,
"Variable expected"
,
"Invalid identifier usage"
,
"Calculation error"
,
"Divide by zero"
,
"MOD by zero"
,
"Invalid expression"
,
"Out of memory"
,
/** Extended abort */
...
...
@@ -469,7 +472,7 @@ static _object_t* _exp_assign = 0;
val->data.integer = strcmp(_str1, _str2) __optr 0; \
} while(0)
#define _proc_div_by_zero(__s, __tuple, __exit, __result) \
#define _proc_div_by_zero(__s, __tuple, __exit, __result
, __kind
) \
do { \
_object_t opndv1; \
_object_t opndv2; \
...
...
@@ -493,7 +496,7 @@ static _object_t* _exp_assign = 0;
val->type = _DT_REAL; \
val->data.integer = _FINF; \
} \
_handle_error_on_obj((__s),
SE_RN_DIVIDE_BY_ZERO
, ((__tuple) && *(__tuple)) ? ((_object_t*)(((_tuple3_t*)(*(__tuple)))->e1)) : 0, MB_FUNC_WARNING, __exit, __result); \
_handle_error_on_obj((__s),
__kind
, ((__tuple) && *(__tuple)) ? ((_object_t*)(((_tuple3_t*)(*(__tuple)))->e1)) : 0, MB_FUNC_WARNING, __exit, __result); \
} \
} while(0)
...
...
@@ -1884,7 +1887,9 @@ void _set_current_error(mb_interpreter_t* s, mb_error_e err) {
/* Set current error information */
mb_assert
(
s
&&
err
>=
0
&&
err
<
_countof
(
_ERR_DESC
));
s
->
last_error
=
err
;
if
(
s
->
last_error
==
SE_NO_ERR
)
{
s
->
last_error
=
err
;
}
}
const
char
*
_get_error_desc
(
mb_error_e
err
)
{
...
...
@@ -3771,6 +3776,20 @@ int mb_set_printer(mb_interpreter_t* s, mb_print_func_t p) {
return
result
;
}
int
mb_gets
(
char
*
buf
,
int
s
)
{
/* Safe stdin reader function */
int
result
=
0
;
if
(
fgets
(
buf
,
s
,
stdin
)
==
0
)
{
fprintf
(
stderr
,
"Error reading.
\n
"
);
exit
(
1
);
}
result
=
(
int
)
strlen
(
buf
);
if
(
buf
[
result
-
1
]
==
'\n'
)
buf
[
result
-
1
]
=
'\0'
;
return
result
;
}
/* ========================================================} */
/*
...
...
@@ -3839,7 +3858,7 @@ int _core_div(mb_interpreter_t* s, void** l) {
mb_assert
(
s
&&
l
);
_proc_div_by_zero
(
s
,
l
,
_exit
,
result
);
_proc_div_by_zero
(
s
,
l
,
_exit
,
result
,
SE_RN_DIVIDE_BY_ZERO
);
_instruct_num_op_num
(
/
,
l
);
_exit:
...
...
@@ -3852,8 +3871,10 @@ int _core_mod(mb_interpreter_t* s, void** l) {
mb_assert
(
s
&&
l
);
_proc_div_by_zero
(
s
,
l
,
_exit
,
result
,
SE_RN_MOD_BY_ZERO
);
_instruct_int_op_int
(
%
,
l
);
_exit:
return
result
;
}
...
...
@@ -4513,6 +4534,9 @@ _to:
goto
_exit
;
}
if
(
!
ast
)
{
_handle_error_on_obj
(
s
,
SE_RN_NEXT_EXPECTED
,
DON
(
ast
),
MB_FUNC_ERR
,
_exit
,
result
);
}
obj
=
(
_object_t
*
)(
ast
->
data
);
}
...
...
@@ -5623,8 +5647,11 @@ int _std_input(mb_interpreter_t* s, void** l) {
ast
=
(
_ls_node_t
*
)(
*
l
);
obj
=
(
_object_t
*
)(
ast
->
data
);
if
(
!
obj
||
obj
->
type
!=
_DT_VAR
)
{
_handle_error_on_obj
(
s
,
SE_RN_VARIABLE_EXPECTED
,
DON
(
ast
),
MB_FUNC_ERR
,
_exit
,
result
);
}
if
(
obj
->
data
.
variable
->
data
->
type
==
_DT_INT
||
obj
->
data
.
variable
->
data
->
type
==
_DT_REAL
)
{
gets
(
line
);
mb_gets
(
line
,
sizeof
(
line
)
);
obj
->
data
.
variable
->
data
->
type
=
_DT_INT
;
obj
->
data
.
variable
->
data
->
data
.
integer
=
(
int_t
)
strtol
(
line
,
&
conv_suc
,
0
);
if
(
*
conv_suc
!=
'\0'
)
{
...
...
@@ -5641,7 +5668,7 @@ int _std_input(mb_interpreter_t* s, void** l) {
}
obj
->
data
.
variable
->
data
->
data
.
string
=
(
char
*
)
mb_malloc
(
256
);
memset
(
obj
->
data
.
variable
->
data
->
data
.
string
,
0
,
256
);
gets
(
line
);
mb_gets
(
line
,
sizeof
(
line
)
);
strcpy
(
obj
->
data
.
variable
->
data
->
data
.
string
,
line
);
}
else
{
result
=
MB_FUNC_ERR
;
...
...
my_basic.h
浏览文件 @
92f5c4f2
...
...
@@ -3,7 +3,7 @@
**
** For the latest info, see http://code.google.com/p/my-basic/
**
** Copyright (c) 2011 - 201
3 Tony & Tony's Toy Game Development Team
** Copyright (c) 2011 - 201
4 paladin_t
**
** Permission is hereby granted, free of charge, to any person obtaining a copy of
** this software and associated documentation files (the "Software"), to deal in
...
...
@@ -141,12 +141,15 @@ typedef enum mb_error_e {
SE_RN_INTEGER_EXPECTED
,
SE_RN_ELSE_EXPECTED
,
SE_RN_TO_EXPECTED
,
SE_RN_NEXT_EXPECTED
,
SE_RN_UNTIL_EXPECTED
,
SE_RN_LOOP_VAR_EXPECTED
,
SE_RN_JUMP_LABEL_EXPECTED
,
SE_RN_VARIABLE_EXPECTED
,
SE_RN_INVALID_ID_USAGE
,
SE_RN_CALCULATION_ERROR
,
SE_RN_DIVIDE_BY_ZERO
,
SE_RN_MOD_BY_ZERO
,
SE_RN_INVALID_EXPRESSION
,
SE_RN_OUT_OF_MEMORY
,
/** Extended abort */
...
...
@@ -226,6 +229,8 @@ MBAPI const char* mb_get_error_desc(mb_error_e err);
MBAPI
int
mb_set_error_handler
(
mb_interpreter_t
*
s
,
mb_error_handler_t
h
);
MBAPI
int
mb_set_printer
(
mb_interpreter_t
*
s
,
mb_print_func_t
p
);
MBAPI
int
mb_gets
(
char
*
buf
,
int
s
);
#ifdef MB_COMPACT_MODE
# pragma pack()
#endif
/* MB_COMPACT_MODE */
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论