X Tutup
Skip to content

Commit 28306b5

Browse files
committed
Core packages of Grease
1 parent 652e0c2 commit 28306b5

File tree

124 files changed

+10089
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+10089
-0
lines changed

repository/.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
#format : #tonel
3+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Extension { #name : #Character }
2+
3+
{ #category : #'*grease-core' }
4+
Character >> print: anObject on: aStream [
5+
aStream nextPut: self
6+
]
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
"
2+
A delayed send that has some or all of the arguments defined in advance. Additionally supplied arguments will be added, if possible, to these when the object is evaluate.
3+
4+
Instance Variables
5+
arguments: <Array>
6+
7+
arguments
8+
- the predefined arguments
9+
10+
"
11+
Class {
12+
#name : #GRBoundMessage,
13+
#superclass : #GRDelayedSendMessage,
14+
#instVars : [
15+
'arguments'
16+
],
17+
#category : #'Grease-Core-Utilities'
18+
}
19+
20+
{ #category : #'instance creation' }
21+
GRBoundMessage class >> selector: aSymbol [
22+
^ self selector: aSymbol arguments: #()
23+
]
24+
25+
{ #category : #'instance creation' }
26+
GRBoundMessage class >> selector: aSymbol arguments: anArray [
27+
^ self basicNew
28+
initializeWithSelector: aSymbol arguments: anArray;
29+
yourself
30+
]
31+
32+
{ #category : #delegation }
33+
GRBoundMessage >> argumentCount [
34+
^ selector numArgs - arguments size
35+
]
36+
37+
{ #category : #initialization }
38+
GRBoundMessage >> initializeWithSelector: aSymbol arguments: anArray [
39+
self initializeWithSelector: aSymbol.
40+
arguments := anArray asArray
41+
]
42+
43+
{ #category : #private }
44+
GRBoundMessage >> mergeArguments: anArray [
45+
^ arguments , anArray
46+
]
47+
48+
{ #category : #printing }
49+
GRBoundMessage >> printOn: aStream [
50+
super printOn: aStream.
51+
aStream nextPutAll: ' arguments: '; print: arguments
52+
]
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
"
2+
A codec defines how Seaside communicates without the outside world and how outside data is converted into the image (decoding) and back outside the image (encoding). The codec is essentially a stream factory that provides wrappers around standard streams. All streams do support binary mode for non-converted transfer.
3+
"
4+
Class {
5+
#name : #GRCodec,
6+
#superclass : #GRObject,
7+
#category : #'Grease-Core-Text'
8+
}
9+
10+
{ #category : #accessing }
11+
GRCodec class >> allCodecs [
12+
"Answer all codecs supported in this system. This is a collection of codec instances."
13+
14+
^ self subclasses
15+
inject: self codecs asArray
16+
into: [ :result :each | result , each allCodecs ]
17+
]
18+
19+
{ #category : #private }
20+
GRCodec class >> basicForEncoding: aString [
21+
"Create the actual instance."
22+
self subclassResponsibility
23+
]
24+
25+
{ #category : #accessing }
26+
GRCodec class >> codecs [
27+
"Answer a collection of possible codecs of the receiver. To be overridden by concrete subclasses."
28+
29+
^ #()
30+
]
31+
32+
{ #category : #'instance creation' }
33+
GRCodec class >> forEncoding: aString [
34+
"Answer a new codec instance for the given encoding name. Raise an WAUnsupportedEncodingError if the encoding name is not supported by this image."
35+
36+
self allSubclassesDo: [ :each |
37+
(each supportsEncoding: aString)
38+
ifTrue: [ ^ each basicForEncoding: aString ] ].
39+
^ self unsupportedEncoding: aString
40+
]
41+
42+
{ #category : #testing }
43+
GRCodec class >> supportsEncoding: aString [
44+
"Answer whether the the given encoding name is supported by this codec class."
45+
self subclassResponsibility
46+
]
47+
48+
{ #category : #private }
49+
GRCodec class >> unsupportedEncoding: aString [
50+
"Signal an unsupported encoding."
51+
52+
^ GRUnsupportedEncodingError signal: 'unsupported encoding: ' , aString
53+
]
54+
55+
{ #category : #convenience }
56+
GRCodec >> decode: aString [
57+
| readStream writeStream |
58+
readStream := self decoderFor: aString readStream.
59+
writeStream := GRPlatform current writeCharacterStreamOn: (String new: aString size).
60+
[ readStream atEnd ]
61+
whileFalse: [ writeStream nextPutAll: (readStream next: 1024) ].
62+
^ writeStream contents
63+
]
64+
65+
{ #category : #conversion }
66+
GRCodec >> decoderFor: aReadStream [
67+
"Wrap aReadStream with an decoder for the codec of the receiver. Answer a read stream that delegates to and shares the state of aReadStream."
68+
69+
self subclassResponsibility
70+
]
71+
72+
{ #category : #convenience }
73+
GRCodec >> encode: aString [
74+
| writeStream |
75+
writeStream := self encoderFor: (GRPlatform current
76+
writeCharacterStreamOn: (self encodedStringClass new: aString size)).
77+
writeStream nextPutAll: aString.
78+
^ writeStream contents
79+
]
80+
81+
{ #category : #conversion }
82+
GRCodec >> encodedStringClass [
83+
^ String
84+
]
85+
86+
{ #category : #conversion }
87+
GRCodec >> encoderFor: aWriteStream [
88+
"Wrap aWriteStream with an encoder for the codec of the receiver. Answer a write stream that delegates to and shares the state of aWriteStream."
89+
90+
self subclassResponsibility
91+
]
92+
93+
{ #category : #accessing }
94+
GRCodec >> name [
95+
"Answer a human readable string of the receivers encoding policy."
96+
97+
self subclassResponsibility
98+
]
99+
100+
{ #category : #printing }
101+
GRCodec >> printOn: aStream [
102+
super printOn: aStream.
103+
aStream nextPutAll: ' name: '; print: self name
104+
]
105+
106+
{ #category : #accessing }
107+
GRCodec >> url [
108+
"Answer a codec that is responsible to encode and decode URLs. In most cases an UTF-8 codec is the only valid choice, but subclasses might decide to do something else."
109+
110+
self subclassResponsibility
111+
]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
"
2+
GRCodecStream is the abstract base class for codec streams
3+
"
4+
Class {
5+
#name : #GRCodecStream,
6+
#superclass : #GRDelegatingStream,
7+
#category : #'Grease-Core-Text'
8+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
"
2+
A GRCountingStream counts how many elements have been added to it. This is necessary because the underlying stream may inflate the number of elements in the stream.
3+
4+
Instance Variables:
5+
count <Integer>
6+
7+
count
8+
- number of elements added to this stream
9+
"
10+
Class {
11+
#name : #GRCountingStream,
12+
#superclass : #GRDelegatingStream,
13+
#instVars : [
14+
'count'
15+
],
16+
#category : #'Grease-Core'
17+
}
18+
19+
{ #category : #accessing }
20+
GRCountingStream >> count [
21+
^ count
22+
]
23+
24+
{ #category : #streaming }
25+
GRCountingStream >> greaseNext: anInteger putAll: aCollection startingAt: startIndex [
26+
super greaseNext: anInteger putAll: aCollection startingAt: startIndex.
27+
count := count + anInteger
28+
]
29+
30+
{ #category : #initialization }
31+
GRCountingStream >> initialize [
32+
super initialize.
33+
count := 0
34+
]
35+
36+
{ #category : #streaming }
37+
GRCountingStream >> next [
38+
self shouldNotImplement
39+
]
40+
41+
{ #category : #streaming }
42+
GRCountingStream >> next: anInteger [
43+
self shouldNotImplement
44+
]
45+
46+
{ #category : #streaming }
47+
GRCountingStream >> nextPut: aCharacter [
48+
stream nextPut: aCharacter.
49+
count := count + 1
50+
]
51+
52+
{ #category : #streaming }
53+
GRCountingStream >> nextPutAll: aString [
54+
stream nextPutAll: aString.
55+
count := count + aString size
56+
]
57+
58+
{ #category : #accessing }
59+
GRCountingStream >> reset [
60+
super reset.
61+
count := 0
62+
]
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
"
2+
A GRDelayedSend is a future message send of a message to an object. Some of the arguments can be predefined. Instances are intended to be interchangeable with blocks.
3+
4+
This class should conform the ANSI (block) valuable protocol. Unlike a block, a GRDelayedSend is not a closure so doesn't hold onto the method context. GRDelayedSend provides similar, but portable, functionality to Pharo's MessageSend.
5+
6+
This is an abstract class. Use the methods in the 'instance-creation' protocol on the class side to create intances.
7+
8+
Instance Variables
9+
receiver: <Object>
10+
selector: <Symbol>
11+
12+
receiver
13+
- the object receiving the message
14+
15+
selector
16+
- the message selector sent to the receiver
17+
18+
"
19+
Class {
20+
#name : #GRDelayedSend,
21+
#superclass : #GRObject,
22+
#instVars : [
23+
'receiver',
24+
'message'
25+
],
26+
#category : #'Grease-Core-Utilities'
27+
}
28+
29+
{ #category : #'instance creation' }
30+
GRDelayedSend class >> empty [
31+
^ self receiver: nil selector: #yourself
32+
]
33+
34+
{ #category : #'instance creation' }
35+
GRDelayedSend class >> new [
36+
^ self empty
37+
]
38+
39+
{ #category : #'instance creation' }
40+
GRDelayedSend class >> receiver: anObject selector: aSymbol [
41+
^ self basicNew
42+
initializeWithReceiver: anObject
43+
message: (GRUnboundMessage selector: aSymbol);
44+
yourself
45+
]
46+
47+
{ #category : #'instance creation' }
48+
GRDelayedSend class >> receiver: anObject selector: aSymbol argument: aParameter [
49+
^ self receiver: anObject selector: aSymbol arguments: (Array with: aParameter)
50+
]
51+
52+
{ #category : #'instance creation' }
53+
GRDelayedSend class >> receiver: anObject selector: aSymbol arguments: anArray [
54+
^ self basicNew
55+
initializeWithReceiver: anObject
56+
message: (GRBoundMessage selector: aSymbol arguments: anArray);
57+
yourself
58+
]
59+
60+
{ #category : #accessing }
61+
GRDelayedSend >> argumentCount [
62+
"Answer the number of arguments that must be provided to the receiver when sending it."
63+
64+
^ message argumentCount
65+
]
66+
67+
{ #category : #initialization }
68+
GRDelayedSend >> initializeWithReceiver: anObject message: aDelayedSendMessage [
69+
self initialize.
70+
receiver := anObject.
71+
message := aDelayedSendMessage
72+
]
73+
74+
{ #category : #printing }
75+
GRDelayedSend >> printOn: aStream [
76+
super printOn: aStream.
77+
aStream nextPutAll: ' receiver: '; print: receiver.
78+
aStream nextPut: $ .
79+
message printOn: aStream
80+
]
81+
82+
{ #category : #evaluating }
83+
GRDelayedSend >> value [
84+
^ self valueWithArguments: #()
85+
]
86+
87+
{ #category : #evaluating }
88+
GRDelayedSend >> value: anObject [
89+
^ self valueWithArguments: (Array with: anObject)
90+
]
91+
92+
{ #category : #evaluating }
93+
GRDelayedSend >> value: aFirstObject value: aSecondObject [
94+
^ self valueWithArguments: (Array with: aFirstObject with: aSecondObject)
95+
]
96+
97+
{ #category : #evaluating }
98+
GRDelayedSend >> valueWithArguments: anArray [
99+
^ message valueFor: receiver withArguments: anArray
100+
]
101+
102+
{ #category : #evaluating }
103+
GRDelayedSend >> valueWithPossibleArguments: anArray [
104+
^ message valueFor: receiver withPossibleArguments: anArray
105+
]

0 commit comments

Comments
 (0)
X Tutup