PCalc is simple programmer calculator with stack instructions. It allows you to create, edit, run and debug simple programs. PCalc program consists of one or more functions. Functions can be nested (as in Pascal). Code written outside the body of any function is considered to belong to main function. Each function may have local variables. Also program may have input parameters which should be specified before starting execution of the program. Result of program execution can be placed in stack or in local variables.

Instruction set

PCalc implements simple stack machine. Operands of each instruction should be pushed on operand's stack before execution of the operation. When operation is executed, it pops it arguments from stack and result of operation is pushed on the stack. Stack can be also used to path data to called functions and get results of execution of thus function. PCalc instructions can be grouped in several units: load/store, operators, functions and flow control:
LITERALConstant value0Push immediate constant to the stack
LOADVariable name0Push value of local variable to the stack
INPUTInput parameter name0Push value of input parameter to the stack
STOREVariable name1Pop value from the stack and store it in local variable
DUP-1Duplicate top stack element
SWAP-2Swap two values on the top of the stack
LOAD_E-0Push E constant to the stack
LOAD_PI-0Push PI constant to the stack

NEG1Negative value
ADD2Add two operands
SUB2Subtract two operands
MUL2Multiply two operands
DIV2Divide two operands
EQ2Check if operands are equal
NE2Check if operands are not equal
GT2Check if first operand is greater than second
GE2Check if first operand is greater or equal than second
LT2Check if first operand is less than second
LE2Check if first operand is less or equal than second

ABS1Absolute value
ACOS1Arc cosine
ASIN1Arc sine
ATAN1Arc tangent
ATAN22the theta component of the point in polar coordinates corresponds to the point Cartesian coordinates specified by function operands.
CEIL1Smallest integer value which is not less than operand
CEIL1Largest integer value which is not greater than operand
FRAC1Fraction part of the operand value
INT1Integer part of the operand value
LOG1Natural logarithm
LOG101Logarithm with base 10
MAX2Maximum of two operand values
MIN2Minimum of two operand values
POW2Raise first operand to the power specified by second operand
RND0Generate random number in range [0,1)
ROUND1Round operand to the closest integer value
SQRT1Square root

Control flow
IFLabel1Pop value from top of stack and if it is zero, then transfer control to the specified label
CALLFunction name0Call specified function. Function can access operands in the operands stack and push return value also to the stack
RETURNnone0Return from the function
IFLabel0Transfer control to the specified label

PCalc development environment

Main menu

PCalc can store several programs. The program is saved each time you try to execute it or exit the application. The main menu allows you to select program from the list and either edit, either run, either debug the program (execute program step-by-step). Also it is possible to create new program or delete existing program and undo the last delete operation (undo is possible until you exit the application).

Edit program menu

When you create new program or edit existing one, you will see code of main function. Use Insert command to add new instruction. To add instruction, you should first select group of instructions and then choose particular instruction in the group. If instruction requires additional information (name of variable, immediate constant,...), then special input dialog will be started. For local variables and program parameters you can either select one of the existed names or add new name. It is possible to delete instructions using Delete command.

It is possible to move the label from one instruction to another. First you should position cursor on the instruction with label, then execute Move command. You then will be asked to select instruction to which label should be moved. Obviously, all transfers to the original instruction referencing this label will now be redirected to new location.

You can get list of all subfunctions of the current function execute Functions command. Selecting function from the list will open edit dialogue for specified function. Nested function can access local variables of the outer functions.

To get list of all visible local variables execute Variables. It will print list of all local variables declared in this and containing functions. It is possible to rename or delete variable (only variables of the self function can be renamed or deleted). Attempt to delete used variable will be rejected.

Run program menu

Run program form first ask you to enter values of the program input parameters (if any) and then start program execution. Elapsed program execution time is displayed at the screen. It is possible to stop the program using Stop command, in this case debugger is activated.

When the program is terminated, it is possible to inspect results of execution. Results of execution can be either stored in stack, either in local variables of main function. Content of the stack is dumped. And to see values of particular local variables of main function use Variables command. Using Restart command it is possible to rerun the program (with new values of parameters).

Debug program menu

Debugger is activated when you start program in debug mode or when you stop execution of the program. In debugger it is possible to execute program step-by-step, inspecting content of stack and local variables. Stack command can be used to dump the operands stack, Variables command - to inspect values of local variables and Trace command - to see back trace (function call stack).

At any moment you can continue normal execution of the program or restart it.