Skip to content

Commit 982d3dd

Browse files
committed
arbitrary stack size at runtime
1 parent d37262e commit 982d3dd

File tree

3 files changed

+40
-10
lines changed

3 files changed

+40
-10
lines changed

README.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ Specifically, RPNcalc has been tested on Linux, Mac and Windows, including:
1010
* Gfortran 6, 7, 8
1111
* ifort 2019
1212

13-
However, due to lack of basic Fortran 2008 support, the following compilers do NOT yet work:
14-
* Flang 5.0
15-
* PGI 2018
13+
The stack size is set by the user with command line option.
14+
Default size is 4.
15+
1616

1717
#### Authors
1818
* Fortran 77 code: David G. Simpson
@@ -43,7 +43,13 @@ For example:
4343
To exit the program, type:
4444

4545
q
46-
46+
47+
### set stack size
48+
The default stack size is 4.
49+
Set the stack size at runtime, say 25 by:
50+
51+
rpncalc 25
52+
4753

4854
Show what modes the calculator is in with:
4955

@@ -391,3 +397,9 @@ Many functions not commonly found in RPN calculators are included:
391397
? Exponential integrals
392398
? Hypergeometric functions
393399
? Hermite polynomials
400+
401+
## Notes
402+
403+
Due to lack of basic Fortran 2008 support, the following compilers do NOT yet work:
404+
* Flang 5.0
405+
* PGI 2018

src/calc.f90

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ PROGRAM RPN
3838

3939
!
4040
! Initialize data.
41-
!
41+
42+
call init_stack()
4243

4344
DEL = IACHAR('a') - IACHAR('A') ! find ASCII position diff between 'A' and 'a'
4445

src/reg.f90

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ MODULE GLOBAL
33

44
IMPLICIT NONE
55

6-
CHARACTER(*), PARAMETER :: VERSION = '1.1.3'
6+
CHARACTER(*), PARAMETER :: VERSION = '1.1.4'
77

8-
INTEGER, PARAMETER :: STACK_SIZE = 4 ! stack size
8+
INTEGER :: STACK_SIZE ! stack size
99
INTEGER, PARAMETER :: REG_SIZE = 10 ! number of storage registers
10-
real(wp), DIMENSION (STACK_SIZE) :: STACK ! real stack
10+
real(wp), allocatable :: STACK(:) ! real stack
1111
real(wp), DIMENSION (0:REG_SIZE-1) :: REG ! real storage registers
12-
COMPLEX(wp), DIMENSION (STACK_SIZE) :: CSTACK ! complex stack
12+
COMPLEX(wp), allocatable :: CSTACK(:) ! complex stack
1313
COMPLEX(wp), DIMENSION (0:REG_SIZE-1) :: CREG ! complex storage registers
14-
INTEGER, DIMENSION (STACK_SIZE) :: RNSTACK, RDSTACK ! rational stack
14+
INTEGER, allocatable :: RNSTACK(:), RDSTACK(:) ! rational stack
1515
INTEGER, DIMENSION (0:REG_SIZE-1) :: RNREG, RDREG ! rational storage registers
1616
real(wp) :: LASTX ! real LAST X register
1717
COMPLEX(wp) :: CLASTX ! complex LAST X register
@@ -32,4 +32,21 @@ MODULE GLOBAL
3232
INTEGER, PARAMETER :: INITIAL_FRACTION_MODE = 1 ! 1=improper, 2=mixed
3333
real(wp), PARAMETER :: INITIAL_FRACTOL = 1.0D-4 ! tolerance for decimal to fraction conversion
3434

35+
36+
contains
37+
38+
39+
subroutine init_stack()
40+
41+
integer :: i
42+
character(16) :: argv
43+
44+
stack_size=4 ! default
45+
call get_command_argument(1, argv, status=i)
46+
if (i==0) read(argv,'(I2)') stack_size
47+
48+
allocate(stack(stack_size), cstack(stack_size), rdstack(stack_size), rnstack(stack_size))
49+
50+
end subroutine init_stack
51+
3552
END MODULE GLOBAL

0 commit comments

Comments
 (0)