mirror of
https://codeberg.org/scip/rpnc.git
synced 2025-12-17 12:31:04 +01:00
fix stack pop order, added stack2collector mode, fixed bit funcs
This commit is contained in:
81
rpnc
81
rpnc
@@ -70,7 +70,7 @@ my %commands = (
|
|||||||
srt => sub { rotatestack(); },
|
srt => sub { rotatestack(); },
|
||||||
# collector
|
# collector
|
||||||
'(' => sub { $sub = 1 },
|
'(' => sub { $sub = 1 },
|
||||||
')' => sub { $sub = 0 },
|
')' => sub { stack2sub(); },
|
||||||
# register stuff
|
# register stuff
|
||||||
r => sub { last_to_reg(); dumpstack(); },
|
r => sub { last_to_reg(); dumpstack(); },
|
||||||
rcx => sub { clearreg(1); dumpstack(); },
|
rcx => sub { clearreg(1); dumpstack(); },
|
||||||
@@ -178,29 +178,6 @@ my %func = (
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
'x' => sub {
|
|
||||||
# XOR
|
|
||||||
my ($a, $b) = getlast(2);
|
|
||||||
if (defined $b) {
|
|
||||||
return "$a ^ $b";
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
'|' => sub {
|
|
||||||
# OR
|
|
||||||
my ($a, $b) = getlast(2);
|
|
||||||
if (defined $b) {
|
|
||||||
return "$a | $b";
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
'|' => sub {
|
|
||||||
# XOR
|
|
||||||
my ($a, $b) = getlast(2);
|
|
||||||
if (defined $b) {
|
|
||||||
return "$a ^ $b";
|
|
||||||
}
|
|
||||||
},
|
|
||||||
# converters:
|
# converters:
|
||||||
# gallons to liters
|
# gallons to liters
|
||||||
'tl' => sub { return convert("* 3.785") },
|
'tl' => sub { return convert("* 3.785") },
|
||||||
@@ -441,20 +418,13 @@ sub getlast {
|
|||||||
if (scalar @stack == 1) {
|
if (scalar @stack == 1) {
|
||||||
if ($request > 1) {
|
if ($request > 1) {
|
||||||
print "At least $request variables must be on the stack!\n";
|
print "At least $request variables must be on the stack!\n";
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@all = pop @stack;
|
@all = pop @stack;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
elsif (scalar @stack >= 2) {
|
||||||
if ($request == 1) {
|
@all = splice(@stack, -1 * $request, $request);
|
||||||
@all = pop @stack;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
# return 2 elements, as we do not support more than 2 anyway
|
|
||||||
@all = reverse (pop @stack, pop @stack);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -507,6 +477,20 @@ sub clearreg {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub stack2sub {
|
||||||
|
if (! $sub && scalar @substack == 0 && scalar @stack > 1) {
|
||||||
|
# not in collector mode, empty substack, move stack to substack, enter collect
|
||||||
|
backup();
|
||||||
|
@substack = @stack;
|
||||||
|
@stack = ();
|
||||||
|
$sub = 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
# leave collector mode
|
||||||
|
$sub = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sub prompt {
|
sub prompt {
|
||||||
my $count;
|
my $count;
|
||||||
my $prompt;
|
my $prompt;
|
||||||
@@ -653,21 +637,22 @@ If <operator> is provided, read numbers from STDIN,
|
|||||||
otherwise runs interactively.
|
otherwise runs interactively.
|
||||||
|
|
||||||
Configure: Available math operators:
|
Configure: Available math operators:
|
||||||
td toggle debugging (-d) ( enter collect mode
|
td toggle debugging (-d) ( enter collect mode
|
||||||
ts toggle display of stack (-n) ) leave collect mode
|
ts toggle display of stack (-n) ) leave collect || stack => collect
|
||||||
+ add
|
+ add
|
||||||
Stack Management: - substract
|
Stack Management: - substract
|
||||||
s show the stack / divide
|
s show the stack / divide
|
||||||
sa show the whole stack * multiply
|
sa show the whole stack * multiply
|
||||||
scx clear X (last stack element) ^ expotentiate
|
scx clear X (last stack element) ^ expotentiate
|
||||||
sc clear stack % percent (%+ add %- substract)
|
sc clear stack % percent (%+ add %- substract)
|
||||||
sr reverse the stack %d percentual difference
|
sr reverse the stack %d percentual difference
|
||||||
srt rotate the stack & bitwise AND
|
srt rotate the stack & bitwise AND
|
||||||
| bitwise OR
|
| bitwise OR
|
||||||
Register Management: x bitwise XOR
|
Register Management: x bitwise XOR
|
||||||
r put X to register v square root
|
r put X to register < > bitwise shift left or right
|
||||||
rcx clear X (last register element) m median
|
R1-9 push value of register to stack v square root
|
||||||
rc clear register a average
|
rcx clear X (last register element) m median
|
||||||
|
rc clear register a average
|
||||||
|
|
||||||
Converters:
|
Converters:
|
||||||
tl gallons => liters tkb bytes => kb
|
tl gallons => liters tkb bytes => kb
|
||||||
|
|||||||
Reference in New Issue
Block a user