resin 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,31 +1,4 @@
1
1
  Smalltalk current createPackage: 'Kernel-Announcements' properties: #{}!
2
- Object subclass: #Announcer
3
- instanceVariableNames: 'registry subscriptions'
4
- category: 'Kernel-Announcements'!
5
-
6
- !Announcer methodsFor: 'announcing'!
7
-
8
- announce: anAnnouncement
9
- subscriptions do: [:each |
10
- each deliver: anAnnouncement]
11
- ! !
12
-
13
- !Announcer methodsFor: 'initialization'!
14
-
15
- initialize
16
- super initialize.
17
- subscriptions := OrderedCollection new
18
- ! !
19
-
20
- !Announcer methodsFor: 'subscribing'!
21
-
22
- on: aClass do: aBlock
23
- subscriptions add: (AnnouncementSubscription new
24
- block: aBlock;
25
- announcementClass: aClass;
26
- yourself)
27
- ! !
28
-
29
2
  Object subclass: #AnnouncementSubscription
30
3
  instanceVariableNames: 'block announcementClass'
31
4
  category: 'Kernel-Announcements'!
@@ -59,3 +32,30 @@ handlesAnnouncement: anAnnouncement
59
32
  ^anAnnouncement isKindOf: self announcementClass
60
33
  ! !
61
34
 
35
+ Object subclass: #Announcer
36
+ instanceVariableNames: 'registry subscriptions'
37
+ category: 'Kernel-Announcements'!
38
+
39
+ !Announcer methodsFor: 'announcing'!
40
+
41
+ announce: anAnnouncement
42
+ subscriptions do: [:each |
43
+ each deliver: anAnnouncement]
44
+ ! !
45
+
46
+ !Announcer methodsFor: 'initialization'!
47
+
48
+ initialize
49
+ super initialize.
50
+ subscriptions := Array new
51
+ ! !
52
+
53
+ !Announcer methodsFor: 'subscribing'!
54
+
55
+ on: aClass do: aBlock
56
+ subscriptions add: (AnnouncementSubscription new
57
+ block: aBlock;
58
+ announcementClass: aClass;
59
+ yourself)
60
+ ! !
61
+
@@ -1,4 +1,214 @@
1
1
  Smalltalk current createPackage: 'Kernel-Collections' properties: #{}!
2
+ Object subclass: #Stream
3
+ instanceVariableNames: 'collection position streamSize'
4
+ category: 'Kernel-Collections'!
5
+
6
+ !Stream methodsFor: 'accessing'!
7
+
8
+ collection
9
+ ^collection
10
+ !
11
+
12
+ setCollection: aCollection
13
+ collection := aCollection
14
+ !
15
+
16
+ position
17
+ ^position ifNil: [position := 0]
18
+ !
19
+
20
+ position: anInteger
21
+ position := anInteger
22
+ !
23
+
24
+ streamSize
25
+ ^streamSize
26
+ !
27
+
28
+ setStreamSize: anInteger
29
+ streamSize := anInteger
30
+ !
31
+
32
+ contents
33
+ ^self collection
34
+ copyFrom: 1
35
+ to: self streamSize
36
+ !
37
+
38
+ size
39
+ ^self streamSize
40
+ ! !
41
+
42
+ !Stream methodsFor: 'actions'!
43
+
44
+ reset
45
+ self position: 0
46
+ !
47
+
48
+ close
49
+ !
50
+
51
+ flush
52
+ !
53
+
54
+ resetContents
55
+ self reset.
56
+ self setStreamSize: 0
57
+ ! !
58
+
59
+ !Stream methodsFor: 'enumerating'!
60
+
61
+ do: aBlock
62
+ [self atEnd] whileFalse: [aBlock value: self next]
63
+ ! !
64
+
65
+ !Stream methodsFor: 'positioning'!
66
+
67
+ setToEnd
68
+ self position: self size
69
+ !
70
+
71
+ skip: anInteger
72
+ self position: ((self position + anInteger) min: self size max: 0)
73
+ ! !
74
+
75
+ !Stream methodsFor: 'reading'!
76
+
77
+ next
78
+ ^self atEnd
79
+ ifTrue: [nil]
80
+ ifFalse: [
81
+ self position: self position + 1.
82
+ collection at: self position]
83
+ !
84
+
85
+ next: anInteger
86
+ | tempCollection |
87
+ tempCollection := self collection class new.
88
+ anInteger timesRepeat: [
89
+ self atEnd ifFalse: [
90
+ tempCollection add: self next]].
91
+ ^tempCollection
92
+ !
93
+
94
+ peek
95
+ ^self atEnd ifFalse: [
96
+ self collection at: self position + 1]
97
+ ! !
98
+
99
+ !Stream methodsFor: 'testing'!
100
+
101
+ atEnd
102
+ ^self position = self size
103
+ !
104
+
105
+ atStart
106
+ ^self position = 0
107
+ !
108
+
109
+ isEmpty
110
+ ^self size = 0
111
+ ! !
112
+
113
+ !Stream methodsFor: 'writing'!
114
+
115
+ nextPut: anObject
116
+ self position: self position + 1.
117
+ self collection at: self position put: anObject.
118
+ self setStreamSize: (self streamSize max: self position)
119
+ !
120
+
121
+ nextPutAll: aCollection
122
+ aCollection do: [:each |
123
+ self nextPut: each]
124
+ ! !
125
+
126
+ !Stream class methodsFor: 'instance creation'!
127
+
128
+ on: aCollection
129
+ ^self new
130
+ setCollection: aCollection;
131
+ setStreamSize: aCollection size;
132
+ yourself
133
+ ! !
134
+
135
+ Object subclass: #Association
136
+ instanceVariableNames: 'key value'
137
+ category: 'Kernel-Collections'!
138
+
139
+ !Association methodsFor: 'accessing'!
140
+
141
+ key: aKey
142
+ key := aKey
143
+ !
144
+
145
+ key
146
+ ^key
147
+ !
148
+
149
+ value: aValue
150
+ value := aValue
151
+ !
152
+
153
+ value
154
+ ^value
155
+ ! !
156
+
157
+ !Association methodsFor: 'comparing'!
158
+
159
+ = anAssociation
160
+ ^self class = anAssociation class and: [
161
+ self key = anAssociation key and: [
162
+ self value = anAssociation value]]
163
+ !
164
+
165
+ storeOn: aStream
166
+ "Store in the format (key->value)"
167
+
168
+ "aStream nextPutAll: '('."
169
+ key storeOn: aStream.
170
+ aStream nextPutAll: '->'.
171
+ value storeOn: aStream.
172
+ "aStream nextPutAll: ')'"
173
+ ! !
174
+
175
+ !Association class methodsFor: 'instance creation'!
176
+
177
+ key: aKey value: aValue
178
+ ^self new
179
+ key: aKey;
180
+ value: aValue;
181
+ yourself
182
+ ! !
183
+
184
+ Object subclass: #RegularExpression
185
+ instanceVariableNames: ''
186
+ category: 'Kernel-Collections'!
187
+
188
+ !RegularExpression methodsFor: 'evaluating'!
189
+
190
+ compile: aString
191
+ <return self.compile(aString)>
192
+ !
193
+
194
+ exec: aString
195
+ <return self.exec(aString) || nil>
196
+ !
197
+
198
+ test: aString
199
+ <return self.test(aString)>
200
+ ! !
201
+
202
+ !RegularExpression class methodsFor: 'instance creation'!
203
+
204
+ fromString: aString flag: anotherString
205
+ <return new RegExp(aString, anotherString)>
206
+ !
207
+
208
+ fromString: aString
209
+ ^self fromString: aString flag: ''
210
+ ! !
211
+
2
212
  Object subclass: #Collection
3
213
  instanceVariableNames: ''
4
214
  category: 'Kernel-Collections'!
@@ -60,7 +270,7 @@ asJSONString
60
270
  !
61
271
 
62
272
  asOrderedCollection
63
- ^OrderedCollection withAll: self
273
+ ^self asArray
64
274
  ! !
65
275
 
66
276
  !Collection methodsFor: 'copying'!
@@ -329,8 +539,8 @@ copyFrom: anIndex to: anotherIndex
329
539
  | range newCollection |
330
540
  range := anIndex to: anotherIndex.
331
541
  newCollection := self class new: range size.
332
- range do: [:each |
333
- newCollection at: each put: (self at: each)].
542
+ range withIndexDo: [:each :i |
543
+ newCollection at: i put: (self at: each)].
334
544
  ^newCollection
335
545
  !
336
546
 
@@ -953,214 +1163,121 @@ withAll: aCollection
953
1163
  ^instance
954
1164
  ! !
955
1165
 
956
- Object subclass: #RegularExpression
1166
+ SequenceableCollection subclass: #Array
957
1167
  instanceVariableNames: ''
958
1168
  category: 'Kernel-Collections'!
959
1169
 
960
- !RegularExpression methodsFor: 'evaluating'!
1170
+ !Array methodsFor: 'accessing'!
961
1171
 
962
- compile: aString
963
- <return self.compile(aString)>
1172
+ size
1173
+ <return self.length>
964
1174
  !
965
1175
 
966
- exec: aString
967
- <return self.exec(aString) || nil>
1176
+ at: anIndex put: anObject
1177
+ <return self[anIndex - 1] = anObject>
968
1178
  !
969
1179
 
970
- test: aString
971
- <return self.test(aString)>
1180
+ at: anIndex ifAbsent: aBlock
1181
+ <
1182
+ var value = self[anIndex - 1];
1183
+ if(value === undefined) {
1184
+ return aBlock();
1185
+ } else {
1186
+ return value;
1187
+ }
1188
+ >
972
1189
  ! !
973
1190
 
974
- !RegularExpression class methodsFor: 'instance creation'!
1191
+ !Array methodsFor: 'adding/removing'!
975
1192
 
976
- fromString: aString flag: anotherString
977
- <return new RegExp(aString, anotherString)>
1193
+ add: anObject
1194
+ <self.push(anObject); return anObject;>
978
1195
  !
979
1196
 
980
- fromString: aString
981
- ^self fromString: aString flag: ''
1197
+ remove: anObject
1198
+ <
1199
+ for(var i=0;i<self.length;i++) {
1200
+ if(self[i] == anObject) {
1201
+ self.splice(i,1);
1202
+ break;
1203
+ }
1204
+ }
1205
+ >
1206
+ !
1207
+
1208
+ removeFrom: aNumber to: anotherNumber
1209
+ <self.splice(aNumber - 1,anotherNumber - 1)>
982
1210
  ! !
983
1211
 
984
- Object subclass: #Association
985
- instanceVariableNames: 'key value'
986
- category: 'Kernel-Collections'!
987
-
988
- !Association methodsFor: 'accessing'!
989
-
990
- key: aKey
991
- key := aKey
992
- !
993
-
994
- key
995
- ^key
996
- !
997
-
998
- value: aValue
999
- value := aValue
1000
- !
1001
-
1002
- value
1003
- ^value
1004
- ! !
1005
-
1006
- !Association methodsFor: 'comparing'!
1007
-
1008
- = anAssociation
1009
- ^self class = anAssociation class and: [
1010
- self key = anAssociation key and: [
1011
- self value = anAssociation value]]
1012
- !
1013
-
1014
- storeOn: aStream
1015
- "Store in the format (key->value)"
1016
-
1017
- "aStream nextPutAll: '('."
1018
- key storeOn: aStream.
1019
- aStream nextPutAll: '->'.
1020
- value storeOn: aStream.
1021
- "aStream nextPutAll: ')'"
1022
- ! !
1023
-
1024
- !Association class methodsFor: 'instance creation'!
1025
-
1026
- key: aKey value: aValue
1027
- ^self new
1028
- key: aKey;
1029
- value: aValue;
1030
- yourself
1031
- ! !
1032
-
1033
- Object subclass: #Stream
1034
- instanceVariableNames: 'collection position streamSize'
1035
- category: 'Kernel-Collections'!
1036
-
1037
- !Stream methodsFor: 'accessing'!
1038
-
1039
- collection
1040
- ^collection
1041
- !
1042
-
1043
- setCollection: aCollection
1044
- collection := aCollection
1045
- !
1046
-
1047
- position
1048
- ^position ifNil: [position := 0]
1049
- !
1050
-
1051
- position: anInteger
1052
- position := anInteger
1053
- !
1054
-
1055
- streamSize
1056
- ^streamSize
1057
- !
1058
-
1059
- setStreamSize: anInteger
1060
- streamSize := anInteger
1061
- !
1212
+ !Array methodsFor: 'converting'!
1062
1213
 
1063
- contents
1064
- ^self collection
1065
- copyFrom: 1
1066
- to: self streamSize
1214
+ asJavascript
1215
+ ^'[', ((self collect: [:each | each asJavascript]) join: ', '), ']'
1067
1216
  !
1068
1217
 
1069
- size
1070
- ^self streamSize
1218
+ reversed
1219
+ <return self._copy().reverse()>
1071
1220
  ! !
1072
1221
 
1073
- !Stream methodsFor: 'actions'!
1222
+ !Array methodsFor: 'enumerating'!
1074
1223
 
1075
- reset
1076
- self position: 0
1224
+ join: aString
1225
+ <return self.join(aString)>
1077
1226
  !
1078
1227
 
1079
- close
1228
+ sort
1229
+ ^self basicPerform: 'sort'
1080
1230
  !
1081
1231
 
1082
- flush
1232
+ sort: aBlock
1233
+ <
1234
+ return self.sort(function(a, b) {
1235
+ if(aBlock(a,b)) {return -1} else {return 1}
1236
+ })
1237
+ >
1083
1238
  !
1084
1239
 
1085
- resetContents
1086
- self reset.
1087
- self setStreamSize: 0
1088
- ! !
1089
-
1090
- !Stream methodsFor: 'enumerating'!
1091
-
1092
- do: aBlock
1093
- [self atEnd] whileFalse: [aBlock value: self next]
1094
- ! !
1095
-
1096
- !Stream methodsFor: 'positioning'!
1097
-
1098
- setToEnd
1099
- self position: self size
1240
+ sorted
1241
+ ^self copy sort
1100
1242
  !
1101
1243
 
1102
- skip: anInteger
1103
- self position: ((self position + anInteger) min: self size max: 0)
1244
+ sorted: aBlock
1245
+ ^self copy sort: aBlock
1104
1246
  ! !
1105
1247
 
1106
- !Stream methodsFor: 'reading'!
1107
-
1108
- next
1109
- ^self atEnd
1110
- ifTrue: [nil]
1111
- ifFalse: [
1112
- self position: self position + 1.
1113
- collection at: self position]
1114
- !
1248
+ !Array class methodsFor: 'instance creation'!
1115
1249
 
1116
- next: anInteger
1117
- | tempCollection |
1118
- tempCollection := self collection class new.
1119
- anInteger timesRepeat: [
1120
- self atEnd ifFalse: [
1121
- tempCollection add: self next]].
1122
- ^tempCollection
1250
+ new: anInteger
1251
+ <return new Array(anInteger)>
1123
1252
  !
1124
1253
 
1125
- peek
1126
- ^self atEnd ifFalse: [
1127
- self collection at: self position + 1]
1128
- ! !
1129
-
1130
- !Stream methodsFor: 'testing'!
1131
-
1132
- atEnd
1133
- ^self position = self size
1254
+ with: anObject
1255
+ ^(self new: 1)
1256
+ at: 1 put: anObject;
1257
+ yourself
1134
1258
  !
1135
1259
 
1136
- atStart
1137
- ^self position = 0
1260
+ with: anObject with: anObject2
1261
+ ^(self new: 2)
1262
+ at: 1 put: anObject;
1263
+ at: 2 put: anObject2;
1264
+ yourself
1138
1265
  !
1139
1266
 
1140
- isEmpty
1141
- ^self size = 0
1142
- ! !
1143
-
1144
- !Stream methodsFor: 'writing'!
1145
-
1146
- nextPut: anObject
1147
- self position: self position + 1.
1148
- self collection at: self position put: anObject.
1149
- self setStreamSize: (self streamSize max: self position)
1267
+ with: anObject with: anObject2 with: anObject3
1268
+ ^(self new: 3)
1269
+ at: 1 put: anObject;
1270
+ at: 2 put: anObject2;
1271
+ at: 3 put: anObject3;
1272
+ yourself
1150
1273
  !
1151
1274
 
1152
- nextPutAll: aCollection
1153
- aCollection do: [:each |
1154
- self nextPut: each]
1155
- ! !
1156
-
1157
- !Stream class methodsFor: 'instance creation'!
1158
-
1159
- on: aCollection
1160
- ^self new
1161
- setCollection: aCollection;
1162
- setStreamSize: aCollection size;
1163
- yourself
1275
+ withAll: aCollection
1276
+ | instance |
1277
+ instance := self new: aCollection size.
1278
+ aCollection withIndexDo: [:index :each |
1279
+ instance at: index put: each].
1280
+ ^instance
1164
1281
  ! !
1165
1282
 
1166
1283
  Stream subclass: #StringStream
@@ -1224,7 +1341,7 @@ size
1224
1341
  add: anObject
1225
1342
  <
1226
1343
  var found;
1227
- for(var i in self['@elements']) {
1344
+ for(var i=0; i < self['@elements'].length; i++) {
1228
1345
  if(anObject == self['@elements'][i]) {
1229
1346
  found = true;
1230
1347
  break;
@@ -1575,99 +1692,3 @@ includesKey: aKey
1575
1692
  ^keys includes: aKey
1576
1693
  ! !
1577
1694
 
1578
- SequenceableCollection subclass: #OrderedCollection
1579
- instanceVariableNames: 'elements'
1580
- category: 'Kernel-Collections'!
1581
-
1582
- !OrderedCollection methodsFor: 'accessing'!
1583
-
1584
- size
1585
- ^elements size
1586
- !
1587
-
1588
- at: anIndex put: anObject
1589
- <return self['@elements'][anIndex - 1] = anObject>
1590
- !
1591
-
1592
- at: anIndex ifAbsent: aBlock
1593
- ^elements at: anIndex ifAbsent: aBlock
1594
- ! !
1595
-
1596
- !OrderedCollection methodsFor: 'adding/removing'!
1597
-
1598
- add: anObject
1599
- <self['@elements'].push(anObject); return anObject;>
1600
- !
1601
-
1602
- remove: anObject
1603
- <
1604
- for(var i=0;i<self['@elements'].length;i++) {
1605
- if(self['@elements'][i] == anObject) {
1606
- self['@elements'].splice(i,1);
1607
- break;
1608
- }
1609
- }
1610
- >
1611
- !
1612
-
1613
- removeFrom: aNumber to: anotherNumber
1614
- <self['@elements'].splice(aNumber - 1,anotherNumber - 1)>
1615
- ! !
1616
-
1617
- !OrderedCollection methodsFor: 'converting'!
1618
-
1619
- reversed
1620
- ^self asArray reversed asOrderedCollection
1621
- !
1622
-
1623
- asOrderedCollection
1624
- ^self
1625
- !
1626
-
1627
- asArray
1628
- ^elements copy
1629
- ! !
1630
-
1631
- !OrderedCollection methodsFor: 'enumerating'!
1632
-
1633
- join: aString
1634
- ^elements join: aString
1635
- !
1636
-
1637
- sort
1638
- elements sort.
1639
- ^self
1640
- !
1641
-
1642
- sort: aBlock
1643
- elements sort: aBlock.
1644
- ^self
1645
- !
1646
-
1647
- sorted
1648
- ^self copy sort
1649
- !
1650
-
1651
- sorted: aBlock
1652
- ^self copy sort: aBlock
1653
- !
1654
-
1655
- withIndexDo: aBlock
1656
- elements withIndexDo: aBlock
1657
- !
1658
-
1659
- detect: aBlock ifNone: anotherBlock
1660
- ^elements detect: aBlock ifNone: anotherBlock
1661
- !
1662
-
1663
- do: aBlock
1664
- elements do: aBlock
1665
- ! !
1666
-
1667
- !OrderedCollection methodsFor: 'initialization'!
1668
-
1669
- initialize
1670
- super initialize.
1671
- elements := #()
1672
- ! !
1673
-