Moved assignment, binding, and case statement macro code into src/syntax/.
[cslatevm.git] / src / syntax / binding.slate
blob762d8c8dc094aa8f024c6d30fe3c647654771a49
2 node@(nodes Node traits) bindTo: value &environment: env
4   overrideThis
5 ].
7 _@(nodes Placeholder traits) bindTo: val &environment: env
9   val
12 literal@(nodes Literal traits) bindTo: val &environment: env
13 [| lhs |
14   lhs: literal value.
15   (lhs is: Symbol) \/ [lhs is: String]
16     ifTrue:
17       [(nodes UnaryMessage sending: lhs intern to: {nodes ImplicitArgument})
18          bindTo: val &environment: env]
19     ifFalse:
20       [error: 'Cannot bind this type of literal: ' ; lhs printString]
23 load@(nodes LoadVariable traits) bindTo: value &environment: env
25   `(load `unquote
26       ifNil: [(load store: value) `unquote]
27       ifNotNil: [error: 'Cannot rebind'])
30 msg@(nodes UnaryMessage traits) bindTo: value &environment: env
32   env isNil \/ [msg arguments first ~= nodes ImplicitArgument]
33     ifTrue:
34       [nodes KeywordMessage sending: #bind:to: to:
35          {msg arguments first. nodes Literal for: msg selector. value}]
36     ifFalse:
37       [(env outermostScopeNotBinding: msg selector)
38          ifNil: [error: 'Cannot rebind']
39          ifNotNilDo:
40            [| :scope |
41             StoreVariable of: value into:
42               (scope addVariableNamed: msg selector &varType: nodes Binding)]]
45 message@(nodes KeywordMessage traits) bindTo: val &environment: env
46 "Expands a message by looking at its selector and picking the right setter."
48   (message selector isKeywordSelector ifTrue:
49     [message selector caseOf: {
50        #addSlotNamed: -> [#bind:to:].
51        #addImmutableSlotNamed: -> [#bind:to:].
52      } otherwise: []])
53     ifNil: [error: 'Cannot rebind'. message]
54     ifNotNilDo:
55       [| :newSel | message sending: newSel to: (message arguments copyWith: val)]
58 "This is the tricky moment at which we activate the special macro.
59 Above here, it is unavailable, and after here, the definitions is not sound."
60 n@(nodes Node traits) ::= val &environment: env [n bindTo: val &environment: env].