aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/llgcode/ps/operators_misc.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/llgcode/ps/operators_misc.go')
-rw-r--r--vendor/github.com/llgcode/ps/operators_misc.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/vendor/github.com/llgcode/ps/operators_misc.go b/vendor/github.com/llgcode/ps/operators_misc.go
new file mode 100644
index 0000000..2971d06
--- /dev/null
+++ b/vendor/github.com/llgcode/ps/operators_misc.go
@@ -0,0 +1,38 @@
+// Copyright 2010 The postscript-go Authors. All rights reserved.
+// created: 13/12/2010 by Laurent Le Goff
+
+// Miscellaneous Operators
+package ps
+
+//proc bind proc Replace operator names in proc with operators; perform idiom recognition
+func bind(interpreter *Interpreter) {
+ pdef := interpreter.PopProcedureDefinition()
+ values := make([]Value, len(pdef.Values))
+ for i, value := range pdef.Values {
+ if s, ok := value.(string); ok {
+ firstChar := s[0]
+ if firstChar != '(' && firstChar != '/' {
+ v, _ := interpreter.FindValueInDictionaries(s)
+ operator, isOperator := v.(Operator)
+ if v == nil {
+ // log.Printf("Can't find def: %s\n", s)
+ }
+ if isOperator {
+ values[i] = operator
+ } else {
+ values[i] = value
+ }
+ } else {
+ values[i] = value
+ }
+ } else {
+ values[i] = value
+ }
+ }
+ pdef.Values = values
+ interpreter.Push(pdef)
+}
+
+func initMiscellaneousOperators(interpreter *Interpreter) {
+ interpreter.SystemDefine("bind", NewOperator(bind))
+}