-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrpengine_help.go
More file actions
237 lines (207 loc) · 9.03 KB
/
rpengine_help.go
File metadata and controls
237 lines (207 loc) · 9.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
package main
import (
"fmt"
"github.com/c-bata/go-prompt"
)
const REPLHelpStr = `
goRPN Command Reference
===============================
goRPN is a full featured console RPN calculator. It provides arbitrary
precision integer and floating point arithmetic where feasible. The following
commands are supported, with max precision noted in parentheses where
applicable.
Arithmetic Operators
===============================
+ Add (arbitrary)
- Subtract (arbitrary)
* Multiply (arbitrary)
/ Divide (arbitrary)
cla Clear the stack and variables
clr Clear the stack
clv Clear the variables
% Modulus (arbitrary)
++ Increment (arbitrary)
-- Decrement (arbitrary)
Bitwise Operators
===============================
& Bitwise AND
| Bitwise OR
^ Bitwise XOR
~ Bitwise NOT
<< Bitwise shift left
>> Bitwise shift right
Boolean Operators
===============================
! Boolean NOT
&& Boolean AND
|| Boolean OR
^^ Boolean XOR
Comparison Operators
===============================
!= Not equal to
< Less than
<= Less than or equal to
== Equal to
> Greater than
>= Greater than or equal to
Trigonometric Functions
===============================
acos Arc Cosine (64-bit floating point)
asin Arc Sine (64-bit floating point)
atan Arc Tangent (64-bit floating point)
cos Cosine (64-bit floating point)
cosh Hyperbolic Cosine (64-bit floating point)
sin Sine (64-bit floating point)
sinh Hyperbolic Sine (64-bit floating point)
tanh Hyperbolic tangent (64-bit floating point)
Numeric Utilities
===============================
ceil Ceiling (64-bit floating point)
floor Floor (64-bit floating point)
round Round (64-bit floating point)
ip Integer part (64-bit floating point)
fp Floating part (64-bit floating point)
sign Push -1, 0, or 0 depending on the sign
abs Absolute value (arbitrary)
max Max
min Min
Display Modes
===============================
hex Switch display mode to hexadecimal
dec Switch display mode to decimal (default)
bin Switch display mode to binary
oct Switch display mode to octal
Constants
===============================
e Push e (64-bit floating point)
pi Push Pi (64-bit floating point)
rand Generate a random number (integer)
Mathematic Functions
===============================
exp Exponentiation (64-bit floating point)
fact Factorial (arbitrary)
sqrt Square Root (arbitrary)
ln Natural Logarithm (64-bit floating point)
log Logarithm (64-bit floating point)
pow Raise a number to a power (64-bit floating point)
Networking
===============================
hnl Host to network long (32-bit unsigned integer)
hns Host to network short (16-bit unsigned integer)
nhl Network to host long (32-bit unsigned integer)
nhs Network to host short (16-bit unsigned integer)
Stack Manipulation
===============================
pick Pick the -n'th item from the stack
repeat Repeat an operation n times, e.g. '3 repeat +'
depth Push the current stack depth
drop Drops the top item from the stack
dropn Drops n items from the stack
dup Duplicates the top stack item
dupn Duplicates the top n stack items in order
roll Roll the stack upwards by n
rolld Roll the stack downwards by n
stack Toggles stack display from horizontal to vertical
swap Swap the top 2 stack items
Macros and Variables
===============================
macro Defines a macro, e.g. 'macro kib 1024 *'
lsmacros List currently defined macros
clm Clear macros
x= Assigns a variable, e.g. '1024 x='
Other
===============================
help Print the help message
type Gets the data type of the element at top of stack
exit Exit the calculator
quit Exit the calculator
`
func (r *RPEngine) replCompleter(d prompt.Document) []prompt.Suggest {
s := []prompt.Suggest{
{Text: "+", Description: "Add"},
{Text: "-", Description: "Subtract"},
{Text: "*", Description: "Multiply"},
{Text: "/", Description: "Divide"},
{Text: "cla", Description: "Clear the stack and variables"},
{Text: "clr", Description: "Clear the stack"},
{Text: "clv", Description: "Clear the variables"},
{Text: "%", Description: "Modulus"},
{Text: "++", Description: "Increment"},
{Text: "--", Description: "Decrement"},
{Text: "&", Description: "Bitwise AND"},
{Text: "|", Description: "Bitwise OR"},
{Text: "^", Description: "Bitwise XOR"},
{Text: "~", Description: "Bitwise NOT"},
{Text: "<<", Description: "Bitwise shift left"},
{Text: ">>", Description: "Bitwise shift right"},
{Text: "!", Description: "Boolean NOT"},
{Text: "&&", Description: "Boolean AND"},
{Text: "||", Description: "Boolean OR"},
{Text: "^^", Description: "Boolean XOR"},
{Text: "!=", Description: "Not equal to"},
{Text: "<", Description: "Less than"},
{Text: "<=", Description: "Less than or equal to"},
{Text: "==", Description: "Equal to"},
{Text: ">", Description: "Greater than"},
{Text: ">=", Description: "Greater than or equal to"},
{Text: "acos", Description: "Arc Cosine"},
{Text: "asin", Description: "Arc Sine"},
{Text: "atan", Description: "Arc Tangent"},
{Text: "cos", Description: "Cosine"},
{Text: "cosh", Description: "Hyperbolic Cosine"},
{Text: "sin", Description: "Sine"},
{Text: "sinh", Description: "Hyperbolic Sine"},
{Text: "tanh", Description: "Hyperbolic tangent"},
{Text: "ceil", Description: "Ceiling"},
{Text: "floor", Description: "Floor"},
{Text: "round", Description: "Round"},
{Text: "ip", Description: "Integer part"},
{Text: "fp", Description: "Floating part"},
{Text: "sign", Description: "Push -1, 0, or 0 depending on the sign"},
{Text: "abs", Description: "Absolute value"},
{Text: "max", Description: "Max"},
{Text: "min", Description: "Min"},
{Text: "hex", Description: "Switch display mode to hexadecimal"},
{Text: "dec", Description: "Switch display mode to decimal (default)"},
{Text: "bin", Description: "Switch display mode to binary"},
{Text: "oct", Description: "Switch display mode to octal"},
{Text: "e", Description: "Push e"},
{Text: "pi", Description: "Push Pi"},
{Text: "rand", Description: "Generate a random number"},
{Text: "exp", Description: "Exponentiation"},
{Text: "fact", Description: "Factorial"},
{Text: "sqrt", Description: "Square Root"},
{Text: "ln", Description: "Natural Logarithm"},
{Text: "log", Description: "Logarithm"},
{Text: "pow", Description: "Raise a number to a power"},
{Text: "hnl", Description: "Host to network long"},
{Text: "hns", Description: "Host to network short"},
{Text: "nhl", Description: "Network to host long"},
{Text: "nhs", Description: "Network to host short"},
{Text: "pick", Description: "Pick the -n'th item from the stack"},
{Text: "repeat", Description: "Repeat an operation n times, e.g. '3 repeat +'"},
{Text: "depth", Description: "Push the current stack depth"},
{Text: "drop", Description: "Drops the top item from the stack"},
{Text: "dropn", Description: "Drops n items from the stack"},
{Text: "dup", Description: "Duplicates the top stack item"},
{Text: "dupn", Description: "Duplicates the top n stack items in order"},
{Text: "roll", Description: "Roll the stack upwards by n"},
{Text: "rolld", Description: "Roll the stack downwards by n"},
{Text: "stack", Description: "Toggles stack display from horizontal to vertical"},
{Text: "swap", Description: "Swap the top 2 stack items"},
{Text: "macro", Description: "Defines a macro, e.g. 'macro kib 1024 *'"},
{Text: "lsmacros", Description: "Lists currently defined macros"},
{Text: "rmmacro", Description: "Remove a defined macro, e.g. 'rmmacro kib'"},
{Text: "clm", Description: "Clears all defined macros"},
{Text: "x=", Description: "Assigns a variable, e.g. '1024 x='"},
{Text: "type", Description: "Prints type of top variable in the stack. (useful for debugging)"},
{Text: "help", Description: "Print the help message"},
{Text: "exit", Description: "Exit the calculator"},
{Text: "quit", Description: "Exit the calculator"},
}
//return prompt.FilterHasPrefix(s, d.GetWordBeforeCursor(), true)
return prompt.FilterContains(s, d.GetWordBeforeCursor(), true)
}
func (r *RPEngine) replHelp() {
fmt.Print(REPLHelpStr)
}