added Integer>>priorTo:do:by:

changed the index of Integer>>bitAt: and stix_bitatint() to be 0 based.
added Error>>asCharacter
allowed underscores in integer literals
This commit is contained in:
hyunghwan.chung
2016-12-28 13:42:12 +00:00
parent d03b97f19d
commit eea13c0bd2
13 changed files with 216 additions and 113 deletions

View File

@ -151,8 +151,8 @@
#method == anObject
{
"check if the receiver is identical to anObject.
this doesn't compare the contents"
(* check if the receiver is identical to anObject.
* this doesn't compare the contents *)
<primitive: #_identical>
}
@ -164,8 +164,8 @@
#method(#class) == anObject
{
"check if the receiver is identical to anObject.
this doesn't compare the contents"
(* check if the receiver is identical to anObject.
* this doesn't compare the contents *)
<primitive: #_identical>
}
@ -234,10 +234,10 @@
#method(#class) isMemberOf: aClass
{
## a class object is an instance of Class
## but Class inherits from Apex. On the other hand,
## most of ordinary classes are under Object again under Apex.
## special consideration is required here.
(* a class object is an instance of Class
* but Class inherits from Apex. On the other hand,
* most of ordinary classes are under Object again under Apex.
* special consideration is required here. *)
^aClass == Class
}
@ -362,6 +362,11 @@
{
<primitive: #_error_as_integer>
}
#method asCharacter
{
<primitive: #_error_as_character>
}
#method asString
{

View File

@ -3,8 +3,6 @@
#include 'Boolean.st'.
#########################################################################################
#class Magnitude(Object)
{
}
@ -70,7 +68,6 @@
self primitiveFailed.
}
#method // aNumber
{
<primitive: #_integer_quo2>
@ -127,9 +124,8 @@
#method bitAt: index
{
"## index is 1-based"
<primitive: #_integer_bitat>
^(self bitShift: (index - 1) negated) bitAnd: 1.
^(self bitShift: index negated) bitAnd: 1.
}
#method bitAnd: aNumber
@ -176,7 +172,6 @@
#method to: end by: step do: aBlock
{
| i |
i := self.
(step > 0)
ifTrue: [
@ -197,6 +192,30 @@
{
^self to: end by: 1 do: aBlock.
}
#method priorTo: end by: step do: aBlock
{
| i |
i := self.
(step > 0)
ifTrue: [
[ i < end ] whileTrue: [
aBlock value: i.
i := i + step.
].
]
ifFalse: [
[ i > end ] whileTrue: [
aBlock value: i.
i := i - step.
].
].
}
#method priorTo: end do: aBlock
{
^self priorTo: end by: 1 do: aBlock.
}
#method abs
{
@ -210,10 +229,8 @@
self > 0 ifTrue: [^1].
^0.
}
}
#class Integer(Number)
{
#method timesRepeat: aBlock
@ -260,6 +277,7 @@
}
}
#########################################################################################
#include 'Collect.st'.
@ -293,10 +311,6 @@
#include 'Except.st'.
#include 'Process.st'.
#class Resource(Object)
{
}
#class FFI(Object)
{
#dcl name handle funcs.
@ -314,9 +328,9 @@
self.handle := self privateOpen: self.name.
"[ self.handle := self privateOpen: self.name ]
on: Error do: [
on: Exception do: [
]
on: XError do: [
on: XException do: [
]."
^self.
@ -372,4 +386,4 @@ f isNil ifTrue: [ self error: 'No such function' ].
#########################################################################################
#include 'Stdio.st'.
#include 'Console.st'.
#include 'Console.st'.

View File

@ -2,7 +2,6 @@
#class MyObject(Object)
{
#method(#class) main
{
| s c f |
@ -56,7 +55,7 @@
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' ' ].
(((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'.

View File

@ -125,14 +125,14 @@
##v1 := Stdio2 open: '/tmp/1.txt' for: 'w+'.
v1 := Stdio2 new open: '/tmp/x/1.txt' for: 'w+'.
v1 := Stdio2 new open: '/tmp/1.txt' for: 'w+'.
(v1 isError)
ifTrue: [
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 puts ('hello', 'world', 'good', C'\n', C'\t', 'under my umbrella 123.', C'\n').
v1 close.
(*v1 format(10, 20) isNil ifFalse: [
@ -147,6 +147,43 @@
self varg_test3 (10, 20, 30, 40, 50) dump.
thisContext vargCount dump.
thisContext vargCount dump.
((2305843009213693951 bitAt: 61) = 0) ifFalse: [
System logNl: 'Test 1 failed'.
thisProcess terminate
].
((-2305843009213693951 bitAt: 62) = 1) ifFalse: [
System logNl: 'Test 2 failed'.
thisProcess terminate
].
((2r1000000000000000000000000000100000000000000000000000000000000000000000000000 bitAt: 120) = 0) ifFalse: [
System logNl: 'Test 3 failed'.
thisProcess terminate
].
((-2r1000000000000000000000000000100000000000000000000000000000000000000000000000 bitAt: 16rFFFFFFFFFFFFFFFF0) = 1) ifFalse: [
System logNl: 'Test 4 failed'.
thisProcess terminate
].
0 priorTo: 200 do: [:i |
| k |
k := 1 bitShift: i.
## (k printStringRadix: 2) dump.
((k bitAt: i) = 1) ifFalse: [
System logNl: 'Test 5 failed'.
thisProcess terminate.
].
((k bitAt: i - 1) = 0) ifFalse: [
System logNl: 'Test 6 failed'.
thisProcess terminate.
].
].
2r100000000_10001111_01010000 dump.
16rFFFFFFFF_12345678 dump.
}
#method(#class) varg_test()
@ -171,6 +208,17 @@
## ^b * 100
^f
}
#method t001(a)
{
a isNil ifTrue: [^E'1'].
(a = 20) ifTrue: [^error].
(a = 10) ifTrue: [^10].
^a.
a := error(10).
[ a = error(10) ] ifTrue: [....].
}
}
#extend MyObject