git.s-ol.nu mmm / e356564
add dynfn type for non-cacheable evaluation s-ol 3 months ago
3 changed file(s) with 15 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
5656 out: '%1',
5757 cost: 1
5858 transform: (val, fileder) => val fileder
59 }
60 {
61 inp: 'dynfn -> (.+)',
62 out: '%1',
63 cost: 1,1
64 transform: (val, fileder) => val fileder
65 dynamic: true
5966 }
6067 {
6168 inp: 'mmm/component',
154154 -- returns converted value
155155 err_and_trace = (msg) -> debug.traceback msg, 2
156156 apply_conversions = (fileder, conversions, value, key) ->
157 static = true
157158 for i=#conversions,1,-1
158159 refs\push!
159160 step = conversions[i]
160161 ok, value = xpcall step.convert.transform, err_and_trace, step, value, fileder, key
161162 refs\pop!
163
164 if step.convert.dynamic
165 static = false
166
162167 if not ok
163168 error "error while converting #{fileder} #{key} from '#{step.from}' to '#{step.to}':\n#{value}"
164169
165 value
170 value, static
166171
167172 -- find and apply a conversion path from 'have' to 'want'
168173 -- * have - start type string or list of type strings
282282 key, conversions = @find want
283283
284284 if key
285 value = apply_conversions @, conversions, @facets[key], key
286 CACHE\set @, want, value if CACHE
285 value, static = apply_conversions @, conversions, @facets[key], key
286 CACHE\set @, want, value if CACHE and static
287287 value, key
288288
289289 -- like @get, throw if no value or conversion path