-
Notifications
You must be signed in to change notification settings - Fork 0
/
infrastructure.coffee
107 lines (82 loc) · 4.44 KB
/
infrastructure.coffee
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
Paws = require '../Paws.coffee'
{ Thing, Label, Execution, Native
, Relation, Combination, Position, Mask
, reactor, parse, debugging, utilities: util } = Paws
{ ENV, verbosity, is_silent, colour
, emergency, alert, critical, error, warning, notice, info, debug, verbose, wtf } = debugging
module.exports =
-> Thing.with(names: yes).construct infrastructure:
# ### Procedures for all `Thing`s
empty: -> new Thing
get: (it, idx)-> return it.at numberish idx
set: (it, idx, to)-> it.set numberish(idx), to ; return null
cut: (it, idx)->
idx = numberish idx
result = it.at idx
delete it.metadata[idx]
return result
affix: (it, other)-> it.push other ; return null
unaffix: (it)-> return it.pop()
prefix: (it, other)-> it.unshift other ; return null
unprefix: (it)-> return it.shift()
length: (it)-> return new Label it.metadata.length - 1
find: (it, other)-> return new Thing it.find(other)...
# FIXME: Not happy with this, at the moment. I'm staunchly against meaningless return-values, and
# in this case, `it` is firmly meaningless. Problem is, I still ain't got booleans decided
# ... so, could go either way.
compare: (it, other)-> if Thing::compare.call it, other then return it else return null
clone: (it)-> return Thing::clone.call it
adopt: (it, other)-> Thing::clone.call other, it ; return null
receiver: (it)-> return it.receiver
receive: (it, receiver)-> it.receiver = receiver ; return null
own: (it, idx)-> it.own_at[numberish idx] ; return null
disown: (it, idx)-> it.disown_at[numberish idx] ; return null
# ### Procedures specific to `Label`s
#---
# FIXME: Clearly, there's currently no semantic for *checking* if the incoming `Thing` is
# actually a `Label` (or rather, duck-typing style, that it has the `Label`-y methods.)
#
# This remains the case for two reasons:
# - there's still no error-handling mechanism in place to interact with such a situation,
# if we tested for it
# - I'd rather like to avoid revealing to libspace the *type* (that is, in the JavaScript
# sense) of an existing value ... it already feels like a hack to me, that there *are*
# any "types" to nodes in the data-graph. If libspace wants "can this be exploded?"-
# information at runtime, then it should encode that information *into* the data-graph
# itself
label:
clone: (it)-> return Label::clone.call it
compare: (it, other)-> if Label::compare.call it, other then return it else return null
explode: (it)-> return it.explode()
# ### Procedures specific to `Execution`s
execution:
# TODO: Add an #asynchronous alternative to the super-useful #synchronous, specifically to aid
# in the implementation of natives like the following
branch: new Native(
(caller, $)->
@caller = caller
$.stage caller, this
(it, $)->
clone = (if it instanceof Native then Native else Execution)::clone.call it
if it == @caller
$.stage clone, @caller
$.stage @caller, clone
else # it != @caller
$.stage @caller, clone
)
# XXX: ... this seems too easy.
# TODO: meaningless return value, clearly, but ... how the fuck does one stage `stage`, then?
stage: (it, value)->
@unit.stage it, value
return value
# NOTE: A noop, 'cuz the default receiver (call-pattern) involves unstaging.
unstage: new Native -> # noop
# FIXME: yadda yadda meaningless arguments
charge: undefined # NYI
discharge: undefined # NYI
# FIXME: I need to replace this `parseInt` call. Hell, I need to *spec* how number-strings are
# supposed to be used. #iamaterribleperson >,>
numberish = (number)->
number = parseInt number.alien, 10 if number instanceof Label
return 0 if not util.isNumber number or isNaN number
return number