diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-21 23:01:26 +0100 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-21 23:01:26 +0100 |
| commit | 24e41946355a77b97b43bc64a2a9861c0185f88a (patch) | |
| tree | 0213dc2a5c00dece4f2d2a82fcc3b07ffef710d4 /miscutils | |
| parent | 8287b1c869564ad90c0b8fac64551bfef4f6eee0 (diff) | |
| download | busybox-w32-24e41946355a77b97b43bc64a2a9861c0185f88a.tar.gz busybox-w32-24e41946355a77b97b43bc64a2a9861c0185f88a.tar.bz2 busybox-w32-24e41946355a77b97b43bc64a2a9861c0185f88a.zip | |
bc: rename BcInstPtr::idx and ::len
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'miscutils')
| -rw-r--r-- | miscutils/bc.c | 57 |
1 files changed, 28 insertions, 29 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c index cf620f8ec..2ba530d43 100644 --- a/miscutils/bc.c +++ b/miscutils/bc.c | |||
| @@ -388,8 +388,8 @@ typedef struct BcResult { | |||
| 388 | 388 | ||
| 389 | typedef struct BcInstPtr { | 389 | typedef struct BcInstPtr { |
| 390 | size_t func; | 390 | size_t func; |
| 391 | size_t idx; | 391 | size_t inst_idx; |
| 392 | IF_BC(size_t len;) | 392 | IF_BC(size_t results_len_before_call;) |
| 393 | } BcInstPtr; | 393 | } BcInstPtr; |
| 394 | 394 | ||
| 395 | // BC_LEX_NEG is not used in lexing; it is only for parsing. | 395 | // BC_LEX_NEG is not used in lexing; it is only for parsing. |
| @@ -3600,7 +3600,7 @@ static void bc_program_reset(void) | |||
| 3600 | 3600 | ||
| 3601 | f = bc_program_func_BC_PROG_MAIN(); | 3601 | f = bc_program_func_BC_PROG_MAIN(); |
| 3602 | ip = bc_vec_top(&G.prog.exestack); | 3602 | ip = bc_vec_top(&G.prog.exestack); |
| 3603 | ip->idx = f->code.len; | 3603 | ip->inst_idx = f->code.len; |
| 3604 | } | 3604 | } |
| 3605 | 3605 | ||
| 3606 | // Called when zbc/zdc_parse_parse() detects a failure, | 3606 | // Called when zbc/zdc_parse_parse() detects a failure, |
| @@ -5252,8 +5252,8 @@ static BC_STATUS zbc_program_read(void) | |||
| 5252 | } | 5252 | } |
| 5253 | 5253 | ||
| 5254 | ip.func = BC_PROG_READ; | 5254 | ip.func = BC_PROG_READ; |
| 5255 | ip.idx = 0; | 5255 | ip.inst_idx = 0; |
| 5256 | IF_BC(ip.len = G.prog.results.len;) | 5256 | IF_BC(ip.results_len_before_call = G.prog.results.len;) |
| 5257 | 5257 | ||
| 5258 | // Update this pointer, just in case. | 5258 | // Update this pointer, just in case. |
| 5259 | f = bc_program_func(BC_PROG_READ); | 5259 | f = bc_program_func(BC_PROG_READ); |
| @@ -5945,7 +5945,7 @@ static BC_STATUS zbc_program_call(char *code, size_t *idx) | |||
| 5945 | BcResult *arg; | 5945 | BcResult *arg; |
| 5946 | 5946 | ||
| 5947 | nparams = bc_program_index(code, idx); | 5947 | nparams = bc_program_index(code, idx); |
| 5948 | ip.idx = 0; | 5948 | ip.inst_idx = 0; |
| 5949 | ip.func = bc_program_index(code, idx); | 5949 | ip.func = bc_program_index(code, idx); |
| 5950 | func = bc_program_func(ip.func); | 5950 | func = bc_program_func(ip.func); |
| 5951 | 5951 | ||
| @@ -5955,7 +5955,7 @@ static BC_STATUS zbc_program_call(char *code, size_t *idx) | |||
| 5955 | if (nparams != func->nparams) { | 5955 | if (nparams != func->nparams) { |
| 5956 | RETURN_STATUS(bc_error_fmt("function has %u parameters, but called with %u", func->nparams, nparams)); | 5956 | RETURN_STATUS(bc_error_fmt("function has %u parameters, but called with %u", func->nparams, nparams)); |
| 5957 | } | 5957 | } |
| 5958 | ip.len = G.prog.results.len - nparams; | 5958 | ip.results_len_before_call = G.prog.results.len - nparams; |
| 5959 | 5959 | ||
| 5960 | for (i = 0; i < nparams; ++i) { | 5960 | for (i = 0; i < nparams; ++i) { |
| 5961 | BcStatus s; | 5961 | BcStatus s; |
| @@ -6000,7 +6000,7 @@ static BC_STATUS zbc_program_return(char inst) | |||
| 6000 | size_t i; | 6000 | size_t i; |
| 6001 | BcInstPtr *ip = bc_vec_top(&G.prog.exestack); | 6001 | BcInstPtr *ip = bc_vec_top(&G.prog.exestack); |
| 6002 | 6002 | ||
| 6003 | if (!STACK_HAS_EQUAL_OR_MORE_THAN(&G.prog.results, ip->len + (inst == BC_INST_RET))) | 6003 | if (!STACK_HAS_EQUAL_OR_MORE_THAN(&G.prog.results, ip->results_len_before_call + (inst == BC_INST_RET))) |
| 6004 | RETURN_STATUS(bc_error_stack_has_too_few_elements()); | 6004 | RETURN_STATUS(bc_error_stack_has_too_few_elements()); |
| 6005 | 6005 | ||
| 6006 | f = bc_program_func(ip->func); | 6006 | f = bc_program_func(ip->func); |
| @@ -6028,7 +6028,7 @@ static BC_STATUS zbc_program_return(char inst) | |||
| 6028 | bc_vec_pop(v); | 6028 | bc_vec_pop(v); |
| 6029 | } | 6029 | } |
| 6030 | 6030 | ||
| 6031 | bc_vec_npop(&G.prog.results, G.prog.results.len - ip->len); | 6031 | bc_vec_npop(&G.prog.results, G.prog.results.len - ip->results_len_before_call); |
| 6032 | bc_vec_push(&G.prog.results, &res); | 6032 | bc_vec_push(&G.prog.results, &res); |
| 6033 | bc_vec_pop(&G.prog.exestack); | 6033 | bc_vec_pop(&G.prog.exestack); |
| 6034 | 6034 | ||
| @@ -6391,8 +6391,7 @@ static BC_STATUS zdc_program_execStr(char *code, size_t *bgn, bool cond) | |||
| 6391 | bc_parse_free(&prs); | 6391 | bc_parse_free(&prs); |
| 6392 | } | 6392 | } |
| 6393 | 6393 | ||
| 6394 | ip.idx = 0; | 6394 | ip.inst_idx = 0; |
| 6395 | IF_BC(ip.len = G.prog.results.len;) | ||
| 6396 | ip.func = fidx; | 6395 | ip.func = fidx; |
| 6397 | 6396 | ||
| 6398 | bc_vec_pop(&G.prog.results); | 6397 | bc_vec_pop(&G.prog.results); |
| @@ -6433,12 +6432,12 @@ static BC_STATUS zbc_program_exec(void) | |||
| 6433 | char *code = func->code.v; | 6432 | char *code = func->code.v; |
| 6434 | 6433 | ||
| 6435 | dbg_exec("func:%zd bytes:%zd ip:%zd results.len:%d", | 6434 | dbg_exec("func:%zd bytes:%zd ip:%zd results.len:%d", |
| 6436 | ip->func, func->code.len, ip->idx, G.prog.results.len); | 6435 | ip->func, func->code.len, ip->inst_idx, G.prog.results.len); |
| 6437 | while (ip->idx < func->code.len) { | 6436 | while (ip->inst_idx < func->code.len) { |
| 6438 | BcStatus s = BC_STATUS_SUCCESS; | 6437 | BcStatus s = BC_STATUS_SUCCESS; |
| 6439 | char inst = code[ip->idx++]; | 6438 | char inst = code[ip->inst_idx++]; |
| 6440 | 6439 | ||
| 6441 | dbg_exec("inst at %zd:%d results.len:%d", ip->idx - 1, inst, G.prog.results.len); | 6440 | dbg_exec("inst at %zd:%d results.len:%d", ip->inst_idx - 1, inst, G.prog.results.len); |
| 6442 | switch (inst) { | 6441 | switch (inst) { |
| 6443 | #if ENABLE_BC | 6442 | #if ENABLE_BC |
| 6444 | case BC_INST_JUMP_ZERO: { | 6443 | case BC_INST_JUMP_ZERO: { |
| @@ -6449,21 +6448,21 @@ static BC_STATUS zbc_program_exec(void) | |||
| 6449 | zero = (bc_num_cmp(num, &G.prog.zero) == 0); | 6448 | zero = (bc_num_cmp(num, &G.prog.zero) == 0); |
| 6450 | bc_vec_pop(&G.prog.results); | 6449 | bc_vec_pop(&G.prog.results); |
| 6451 | if (!zero) { | 6450 | if (!zero) { |
| 6452 | bc_program_index(code, &ip->idx); | 6451 | bc_program_index(code, &ip->inst_idx); |
| 6453 | break; | 6452 | break; |
| 6454 | } | 6453 | } |
| 6455 | // else: fall through | 6454 | // else: fall through |
| 6456 | } | 6455 | } |
| 6457 | case BC_INST_JUMP: { | 6456 | case BC_INST_JUMP: { |
| 6458 | size_t idx = bc_program_index(code, &ip->idx); | 6457 | size_t idx = bc_program_index(code, &ip->inst_idx); |
| 6459 | size_t *addr = bc_vec_item(&func->labels, idx); | 6458 | size_t *addr = bc_vec_item(&func->labels, idx); |
| 6460 | dbg_exec("BC_INST_JUMP: to %ld", (long)*addr); | 6459 | dbg_exec("BC_INST_JUMP: to %ld", (long)*addr); |
| 6461 | ip->idx = *addr; | 6460 | ip->inst_idx = *addr; |
| 6462 | break; | 6461 | break; |
| 6463 | } | 6462 | } |
| 6464 | case BC_INST_CALL: | 6463 | case BC_INST_CALL: |
| 6465 | dbg_exec("BC_INST_CALL:"); | 6464 | dbg_exec("BC_INST_CALL:"); |
| 6466 | s = zbc_program_call(code, &ip->idx); | 6465 | s = zbc_program_call(code, &ip->inst_idx); |
| 6467 | goto read_updated_ip; | 6466 | goto read_updated_ip; |
| 6468 | case BC_INST_INC_PRE: | 6467 | case BC_INST_INC_PRE: |
| 6469 | case BC_INST_DEC_PRE: | 6468 | case BC_INST_DEC_PRE: |
| @@ -6499,12 +6498,12 @@ static BC_STATUS zbc_program_exec(void) | |||
| 6499 | goto read_updated_ip; | 6498 | goto read_updated_ip; |
| 6500 | case BC_INST_VAR: | 6499 | case BC_INST_VAR: |
| 6501 | dbg_exec("BC_INST_VAR:"); | 6500 | dbg_exec("BC_INST_VAR:"); |
| 6502 | s = zbc_program_pushVar(code, &ip->idx, false, false); | 6501 | s = zbc_program_pushVar(code, &ip->inst_idx, false, false); |
| 6503 | break; | 6502 | break; |
| 6504 | case BC_INST_ARRAY_ELEM: | 6503 | case BC_INST_ARRAY_ELEM: |
| 6505 | case BC_INST_ARRAY: | 6504 | case BC_INST_ARRAY: |
| 6506 | dbg_exec("BC_INST_ARRAY[_ELEM]:"); | 6505 | dbg_exec("BC_INST_ARRAY[_ELEM]:"); |
| 6507 | s = zbc_program_pushArray(code, &ip->idx, inst); | 6506 | s = zbc_program_pushArray(code, &ip->inst_idx, inst); |
| 6508 | break; | 6507 | break; |
| 6509 | case BC_INST_LAST: | 6508 | case BC_INST_LAST: |
| 6510 | r.t = BC_RESULT_LAST; | 6509 | r.t = BC_RESULT_LAST; |
| @@ -6524,7 +6523,7 @@ static BC_STATUS zbc_program_exec(void) | |||
| 6524 | case BC_INST_NUM: | 6523 | case BC_INST_NUM: |
| 6525 | dbg_exec("BC_INST_NUM:"); | 6524 | dbg_exec("BC_INST_NUM:"); |
| 6526 | r.t = BC_RESULT_CONSTANT; | 6525 | r.t = BC_RESULT_CONSTANT; |
| 6527 | r.d.id.idx = bc_program_index(code, &ip->idx); | 6526 | r.d.id.idx = bc_program_index(code, &ip->inst_idx); |
| 6528 | bc_vec_push(&G.prog.results, &r); | 6527 | bc_vec_push(&G.prog.results, &r); |
| 6529 | break; | 6528 | break; |
| 6530 | case BC_INST_POP: | 6529 | case BC_INST_POP: |
| @@ -6547,7 +6546,7 @@ static BC_STATUS zbc_program_exec(void) | |||
| 6547 | case BC_INST_STR: | 6546 | case BC_INST_STR: |
| 6548 | dbg_exec("BC_INST_STR:"); | 6547 | dbg_exec("BC_INST_STR:"); |
| 6549 | r.t = BC_RESULT_STR; | 6548 | r.t = BC_RESULT_STR; |
| 6550 | r.d.id.idx = bc_program_index(code, &ip->idx); | 6549 | r.d.id.idx = bc_program_index(code, &ip->inst_idx); |
| 6551 | bc_vec_push(&G.prog.results, &r); | 6550 | bc_vec_push(&G.prog.results, &r); |
| 6552 | break; | 6551 | break; |
| 6553 | case BC_INST_POWER: | 6552 | case BC_INST_POWER: |
| @@ -6594,7 +6593,7 @@ static BC_STATUS zbc_program_exec(void) | |||
| 6594 | break; | 6593 | break; |
| 6595 | case BC_INST_EXECUTE: | 6594 | case BC_INST_EXECUTE: |
| 6596 | case BC_INST_EXEC_COND: | 6595 | case BC_INST_EXEC_COND: |
| 6597 | s = zdc_program_execStr(code, &ip->idx, inst == BC_INST_EXEC_COND); | 6596 | s = zdc_program_execStr(code, &ip->inst_idx, inst == BC_INST_EXEC_COND); |
| 6598 | goto read_updated_ip; | 6597 | goto read_updated_ip; |
| 6599 | case BC_INST_PRINT_STACK: { | 6598 | case BC_INST_PRINT_STACK: { |
| 6600 | size_t idx; | 6599 | size_t idx; |
| @@ -6637,11 +6636,11 @@ static BC_STATUS zbc_program_exec(void) | |||
| 6637 | case BC_INST_LOAD: | 6636 | case BC_INST_LOAD: |
| 6638 | case BC_INST_PUSH_VAR: { | 6637 | case BC_INST_PUSH_VAR: { |
| 6639 | bool copy = inst == BC_INST_LOAD; | 6638 | bool copy = inst == BC_INST_LOAD; |
| 6640 | s = zbc_program_pushVar(code, &ip->idx, true, copy); | 6639 | s = zbc_program_pushVar(code, &ip->inst_idx, true, copy); |
| 6641 | break; | 6640 | break; |
| 6642 | } | 6641 | } |
| 6643 | case BC_INST_PUSH_TO_VAR: { | 6642 | case BC_INST_PUSH_TO_VAR: { |
| 6644 | char *name = bc_program_name(code, &ip->idx); | 6643 | char *name = bc_program_name(code, &ip->inst_idx); |
| 6645 | s = zbc_program_copyToVar(name, true); | 6644 | s = zbc_program_copyToVar(name, true); |
| 6646 | free(name); | 6645 | free(name); |
| 6647 | break; | 6646 | break; |
| @@ -6661,7 +6660,7 @@ static BC_STATUS zbc_program_exec(void) | |||
| 6661 | ip = bc_vec_top(&G.prog.exestack); | 6660 | ip = bc_vec_top(&G.prog.exestack); |
| 6662 | func = bc_program_func(ip->func); | 6661 | func = bc_program_func(ip->func); |
| 6663 | code = func->code.v; | 6662 | code = func->code.v; |
| 6664 | dbg_exec("func:%zd bytes:%zd ip:%zd", ip->func, func->code.len, ip->idx); | 6663 | dbg_exec("func:%zd bytes:%zd ip:%zd", ip->func, func->code.len, ip->inst_idx); |
| 6665 | } | 6664 | } |
| 6666 | 6665 | ||
| 6667 | if (s || G_interrupt) { | 6666 | if (s || G_interrupt) { |
| @@ -6731,11 +6730,11 @@ static BC_STATUS zbc_vm_process(const char *text) | |||
| 6731 | if (ip->func != BC_PROG_MAIN) | 6730 | if (ip->func != BC_PROG_MAIN) |
| 6732 | bb_error_msg_and_die("BUG:not MAIN"); | 6731 | bb_error_msg_and_die("BUG:not MAIN"); |
| 6733 | #endif | 6732 | #endif |
| 6734 | //bb_error_msg("ip->func:%d >idx:%d >len:%d", ip->func, ip->idx, ip->len); | 6733 | //bb_error_msg("ip->func:%d >idx:%d >len:%d", ip->func, ip->inst_idx, ip->len); |
| 6735 | f = bc_program_func_BC_PROG_MAIN(); | 6734 | f = bc_program_func_BC_PROG_MAIN(); |
| 6736 | //bb_error_msg("MAIN->code.len:%d >strs.len:%d >consts.len:%d", f->code.len, f->strs.len, f->consts.len); // labels, autos, nparams | 6735 | //bb_error_msg("MAIN->code.len:%d >strs.len:%d >consts.len:%d", f->code.len, f->strs.len, f->consts.len); // labels, autos, nparams |
| 6737 | bc_vec_pop_all(&f->code); | 6736 | bc_vec_pop_all(&f->code); |
| 6738 | ip->idx = 0; | 6737 | ip->inst_idx = 0; |
| 6739 | IF_BC(bc_vec_pop_all(&f->strs);) | 6738 | IF_BC(bc_vec_pop_all(&f->strs);) |
| 6740 | IF_BC(bc_vec_pop_all(&f->consts);) | 6739 | IF_BC(bc_vec_pop_all(&f->consts);) |
| 6741 | } | 6740 | } |
