Skip to content

Commit f9cce7b

Browse files
committed
lwsh: fixed bugs
1 parent 95595ca commit f9cce7b

File tree

2 files changed

+34
-48
lines changed

2 files changed

+34
-48
lines changed

include/core/config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#define APP_VERSION_PATCH 0
2424
#define APP_VERSION_SUFFIX "-dev"
2525

26-
#define BUILD_NUMBER 500
26+
#define BUILD_NUMBER 511
2727

2828
#define APP_VERSION_RELEASE_DATE 1540715722
2929

service/lsh.c

Lines changed: 33 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ sh_forall_func_find (void *ptr, void *data)
196196
{
197197
sh_func_entry_t *entry = d_pointer_as (sh_func_entry_t, ptr);
198198
sh_func_find_ctx_t *find_ctx = d_pointer_as (sh_func_find_ctx_t, data);
199-
os_printf("--- 9 %s %s\n", entry->func_name, find_ctx->func_name);
200199
if (os_strncmp (entry->func_name, find_ctx->func_name, sizeof (sh_func_name_t)) == 0) {
201200
find_ctx->entry = entry;
202201
return IMDB_CURSOR_BREAK;
@@ -515,6 +514,8 @@ bc_set_pointer_arg (sh_parse_ctx_t * ctx, char **pbuf_ptr, sh_bc_oper_t * bc_ope
515514
bytecode_size_t *vptr = d_pointer_as (bytecode_size_t, &arg_ptr->data);
516515
*vptr = d_pointer_diff (bc_oper, ctx->bc_buf);
517516
*pbuf_ptr = d_pointer_add (char, arg_ptr, sizeof (sh_parse_arg_t) + d_align (arg_ptr->length));
517+
os_printf("-- 30 bc_set_pointer_arg: arg_addr=%p, vptr=%04x, bufptr=%p \n", arg_ptr, *vptr,
518+
*pbuf_ptr);
518519
d_log_dprintf (LSH_SERVICE_NAME, "bc_set_pointer_arg: arg_addr=%p, vptr=%04x, bufptr=%p", arg_ptr, *vptr,
519520
*pbuf_ptr);
520521
}
@@ -530,22 +531,20 @@ bc_global_add (sh_parse_arg_t * arg, sh_parse_arg_type_t type, sh_gvar_t ** gadd
530531
{
531532
sh_gvar_t *gvar;
532533
*gaddr = NULL;
533-
os_printf("-- 24.1\n");
534534
if (ih_hash8_search (sdata->token_idx, arg->data, arg->length - 1, (char **) &gvar) == IH_ENTRY_NOTFOUND) {
535-
os_printf("-- 24.2\n");
536535
ih_hash8_add (sdata->token_idx, arg->data, arg->length - 1, (char **) &gvar);
537536
gvar->type = type;
538537
gvar->use_count = 1;
539538

540-
os_printf("-- 24.3\n");
541539
switch (type) {
542540
case SH_ARG_FUNC:
543541
gvar->arg.arg.ptr = 0;
544542
break;
545543
default:
546544
gvar->arg.arg.value = 0;
547545
}
548-
os_printf("-- 24.4\n");
546+
os_printf("-- bc_global_add: token=%s, addr=%p\n", arg->data, gvar);
547+
549548
d_log_dprintf (LSH_SERVICE_NAME, "bc_global_add: token=%s, addr=%p", arg->data, gvar);
550549
}
551550
else
@@ -567,7 +566,7 @@ LOCAL sh_errcode_t ICACHE_FLASH_ATTR
567566
bc_serialize_arg (sh_parse_ctx_t * ctx, char **bc_ptr, sh_bc_oper_t * bc_oper, sh_parse_arg_t * arg, uint8 * bytepos)
568567
{
569568
sh_bc_arg_t *bc_arg = d_pointer_as (sh_bc_arg_t, *bc_ptr);
570-
os_printf("-- 23.1 %p\n", bc_arg);
569+
os_printf("-- serialize arg %p, %u\n", d_pointer_diff(bc_arg, ctx->bc_buf), arg->type);
571570
d_bc_buffer_alloc (ctx, bc_ptr, sizeof (sh_bc_arg_t));
572571

573572
switch (arg->type) {
@@ -595,20 +594,18 @@ bc_serialize_arg (sh_parse_ctx_t * ctx, char **bc_ptr, sh_bc_oper_t * bc_oper, s
595594
break;
596595
case SH_ARG_FUNC:
597596
{
598-
os_printf("-- 23.2 %p\n", arg);
599597
sh_gvar_t *gaddr;
600598
sh_errcode_t err = bc_global_add (arg, SH_ARG_FUNC, &gaddr);
601-
os_printf("-- 23.3\n");
602599
if (err != SH_ERR_SUCCESS)
603600
d_stmt_err_ret (ctx, err);
604601
bc_arg->arg.ptr = gaddr;
605602
bc_oper->bitmask |= (0x3 << *bytepos);
606603
(*bytepos)++;
607-
os_printf("-- 23.4\n");
608604
break;
609605
}
610606
case SH_ARG_POINTER:
611607
bc_arg->arg.ptr = (void *) ((uint32) 0 + *d_pointer_as (bytecode_size_t, arg->data));
608+
os_printf("-- serialize arg ptr %p\n", bc_arg->arg.ptr);
612609
bc_oper->bitmask |= (0x3 << *bytepos);
613610
(*bytepos)++;
614611
break;
@@ -617,8 +614,6 @@ bc_serialize_arg (sh_parse_ctx_t * ctx, char **bc_ptr, sh_bc_oper_t * bc_oper, s
617614
}
618615
(*bytepos)++;
619616

620-
os_printf("-- 23.5\n");
621-
622617
return SH_ERR_SUCCESS;
623618
}
624619

@@ -635,6 +630,9 @@ bc_serialize_oper_header (sh_parse_ctx_t * ctx, char **bc_ptr, sh_oper_type_t op
635630
{
636631
sh_bc_oper_t *bc_oper_ptr = d_pointer_as (sh_bc_oper_t, *bc_ptr);
637632
sh_oper_desc_t *opdesc = &sh_oper_desc[optype];
633+
634+
os_printf("-- bc_serialize_ophdr: depth=%u, addr=%04x, " OD2T_STR " , args=%u\n", ctx->depth,
635+
*bc_ptr - ctx->bc_buf, OD2T (opdesc), arg_count);
638636
d_log_dprintf (LSH_SERVICE_NAME, "bc_serialize_ophdr: depth=%u, addr=%04x, " OD2T_STR " , args=%u", ctx->depth,
639637
*bc_ptr - ctx->bc_buf, OD2T (opdesc), arg_count);
640638

@@ -666,23 +664,29 @@ INLINED sh_errcode_t ICACHE_FLASH_ATTR
666664
bc_serialize_oper_ctl (sh_parse_ctx_t * ctx, char **bc_ptr, char **pbuf_ptr, sh_parse_arg_t ** arg,
667665
sh_oper_type_t optype)
668666
{
667+
os_printf("-- serialize_oper_ctl: depth=%u, addr=%04x, optype=%u\n", ctx->depth,
668+
*bc_ptr - ctx->bc_buf, optype);
669+
669670
d_log_dprintf (LSH_SERVICE_NAME, "serialize_oper_ctl: depth=%u, addr=%04x, optype=%u", ctx->depth,
670671
*bc_ptr - ctx->bc_buf, optype);
671672
sh_bc_oper_t *bc_oper_ptr;
672673
uint8 bytepos = 0;
673674
bc_serialize_oper_header (ctx, bc_ptr, optype, 2, &bc_oper_ptr, &bytepos);
674675
d_stmt_check_err (ctx);
675676

677+
// condition arg
678+
d_assert ((*arg), "left argument missed");
679+
bc_serialize_arg (ctx, bc_ptr, bc_oper_ptr, *arg, &bytepos);
680+
d_stmt_check_err (ctx);
681+
676682
// jump arg
677683
bc_oper_ptr->bitmask |= (0x3 << bytepos);
678684
bytepos += 2;
679685
sh_bc_arg_t *bc_arg = d_pointer_as (sh_bc_arg_t, *bc_ptr);
686+
os_printf("-- serialize jmparg %p\n", d_pointer_diff(bc_arg, ctx->bc_buf));
680687
d_bc_buffer_alloc (ctx, bc_ptr, sizeof (sh_bc_arg_t));
681688
bc_arg->arg.ptr = 0;
682689

683-
d_assert ((*arg), "left argument missed");
684-
bc_serialize_arg (ctx, bc_ptr, bc_oper_ptr, *arg, &bytepos);
685-
d_stmt_check_err (ctx);
686690
// set left_arg pointer to bc_oper jump arg
687691
bc_set_pointer_arg (ctx, pbuf_ptr, bc_oper_ptr, arg);
688692

@@ -749,31 +753,26 @@ bc_serialize_foper (sh_parse_ctx_t * ctx, char **bc_ptr, sh_parse_oper_t * oper,
749753
{
750754
sh_bc_oper_t *bc_oper_ptr;
751755
uint8 bytepos = 0;
752-
os_printf("-- 22.1\n");
753756
bc_serialize_oper_header (ctx, bc_ptr, oper->optype, oper->arg_count, &bc_oper_ptr, &bytepos);
754757
d_stmt_check_err (ctx);
755758

756759
arg_count_t arg_idx = 0;
757-
os_printf("-- 22.2\n");
758760
if (oper->left_arg) {
759761
bc_serialize_arg (ctx, bc_ptr, bc_oper_ptr, oper->left_arg, &bytepos);
760762
d_stmt_check_err (ctx);
761763
arg_idx++;
762764
}
763765

764-
os_printf("-- 22.3\n");
765766
sh_parse_arg_t *arg_ptr = d_pointer_as (sh_parse_arg_t, oper->varargs);
766767
while (arg_idx < oper->arg_count) {
767768
if (arg_ptr->type != SH_ARG_NONE) {
768-
os_printf("-- 22.4\n");
769769
bc_serialize_arg (ctx, bc_ptr, bc_oper_ptr, arg_ptr, &bytepos);
770770
d_stmt_check_err (ctx);
771771
arg_idx++;
772772
}
773773
arg_ptr = d_pointer_add (sh_parse_arg_t, arg_ptr, sizeof (sh_parse_arg_t) + d_align (arg_ptr->length));
774774
}
775775
*bc_oper = bc_oper_ptr;
776-
os_printf("-- 22.5\n");
777776

778777
return SH_ERR_SUCCESS;
779778
}
@@ -842,7 +841,7 @@ bc_serialize_oper (sh_parse_ctx_t * ctx, char **bc_ptr, char **pbuf_ptr, sh_pars
842841
return SH_ERR_SUCCESS;
843842

844843
sh_bc_oper_t *bc_oper_ptr;
845-
os_printf("-- 21.1 %p\n", bc_oper_ptr);
844+
os_printf("-- bc_serialize_oper %p\n", bc_oper_ptr);
846845
if (oper_tmp->optype == SH_OPER_BLOCK) {
847846
uint8 bytepos;
848847
bc_serialize_oper_header (ctx, bc_ptr, oper_tmp->optype, 0, &bc_oper_ptr, &bytepos);
@@ -855,18 +854,16 @@ bc_serialize_oper (sh_parse_ctx_t * ctx, char **bc_ptr, char **pbuf_ptr, sh_pars
855854
bc_arg->arg.ptr = (void *) d_pointer_diff (*bc_ptr, ctx->bc_buf);
856855
}
857856
else {
858-
os_printf("-- 21.4\n");
857+
os_printf("-- bc_serialize_oper: depth=%u, addr=%04x, " OP2T_STR " , args=%u\n", ctx->depth,
858+
*bc_ptr - ctx->bc_buf, OP2T (ctx, oper_tmp), oper_tmp->arg_count);
859859
d_log_dprintf (LSH_SERVICE_NAME, "bc_serialize_oper: depth=%u, addr=%04x, " OP2T_STR " , args=%u", ctx->depth,
860860
*bc_ptr - ctx->bc_buf, OP2T (ctx, oper_tmp), oper_tmp->arg_count);
861861
if ((oper_tmp->optype == SH_OPER_VAR) || (oper_tmp->optype == SH_OPER_GVAR)) {
862-
os_printf("-- 21.5a\n");
863862
bc_serialize_var (ctx, bc_ptr, oper_tmp, &bc_oper_ptr);
864863
}
865864
else {
866-
os_printf("-- 21.5b\n");
867865
bc_serialize_foper (ctx, bc_ptr, oper_tmp, &bc_oper_ptr);
868866
}
869-
os_printf("-- 21.6\n");
870867
d_stmt_check_err (ctx);
871868
}
872869

@@ -875,16 +872,13 @@ bc_serialize_oper (sh_parse_ctx_t * ctx, char **bc_ptr, char **pbuf_ptr, sh_pars
875872
}
876873

877874
// pop oper and set left_arg pointer to bc_oper result
878-
os_printf("-- 21.7\n");
879875
*oper = oper_tmp->prev_oper;
880876
sh_parse_arg_t *arg_ptr = oper_tmp->left_arg;
881877
if (!arg_ptr) {
882878
arg_ptr = d_pointer_as (sh_parse_arg_t, oper_tmp); // write position
883879
}
884880
*arg = arg_ptr;
885-
os_printf("-- 21.8\n");
886881
bc_set_pointer_arg (ctx, pbuf_ptr, bc_oper_ptr, arg);
887-
os_printf("-- 21.9\n");
888882
ctx->depth--;
889883

890884
return SH_ERR_SUCCESS;
@@ -1005,57 +999,46 @@ stmt_parse_arg (sh_parse_ctx_t * ctx, char **szstr, char **pbuf_ptr, sh_parse_op
1005999
// Fixme: Check buffer length
10061000
sh_parse_arg_t *arg_ptr = d_pointer_as (sh_parse_arg_t, *pbuf_ptr);
10071001

1008-
os_printf("-- 8.1 %u\n", *pbuf_ptr - ctx->parse_buf);
10091002
if (d_char_is_digit (*szstr)) {
1010-
os_printf("-- 8.2\n");
10111003
// constant number
10121004
arg_ptr->type = SH_ARG_INT;
10131005
arg_ptr->length = sizeof (uint32);
10141006
uint32 *value_uint = d_pointer_as (uint32, &arg_ptr->data);
10151007

1016-
os_printf("-- 8.3 %p\n", value_uint);
10171008
if (!parse_uint (szstr, value_uint)) {
1018-
os_printf("-- 8.3 !\n");
10191009
d_stmt_err_ret (ctx, SH_PARSE_ERROR_NUMINV, d_stmt_pos (ctx, *szstr));
10201010
}
1021-
os_printf("-- 8.4\n");
10221011

10231012
d_log_dprintf (LSH_SERVICE_NAME, "parse_arg: depth=%d, pos=%d, num:%u", ctx->depth, (*szstr - ctx->stmt_start),
10241013
*value_uint);
10251014
}
10261015
else if (d_char_is_quote (*szstr)) {
1027-
os_printf("-- 8.5\n");
10281016
// constant string
10291017
arg_ptr->type = SH_ARG_CHAR;
10301018
estlen_qstr (szstr, (unsigned int *) &arg_ptr->length);
10311019
// null-terminate
10321020
arg_ptr->data[arg_ptr->length] = '\0';
10331021
arg_ptr->length++;
10341022

1035-
os_printf("-- 8.6\n");
10361023
if (!parse_qstr (szstr, (char *) arg_ptr->data)) {
10371024
d_stmt_err_ret (ctx, SH_PARSE_ERROR_STRINV, d_stmt_pos (ctx, *szstr));
10381025
}
10391026

1040-
os_printf("-- 8.7\n");
10411027
d_log_dprintf (LSH_SERVICE_NAME, "parse_arg: depth=%d, pos=%d, str:%s", ctx->depth, (*szstr - ctx->stmt_start),
10421028
arg_ptr->data);
10431029
}
10441030
else if (d_char_is_token1 (*szstr)) {
10451031
// function | variable | extended operator | nested statement
1046-
os_printf("-- 8.8\n");
10471032
arg_ptr->type = SH_ARG_TOKEN;
10481033
estlen_token (szstr, (unsigned int *) &arg_ptr->length);
10491034
// null-terminate
10501035
arg_ptr->data[arg_ptr->length] = '\0';
10511036
arg_ptr->length++;
10521037

1053-
os_printf("-- 8.9\n");
10541038
if (!parse_token (szstr, (char *) arg_ptr->data)) {
10551039
d_stmt_err_ret (ctx, SH_PARSE_ERROR_TOKENINV, d_stmt_pos (ctx, *szstr));
10561040
}
10571041

1058-
os_printf("-- 8.10\n");
10591042
d_log_dprintf (LSH_SERVICE_NAME, "parse_arg: depth=%d, pos=%d, token:%s", ctx->depth,
10601043
(*szstr - ctx->stmt_start), arg_ptr->data);
10611044
}
@@ -1067,7 +1050,6 @@ stmt_parse_arg (sh_parse_ctx_t * ctx, char **szstr, char **pbuf_ptr, sh_parse_op
10671050
oper->arg_count++;
10681051
}
10691052
(*pbuf_ptr) += sizeof (sh_parse_arg_t) + d_align (arg_ptr->length);
1070-
os_printf("-- 8.11 %u\n", *pbuf_ptr - ctx->parse_buf);
10711053
*arg = arg_ptr;
10721054

10731055
return SH_ERR_SUCCESS;
@@ -1083,6 +1065,8 @@ stmt_parse_ext (sh_parse_ctx_t * ctx, char **szstr, char **bc_ptr, char **pbuf_p
10831065
while (**szstr != '\0') {
10841066
char *ptr_start = *szstr;
10851067
// check operator term
1068+
os_printf("-- 000 %p %c\n", oper, **szstr);
1069+
10861070
d_skip_space (*szstr);
10871071
if ((ctx->term_oper) && (ctx->term_oper->term == **szstr)) {
10881072
(*szstr)++;
@@ -1108,13 +1092,15 @@ stmt_parse_ext (sh_parse_ctx_t * ctx, char **szstr, char **bc_ptr, char **pbuf_p
11081092
ctx->term_oper = oper2;
11091093
continue;
11101094
}
1111-
else if ((**szstr == ';') && oper) { // default terminator
1095+
else if (**szstr == ';') {
11121096
(*szstr)++;
1113-
while (oper && (oper->optype != SH_OPER_BLOCK)) {
1114-
os_printf("-- 5\n");
1115-
bc_serialize_oper (ctx, bc_ptr, pbuf_ptr, &arg, &oper);
1116-
os_printf("-- 6\n");
1117-
d_stmt_check_err (ctx);
1097+
if (oper) { // default terminator
1098+
while (oper && (oper->optype != SH_OPER_BLOCK)) {
1099+
os_printf("-- 5\n");
1100+
bc_serialize_oper (ctx, bc_ptr, pbuf_ptr, &arg, &oper);
1101+
os_printf("-- 6\n");
1102+
d_stmt_check_err (ctx);
1103+
}
11181104
}
11191105
arg = NULL;
11201106
continue;
@@ -1448,7 +1434,7 @@ stmt_eval_func (sh_stmt_t * stmt, sh_bc_oper_t * bc_oper, char ** bc_ptr)
14481434
LOCAL sh_errcode_t ICACHE_FLASH_ATTR
14491435
stmt_eval_foper (sh_stmt_t * stmt, sh_bc_oper_t * bc_oper, char ** bc_ptr)
14501436
{
1451-
if ((bc_oper->arg_count != 2) || (bc_oper->arg_count != 1))
1437+
if ((bc_oper->arg_count != 2) && (bc_oper->arg_count != 1))
14521438
return SH_INTERNAL_ERROR;
14531439

14541440
sh_bc_arg_type_t arg_type;
@@ -1586,7 +1572,7 @@ stmt_eval (const sh_hndlr_t hstmt, sh_eval_ctx_t * ctx)
15861572
while (bc_ptr < ptr_max) {
15871573
sh_bc_oper_t *bc_oper_ptr = d_pointer_as (sh_bc_oper_t, bc_ptr);
15881574
sh_oper_desc_t *opdesc = &sh_oper_desc[bc_oper_ptr->optype];
1589-
os_printf ("%04x:\t%s%s\n", bc_ptr - (char *) stmt->vardata, opdesc->token, opdesc->term);
1575+
os_printf ("%04x:\t%s%s %u\n", bc_ptr - (char *) stmt->vardata, opdesc->token, opdesc->term, bc_oper_ptr->arg_count);
15901576

15911577
bc_ptr += sizeof (sh_bc_oper_t);
15921578
if (bc_ptr > ptr_max)

0 commit comments

Comments
 (0)