-
Notifications
You must be signed in to change notification settings - Fork 7
/
operators_conflict.go
96 lines (89 loc) · 2.38 KB
/
operators_conflict.go
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
package ps
import (
"fmt"
"log"
)
// dictionary copy conflict with stack copy
// type dicriminant
func commonCopy(interpreter *Interpreter) {
switch v := interpreter.Peek().(type) {
case float64:
copystack(interpreter)
case Dictionary:
copydict(interpreter)
default:
panic(fmt.Sprintf("Not yet implemented: %v copy", v))
}
}
func commonforall(interpreter *Interpreter) {
switch v := interpreter.Get(1).(type) {
case Dictionary:
foralldict(interpreter)
case []Value:
forallarray(interpreter)
case string:
panic("Not yet implemented: string proc forall")
default:
panic(fmt.Sprintf("Not yet implemented: %v proc forall", v))
}
}
func length(interpreter *Interpreter) {
switch v := interpreter.Peek().(type) {
case Dictionary:
lengthdict(interpreter)
case []Value:
lengtharray(interpreter)
case string:
panic("Not yet implemented: string proc forall")
default:
panic(fmt.Sprintf("Not yet implemented: %v length", v))
}
}
func get(interpreter *Interpreter) {
switch v := interpreter.Get(1).(type) {
case Dictionary:
getdict(interpreter)
case []Value:
getarray(interpreter)
case string:
panic("Not yet implemented: string proc forall")
default:
panic(fmt.Sprintf("Not yet implemented: %v index get", v))
}
}
func put(interpreter *Interpreter) {
switch v := interpreter.Get(2).(type) {
case Dictionary:
putdict(interpreter)
case []Value:
putarray(interpreter)
case string:
panic("Not yet implemented: string proc forall")
default:
panic(fmt.Sprintf("Not yet implemented: %v index any put", v))
}
}
func readonly(interpreter *Interpreter) {
log.Println("readonly, not yet implemented")
}
func cvlit(interpreter *Interpreter) {
log.Println("cvlit, not yet implemented")
}
func xcheck(interpreter *Interpreter) {
value := interpreter.Pop()
if _, ok := value.(*ProcedureDefinition); ok {
interpreter.Push(true)
} else {
interpreter.Push(false)
}
}
func initConflictingOperators(interpreter *Interpreter) {
interpreter.SystemDefine("copy", NewOperator(commonCopy))
interpreter.SystemDefine("forall", NewOperator(commonforall))
interpreter.SystemDefine("length", NewOperator(length))
interpreter.SystemDefine("get", NewOperator(get))
interpreter.SystemDefine("put", NewOperator(put))
interpreter.SystemDefine("readonly", NewOperator(readonly))
interpreter.SystemDefine("cvlit", NewOperator(cvlit))
interpreter.SystemDefine("xcheck", NewOperator(xcheck))
}