-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbxobj
More file actions
executable file
·105 lines (91 loc) · 1.9 KB
/
bxobj
File metadata and controls
executable file
·105 lines (91 loc) · 1.9 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
#!/bin/bash
source bxcommon
function boilerplate {
local -a fn
local deffn="function $2"$'\n'
mapfile fn <<<"$(declare -f "$1")"
deffn+="${fn[1]}"
deffn+="$(injectobj)"
for ((i=2; i<${#fn[@]}; i++)) {
deffn+="${fn[i]}"
}
eval "$deffn"
}
function injectobj {
echo local -n "${_obj[target]}"='_obj[value]'\;
}
function construct {
declare -ag _level=(construct)
declare -ag _path=("${1}")
function type: { _hold[type]="${1}"; }
function target: { _hold[target]="${1}"; }
function value: { _hold[value]="${1}"; }
function field {
_level+=('field')
_path+=("${1}")
declare -Ag "_hold_${1}"
declare -ng _hold="_hold_${1}"
_hold[name]="${1}"
#_hold=()
}
function field:finish {
_hold[path]=''
for __frag in "${_path[@]}"; do
_hold[path]+=".${__frag}"
done
_hold[path]="${_hold[path]:1}"
#echo "${_hold[path]}"
local -n type=_hold[type]
#echo "${_hold[name]}"
case "$type" in
var) field:var "${_hold[path]}" "${_hold[value]}" "${_hold[name]}";;
com) field:com "${_hold[path]}" "${_hold[name]}";;
*) error "unsupported type $type";;
esac
}
function field:var {
eval "function ${1} { give ${2}; }"
eval "function ${1}.set { eval \"function ${1} { give "'${1}'"; }\" ; }"
# eval "function this.${3} { ${1} \${@}; }"
# eval "function this.${3}.set { ${1}.set \${@}; }"
}
function field:com {
copy-function value "${1}"
# copy-function value "this.${2}"
}
function }, {
case "${_level[-1]}" in
'construct')
;;
'field')
field:finish;;
*)
error 'Object subgroup unsupported' "_level[-1]=${_level[-1]}"
esac
unset _level[-1]
unset _path[-1]
}
}
function hellot {
construct hello {
field x {
type: var
value: 4
},
field y {
type: var
value: 2
},
field square {
type: com
value() {
req x; hello.x
req y; hello.y
echo "$((x*y))"
}
},
},
hello.x.set 9
hello.y.set 8
hello.square
}