added moo_pfbase_t and changed some functions to return moo_pfbase_t* instead of moo_pfimpl_t
touched up some modules
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
## TODO: move Pointe to a separate file
|
||||
class Point(Object)
|
||||
{
|
||||
dcl x y.
|
||||
@ -46,20 +47,22 @@ extend SmallInteger
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
class Console(Object)
|
||||
class Console(Object) from 'console'
|
||||
{
|
||||
dcl handle.
|
||||
"
|
||||
method(#primitive) _open.
|
||||
method(#primitive) _close.
|
||||
method(#primitive) _clear.
|
||||
method(#primitive) _setcursor(x, y).
|
||||
method(#primitive) _write(msg).
|
||||
|
||||
(*
|
||||
method finalize
|
||||
{
|
||||
handle notNil ifTrue: [
|
||||
self _close: handle.
|
||||
]
|
||||
if (still open) {
|
||||
self _close.
|
||||
}
|
||||
}
|
||||
"
|
||||
*)
|
||||
|
||||
|
||||
## method(#class) input
|
||||
@ -72,7 +75,7 @@ class Console(Object)
|
||||
| c |
|
||||
|
||||
c := self new.
|
||||
c handle: (c _open).
|
||||
c _open. ## TODO error check - if ((e := c _open) isError) { ^e }.
|
||||
^c
|
||||
}
|
||||
|
||||
@ -80,127 +83,24 @@ class Console(Object)
|
||||
## {
|
||||
## }
|
||||
|
||||
|
||||
method handle: v
|
||||
{
|
||||
self.handle := v.
|
||||
}
|
||||
|
||||
method close
|
||||
{
|
||||
self _close: self.handle.
|
||||
self.handle := nil.
|
||||
self _close.
|
||||
}
|
||||
|
||||
method write: text
|
||||
{
|
||||
^self _writeOn: self.handle text: text.
|
||||
^self _write(text)
|
||||
}
|
||||
|
||||
method clear
|
||||
{
|
||||
^self _clear: self.handle
|
||||
^self _clear.
|
||||
}
|
||||
|
||||
method setCursor: point
|
||||
{
|
||||
^self _setCursor: self.handle point: point.
|
||||
}
|
||||
"
|
||||
method _open: filename mode: mode
|
||||
{
|
||||
self.handle := self __open: filename mode: mode.
|
||||
^self.
|
||||
}
|
||||
|
||||
method __open: filename mode: mode
|
||||
{
|
||||
<primitive: #console.open>
|
||||
##StdioException signal: ('cannot open ' & filename).
|
||||
}
|
||||
"
|
||||
|
||||
method _open
|
||||
{
|
||||
<primitive: #console.open>
|
||||
}
|
||||
|
||||
method _close: handle
|
||||
{
|
||||
<primitive: #console.close>
|
||||
self primitiveFailed.
|
||||
}
|
||||
|
||||
method _clear: handle
|
||||
{
|
||||
<primitive: #console.clear>
|
||||
self primitiveFailed.
|
||||
}
|
||||
|
||||
method _writeOn: handle text: text
|
||||
{
|
||||
<primitive: #console.write>
|
||||
self primitiveFailed.
|
||||
}
|
||||
|
||||
method _setCursor: handle point: point
|
||||
{
|
||||
<primitive: #console.setcursor>
|
||||
self primitiveFailed.
|
||||
}
|
||||
|
||||
|
||||
|
||||
"
|
||||
method(#class) open
|
||||
{
|
||||
<primitive: #console.open>
|
||||
self primitiveFailed.
|
||||
}
|
||||
|
||||
method close
|
||||
{
|
||||
<primitive: #console.close>
|
||||
self primitiveFailed.
|
||||
}
|
||||
|
||||
method setCursorTo: point
|
||||
{
|
||||
<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.
|
||||
}
|
||||
|
||||
"
|
||||
Moo define: 'console_write'
|
||||
forClass: Console
|
||||
method: 'write: aString upto: length'
|
||||
returns: 'size_t'
|
||||
arguments: 'void* size_t'
|
||||
|
||||
---> produces a method like this internally...
|
||||
|
||||
class Console
|
||||
{
|
||||
method write: aString upto: length
|
||||
{
|
||||
<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.
|
||||
^self _setcursor(point x, point y)
|
||||
}
|
||||
}
|
||||
"
|
||||
|
||||
|
@ -1,13 +1,11 @@
|
||||
class _FFI(Object) from 'ffi'
|
||||
{
|
||||
(*
|
||||
* the ffi module installs the following methods
|
||||
* method(#class) _newInstSize
|
||||
* method open: name
|
||||
* method close
|
||||
* method call
|
||||
* method call: func sig: sig with: args.
|
||||
*)
|
||||
method(#primitive) open(name).
|
||||
method(#primitive) close().
|
||||
method(#primitive) getsym(name).
|
||||
|
||||
(* TODO: make call variadic? method(#primitive,#variadic) call (func, sig). *)
|
||||
method(#primitive) call(func, sig, args).
|
||||
}
|
||||
|
||||
class FFI(Object)
|
||||
@ -31,7 +29,7 @@ class FFI(Object)
|
||||
self.funcs removeAllKeys.
|
||||
self.name := name.
|
||||
|
||||
x := self.ffi open: name.
|
||||
x := self.ffi open(name).
|
||||
(x isError) ifTrue: [^x].
|
||||
|
||||
^self.
|
||||
@ -47,12 +45,11 @@ class FFI(Object)
|
||||
| f |
|
||||
f := self.funcs at: name.
|
||||
(f isError) ifTrue: [
|
||||
f := self.ffi getsym: name.
|
||||
f := self.ffi getsym(name).
|
||||
(f isError) ifTrue: [^f].
|
||||
self.funcs at: name put: f.
|
||||
].
|
||||
|
||||
(*^self.ffi call: f sig: sig with: args*)
|
||||
^self.ffi call(f, sig, args)
|
||||
}
|
||||
}
|
||||
|
@ -331,6 +331,7 @@ class MyObject(Object)
|
||||
|
||||
(System at: #Processor) dump.
|
||||
System logNl: 'Sleeping start now....'.
|
||||
|
||||
Processor sleepFor: 2.
|
||||
}
|
||||
|
||||
|
@ -3,16 +3,15 @@ class Stdio(Object) from 'stdio'
|
||||
{
|
||||
dcl(#class) in out err.
|
||||
|
||||
(*
|
||||
* The following methods are generated by the module.
|
||||
* method(#class) _newInstSize { <primitive: #stdio._newInstSize> }
|
||||
* method open: name for: mode { <primitive: #stdio.open> }
|
||||
* method close { <primitive: #stdio.close> }
|
||||
*)
|
||||
method(#primitive) open(name, mode).
|
||||
method(#primitive) close.
|
||||
method(#primitive) gets.
|
||||
method(#primitive,#variadic) puts().
|
||||
method(#primitive,#variadic) putc().
|
||||
|
||||
method(#class) open: name for: mode
|
||||
{
|
||||
^(self new) open: name for: mode
|
||||
^(self new) open(name, mode)
|
||||
}
|
||||
|
||||
(* ---------------------
|
||||
@ -71,5 +70,4 @@ class Stdio2(Stdio)
|
||||
##raise exception. prohibited...
|
||||
^(super new).
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -51,12 +51,12 @@ class B.TestObject(Object)
|
||||
|
||||
pooldic ABC
|
||||
{
|
||||
#KKK := 20.
|
||||
KKK := 20.
|
||||
}
|
||||
|
||||
pooldic SRX.ABC
|
||||
{
|
||||
#JJJ := 1000.
|
||||
JJJ := 1000.
|
||||
}
|
||||
class MyConsole(Console)
|
||||
{
|
||||
@ -125,7 +125,7 @@ class MyObject(TestObject)
|
||||
|
||||
|
||||
##v1 := Stdio2 open: '/tmp/1.txt' for: 'w+'.
|
||||
v1 := Stdio2 new open: '/tmp/1.txt' for: 'w+'.
|
||||
v1 := Stdio2 new open('/tmp/1.txt', 'w+').
|
||||
(v1 isError)
|
||||
ifTrue: [
|
||||
System logNl: ('Error in opening a file....' & v1 asString).
|
||||
@ -195,21 +195,21 @@ class MyObject(TestObject)
|
||||
v2 dump.
|
||||
}
|
||||
|
||||
method(#class) varg_test()
|
||||
method(#class,#variadic) varg_test()
|
||||
{
|
||||
0 to: (thisContext vargCount - 1) do: [:k |
|
||||
(thisContext vargAt: k) dump.
|
||||
].
|
||||
^999
|
||||
}
|
||||
method(#class) varg_test2(a,b,c)
|
||||
method(#class,#variadic) varg_test2(a,b,c)
|
||||
{
|
||||
0 to: (thisContext vargCount - 1) do: [:k |
|
||||
(thisContext vargAt: k) dump.
|
||||
].
|
||||
^a
|
||||
}
|
||||
method(#class) varg_test3(a,b,c,d,e,f)
|
||||
method(#class,#variadic) varg_test3(a,b,c,d,e,f)
|
||||
{
|
||||
0 to: (thisContext vargCount - 1) do: [:k |
|
||||
(thisContext vargAt: k) dump.
|
||||
@ -218,7 +218,7 @@ class MyObject(TestObject)
|
||||
^f
|
||||
}
|
||||
|
||||
method(#class) t001(a)
|
||||
method(#class,#variadic) t001(a)
|
||||
{
|
||||
a isNil ifTrue: [^error(10)].
|
||||
(a = 20) ifTrue: [^error].
|
||||
@ -242,4 +242,4 @@ extend MyObject
|
||||
System logNl: JJJ.
|
||||
System logNl: -200 asString.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user