summaryrefslogtreecommitdiff
path: root/internal/rpn/operations_interfaces.go
blob: 3016f28f4117307f86e31d422639d9b08e6cb9aa (plain)
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
// SPDX-License-Identifier: MIT
// Copyright (c) 2026 Paul Buetow

package rpn

// ArithmeticOperator defines the interface for basic arithmetic operators.
type ArithmeticOperator interface {
	Add(stack *Stack) error
	Subtract(stack *Stack) error
	Multiply(stack *Stack) error
	Divide(stack *Stack) error
	Power(stack *Stack) error
	Modulo(stack *Stack) error
}

// LogarithmicOperator defines the interface for logarithmic operators.
type LogarithmicOperator interface {
	Log2(stack *Stack) error
	Log10(stack *Stack) error
	Ln(stack *Stack) error
}

// MetricOperator defines the interface for metric unit conversion.
type MetricOperator interface {
	Convert(stack *Stack) error
}

// BooleanOperator defines the interface for boolean comparison operators.
type BooleanOperator interface {
	GT(stack *Stack) error
	LT(stack *Stack) error
	GTE(stack *Stack) error
	LTE(stack *Stack) error
	EQ(stack *Stack) error
	NEQ(stack *Stack) error
}

// HyperOperator defines the interface for hyper operators.
type HyperOperator interface {
	HyperAdd(stack *Stack) error
	HyperSubtract(stack *Stack) error
	HyperMultiply(stack *Stack) error
	HyperDivide(stack *Stack) error
	HyperPower(stack *Stack) error
	HyperModulo(stack *Stack) error
	HyperLog2(stack *Stack) error
	HyperLog10(stack *Stack) error
	HyperLn(stack *Stack) error
}

// StackOperator defines the interface for stack manipulation operators.
type StackOperator interface {
	Dup(stack *Stack) error
	Swap(stack *Stack) error
	Pop(stack *Stack) error
	Delete(stack *Stack) error
	Show(stack *Stack) (string, error)
}

// VariableOperator defines the interface for variable operations.
type VariableOperator interface {
	ListVariables() (string, error)
	ClearVariables()
	AssignLeft(stack *Stack) error
	AssignRight(stack *Stack) error
	DeleteVariable(name string) error
}

// ConstantOperator defines the interface for constant operations.
type ConstantOperator interface {
	ListConstants() (string, error)
	ClearConstants()
}

// PowerIntOperator defines the interface for integer power operations (**) using binary exponentiation.
type PowerIntOperator interface {
	FastPower(stack *Stack) error
}

// ModeController defines the interface for calculation mode and prefix mode control.
type ModeController interface {
	SetMode(CalculationMode)
	GetMode() CalculationMode
	SetPrefixMode(PrefixMode)
	GetPrefixMode() PrefixMode
}

// MetricCommander defines the interface for metric query commands.
type MetricCommander interface {
	MetricRegistry() *MetricRegistry
	MetricShow(stack *Stack) (string, error)
	MetricList(stack *Stack) (string, error)
	MetricCategory(stack *Stack, categoryName string) (string, error)
	MetricCompatible(stack *Stack) (string, error)
}

// CustomMetricManager defines the interface for custom metric operations.
type CustomMetricManager interface {
	CustomShow(stack *Stack, name string) (string, error)
	CustomList(stack *Stack) (string, error)
	CustomDefine(name string, factor float64, category string) error
	CustomUndefine(name string) error
}

// OperatorProvider combines all operator interfaces needed by the OperatorRegistry.
// This satisfies DIP by decoupling the registry from the concrete *Operations type.
type OperatorProvider interface {
	ArithmeticOperator
	PowerIntOperator
	LogarithmicOperator
	BooleanOperator
	StackOperator
	VariableOperator
	ConstantOperator
	MetricOperator
	HyperOperator
}

// OperationsProvider combines all interfaces that RPN needs from Operations.
// RPN depends on this interface (DIP) rather than the concrete *Operations type.
type OperationsProvider interface {
	ModeController
	StackOperator
	MetricCommander
	CustomMetricManager
}

// Operator implementations are split across focused sub-interfaces
// (ArithmeticOperator, LogarithmicOperator, MetricOperator, BooleanOperator,
// HyperOperator, StackOperator, VariableOperator, ConstantOperator,
// PowerIntOperator) for clarity.
//
// The OperationsProvider interface is the combined interface that RPN depends
// on, satisfying DIP by decoupling RPN from the concrete *Operations type.
//
// Each sub-interface and OperationsProvider is satisfied by *Operations,
// verified by compile-time checks in operations.go.