resin 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,74 +1,90 @@
1
1
  Smalltalk current createPackage: 'Kernel-Methods' properties: #{}!
2
- Object subclass: #CompiledMethod
3
- instanceVariableNames: ''
2
+ Object subclass: #Message
3
+ instanceVariableNames: 'selector arguments'
4
4
  category: 'Kernel-Methods'!
5
- !CompiledMethod commentStamp!
6
- CompiledMethod hold the source and compiled code of a class method.
7
-
8
- You can get a CompiledMethod using `Behavior>>methodAt:`
5
+ !Message commentStamp!
6
+ Generally, the system does not use instances of Message for efficiency reasons.
7
+ However, when a message is not understood by its receiver, the interpreter will make up an instance of it in order to capture the information involved in an actual message transmission.
8
+ This instance is sent it as an argument with the message `doesNotUnderstand:` to the receiver.
9
9
 
10
- String methodAt: 'lines'
10
+ See boot.js, `messageNotUnderstood` and its counterpart `Object>>doesNotUnderstand:`!
11
11
 
12
- and read the source code
12
+ !Message methodsFor: 'accessing'!
13
13
 
14
- (String methodAt: 'lines') source
14
+ selector
15
+ ^selector
16
+ !
15
17
 
16
- See referenced classes:
18
+ selector: aString
19
+ selector := aString
20
+ !
17
21
 
18
- (String methodAt: 'lines') referencedClasses
22
+ arguments: anArray
23
+ arguments := anArray
24
+ !
19
25
 
20
- or messages sent from this method:
21
-
22
- (String methodAt: 'lines') messageSends!
26
+ arguments
27
+ ^arguments
28
+ ! !
23
29
 
24
- !CompiledMethod methodsFor: 'accessing'!
30
+ !Message methodsFor: 'printing'!
25
31
 
26
- source
27
- ^(self basicAt: 'source') ifNil: ['']
32
+ printString
33
+ ^ String streamContents: [:aStream|
34
+ aStream
35
+ nextPutAll: super printString;
36
+ nextPutAll: '(';
37
+ nextPutAll: selector;
38
+ nextPutAll: ')' ]
28
39
  !
29
40
 
30
- source: aString
31
- self basicAt: 'source' put: aString
32
- !
41
+ sendTo: anObject
42
+ Smalltalk current send: self selector to: anObject arguments: self arguments
43
+ ! !
33
44
 
34
- category
35
- ^(self basicAt: 'category') ifNil: ['']
36
- !
45
+ !Message class methodsFor: 'instance creation'!
37
46
 
38
- category: aString
39
- self basicAt: 'category' put: aString
40
- !
47
+ selector: aString arguments: anArray
48
+ ^self new
49
+ selector: aString;
50
+ arguments: anArray;
51
+ yourself
52
+ ! !
41
53
 
42
- selector
43
- ^self basicAt: 'selector'
44
- !
54
+ Object subclass: #MethodContext
55
+ instanceVariableNames: ''
56
+ category: 'Kernel-Methods'!
57
+ !MethodContext commentStamp!
58
+ MethodContext holds all the dynamic state associated with the execution of either a method activation resulting from a message send. That is used to build the call stack while debugging.
59
+
60
+ MethodContext instances are JavaScript `SmalltalkMethodContext` objects defined in boot.js
45
61
 
46
- selector: aString
47
- self basicAt: 'selector' put: aString
48
- !
62
+ Current limitation: MethodContext instances are not created on Block evaluation. That means it's actually impossible to debug inside a Block.!
49
63
 
50
- fn
51
- ^self basicAt: 'fn'
64
+ !MethodContext methodsFor: 'accessing'!
65
+
66
+ receiver
67
+ <return self.receiver>
52
68
  !
53
69
 
54
- fn: aBlock
55
- self basicAt: 'fn' put: aBlock
70
+ selector
71
+ <return smalltalk.convertSelector(self.selector)>
56
72
  !
57
73
 
58
- messageSends
59
- ^self basicAt: 'messageSends'
74
+ home
75
+ <return self.homeContext>
60
76
  !
61
77
 
62
- methodClass
63
- ^self basicAt: 'methodClass'
78
+ temps
79
+ <return self.temps>
64
80
  !
65
81
 
66
- referencedClasses
67
- ^self basicAt: 'referencedClasses'
82
+ printString
83
+ ^super printString, '(', self asString, ')'
68
84
  !
69
85
 
70
- arguments
71
- <return self.args || []>
86
+ asString
87
+ ^self receiver class printString, ' >> ', self selector
72
88
  ! !
73
89
 
74
90
  Object subclass: #BlockClosure
@@ -201,87 +217,75 @@ valueWithInterval: aNumber
201
217
  <return setInterval(self, aNumber)>
202
218
  ! !
203
219
 
204
- Object subclass: #MethodContext
220
+ Object subclass: #CompiledMethod
205
221
  instanceVariableNames: ''
206
222
  category: 'Kernel-Methods'!
207
- !MethodContext commentStamp!
208
- MethodContext holds all the dynamic state associated with the execution of either a method activation resulting from a message send. That is used to build the call stack while debugging.
209
-
210
- MethodContext instances are JavaScript `SmalltalkMethodContext` objects defined in boot.js
223
+ !CompiledMethod commentStamp!
224
+ CompiledMethod hold the source and compiled code of a class method.
211
225
 
212
- Current limitation: MethodContext instances are not created on Block evaluation. That means it's actually impossible to debug inside a Block.!
226
+ You can get a CompiledMethod using `Behavior>>methodAt:`
213
227
 
214
- !MethodContext methodsFor: 'accessing'!
228
+ String methodAt: 'lines'
215
229
 
216
- receiver
217
- <return self.receiver>
218
- !
230
+ and read the source code
219
231
 
220
- selector
221
- <return smalltalk.convertSelector(self.selector)>
222
- !
232
+ (String methodAt: 'lines') source
223
233
 
224
- home
225
- <return self.homeContext>
226
- !
234
+ See referenced classes:
227
235
 
228
- temps
229
- <return self.temps>
230
- !
236
+ (String methodAt: 'lines') referencedClasses
231
237
 
232
- printString
233
- ^super printString, '(', self asString, ')'
234
- !
238
+ or messages sent from this method:
239
+
240
+ (String methodAt: 'lines') messageSends!
235
241
 
236
- asString
237
- ^self receiver class printString, ' >> ', self selector
238
- ! !
242
+ !CompiledMethod methodsFor: 'accessing'!
239
243
 
240
- Object subclass: #Message
241
- instanceVariableNames: 'selector arguments'
242
- category: 'Kernel-Methods'!
243
- !Message commentStamp!
244
- Generally, the system does not use instances of Message for efficiency reasons.
245
- However, when a message is not understood by its receiver, the interpreter will make up an instance of it in order to capture the information involved in an actual message transmission.
246
- This instance is sent it as an argument with the message `doesNotUnderstand:` to the receiver.
244
+ source
245
+ ^(self basicAt: 'source') ifNil: ['']
246
+ !
247
247
 
248
- See boot.js, `messageNotUnderstood` and its counterpart `Object>>doesNotUnderstand:`!
248
+ source: aString
249
+ self basicAt: 'source' put: aString
250
+ !
249
251
 
250
- !Message methodsFor: 'accessing'!
252
+ category
253
+ ^(self basicAt: 'category') ifNil: ['']
254
+ !
255
+
256
+ category: aString
257
+ self basicAt: 'category' put: aString
258
+ !
251
259
 
252
260
  selector
253
- ^selector
261
+ ^self basicAt: 'selector'
254
262
  !
255
263
 
256
264
  selector: aString
257
- selector := aString
265
+ self basicAt: 'selector' put: aString
258
266
  !
259
267
 
260
- arguments: anArray
261
- arguments := anArray
268
+ fn
269
+ ^self basicAt: 'fn'
262
270
  !
263
271
 
264
- arguments
265
- ^arguments
266
- ! !
272
+ fn: aBlock
273
+ self basicAt: 'fn' put: aBlock
274
+ !
267
275
 
268
- !Message methodsFor: 'printing'!
276
+ messageSends
277
+ ^self basicAt: 'messageSends'
278
+ !
269
279
 
270
- printString
271
- ^ String streamContents: [:aStream|
272
- aStream
273
- nextPutAll: super printString;
274
- nextPutAll: '(';
275
- nextPutAll: selector;
276
- nextPutAll: ')' ]
277
- ! !
280
+ methodClass
281
+ ^self basicAt: 'methodClass'
282
+ !
278
283
 
279
- !Message class methodsFor: 'instance creation'!
284
+ referencedClasses
285
+ ^self basicAt: 'referencedClasses'
286
+ !
280
287
 
281
- selector: aString arguments: anArray
282
- ^self new
283
- selector: aString;
284
- arguments: anArray;
285
- yourself
288
+ arguments
289
+ <return self.args || []>
286
290
  ! !
287
291
 
@@ -384,6 +384,12 @@ reservedWords
384
384
 
385
385
  readJSObject: anObject
386
386
  <return self.readJSObject(anObject)>
387
+ !
388
+
389
+ send: aSelector to: anObject arguments: aCollection
390
+ | selector |
391
+ selector := aSelector asString asSelector.
392
+ <self.send(anObject, selector, aCollection)>
387
393
  ! !
388
394
 
389
395
  !Smalltalk methodsFor: 'classes'!
@@ -545,6 +551,17 @@ commitPathSt: aString
545
551
  classes
546
552
  "We need to do a reverse scan."
547
553
  ^Smalltalk current classes select: [:c | c package == self]
554
+ !
555
+
556
+ sortedClasses
557
+ "Answer all classes in the receiver, sorted by superclass/subclasses"
558
+
559
+ ^self classes inject: #() into: [:acc :each |
560
+ acc isEmpty
561
+ ifTrue: [acc add: each; yourself]
562
+ ifFalse: [(acc includes: each superclass)
563
+ ifTrue: [acc add: each; yourself]
564
+ ifFalse: [{each}, acc]]]
548
565
  ! !
549
566
 
550
567
  !Package methodsFor: 'printing'!
@@ -662,11 +679,6 @@ A Number can be used to evaluate a Block a fixed number of times:
662
679
 
663
680
  1 to: 10 by: 2 do: [:aNumber| Transcript show: aNumber asString; cr].!
664
681
 
665
- !Number methodsFor: ''!
666
-
667
-
668
- ! !
669
-
670
682
  !Number methodsFor: 'accessing'!
671
683
 
672
684
  identityHash
@@ -1271,137 +1283,189 @@ new
1271
1283
  self error: 'You cannot create new instances of UndefinedObject. Use nil'
1272
1284
  ! !
1273
1285
 
1274
- Object subclass: #Random
1286
+ Object subclass: #Date
1275
1287
  instanceVariableNames: ''
1276
1288
  category: 'Kernel-Objects'!
1277
- !Random commentStamp!
1278
- `Random` is a random number generator and is implemented as a trivial wrapper around javascript `Math.random()` and is used like this:
1289
+ !Date commentStamp!
1290
+ The Date class is used to work with dates and times. Therefore `Date today` and `Date now` are both valid in
1291
+ Amber and answer the same date object.
1279
1292
 
1280
- Random new next
1293
+ Date wraps the `Date()` JavaScript constructor, and Smalltalk date objects are JavaScript date objects.!
1281
1294
 
1282
- This will return a float x where x < 1 and x > 0. If you want a random integer from 1 to 10 you can use `#atRandom`
1295
+ !Date methodsFor: 'accessing'!
1283
1296
 
1284
- 10 atRandom
1297
+ year
1298
+ <return self.getFullYear()>
1299
+ !
1285
1300
 
1286
- ...and if you want a random number in a specific interval this also works:
1301
+ month
1302
+ <return self.getMonth() + 1>
1303
+ !
1287
1304
 
1288
- (3 to: 7) atRandom
1305
+ month: aNumber
1306
+ <self.setMonth(aNumber - 1)>
1307
+ !
1289
1308
 
1290
- ...but be aware that `#to:` does not create an Interval as in other Smalltalk implementations but in fact an `Array` of numbers, so it's better to use:
1309
+ day
1310
+ ^self dayOfWeek
1311
+ !
1291
1312
 
1292
- 5 atRandom + 2
1313
+ dayOfWeek
1314
+ <return self.getDay() + 1>
1315
+ !
1293
1316
 
1294
- Since `#atRandom` is implemented in `SequencableCollection` you can easy pick an element at random:
1317
+ dayOfWeek: aNumber
1318
+ <return self.setDay(aNumber - 1)>
1319
+ !
1295
1320
 
1296
- #('a' 'b' 'c') atRandom
1321
+ day: aNumber
1322
+ self day: aNumber
1323
+ !
1297
1324
 
1298
- ...or perhaps a letter from a `String`:
1325
+ year: aNumber
1326
+ <self.setFullYear(aNumber)>
1327
+ !
1299
1328
 
1300
- 'abc' atRandom
1329
+ dayOfMonth
1330
+ <return self.getDate()>
1331
+ !
1301
1332
 
1302
- Since Amber does not have Characters this will return a `String` of length 1 like for example `'b'`.!
1333
+ dayOfMonth: aNumber
1334
+ <self.setDate(aNumber)>
1335
+ !
1303
1336
 
1304
- !Random methodsFor: 'accessing'!
1337
+ time
1338
+ <return self.getTime()>
1339
+ !
1305
1340
 
1306
- next
1307
- <return Math.random()>
1341
+ time: aNumber
1342
+ <self.setTime(aNumber)>
1308
1343
  !
1309
1344
 
1310
- next: anInteger
1311
- ^(1 to: anInteger) collect: [:each | self next]
1312
- ! !
1345
+ hours: aNumber
1346
+ <self.setHours(aNumber)>
1347
+ !
1313
1348
 
1314
- Object subclass: #Point
1315
- instanceVariableNames: 'x y'
1316
- category: 'Kernel-Objects'!
1317
- !Point commentStamp!
1318
- A `Point` represents an x-y pair of numbers usually designating a geometric coordinate.
1319
- Points are traditionally created using the binary `#@` message to a number:
1349
+ minutes: aNumber
1350
+ <self.setMinutes(aNumber)>
1351
+ !
1320
1352
 
1321
- 100@120
1353
+ seconds: aNumber
1354
+ <self.setSeconds(aNumber)>
1355
+ !
1322
1356
 
1323
- Points can then be arithmetically manipulated:
1357
+ milliseconds: aNumber
1358
+ <self.setMilliseconds(aNumber)>
1359
+ !
1324
1360
 
1325
- 100@100 + (10@10)
1361
+ hours
1362
+ <return self.getHours()>
1363
+ !
1326
1364
 
1327
- ...or for example:
1365
+ minutes
1366
+ <return self.getMinutes()>
1367
+ !
1328
1368
 
1329
- (100@100) * 2
1369
+ seconds
1370
+ <return self.getSeconds()>
1371
+ !
1330
1372
 
1331
- **NOTE:** Creating a Point with a negative y-value will need a space after `@` in order to avoid a parsing error:
1373
+ milliseconds
1374
+ <return self.getMilliseconds()>
1375
+ ! !
1332
1376
 
1333
- 100@ -100 "but 100@-100 would not parse"
1377
+ !Date methodsFor: 'arithmetic'!
1334
1378
 
1335
- Amber does not have much behavior in this class out-of-the-box.!
1379
+ - aDate
1380
+ <return self - aDate>
1381
+ !
1336
1382
 
1337
- !Point methodsFor: 'accessing'!
1383
+ + aDate
1384
+ <return self + aDate>
1385
+ ! !
1338
1386
 
1339
- x
1340
- ^x
1387
+ !Date methodsFor: 'comparing'!
1388
+
1389
+ < aDate
1390
+ <return self < aDate>
1341
1391
  !
1342
1392
 
1343
- y
1344
- ^y
1393
+ > aDate
1394
+ <return self >> aDate>
1345
1395
  !
1346
1396
 
1347
- y: aNumber
1348
- y := aNumber
1397
+ <= aDate
1398
+ <return self <= aDate>
1349
1399
  !
1350
1400
 
1351
- x: aNumber
1352
- x := aNumber
1401
+ >= aDate
1402
+ <return self >>= aDate>
1353
1403
  ! !
1354
1404
 
1355
- !Point methodsFor: 'arithmetic'!
1405
+ !Date methodsFor: 'converting'!
1356
1406
 
1357
- * aPoint
1358
- ^Point x: self x * aPoint asPoint x y: self y * aPoint asPoint y
1407
+ asString
1408
+ <return self.toString()>
1359
1409
  !
1360
1410
 
1361
- + aPoint
1362
- ^Point x: self x + aPoint asPoint x y: self y + aPoint asPoint y
1411
+ asMilliseconds
1412
+ ^self time
1363
1413
  !
1364
1414
 
1365
- - aPoint
1366
- ^Point x: self x - aPoint asPoint x y: self y - aPoint asPoint y
1415
+ asDateString
1416
+ <return self.toDateString()>
1367
1417
  !
1368
1418
 
1369
- / aPoint
1370
- ^Point x: self x / aPoint asPoint x y: self y / aPoint asPoint y
1419
+ asTimeString
1420
+ <return self.toTimeString()>
1371
1421
  !
1372
1422
 
1373
- = aPoint
1374
- ^aPoint class = self class and: [
1375
- (aPoint x = self x) & (aPoint y = self y)]
1423
+ asLocaleString
1424
+ <return self.toLocaleString()>
1425
+ !
1426
+
1427
+ asNumber
1428
+ ^self asMilliseconds
1376
1429
  ! !
1377
1430
 
1378
- !Point methodsFor: 'converting'!
1431
+ !Date methodsFor: 'printing'!
1379
1432
 
1380
- asPoint
1381
- ^self
1433
+ printString
1434
+ ^self asString
1382
1435
  ! !
1383
1436
 
1384
- !Point methodsFor: 'printing'!
1437
+ !Date class methodsFor: 'instance creation'!
1385
1438
 
1386
- printString
1387
- "Print receiver in classic x@y notation."
1439
+ new: anObject
1440
+ <return new Date(anObject)>
1441
+ !
1388
1442
 
1389
- ^String streamContents: [:stream |
1390
- stream nextPutAll: x printString, '@'.
1391
- (y notNil and: [y negative])
1392
- ifTrue: [
1393
- "Avoid ambiguous @- construct"
1394
- stream space].
1395
- stream nextPutAll: y printString]
1396
- ! !
1443
+ fromString: aString
1444
+ "Example: Date fromString('2011/04/15 00:00:00')"
1445
+ ^self new: aString
1446
+ !
1397
1447
 
1398
- !Point class methodsFor: 'instance creation'!
1448
+ fromSeconds: aNumber
1449
+ ^self fromMilliseconds: aNumber * 1000
1450
+ !
1399
1451
 
1400
- x: aNumber y: anotherNumber
1452
+ fromMilliseconds: aNumber
1453
+ ^self new: aNumber
1454
+ !
1455
+
1456
+ today
1401
1457
  ^self new
1402
- x: aNumber;
1403
- y: anotherNumber;
1404
- yourself
1458
+ !
1459
+
1460
+ now
1461
+ ^self today
1462
+ !
1463
+
1464
+ millisecondsToRun: aBlock
1465
+ | t |
1466
+ t := Date now.
1467
+ aBlock value.
1468
+ ^Date now - t
1405
1469
  ! !
1406
1470
 
1407
1471
  Object subclass: #JSObjectProxy
@@ -1487,3 +1551,136 @@ on: aJSObject
1487
1551
  yourself
1488
1552
  ! !
1489
1553
 
1554
+ Object subclass: #Point
1555
+ instanceVariableNames: 'x y'
1556
+ category: 'Kernel-Objects'!
1557
+ !Point commentStamp!
1558
+ A `Point` represents an x-y pair of numbers usually designating a geometric coordinate.
1559
+ Points are traditionally created using the binary `#@` message to a number:
1560
+
1561
+ 100@120
1562
+
1563
+ Points can then be arithmetically manipulated:
1564
+
1565
+ 100@100 + (10@10)
1566
+
1567
+ ...or for example:
1568
+
1569
+ (100@100) * 2
1570
+
1571
+ **NOTE:** Creating a Point with a negative y-value will need a space after `@` in order to avoid a parsing error:
1572
+
1573
+ 100@ -100 "but 100@-100 would not parse"
1574
+
1575
+ Amber does not have much behavior in this class out-of-the-box.!
1576
+
1577
+ !Point methodsFor: 'accessing'!
1578
+
1579
+ x
1580
+ ^x
1581
+ !
1582
+
1583
+ y
1584
+ ^y
1585
+ !
1586
+
1587
+ y: aNumber
1588
+ y := aNumber
1589
+ !
1590
+
1591
+ x: aNumber
1592
+ x := aNumber
1593
+ ! !
1594
+
1595
+ !Point methodsFor: 'arithmetic'!
1596
+
1597
+ * aPoint
1598
+ ^Point x: self x * aPoint asPoint x y: self y * aPoint asPoint y
1599
+ !
1600
+
1601
+ + aPoint
1602
+ ^Point x: self x + aPoint asPoint x y: self y + aPoint asPoint y
1603
+ !
1604
+
1605
+ - aPoint
1606
+ ^Point x: self x - aPoint asPoint x y: self y - aPoint asPoint y
1607
+ !
1608
+
1609
+ / aPoint
1610
+ ^Point x: self x / aPoint asPoint x y: self y / aPoint asPoint y
1611
+ !
1612
+
1613
+ = aPoint
1614
+ ^aPoint class = self class and: [
1615
+ (aPoint x = self x) & (aPoint y = self y)]
1616
+ ! !
1617
+
1618
+ !Point methodsFor: 'converting'!
1619
+
1620
+ asPoint
1621
+ ^self
1622
+ ! !
1623
+
1624
+ !Point methodsFor: 'printing'!
1625
+
1626
+ printString
1627
+ "Print receiver in classic x@y notation."
1628
+
1629
+ ^String streamContents: [:stream |
1630
+ stream nextPutAll: x printString, '@'.
1631
+ (y notNil and: [y negative])
1632
+ ifTrue: [
1633
+ "Avoid ambiguous @- construct"
1634
+ stream space].
1635
+ stream nextPutAll: y printString]
1636
+ ! !
1637
+
1638
+ !Point class methodsFor: 'instance creation'!
1639
+
1640
+ x: aNumber y: anotherNumber
1641
+ ^self new
1642
+ x: aNumber;
1643
+ y: anotherNumber;
1644
+ yourself
1645
+ ! !
1646
+
1647
+ Object subclass: #Random
1648
+ instanceVariableNames: ''
1649
+ category: 'Kernel-Objects'!
1650
+ !Random commentStamp!
1651
+ `Random` is a random number generator and is implemented as a trivial wrapper around javascript `Math.random()` and is used like this:
1652
+
1653
+ Random new next
1654
+
1655
+ This will return a float x where x < 1 and x > 0. If you want a random integer from 1 to 10 you can use `#atRandom`
1656
+
1657
+ 10 atRandom
1658
+
1659
+ ...and if you want a random number in a specific interval this also works:
1660
+
1661
+ (3 to: 7) atRandom
1662
+
1663
+ ...but be aware that `#to:` does not create an Interval as in other Smalltalk implementations but in fact an `Array` of numbers, so it's better to use:
1664
+
1665
+ 5 atRandom + 2
1666
+
1667
+ Since `#atRandom` is implemented in `SequencableCollection` you can easy pick an element at random:
1668
+
1669
+ #('a' 'b' 'c') atRandom
1670
+
1671
+ ...or perhaps a letter from a `String`:
1672
+
1673
+ 'abc' atRandom
1674
+
1675
+ Since Amber does not have Characters this will return a `String` of length 1 like for example `'b'`.!
1676
+
1677
+ !Random methodsFor: 'accessing'!
1678
+
1679
+ next
1680
+ <return Math.random()>
1681
+ !
1682
+
1683
+ next: anInteger
1684
+ ^(1 to: anInteger) collect: [:each | self next]
1685
+ ! !
1686
+