@@ -196,7 +196,6 @@ sh_forall_func_find (void *ptr, void *data)
196
196
{
197
197
sh_func_entry_t * entry = d_pointer_as (sh_func_entry_t , ptr );
198
198
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 );
200
199
if (os_strncmp (entry -> func_name , find_ctx -> func_name , sizeof (sh_func_name_t )) == 0 ) {
201
200
find_ctx -> entry = entry ;
202
201
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
515
514
bytecode_size_t * vptr = d_pointer_as (bytecode_size_t , & arg_ptr -> data );
516
515
* vptr = d_pointer_diff (bc_oper , ctx -> bc_buf );
517
516
* 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 );
518
519
d_log_dprintf (LSH_SERVICE_NAME , "bc_set_pointer_arg: arg_addr=%p, vptr=%04x, bufptr=%p" , arg_ptr , * vptr ,
519
520
* pbuf_ptr );
520
521
}
@@ -530,22 +531,20 @@ bc_global_add (sh_parse_arg_t * arg, sh_parse_arg_type_t type, sh_gvar_t ** gadd
530
531
{
531
532
sh_gvar_t * gvar ;
532
533
* gaddr = NULL ;
533
- os_printf ("-- 24.1\n" );
534
534
if (ih_hash8_search (sdata -> token_idx , arg -> data , arg -> length - 1 , (char * * ) & gvar ) == IH_ENTRY_NOTFOUND ) {
535
- os_printf ("-- 24.2\n" );
536
535
ih_hash8_add (sdata -> token_idx , arg -> data , arg -> length - 1 , (char * * ) & gvar );
537
536
gvar -> type = type ;
538
537
gvar -> use_count = 1 ;
539
538
540
- os_printf ("-- 24.3\n" );
541
539
switch (type ) {
542
540
case SH_ARG_FUNC :
543
541
gvar -> arg .arg .ptr = 0 ;
544
542
break ;
545
543
default :
546
544
gvar -> arg .arg .value = 0 ;
547
545
}
548
- os_printf ("-- 24.4\n" );
546
+ os_printf ("-- bc_global_add: token=%s, addr=%p\n" , arg -> data , gvar );
547
+
549
548
d_log_dprintf (LSH_SERVICE_NAME , "bc_global_add: token=%s, addr=%p" , arg -> data , gvar );
550
549
}
551
550
else
@@ -567,7 +566,7 @@ LOCAL sh_errcode_t ICACHE_FLASH_ATTR
567
566
bc_serialize_arg (sh_parse_ctx_t * ctx , char * * bc_ptr , sh_bc_oper_t * bc_oper , sh_parse_arg_t * arg , uint8 * bytepos )
568
567
{
569
568
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 );
571
570
d_bc_buffer_alloc (ctx , bc_ptr , sizeof (sh_bc_arg_t ));
572
571
573
572
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
595
594
break ;
596
595
case SH_ARG_FUNC :
597
596
{
598
- os_printf ("-- 23.2 %p\n" , arg );
599
597
sh_gvar_t * gaddr ;
600
598
sh_errcode_t err = bc_global_add (arg , SH_ARG_FUNC , & gaddr );
601
- os_printf ("-- 23.3\n" );
602
599
if (err != SH_ERR_SUCCESS )
603
600
d_stmt_err_ret (ctx , err );
604
601
bc_arg -> arg .ptr = gaddr ;
605
602
bc_oper -> bitmask |= (0x3 << * bytepos );
606
603
(* bytepos )++ ;
607
- os_printf ("-- 23.4\n" );
608
604
break ;
609
605
}
610
606
case SH_ARG_POINTER :
611
607
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 );
612
609
bc_oper -> bitmask |= (0x3 << * bytepos );
613
610
(* bytepos )++ ;
614
611
break ;
@@ -617,8 +614,6 @@ bc_serialize_arg (sh_parse_ctx_t * ctx, char **bc_ptr, sh_bc_oper_t * bc_oper, s
617
614
}
618
615
(* bytepos )++ ;
619
616
620
- os_printf ("-- 23.5\n" );
621
-
622
617
return SH_ERR_SUCCESS ;
623
618
}
624
619
@@ -635,6 +630,9 @@ bc_serialize_oper_header (sh_parse_ctx_t * ctx, char **bc_ptr, sh_oper_type_t op
635
630
{
636
631
sh_bc_oper_t * bc_oper_ptr = d_pointer_as (sh_bc_oper_t , * bc_ptr );
637
632
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 );
638
636
d_log_dprintf (LSH_SERVICE_NAME , "bc_serialize_ophdr: depth=%u, addr=%04x, " OD2T_STR " , args=%u" , ctx -> depth ,
639
637
* bc_ptr - ctx -> bc_buf , OD2T (opdesc ), arg_count );
640
638
@@ -666,23 +664,29 @@ INLINED sh_errcode_t ICACHE_FLASH_ATTR
666
664
bc_serialize_oper_ctl (sh_parse_ctx_t * ctx , char * * bc_ptr , char * * pbuf_ptr , sh_parse_arg_t * * arg ,
667
665
sh_oper_type_t optype )
668
666
{
667
+ os_printf ("-- serialize_oper_ctl: depth=%u, addr=%04x, optype=%u\n" , ctx -> depth ,
668
+ * bc_ptr - ctx -> bc_buf , optype );
669
+
669
670
d_log_dprintf (LSH_SERVICE_NAME , "serialize_oper_ctl: depth=%u, addr=%04x, optype=%u" , ctx -> depth ,
670
671
* bc_ptr - ctx -> bc_buf , optype );
671
672
sh_bc_oper_t * bc_oper_ptr ;
672
673
uint8 bytepos = 0 ;
673
674
bc_serialize_oper_header (ctx , bc_ptr , optype , 2 , & bc_oper_ptr , & bytepos );
674
675
d_stmt_check_err (ctx );
675
676
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
+
676
682
// jump arg
677
683
bc_oper_ptr -> bitmask |= (0x3 << bytepos );
678
684
bytepos += 2 ;
679
685
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 ));
680
687
d_bc_buffer_alloc (ctx , bc_ptr , sizeof (sh_bc_arg_t ));
681
688
bc_arg -> arg .ptr = 0 ;
682
689
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 );
686
690
// set left_arg pointer to bc_oper jump arg
687
691
bc_set_pointer_arg (ctx , pbuf_ptr , bc_oper_ptr , arg );
688
692
@@ -749,31 +753,26 @@ bc_serialize_foper (sh_parse_ctx_t * ctx, char **bc_ptr, sh_parse_oper_t * oper,
749
753
{
750
754
sh_bc_oper_t * bc_oper_ptr ;
751
755
uint8 bytepos = 0 ;
752
- os_printf ("-- 22.1\n" );
753
756
bc_serialize_oper_header (ctx , bc_ptr , oper -> optype , oper -> arg_count , & bc_oper_ptr , & bytepos );
754
757
d_stmt_check_err (ctx );
755
758
756
759
arg_count_t arg_idx = 0 ;
757
- os_printf ("-- 22.2\n" );
758
760
if (oper -> left_arg ) {
759
761
bc_serialize_arg (ctx , bc_ptr , bc_oper_ptr , oper -> left_arg , & bytepos );
760
762
d_stmt_check_err (ctx );
761
763
arg_idx ++ ;
762
764
}
763
765
764
- os_printf ("-- 22.3\n" );
765
766
sh_parse_arg_t * arg_ptr = d_pointer_as (sh_parse_arg_t , oper -> varargs );
766
767
while (arg_idx < oper -> arg_count ) {
767
768
if (arg_ptr -> type != SH_ARG_NONE ) {
768
- os_printf ("-- 22.4\n" );
769
769
bc_serialize_arg (ctx , bc_ptr , bc_oper_ptr , arg_ptr , & bytepos );
770
770
d_stmt_check_err (ctx );
771
771
arg_idx ++ ;
772
772
}
773
773
arg_ptr = d_pointer_add (sh_parse_arg_t , arg_ptr , sizeof (sh_parse_arg_t ) + d_align (arg_ptr -> length ));
774
774
}
775
775
* bc_oper = bc_oper_ptr ;
776
- os_printf ("-- 22.5\n" );
777
776
778
777
return SH_ERR_SUCCESS ;
779
778
}
@@ -842,7 +841,7 @@ bc_serialize_oper (sh_parse_ctx_t * ctx, char **bc_ptr, char **pbuf_ptr, sh_pars
842
841
return SH_ERR_SUCCESS ;
843
842
844
843
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 );
846
845
if (oper_tmp -> optype == SH_OPER_BLOCK ) {
847
846
uint8 bytepos ;
848
847
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
855
854
bc_arg -> arg .ptr = (void * ) d_pointer_diff (* bc_ptr , ctx -> bc_buf );
856
855
}
857
856
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 );
859
859
d_log_dprintf (LSH_SERVICE_NAME , "bc_serialize_oper: depth=%u, addr=%04x, " OP2T_STR " , args=%u" , ctx -> depth ,
860
860
* bc_ptr - ctx -> bc_buf , OP2T (ctx , oper_tmp ), oper_tmp -> arg_count );
861
861
if ((oper_tmp -> optype == SH_OPER_VAR ) || (oper_tmp -> optype == SH_OPER_GVAR )) {
862
- os_printf ("-- 21.5a\n" );
863
862
bc_serialize_var (ctx , bc_ptr , oper_tmp , & bc_oper_ptr );
864
863
}
865
864
else {
866
- os_printf ("-- 21.5b\n" );
867
865
bc_serialize_foper (ctx , bc_ptr , oper_tmp , & bc_oper_ptr );
868
866
}
869
- os_printf ("-- 21.6\n" );
870
867
d_stmt_check_err (ctx );
871
868
}
872
869
@@ -875,16 +872,13 @@ bc_serialize_oper (sh_parse_ctx_t * ctx, char **bc_ptr, char **pbuf_ptr, sh_pars
875
872
}
876
873
877
874
// pop oper and set left_arg pointer to bc_oper result
878
- os_printf ("-- 21.7\n" );
879
875
* oper = oper_tmp -> prev_oper ;
880
876
sh_parse_arg_t * arg_ptr = oper_tmp -> left_arg ;
881
877
if (!arg_ptr ) {
882
878
arg_ptr = d_pointer_as (sh_parse_arg_t , oper_tmp ); // write position
883
879
}
884
880
* arg = arg_ptr ;
885
- os_printf ("-- 21.8\n" );
886
881
bc_set_pointer_arg (ctx , pbuf_ptr , bc_oper_ptr , arg );
887
- os_printf ("-- 21.9\n" );
888
882
ctx -> depth -- ;
889
883
890
884
return SH_ERR_SUCCESS ;
@@ -1005,57 +999,46 @@ stmt_parse_arg (sh_parse_ctx_t * ctx, char **szstr, char **pbuf_ptr, sh_parse_op
1005
999
// Fixme: Check buffer length
1006
1000
sh_parse_arg_t * arg_ptr = d_pointer_as (sh_parse_arg_t , * pbuf_ptr );
1007
1001
1008
- os_printf ("-- 8.1 %u\n" , * pbuf_ptr - ctx -> parse_buf );
1009
1002
if (d_char_is_digit (* szstr )) {
1010
- os_printf ("-- 8.2\n" );
1011
1003
// constant number
1012
1004
arg_ptr -> type = SH_ARG_INT ;
1013
1005
arg_ptr -> length = sizeof (uint32 );
1014
1006
uint32 * value_uint = d_pointer_as (uint32 , & arg_ptr -> data );
1015
1007
1016
- os_printf ("-- 8.3 %p\n" , value_uint );
1017
1008
if (!parse_uint (szstr , value_uint )) {
1018
- os_printf ("-- 8.3 !\n" );
1019
1009
d_stmt_err_ret (ctx , SH_PARSE_ERROR_NUMINV , d_stmt_pos (ctx , * szstr ));
1020
1010
}
1021
- os_printf ("-- 8.4\n" );
1022
1011
1023
1012
d_log_dprintf (LSH_SERVICE_NAME , "parse_arg: depth=%d, pos=%d, num:%u" , ctx -> depth , (* szstr - ctx -> stmt_start ),
1024
1013
* value_uint );
1025
1014
}
1026
1015
else if (d_char_is_quote (* szstr )) {
1027
- os_printf ("-- 8.5\n" );
1028
1016
// constant string
1029
1017
arg_ptr -> type = SH_ARG_CHAR ;
1030
1018
estlen_qstr (szstr , (unsigned int * ) & arg_ptr -> length );
1031
1019
// null-terminate
1032
1020
arg_ptr -> data [arg_ptr -> length ] = '\0' ;
1033
1021
arg_ptr -> length ++ ;
1034
1022
1035
- os_printf ("-- 8.6\n" );
1036
1023
if (!parse_qstr (szstr , (char * ) arg_ptr -> data )) {
1037
1024
d_stmt_err_ret (ctx , SH_PARSE_ERROR_STRINV , d_stmt_pos (ctx , * szstr ));
1038
1025
}
1039
1026
1040
- os_printf ("-- 8.7\n" );
1041
1027
d_log_dprintf (LSH_SERVICE_NAME , "parse_arg: depth=%d, pos=%d, str:%s" , ctx -> depth , (* szstr - ctx -> stmt_start ),
1042
1028
arg_ptr -> data );
1043
1029
}
1044
1030
else if (d_char_is_token1 (* szstr )) {
1045
1031
// function | variable | extended operator | nested statement
1046
- os_printf ("-- 8.8\n" );
1047
1032
arg_ptr -> type = SH_ARG_TOKEN ;
1048
1033
estlen_token (szstr , (unsigned int * ) & arg_ptr -> length );
1049
1034
// null-terminate
1050
1035
arg_ptr -> data [arg_ptr -> length ] = '\0' ;
1051
1036
arg_ptr -> length ++ ;
1052
1037
1053
- os_printf ("-- 8.9\n" );
1054
1038
if (!parse_token (szstr , (char * ) arg_ptr -> data )) {
1055
1039
d_stmt_err_ret (ctx , SH_PARSE_ERROR_TOKENINV , d_stmt_pos (ctx , * szstr ));
1056
1040
}
1057
1041
1058
- os_printf ("-- 8.10\n" );
1059
1042
d_log_dprintf (LSH_SERVICE_NAME , "parse_arg: depth=%d, pos=%d, token:%s" , ctx -> depth ,
1060
1043
(* szstr - ctx -> stmt_start ), arg_ptr -> data );
1061
1044
}
@@ -1067,7 +1050,6 @@ stmt_parse_arg (sh_parse_ctx_t * ctx, char **szstr, char **pbuf_ptr, sh_parse_op
1067
1050
oper -> arg_count ++ ;
1068
1051
}
1069
1052
(* pbuf_ptr ) += sizeof (sh_parse_arg_t ) + d_align (arg_ptr -> length );
1070
- os_printf ("-- 8.11 %u\n" , * pbuf_ptr - ctx -> parse_buf );
1071
1053
* arg = arg_ptr ;
1072
1054
1073
1055
return SH_ERR_SUCCESS ;
@@ -1083,6 +1065,8 @@ stmt_parse_ext (sh_parse_ctx_t * ctx, char **szstr, char **bc_ptr, char **pbuf_p
1083
1065
while (* * szstr != '\0' ) {
1084
1066
char * ptr_start = * szstr ;
1085
1067
// check operator term
1068
+ os_printf ("-- 000 %p %c\n" , oper , * * szstr );
1069
+
1086
1070
d_skip_space (* szstr );
1087
1071
if ((ctx -> term_oper ) && (ctx -> term_oper -> term == * * szstr )) {
1088
1072
(* szstr )++ ;
@@ -1108,13 +1092,15 @@ stmt_parse_ext (sh_parse_ctx_t * ctx, char **szstr, char **bc_ptr, char **pbuf_p
1108
1092
ctx -> term_oper = oper2 ;
1109
1093
continue ;
1110
1094
}
1111
- else if (( * * szstr == ';' ) && oper ) { // default terminator
1095
+ else if (* * szstr == ';' ) {
1112
1096
(* 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
+ }
1118
1104
}
1119
1105
arg = NULL ;
1120
1106
continue ;
@@ -1448,7 +1434,7 @@ stmt_eval_func (sh_stmt_t * stmt, sh_bc_oper_t * bc_oper, char ** bc_ptr)
1448
1434
LOCAL sh_errcode_t ICACHE_FLASH_ATTR
1449
1435
stmt_eval_foper (sh_stmt_t * stmt , sh_bc_oper_t * bc_oper , char * * bc_ptr )
1450
1436
{
1451
- if ((bc_oper -> arg_count != 2 ) || (bc_oper -> arg_count != 1 ))
1437
+ if ((bc_oper -> arg_count != 2 ) && (bc_oper -> arg_count != 1 ))
1452
1438
return SH_INTERNAL_ERROR ;
1453
1439
1454
1440
sh_bc_arg_type_t arg_type ;
@@ -1586,7 +1572,7 @@ stmt_eval (const sh_hndlr_t hstmt, sh_eval_ctx_t * ctx)
1586
1572
while (bc_ptr < ptr_max ) {
1587
1573
sh_bc_oper_t * bc_oper_ptr = d_pointer_as (sh_bc_oper_t , bc_ptr );
1588
1574
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 );
1590
1576
1591
1577
bc_ptr += sizeof (sh_bc_oper_t );
1592
1578
if (bc_ptr > ptr_max )
0 commit comments