added putc to Stdio.
renamed/refactored some encoding conversion functions. added stix_errnumtoerrstr(). added generr.st to generate error string code
This commit is contained in:
@ -332,10 +332,39 @@
|
||||
}
|
||||
}
|
||||
|
||||
(* --------------------
|
||||
#pooldic Error
|
||||
{
|
||||
#NONE := error(0).
|
||||
#GENERIC := error(1).
|
||||
#
|
||||
}
|
||||
------------------- *)
|
||||
|
||||
#class Error(Apex)
|
||||
{
|
||||
(* ----------------------------
|
||||
TODO: support constant declaration...
|
||||
|
||||
#const
|
||||
{
|
||||
#NONE := error(0).
|
||||
#GENERIC := error(1).
|
||||
}
|
||||
-------------------------------- *)
|
||||
|
||||
#method isError
|
||||
{
|
||||
^true
|
||||
}
|
||||
|
||||
#method asInteger
|
||||
{
|
||||
<primitive: #_error_as_integer>
|
||||
}
|
||||
|
||||
#method asString
|
||||
{
|
||||
<primitive: #_error_as_string>
|
||||
}
|
||||
}
|
||||
|
85
stix/kernel/generr.st
Normal file
85
stix/kernel/generr.st
Normal file
@ -0,0 +1,85 @@
|
||||
#include 'Stix.st'.
|
||||
|
||||
#class MyObject(Object)
|
||||
{
|
||||
|
||||
#method(#class) main
|
||||
{
|
||||
| s c f |
|
||||
|
||||
s := #(
|
||||
'no error'
|
||||
'generic error'
|
||||
|
||||
'not implemented'
|
||||
'subsystem error'
|
||||
'internal error that should never have happened'
|
||||
|
||||
'insufficient system memory'
|
||||
'insufficient object memory'
|
||||
|
||||
'invalid parameter or argument'
|
||||
'data not found'
|
||||
'existing/duplicate data'
|
||||
'busy'
|
||||
'access denied'
|
||||
'operation not permitted'
|
||||
'not a directory'
|
||||
'interrupted'
|
||||
'pipe error'
|
||||
'resource temporarily unavailable'
|
||||
|
||||
'data too large'
|
||||
'message sending error'
|
||||
'range error'
|
||||
'byte-code full'
|
||||
'dictionary full'
|
||||
'processor full'
|
||||
'semaphore heap full'
|
||||
'semaphore list full'
|
||||
'divide by zero'
|
||||
'I/O error'
|
||||
'encoding conversion error'
|
||||
).
|
||||
|
||||
f := Stdio open: 'generr.out' for: 'w'.
|
||||
[ f isError ] ifTrue: [ System logNl: 'Cannot open generr.out'. thisProcess terminate. ].
|
||||
|
||||
c := s size - 1.
|
||||
0 to: c do: [:i |
|
||||
self printString: (s at: i) index: i on: f.
|
||||
].
|
||||
|
||||
f puts: S'static stix_ooch_t* errstr[] =\n{\n'.
|
||||
0 to: c do: [:i |
|
||||
((i rem: 8) = 0) ifTrue: [ f putc: C'\t' ].
|
||||
f puts: S'e'.
|
||||
f puts: (i asString).
|
||||
(i = c) ifFalse: [f puts: S',' ].
|
||||
(((i + 1) rem: 8) = 0) ifTrue: [ f putc: C'\n' ] ifFalse: [ f putc: C' ' ].
|
||||
].
|
||||
(((c + 1) rem: 8) = 0) ifFalse: [ f putc: C'\n' ].
|
||||
f puts: S'};\n'.
|
||||
|
||||
f close.
|
||||
}
|
||||
|
||||
#method(#class) printString: s index: index on: f
|
||||
{
|
||||
| c |
|
||||
c := s size - 1.
|
||||
|
||||
f puts: 'static stix_ooch_t e'.
|
||||
f puts: index asString.
|
||||
f puts: '[] = {'.
|
||||
|
||||
0 to: c do: [:i |
|
||||
f putc: $'.
|
||||
f putc: (s at: i).
|
||||
f putc: $'.
|
||||
(i = c) ifFalse: [f putc: $, ].
|
||||
].
|
||||
|
||||
f puts: S',\'\\0\'};\n'.
|
||||
}
|
||||
}
|
@ -125,17 +125,16 @@
|
||||
|
||||
|
||||
##v1 := Stdio2 open: '/tmp/1.txt' for: 'w+'.
|
||||
v1 := Stdio2 new open: '/tmp/1.txt' for: 'w+'.
|
||||
v1 := Stdio2 new open: '/tmp/x/1.txt' for: 'w+'.
|
||||
(v1 isError)
|
||||
ifTrue: [
|
||||
System logNl: ('Error in opening a file....').
|
||||
System logNl: ('Error in opening a file....' & v1 asString).
|
||||
]
|
||||
ifFalse: [
|
||||
## v1 puts: 'hello'.
|
||||
v1 puts ('hello', 'world', 'good', C'\n', C'\t', 'under my umbrella.', C'\n').
|
||||
v1 close.
|
||||
|
||||
|
||||
(*v1 format(10, 20) isNil ifFalse: [
|
||||
'Beautiful life' dump.
|
||||
].*)
|
||||
|
Reference in New Issue
Block a user