2017-01-06 09:53:40 +00:00
|
|
|
class Point(Object)
|
2016-12-31 17:22:57 +00:00
|
|
|
{
|
2017-01-06 09:53:40 +00:00
|
|
|
dcl x y.
|
2016-12-31 17:22:57 +00:00
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method(#class) new
|
2016-12-31 17:22:57 +00:00
|
|
|
{
|
|
|
|
^self basicNew x: 0 y: 0.
|
|
|
|
}
|
2017-01-06 09:53:40 +00:00
|
|
|
method(#class) x: x y: y
|
2016-12-31 17:22:57 +00:00
|
|
|
{
|
|
|
|
^self basicNew x: x y: y.
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method x
|
2016-12-31 17:22:57 +00:00
|
|
|
{
|
|
|
|
^self.x
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method y
|
2016-12-31 17:22:57 +00:00
|
|
|
{
|
|
|
|
^self.y
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method x: x
|
2016-12-31 17:22:57 +00:00
|
|
|
{
|
|
|
|
self.x := x
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method y: y
|
2016-12-31 17:22:57 +00:00
|
|
|
{
|
|
|
|
self.y := y
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method x: x y: y
|
2016-12-31 17:22:57 +00:00
|
|
|
{
|
|
|
|
self.x := x.
|
|
|
|
self.y := y
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
extend SmallInteger
|
2016-12-31 17:22:57 +00:00
|
|
|
{
|
2017-01-06 09:53:40 +00:00
|
|
|
method @ y
|
2016-12-31 17:22:57 +00:00
|
|
|
{
|
|
|
|
^Point x: self y: y
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
class Console(Object)
|
2016-12-31 17:22:57 +00:00
|
|
|
{
|
2017-01-06 09:53:40 +00:00
|
|
|
dcl handle.
|
2016-12-31 17:22:57 +00:00
|
|
|
"
|
2017-01-06 09:53:40 +00:00
|
|
|
method finalize
|
2016-12-31 17:22:57 +00:00
|
|
|
{
|
|
|
|
handle notNil ifTrue: [
|
|
|
|
self _close: handle.
|
|
|
|
]
|
|
|
|
}
|
|
|
|
"
|
|
|
|
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
## method(#class) input
|
2016-12-31 17:22:57 +00:00
|
|
|
## {
|
|
|
|
## ^self new _open: filename mode: mode
|
|
|
|
## }
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method(#class) output
|
2016-12-31 17:22:57 +00:00
|
|
|
{
|
|
|
|
| c |
|
|
|
|
|
|
|
|
c := self new.
|
|
|
|
c handle: (c _open).
|
|
|
|
^c
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
## method(#class) error
|
2016-12-31 17:22:57 +00:00
|
|
|
## {
|
|
|
|
## }
|
|
|
|
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method handle: v
|
2016-12-31 17:22:57 +00:00
|
|
|
{
|
|
|
|
self.handle := v.
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method close
|
2016-12-31 17:22:57 +00:00
|
|
|
{
|
|
|
|
self _close: self.handle.
|
|
|
|
self.handle := nil.
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method write: text
|
2016-12-31 17:22:57 +00:00
|
|
|
{
|
|
|
|
^self _writeOn: self.handle text: text.
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method clear
|
2016-12-31 17:22:57 +00:00
|
|
|
{
|
|
|
|
^self _clear: self.handle
|
|
|
|
}
|
2017-01-06 09:53:40 +00:00
|
|
|
method setCursor: point
|
2016-12-31 17:22:57 +00:00
|
|
|
{
|
|
|
|
^self _setCursor: self.handle point: point.
|
|
|
|
}
|
|
|
|
"
|
2017-01-06 09:53:40 +00:00
|
|
|
method _open: filename mode: mode
|
2016-12-31 17:22:57 +00:00
|
|
|
{
|
|
|
|
self.handle := self __open: filename mode: mode.
|
|
|
|
^self.
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method __open: filename mode: mode
|
2016-12-31 17:22:57 +00:00
|
|
|
{
|
|
|
|
<primitive: #console.open>
|
|
|
|
##StdioException signal: ('cannot open ' & filename).
|
|
|
|
}
|
|
|
|
"
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method _open
|
2016-12-31 17:22:57 +00:00
|
|
|
{
|
|
|
|
<primitive: #console.open>
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method _close: handle
|
2016-12-31 17:22:57 +00:00
|
|
|
{
|
|
|
|
<primitive: #console.close>
|
|
|
|
self primitiveFailed.
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method _clear: handle
|
2016-12-31 17:22:57 +00:00
|
|
|
{
|
|
|
|
<primitive: #console.clear>
|
|
|
|
self primitiveFailed.
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method _writeOn: handle text: text
|
2016-12-31 17:22:57 +00:00
|
|
|
{
|
|
|
|
<primitive: #console.write>
|
|
|
|
self primitiveFailed.
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method _setCursor: handle point: point
|
2016-12-31 17:22:57 +00:00
|
|
|
{
|
|
|
|
<primitive: #console.setcursor>
|
|
|
|
self primitiveFailed.
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"
|
2017-01-06 09:53:40 +00:00
|
|
|
method(#class) open
|
2016-12-31 17:22:57 +00:00
|
|
|
{
|
|
|
|
<primitive: #console.open>
|
|
|
|
self primitiveFailed.
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method close
|
2016-12-31 17:22:57 +00:00
|
|
|
{
|
|
|
|
<primitive: #console.close>
|
|
|
|
self primitiveFailed.
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method setCursorTo: point
|
2016-12-31 17:22:57 +00:00
|
|
|
{
|
|
|
|
<primitive: #console.setcursor>
|
|
|
|
self primitiveFailed.
|
|
|
|
}
|
|
|
|
"
|
|
|
|
|
|
|
|
##x := Colsole new.
|
|
|
|
##x := Console open.
|
|
|
|
##(x isError) ifTrue: [
|
|
|
|
## handle error...
|
|
|
|
## ]
|
|
|
|
## ifFalse: [
|
|
|
|
## x setCursor (1, 2).
|
|
|
|
## x clear.
|
|
|
|
## x close.
|
|
|
|
## ]
|
|
|
|
|
|
|
|
##x := File open: 'abc.def'
|
|
|
|
##t := x read: 1000.
|
|
|
|
##x close.
|
|
|
|
}
|
|
|
|
|
|
|
|
"
|
|
|
|
Stix define: 'console_write'
|
|
|
|
forClass: Console
|
|
|
|
method: 'write: aString upto: length'
|
|
|
|
returns: 'size_t'
|
|
|
|
arguments: 'void* size_t'
|
|
|
|
|
|
|
|
---> produces a method like this internally...
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
class Console
|
2016-12-31 17:22:57 +00:00
|
|
|
{
|
2017-01-06 09:53:40 +00:00
|
|
|
method write: aString upto: length
|
2016-12-31 17:22:57 +00:00
|
|
|
{
|
|
|
|
<ffi: int console_write (int*, char*, [int, int, char]* )> <== parse the string, create a descriptor table, key is console_write, value is resolved to a function pointer.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"
|
|
|
|
|