version 1.31, 2006/01/15 19:11:59 |
version 1.32, 2006/01/15 19:14:40 |
|
|
static int |
static int |
readreg(void) |
readreg(void) |
{ |
{ |
int index, ch1, ch2; |
int idx, ch1, ch2; |
|
|
index = readch(); |
idx = readch(); |
if (index == 0xff && bmachine.extended_regs) { |
if (idx == 0xff && bmachine.extended_regs) { |
ch1 = readch(); |
ch1 = readch(); |
ch2 = readch(); |
ch2 = readch(); |
if (ch1 == EOF || ch2 == EOF) { |
if (ch1 == EOF || ch2 == EOF) { |
warnx("unexpected eof"); |
warnx("unexpected eof"); |
index = -1; |
idx = -1; |
} else |
} else |
index = (ch1 << 8) + ch2 + UCHAR_MAX + 1; |
idx = (ch1 << 8) + ch2 + UCHAR_MAX + 1; |
} |
} |
if (index < 0 || index >= bmachine.reg_array_size) { |
if (idx < 0 || idx >= bmachine.reg_array_size) { |
warnx("internal error: reg num = %d", index); |
warnx("internal error: reg num = %d", idx); |
index = -1; |
idx = -1; |
} |
} |
return index; |
return idx; |
} |
} |
|
|
static void |
static void |
load(void) |
load(void) |
{ |
{ |
int index; |
int idx; |
struct value *v, copy; |
struct value *v, copy; |
struct number *n; |
struct number *n; |
|
|
index = readreg(); |
idx = readreg(); |
if (index >= 0) { |
if (idx >= 0) { |
v = stack_tos(&bmachine.reg[index]); |
v = stack_tos(&bmachine.reg[idx]); |
if (v == NULL) { |
if (v == NULL) { |
n = new_number(); |
n = new_number(); |
bn_check(BN_zero(n->number)); |
bn_check(BN_zero(n->number)); |
|
|
static void |
static void |
store(void) |
store(void) |
{ |
{ |
int index; |
int idx; |
struct value *val; |
struct value *val; |
|
|
index = readreg(); |
idx = readreg(); |
if (index >= 0) { |
if (idx >= 0) { |
val = pop(); |
val = pop(); |
if (val == NULL) { |
if (val == NULL) { |
return; |
return; |
} |
} |
stack_set_tos(&bmachine.reg[index], val); |
stack_set_tos(&bmachine.reg[idx], val); |
} |
} |
} |
} |
|
|
static void |
static void |
load_stack(void) |
load_stack(void) |
{ |
{ |
int index; |
int idx; |
struct stack *stack; |
struct stack *stack; |
struct value *value, copy; |
struct value *value, copy; |
|
|
index = readreg(); |
idx = readreg(); |
if (index >= 0) { |
if (idx >= 0) { |
stack = &bmachine.reg[index]; |
stack = &bmachine.reg[idx]; |
value = NULL; |
value = NULL; |
if (stack_size(stack) > 0) { |
if (stack_size(stack) > 0) { |
value = stack_pop(stack); |
value = stack_pop(stack); |
|
|
push(stack_dup_value(value, ©)); |
push(stack_dup_value(value, ©)); |
else |
else |
warnx("stack register '%c' (0%o) is empty", |
warnx("stack register '%c' (0%o) is empty", |
index, index); |
idx, idx); |
} |
} |
} |
} |
|
|
static void |
static void |
store_stack(void) |
store_stack(void) |
{ |
{ |
int index; |
int idx; |
struct value *value; |
struct value *value; |
|
|
index = readreg(); |
idx = readreg(); |
if (index >= 0) { |
if (idx >= 0) { |
value = pop(); |
value = pop(); |
if (value == NULL) |
if (value == NULL) |
return; |
return; |
stack_push(&bmachine.reg[index], value); |
stack_push(&bmachine.reg[idx], value); |
} |
} |
} |
} |
|
|
|
|
{ |
{ |
int reg; |
int reg; |
struct number *inumber, *n; |
struct number *inumber, *n; |
u_long index; |
u_long idx; |
struct stack *stack; |
struct stack *stack; |
struct value *v, copy; |
struct value *v, copy; |
|
|
|
|
inumber = pop_number(); |
inumber = pop_number(); |
if (inumber == NULL) |
if (inumber == NULL) |
return; |
return; |
index = get_ulong(inumber); |
idx = get_ulong(inumber); |
if (BN_cmp(inumber->number, &zero) < 0) |
if (BN_cmp(inumber->number, &zero) < 0) |
warnx("negative index"); |
warnx("negative idx"); |
else if (index == BN_MASK2 || index > MAX_ARRAY_INDEX) |
else if (idx == BN_MASK2 || idx > MAX_ARRAY_INDEX) |
warnx("index too big"); |
warnx("idx too big"); |
else { |
else { |
stack = &bmachine.reg[reg]; |
stack = &bmachine.reg[reg]; |
v = frame_retrieve(stack, index); |
v = frame_retrieve(stack, idx); |
if (v == NULL) { |
if (v == NULL) { |
n = new_number(); |
n = new_number(); |
bn_check(BN_zero(n->number)); |
bn_check(BN_zero(n->number)); |
|
|
{ |
{ |
int reg; |
int reg; |
struct number *inumber; |
struct number *inumber; |
u_long index; |
u_long idx; |
struct value *value; |
struct value *value; |
struct stack *stack; |
struct stack *stack; |
|
|
|
|
free_number(inumber); |
free_number(inumber); |
return; |
return; |
} |
} |
index = get_ulong(inumber); |
idx = get_ulong(inumber); |
if (BN_cmp(inumber->number, &zero) < 0) { |
if (BN_cmp(inumber->number, &zero) < 0) { |
warnx("negative index"); |
warnx("negative idx"); |
stack_free_value(value); |
stack_free_value(value); |
} else if (index == BN_MASK2 || index > MAX_ARRAY_INDEX) { |
} else if (idx == BN_MASK2 || idx > MAX_ARRAY_INDEX) { |
warnx("index too big"); |
warnx("idx too big"); |
stack_free_value(value); |
stack_free_value(value); |
} else { |
} else { |
stack = &bmachine.reg[reg]; |
stack = &bmachine.reg[reg]; |
frame_assign(stack, index, value); |
frame_assign(stack, idx, value); |
} |
} |
free_number(inumber); |
free_number(inumber); |
} |
} |
|
|
static void |
static void |
compare(enum bcode_compare type) |
compare(enum bcode_compare type) |
{ |
{ |
int index, elseindex; |
int idx, elseidx; |
struct number *a, *b; |
struct number *a, *b; |
bool ok; |
bool ok; |
struct value *v; |
struct value *v; |
|
|
elseindex = NO_ELSE; |
elseidx = NO_ELSE; |
index = readreg(); |
idx = readreg(); |
if (readch() == 'e') |
if (readch() == 'e') |
elseindex = readreg(); |
elseidx = readreg(); |
else |
else |
unreadch(); |
unreadch(); |
|
|
|
|
|
|
ok = compare_numbers(type, a, b); |
ok = compare_numbers(type, a, b); |
|
|
if (!ok && elseindex != NO_ELSE) |
if (!ok && elseidx != NO_ELSE) |
index = elseindex; |
idx = elseidx; |
|
|
if (index >= 0 && (ok || (!ok && elseindex != NO_ELSE))) { |
if (idx >= 0 && (ok || (!ok && elseidx != NO_ELSE))) { |
v = stack_tos(&bmachine.reg[index]); |
v = stack_tos(&bmachine.reg[idx]); |
if (v == NULL) |
if (v == NULL) |
warnx("register '%c' (0%o) is empty", index, index); |
warnx("register '%c' (0%o) is empty", idx, idx); |
else { |
else { |
switch(v->type) { |
switch(v->type) { |
case BCODE_NONE: |
case BCODE_NONE: |
warnx("register '%c' (0%o) is empty", |
warnx("register '%c' (0%o) is empty", idx, idx); |
index, index); |
|
break; |
break; |
case BCODE_NUMBER: |
case BCODE_NUMBER: |
warn("eval called with non-string argument"); |
warn("eval called with non-string argument"); |