diff --git a/stix/kernel/Apex.st b/stix/kernel/Apex.st index d8599da..744e564 100644 --- a/stix/kernel/Apex.st +++ b/stix/kernel/Apex.st @@ -1,16 +1,16 @@ -#class Apex(nil) +class Apex(nil) { - #dcl(#class) sysdic. + dcl(#class) sysdic. ## ------------------------------------------------------- ## ------------------------------------------------------- - #method(#class) dump + method(#class) dump { } - #method dump + method dump { } @@ -18,12 +18,12 @@ ## ------------------------------------------------------- ## ------------------------------------------------------- - #method(#class) yourself + method(#class) yourself { ^self. } - #method yourself + method yourself { ^self. } @@ -31,31 +31,31 @@ ## ------------------------------------------------------- ## ------------------------------------------------------- - #method(#class) basicNew + method(#class) basicNew { self primitiveFailed. } - #method(#class) basicNew: anInteger + method(#class) basicNew: anInteger { self primitiveFailed. } - #method(#class) ngcNew + method(#class) ngcNew { self primitiveFailed. } - #method(#class) ngcNew: anInteger + method(#class) ngcNew: anInteger { self primitiveFailed. } - #method(#class) new + method(#class) new { | x | x := self basicNew. @@ -63,7 +63,7 @@ ^x. } - #method(#class) new: anInteger + method(#class) new: anInteger { | x | ## TODO: check if the class is a fixed class. @@ -73,20 +73,20 @@ ^x. } - #method initialize + method initialize { "a subclass may override this method." ^self. } - #method ngcDispose + method ngcDispose { self primitiveFailed. } ## ------------------------------------------------------- ## ------------------------------------------------------- - #method shallowCopy + method shallowCopy { self primitiveFailed. @@ -95,12 +95,12 @@ ## ------------------------------------------------------- ## ------------------------------------------------------- - #method class + method class { } - #method(#class) class + method(#class) class { ^Class @@ -109,123 +109,152 @@ ## ------------------------------------------------------- ## ------------------------------------------------------- - #method basicSize + method basicSize { self primitiveFailed. } - #method(#class) basicSize + method(#class) basicSize { self primitiveFailed. } - #method basicAt: index + method basicAt: index { self index: index outOfRange: (self basicSize). } - #method basicAt: index put: anObject + method basicAt: index put: anObject { self index: index outOfRange: (self basicSize). } - #method(#class) basicAt: index + method(#class) basicAt: index { self index: index outOfRange: (self basicSize). } - #method(#class) basicAt: index put: anObject + method(#class) basicAt: index put: anObject { self index: index outOfRange: (self basicSize). } - ## ------------------------------------------------------- - ## ------------------------------------------------------- - #method(#class) hash + (* ------------------------------------------------------------------ + * HASHING + * ------------------------------------------------------------------ *) + method hash { self subclassResponsibility: #hash } - #method hash + + method(#class) hash { self subclassResponsibility: #hash } - ## ------------------------------------------------------- - ## ------------------------------------------------------- + (* ------------------------------------------------------------------ + * IDENTITY TEST + * ------------------------------------------------------------------ *) - #method == anObject + method == anObject { (* check if the receiver is identical to anObject. * this doesn't compare the contents *) + self primitiveFailed. } - #method ~~ anObject + method ~~ anObject { ^(self == anObject) not. } - #method(#class) == anObject + method(#class) == anObject { (* check if the receiver is identical to anObject. * this doesn't compare the contents *) + self primitiveFailed. } - #method(#class) ~~ anObject + method(#class) ~~ anObject { ^(self == anObject) not. } - ## TODO: add = and ~= for equality check. + (* ------------------------------------------------------------------ + * EQUALITY TEST + * ------------------------------------------------------------------ *) + method = anObject + { + + self subclassResponsibility: #= + } + + method ~= anObject + { + + ^(self = anObject) not. + } + method(#class) = anObject + { + + self subclassResponsibility: #= + } + + method(#class) ~= anObject + { + + ^(self = anObject) not. + } + + (* ------------------------------------------------------------------ + * COMMON QUERIES + * ------------------------------------------------------------------ *) - ## ------------------------------------------------------- - ## COMMON QUERIES - ## ------------------------------------------------------- - - #method isNil + method isNil { "^self == nil." ^false } - #method notNil + method notNil { "^(self == nil) not" "^self ~= nil." ^true. } - #method(#class) isNil + method(#class) isNil { "^self == nil." ^false } - #method(#class) notNil + method(#class) notNil { "^(self == nil) not" "^self ~= nil." ^true. } - #method isError + method isError { ^false } - #method(#class) isError + method(#class) isError { ^false } @@ -233,7 +262,7 @@ ## ------------------------------------------------------- ## ------------------------------------------------------- - #method(#class) inheritsFrom: aClass + method(#class) inheritsFrom: aClass { | c | c := self superclass. @@ -244,7 +273,7 @@ ^false } - #method(#class) isMemberOf: aClass + method(#class) isMemberOf: aClass { (* a class object is an instance of Class * but Class inherits from Apex. On the other hand, @@ -253,109 +282,103 @@ ^aClass == Class } - #method(#class) isKindOf: aClass + method(#class) isKindOf: aClass { ^(self isMemberOf: aClass) or: [self inheritsFrom: aClass]. } - #method isMemberOf: aClass + method isMemberOf: aClass { ^self class == aClass } - #method isKindOf: aClass + method isKindOf: aClass { ^(self isMemberOf: aClass) or: [self class inheritsFrom: aClass]. } - ## ------------------------------------------------------- - ## ------------------------------------------------------- - " - #method(#class) respondsTo: selectorSymbol + (* ----------------- + method(#class) respondsTo: selectorSymbol { TODO: find selectorSymbol in the class method dictionary... } - #method respondsTo: selectorSymbol + method respondsTo: selectorSymbol { TODO: find selectorSymbol in the method dictionary... } - " + ------------ *) - ## ------------------------------------------------------- + method exceptionizeError: trueOrFalse + { + + self class cannotExceptionizeError + } - ## method(#class) primitiveFailed - ## { - ## this method will be added after Exception class has been defined. - ## } - - #method primitiveFailed + (* ------------------------------------------------------------------ + * COMMON ERROR/EXCEPTION HANDLERS + * ------------------------------------------------------------------ *) + method primitiveFailed { self class primitiveFailed. } - #method doesNotUnderstand: messageSymbol + method doesNotUnderstand: messageSymbol { self class doesNotUnderstand: messageSymbol } - #method(#class) error: msgText + method index: index outOfRange: ubound + { + self class index: index outOfRange: ubound. + } + + method cannotInstantiate + { + self class cannotInstantiate + } + + method subclassResponsibility: message_name + { + self class subclassResponsibility: message_name + } + + method cannotExceptionizeError + { + self class cannotExceptionizeError + } + + method(#class) error: msgText { ## TODO: implement this ## Error signal: msgText. msgText dump. } - #method error: aString + method error: aString { self class error: aString. } - - #method index: index outOfRange: ubound - { - self class index: index outOfRange: ubound. - } - - #method cannotInstantiate - { - self class cannotInstantiate - } - - #method subclassResponsibility: message_name - { - self class subclassResponsibility: message_name - } - - #method cannotExceptionizeError - { - self class cannotExceptionizeError - } - - #method exceptionizeError: trueOrFalse - { - - self class cannotExceptionizeError - } } -#class Object(Apex) +class Object(Apex) { } -#class UndefinedObject(Apex) +class UndefinedObject(Apex) { - #method isNil + method isNil { ^true } - #method notNil + method notNil { ^false. } - #method handleException: exception + method handleException: exception { ('### EXCEPTION NOT HANDLED #### ' & exception class name & ' - ' & exception messageText) dump. ## TODO: debug the current process???? " @@ -365,7 +388,7 @@ } -#pooldic ErrorCode +pooldic ErrorCode { (* migrate it into Error class *) #NONE := error(0). @@ -373,7 +396,7 @@ #NOENT := error(2). } -#class Error(Apex) +class Error(Apex) { (* ---------------------------- TODO: support constant declaration... @@ -385,22 +408,22 @@ } -------------------------------- *) - #method isError + method isError { ^true } - #method asInteger + method asInteger { } - #method asCharacter + method asCharacter { } - #method asString + method asString { } diff --git a/stix/kernel/Boolean.st b/stix/kernel/Boolean.st index 35c31f3..85b784d 100644 --- a/stix/kernel/Boolean.st +++ b/stix/kernel/Boolean.st @@ -1,90 +1,90 @@ -#class Boolean(Object) +class Boolean(Object) { - "TODO: do i need to really define methods defined in True and False here? - and call subclassResponsibiltiy?" + (* TODO: do i need to really define methods defined in True and False here? + and call subclassResponsibiltiy?" *) } -#class True(Boolean) +class True(Boolean) { - #method not + method not { ^false } - #method & aBoolean + method & aBoolean { ^aBoolean } - #method | aBoolean + method | aBoolean { ^true } - #method and: aBlock + method and: aBlock { ^aBlock value } - #method or: aBlock + method or: aBlock { ^true } - #method ifTrue: trueBlock ifFalse: falseBlock + method ifTrue: trueBlock ifFalse: falseBlock { ^trueBlock value. } - #method ifTrue: trueBlock + method ifTrue: trueBlock { ^trueBlock value. } - #method ifFalse: falseBlock + method ifFalse: falseBlock { ^nil. } } -#class False(Boolean) +class False(Boolean) { - #method not + method not { ^true } - #method & aBoolean + method & aBoolean { ^false } - #method | aBoolean + method | aBoolean { ^aBoolean } - #method and: aBlock + method and: aBlock { ^false } - #method or: aBlock + method or: aBlock { ^aBlock value } - #method ifTrue: trueBlock ifFalse: falseBlock + method ifTrue: trueBlock ifFalse: falseBlock { ^falseBlock value. } - #method ifTrue: trueBlock + method ifTrue: trueBlock { ^nil. } - #method ifFalse: falseBlock + method ifFalse: falseBlock { ^falseBlock value. } diff --git a/stix/kernel/Class.st b/stix/kernel/Class.st index 7cac092..2c0ff45 100644 --- a/stix/kernel/Class.st +++ b/stix/kernel/Class.st @@ -2,45 +2,42 @@ ## the Class object should be a variable-pointer object because ## it needs to accomodate class instance variables. ## -#class(#pointer) Class(Apex) +class(#pointer) Class(Apex) { - #dcl spec selfspec superclass subclasses name instvars classvars classinstvars pooldics instmthdic classmthdic. + dcl spec selfspec superclass subclasses name instvars classvars classinstvars pooldics instmthdic classmthdic. - #method(#class) basicNew + method(#class) basicNew { ## you must not instantiate a new class this way. self cannotInstantiate. } - #method(#class) initialize + method(#class) initialize { ^self. } - - ## ######################################################################## - ## most of the following methods can actually become class methods of Apex. - ## if the instance varibles can be made accessible from the Apex class. - ## ######################################################################## - - #method name + (* most of the following methods can actually become class methods of Apex. + * if the instance varibles can be made accessible from the Apex class. *) + + method name { ^self.name } - #method superclass + method superclass { ^self.superclass } - #method specNumInstVars + method specNumInstVars { ## shift right by 7 bits. ## see stix-prv.h for details. ^self.spec bitShift: -7 } - "#method inheritsFrom: aSuperclass + (*method inheritsFrom: aSuperclass { | c | c := self superclass. @@ -49,5 +46,5 @@ c := c superclass. ]. ^false - }" + }*) } diff --git a/stix/kernel/Collect.st b/stix/kernel/Collect.st index 1e9f571..d5e86f6 100644 --- a/stix/kernel/Collect.st +++ b/stix/kernel/Collect.st @@ -1,57 +1,52 @@ -#class Collection(Object) + +class Collection(Object) { } ## ------------------------------------------------------------------------------- - -#class(#pointer) Array(Collection) +class(#pointer) Array(Collection) { - #method size + method size { - ^self basicSize. + ^self basicSize } - #method ubound - { - ^(self basicSize - 1). - } - - #method at: anInteger + method at: anInteger { ^self basicAt: anInteger. } - #method at: anInteger put: aValue + method at: anInteger put: aValue { ^self basicAt: anInteger put: aValue. } - #method first + method first { ^self at: 0. } - #method last + method last { - ^self at: (self ubound). + ^self at: (self basicSize - 1). } - #method do: aBlock + method do: aBlock { - 0 to: (self ubound) do: [:i | aBlock value: (self at: i)]. + 0 priorTo: (self basicSize) do: [:i | aBlock value: (self at: i)]. } - #method copy: anArray + method copy: anArray { - 0 to: (anArray ubound) do: [:i | self at: i put: (anArray at: i) ]. + 0 priorTo: (anArray basicSize) do: [:i | self at: i put: (anArray at: i) ]. } } ## ------------------------------------------------------------------------------- -#class(#character) String(Array) +class(#character) String(Array) { - #method & string + method & string { (* TOOD: make this a primitive for performance. *) @@ -70,7 +65,7 @@ ^newstr } - #method asString + method asString { ^self } @@ -78,9 +73,9 @@ ## ------------------------------------------------------------------------------- -#class(#character) Symbol(String) +class(#character) Symbol(String) { - #method asString + method asString { (* TODO: make this a primitive for performance *) @@ -96,14 +91,14 @@ ## ------------------------------------------------------------------------------- -#class(#byte) ByteArray(Collection) +class(#byte) ByteArray(Collection) { - #method at: anInteger + method at: anInteger { ^self basicAt: anInteger. } - #method at: anInteger put: aValue + method at: anInteger put: aValue { ^self basicAt: anInteger put: aValue. } @@ -111,22 +106,22 @@ ## ------------------------------------------------------------------------------- -#class Set(Collection) +class Set(Collection) { - #dcl tally bucket. + dcl tally bucket. - #method initialize + method initialize { self.tally := 0. self.bucket := Array new: 100. } - #method size + method size { ^self.tally } - #method at: key + method at: key { | ass | ass := self __find: key or_upsert: false with: nil. @@ -134,7 +129,7 @@ ^ErrorCode.NOENT } - #method at: key ifAbsent: error_block + method at: key ifAbsent: error_block { | ass | ass := self __find: key or_upsert: false with: nil. @@ -142,13 +137,13 @@ ^error_block value. } - #method at: key put: value + method at: key put: value { self __find: key or_upsert: true with: value. ^value } - #method __find: key or_upsert: upsert with: value + method __find: key or_upsert: upsert with: value { | hv ass bs index ntally | @@ -158,7 +153,7 @@ [(ass := self.bucket at: index) notNil] whileTrue: [ - [key == ass key] ifTrue: [ + [key == ass key] ifTrue: [ (* TODO: change it to equality??? *) (* found *) upsert ifTrue: [ass value: value]. ^ass @@ -181,7 +176,7 @@ ^ass } - #method do: block + method do: block { | bs | @@ -192,7 +187,7 @@ ]. } - #method keysAndValuesDo: block + method keysAndValuesDo: block { | bs | @@ -204,15 +199,15 @@ } } -#class SymbolSet(Set) +class SymbolSet(Set) { } -#class Dictionary(Set) +class Dictionary(Set) { } -#pooldic Log +pooldic Log { ## ----------------------------------------------------------- ## defines log levels @@ -226,7 +221,7 @@ #FATAL := 16. } -#class SystemDictionary(Dictionary) +class SystemDictionary(Dictionary) { ## the following methods may not look suitable to be placed ## inside a system dictionary. but they are here for quick and dirty @@ -234,27 +229,27 @@ ## System logNl: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'. ## - #dcl(#pooldic) Log. + dcl(#pooldic) Log. - #method atLevel: level log: message + method atLevel: level log: message { ## do nothing upon logging failure } - #method atLevel: level log: message and: message2 + method atLevel: level log: message and: message2 { ## do nothing upon logging failure } - #method atLevel: level log: message and: message2 and: message3 + method atLevel: level log: message and: message2 and: message3 { ## do nothing upon logging failure } - #method atLevel: level logNl: message + method atLevel: level logNl: message { ## the #_log primitive accepts an array. ## so the following lines should work also. @@ -267,58 +262,64 @@ ^self atLevel: level log: message and: S'\n'. } - #method atLevel: level logNl: message and: message2 + method atLevel: level logNl: message and: message2 { ^self atLevel: level log: message and: message2 and: S'\n'. } - #method log: message + method log: message { ^self atLevel: Log.INFO log: message. } - #method log: message and: message2 + method log: message and: message2 { ^self atLevel: Log.INFO log: message and: message2. } - #method logNl: message + method logNl: message { ^self atLevel: Log.INFO logNl: message. } - #method logNl: message and: message2 + method logNl: message and: message2 { ^self atLevel: Log.INFO logNl: message and: message2. } + + method at: key + { + (key class = Symbol) ifTrue: [InvalidArgumentException signal: 'argument is not a symbol']. + ^super at: key. + } } -#class Namespace(Set) +class Namespace(Set) { } -#class PoolDictionary(Set) +class PoolDictionary(Set) { } -#class MethodDictionary(Dictionary) +class MethodDictionary(Dictionary) { } -#extend Apex +extend Apex { ## ------------------------------------------------------- ## Association has been defined now. let's add association ## creating methods ## ------------------------------------------------------- - #method(#class) -> object + method(#class) -> object { ^Association new key: self value: object } - #method -> object + method -> object { ^Association new key: self value: object } diff --git a/stix/kernel/Console.st b/stix/kernel/Console.st index b4cfe5e..88ff978 100644 --- a/stix/kernel/Console.st +++ b/stix/kernel/Console.st @@ -1,46 +1,46 @@ -#class Point(Object) +class Point(Object) { - #dcl x y. + dcl x y. - #method(#class) new + method(#class) new { ^self basicNew x: 0 y: 0. } - #method(#class) x: x y: y + method(#class) x: x y: y { ^self basicNew x: x y: y. } - #method x + method x { ^self.x } - #method y + method y { ^self.y } - #method x: x + method x: x { self.x := x } - #method y: y + method y: y { self.y := y } - #method x: x y: y + method x: x y: y { self.x := x. self.y := y } } -#extend SmallInteger +extend SmallInteger { - #method @ y + method @ y { ^Point x: self y: y } @@ -49,11 +49,11 @@ -#class Console(Object) +class Console(Object) { - #dcl handle. + dcl handle. " - #method finalize + method finalize { handle notNil ifTrue: [ self _close: handle. @@ -62,12 +62,12 @@ " -## #method(#class) input +## method(#class) input ## { ## ^self new _open: filename mode: mode ## } - #method(#class) output + method(#class) output { | c | @@ -76,73 +76,73 @@ ^c } -## #method(#class) error +## method(#class) error ## { ## } - #method handle: v + method handle: v { self.handle := v. } - #method close + method close { self _close: self.handle. self.handle := nil. } - #method write: text + method write: text { ^self _writeOn: self.handle text: text. } - #method clear + method clear { ^self _clear: self.handle } - #method setCursor: point + method setCursor: point { ^self _setCursor: self.handle point: point. } " - #method _open: filename mode: mode + method _open: filename mode: mode { self.handle := self __open: filename mode: mode. ^self. } - #method __open: filename mode: mode + method __open: filename mode: mode { ##StdioException signal: ('cannot open ' & filename). } " - #method _open + method _open { } - #method _close: handle + method _close: handle { self primitiveFailed. } - #method _clear: handle + method _clear: handle { self primitiveFailed. } - #method _writeOn: handle text: text + method _writeOn: handle text: text { self primitiveFailed. } - #method _setCursor: handle point: point + method _setCursor: handle point: point { self primitiveFailed. @@ -151,19 +151,19 @@ " - #method(#class) open + method(#class) open { self primitiveFailed. } - #method close + method close { self primitiveFailed. } - #method setCursorTo: point + method setCursorTo: point { self primitiveFailed. @@ -195,9 +195,9 @@ Stix define: 'console_write' ---> produces a method like this internally... -#class Console +class Console { - #method write: aString upto: length + method write: aString upto: length { <== parse the string, create a descriptor table, key is console_write, value is resolved to a function pointer. } diff --git a/stix/kernel/Context.st b/stix/kernel/Context.st index e790cfc..0205e90 100644 --- a/stix/kernel/Context.st +++ b/stix/kernel/Context.st @@ -1,24 +1,24 @@ -#class(#pointer) Context(Apex) +class(#pointer) Context(Apex) { - #dcl sender ip sp ntmprs. + dcl sender ip sp ntmprs. - #method sender + method sender { ^self.sender } - #method isDead + method isDead { ^self.ip < 0 } - #method temporaryCount + method temporaryCount { ^self.ntmprs } (* --------------------------------- -#method varargCount +method varargCount { method context, @@ -30,7 +30,7 @@ for a block context, it must access homeContext first and call varargCount ^self.home varargCount... } -#method varargAt: index +method varargAt: index { method context ^do calculation... @@ -42,91 +42,91 @@ block context... ---------------------------------- *) } -#class(#pointer) MethodContext(Context) +class(#pointer) MethodContext(Context) { - #dcl method receiver home origin. + dcl method receiver home origin. - #method pc + method pc { ^self.ip } - #method pcplus1 + method pcplus1 { ^self.ip + 1 } - #method goto: anInteger + method goto: anInteger { self primitiveFailed. ## TODO: need to make this a hard failure? } - #method pc: anInteger + method pc: anInteger { self.ip := anInteger. } - #method sp + method sp { ^self.sp. } - #method sp: new_sp + method sp: new_sp { self.sp := new_sp } - #method pc: new_pc sp: new_sp + method pc: new_pc sp: new_sp { self.ip := new_pc. self.sp := new_sp. } - #method method + method method { ^self.method } - #method vargCount + method vargCount { ^self basicSize - self class specNumInstVars - self.ntmprs } - #method vargAt: index + method vargAt: index { ^self basicAt: (index + self class specNumInstVars + self.ntmprs) } } -#class(#pointer) BlockContext(Context) +class(#pointer) BlockContext(Context) { - #dcl nargs source home origin. + dcl nargs source home origin. - #method vargCount + method vargCount { ^self.home vargCount } - #method vargAt: index + method vargAt: index { ^self.home vargAt: index } - #method fork + method fork { "crate a new process in the runnable state" ^self newProcess resume. } - #method newProcess + method newProcess { "create a new process in the suspended state" self primitiveFailed. } - #method newProcessWith: anArray + method newProcessWith: anArray { "create a new process in the suspended state passing the elements of anArray as block arguments" @@ -134,53 +134,53 @@ block context... self primitiveFailed. } - #method value + method value { self primitiveFailed. } - #method value: a + method value: a { self primitiveFailed. } - #method value: a value: b + method value: a value: b { self primitiveFailed. } - #method value: a value: b value: c + method value: a value: b value: c { self primitiveFailed. } - #method value: a value: b value: c value: d + method value: a value: b value: c value: d { self primitiveFailed. } - #method value: a value: b value: c value: d value: e + method value: a value: b value: c value: d value: e { self primitiveFailed. } - #method ifTrue: aBlock + method ifTrue: aBlock { ^(self value) ifTrue: aBlock. } - #method ifFalse: aBlock + method ifFalse: aBlock { ^(self value) ifFalse: aBlock. } - #method ifTrue: trueBlock ifFalse: falseBlock + method ifTrue: trueBlock ifFalse: falseBlock { ^(self value) ifTrue: trueBlock ifFalse: falseBlock } - #method whileTrue: aBlock + method whileTrue: aBlock { ## -------------------------------------------------- ## Naive implementation @@ -208,7 +208,7 @@ block context... ## -------------------------------------------------- } - #method whileTrue + method whileTrue { ## (self value) ifFalse: [^nil]. ## self whileTrue. @@ -223,7 +223,7 @@ block context... ## -------------------------------------------------- } - #method whileFalse: aBlock + method whileFalse: aBlock { ## -------------------------------------------------- ## Naive implementation @@ -256,7 +256,7 @@ block context... ## -------------------------------------------------- } - #method whileFalse + method whileFalse { ## (self value) ifTrue: [^nil]. ## self whileFalse. @@ -271,28 +271,55 @@ block context... ## -------------------------------------------------- } - #method pc + method pc { ^self.ip } - #method pc: anInteger + method pc: anInteger { self.ip := anInteger. } - #method sp + method sp { ^self.sp } - #method sp: anInteger + method sp: anInteger { self.sp := anInteger. } - #method restart + method restart { ip := self.source pc. } } + + +class(#pointer) CompiledMethod(Object) +{ + ## dcl owner name preamble preamble_data_1 preamble_data_2 ntmprs nargs code source. + dcl owner name preamble preamble_data_1 preamble_data_2 ntmprs nargs source. + + method preamble + { + ^self.preamble + } + + method preambleCode + { + ^(self.preamble bitAnd: 16rFF) bitShift: -2. + } + + method owner + { + ^self.owner + } + + method name + { + ^self.name + } +} \ No newline at end of file diff --git a/stix/kernel/Except.st b/stix/kernel/Except.st index 9979bd5..3eb6437 100644 --- a/stix/kernel/Except.st +++ b/stix/kernel/Except.st @@ -4,42 +4,42 @@ ## TODO: is it better to inherit from Object??? ## or treat Exception specially like UndefinedObject or Class??? ## -#class Exception(Apex) +class Exception(Apex) { - #dcl signalContext handlerContext messageText. + dcl signalContext handlerContext messageText. - #method(#class) signal + method(#class) signal { ^self new signal } - #method(#class) signal: text + method(#class) signal: text { ^self new signal: text } - #method handlerContext: context + method handlerContext: context { self.handlerContext := context. } - #method messageText + method messageText { ^self.messageText } - #method asString + method asString { ^(self class name) & ' - ' & self.messageText. } - #method __signal + method __signal { self.signalContext := thisContext. ((thisContext sender) findExceptionContext) handleException: self. } - #method signal + method signal { | exctx exblk retval actpos | @@ -74,26 +74,26 @@ thisProcess terminate. } - #method signal: text + method signal: text { self.messageText := text. ^self signal. } - #method pass + method pass { ## pass the exception to the outer context ((self.handlerContext sender) findExceptionContext) handleException: self. } - #method return: value + method return: value { (self.handlerContext notNil) ifTrue: [ Processor return: value to: self.handlerContext. ]. } - #method retry + method retry { ## TODO: verify if return:to: causes unnecessary stack growth. (self.handlerContext notNil) ifTrue: [ @@ -102,7 +102,7 @@ ]. } - #method resume: value + method resume: value { ## TODO: verify if return:to: causes unnecessary stack growth. ## is this correct??? @@ -115,31 +115,31 @@ ]. } - #method resume + method resume { ^self resume: nil. } } ##============================================================================ -#extend Context +extend Context { - #method isExceptionContext + method isExceptionContext { ^false } - #method isEnsureContext + method isEnsureContext { ^false } - #method ensureBlock + method ensureBlock { ^nil } - #method findExceptionContext + method findExceptionContext { | ctx | ctx := self. @@ -150,7 +150,7 @@ ^nil } - #method unwindTo: context return: retval + method unwindTo: context return: retval { ## ------------------------------------------------------------------- ## <> @@ -183,21 +183,21 @@ } ##============================================================================ -#extend MethodContext +extend MethodContext { - #method isExceptionContext + method isExceptionContext { ## 10 - STIX_METHOD_PREAMBLE_EXCEPTION in VM. ^self.method preambleCode == 10. } - #method isEnsureContext + method isEnsureContext { ## 10 - STIX_METHOD_PREAMBLE_ENSURE in VM. ^self.method preambleCode == 11 } - #method ensureBlock + method ensureBlock { ## TODO: change 8 to a constant when stix is enhanced to support constant definition @@ -213,7 +213,7 @@ } - #method findExceptionHandlerFor: exception_class + method findExceptionHandlerFor: exception_class { (* find an exception handler block for a given exception class. * @@ -242,7 +242,7 @@ ^nil. } - #method handleException: exception + method handleException: exception { (* ----------------------------------------------------------------- * <> @@ -295,9 +295,9 @@ } ##============================================================================ -#extend BlockContext +extend BlockContext { - #method on: anException do: anExceptionBlock + method on: anException do: anExceptionBlock { | exception_active | @@ -314,7 +314,7 @@ thisContext isExceptionContext dump. ^self value. } - #method on: exc1 do: blk1 on: exc2 do: blk2 + method on: exc1 do: blk1 on: exc2 do: blk2 { | exception_active | @@ -322,7 +322,7 @@ thisContext isExceptionContext dump. ^self value. } - #method ensure: aBlock + method ensure: aBlock { | retval done | @@ -339,7 +339,7 @@ thisContext isExceptionContext dump. ^retval } - #method ifCurtailed: aBlock + method ifCurtailed: aBlock { | v ok | @@ -351,33 +351,37 @@ thisContext isExceptionContext dump. ##============================================================================ -#class InstantiationFailureException(Exception) +class InstantiationFailureException(Exception) { } -#class NoSuchMessageException(Exception) +class NoSuchMessageException(Exception) { } -#class PrimitiveFailureException(Exception) +class PrimitiveFailureException(Exception) { } -#class IndexOutOfRangeException(Exception) +class IndexOutOfRangeException(Exception) { } -#class SubclassResponsibilityException(Exception) +class SubclassResponsibilityException(Exception) { } -#class ErrorExceptionizationFailureException(Exception) +class InvalidArgumentException(Exception) { } -#extend Apex +class ErrorExceptionizationFailureException(Exception) { - #method(#class) primitiveFailed +} + +extend Apex +{ + method(#class) primitiveFailed { ## TODO: implement this ## experimental backtrace... @@ -393,29 +397,29 @@ ctx := thisContext. PrimitiveFailureException signal: 'PRIMITIVE FAILED'. } - #method(#class) cannotInstantiate + method(#class) cannotInstantiate { ## TOOD: accept a class InstantiationFailureException signal: 'Cannot instantiate'. } - #method(#class) doesNotUnderstand: message_name + method(#class) doesNotUnderstand: message_name { ## TODO: implement this properly NoSuchMessageException signal: (message_name & ' not understood by ' & (self name)). } - #method(#class) index: index outOfRange: ubound + method(#class) index: index outOfRange: ubound { IndexOutOfRangeException signal: 'Out of range'. } - #method(#class) subclassResponsibility: message_name + method(#class) subclassResponsibility: message_name { SubclassResponsibilityException signal: ('Subclass must implment ' & message_name). } - #method(#class) cannotExceptionizeError + method(#class) cannotExceptionizeError { ## todo: accept the object ErrorExceptionizationFailureException signal: 'Cannot exceptionize an error' diff --git a/stix/kernel/Process.st b/stix/kernel/Process.st index 2935936..3224139 100644 --- a/stix/kernel/Process.st +++ b/stix/kernel/Process.st @@ -1,35 +1,35 @@ -#class(#pointer) Process(Object) +class(#pointer) Process(Object) { - #dcl initial_context current_context state sp prev next sem. + dcl initial_context current_context state sp prev next sem. - #method new + method new { "instantiation is not allowed" ^nil. "TODO: raise an exception" } - #method prev + method prev { ^self.prev. } - #method next + method next { ^self.next. } - #method next: process + method next: process { self.next := process. } - #method prev: process + method prev: process { self.prev := process. } - #method resume + method resume { self primitiveFailed @@ -37,19 +37,19 @@ ##^Processor resume: self. } - #method _terminate + method _terminate { self primitiveFailed } - #method _suspend + method _suspend { self primitiveFailed } - #method terminate + method terminate { ##search from the top contextof the process down to intial_contextand find ensure blocks and execute them. ## if a different process calls 'terminate' on a process, @@ -80,28 +80,28 @@ ^self _terminate } - #method yield + method yield { self primitiveFailed } - #method sp + method sp { ^self.sp. } - #method initialContext + method initialContext { ^self.initial_context } } -#class Semaphore(Object) +class Semaphore(Object) { - #dcl count waiting_head waiting_tail heapIndex fireTimeSec fireTimeNsec. + dcl count waiting_head waiting_tail heapIndex fireTimeSec fireTimeNsec. - #method(#class) forMutualExclusion + method(#class) forMutualExclusion { | sem | sem := self new. @@ -109,7 +109,7 @@ ^sem } - #method initialize + method initialize { self.count := 0. self.heapIndex := -1. @@ -119,31 +119,31 @@ ## ================================================================== - #method signal + method signal { self primitiveFailed. } - #method wait + method wait { self primitiveFailed. } - #method waitWithTimeout: seconds + method waitWithTimeout: seconds { self primitiveFailed } - #method waitWithTimeout: seconds and: nanoSeconds + method waitWithTimeout: seconds and: nanoSeconds { self primitiveFailed } - #method critical: aBlock + method critical: aBlock { self wait. ^aBlock ensure: [ self signal ] @@ -151,53 +151,53 @@ ## ================================================================== - #method heapIndex + method heapIndex { ^heapIndex } - #method heapIndex: anIndex + method heapIndex: anIndex { heapIndex := anIndex } - #method fireTime + method fireTime { ^fireTimeSec } - #method fireTime: anInteger + method fireTime: anInteger { self.fireTimeSec := anInteger. } - #method youngerThan: aSemaphore + method youngerThan: aSemaphore { ^self.fireTimeSec < (aSemaphore fireTime) } } -#class SemaphoreHeap(Object) +class SemaphoreHeap(Object) { - #dcl arr size. + dcl arr size. - #method initialize + method initialize { self.size := 0. self.arr := Array new: 100. } - #method size + method size { ^self.size } - #method at: anIndex + method at: anIndex { ^self.arr at: anIndex. } - #method insert: aSemaphore + method insert: aSemaphore { | index | @@ -217,7 +217,7 @@ ^self siftUp: index } - #method popTop + method popTop { | top | @@ -226,7 +226,7 @@ ^top } - #method updateAt: anIndex with: aSemaphore + method updateAt: anIndex with: aSemaphore { | item | @@ -241,7 +241,7 @@ ifFalse: [ self siftDown: anIndex ]. } - #method deleteAt: anIndex + method deleteAt: anIndex { | item | @@ -268,22 +268,22 @@ ] } - #method parentIndex: anIndex + method parentIndex: anIndex { ^(anIndex - 1) quo: 2 } - #method leftChildIndex: anIndex + method leftChildIndex: anIndex { ^(anIndex * 2) + 1. } - #method rightChildIndex: anIndex + method rightChildIndex: anIndex { ^(anIndex * 2) + 2. } - #method siftUp: anIndex + method siftUp: anIndex { | pindex cindex par item stop | @@ -319,7 +319,7 @@ ^cindex } - #method siftDown: anIndex + method siftDown: anIndex { | base capa cindex item | @@ -359,22 +359,22 @@ } } -#class ProcessScheduler(Object) +class ProcessScheduler(Object) { - #dcl tally active runnable_head runnable_tail sem_heap. + dcl tally active runnable_head runnable_tail sem_heap. - #method new + method new { "instantiation is not allowed" ^nil. "TODO: raise an exception" } - #method activeProcess + method activeProcess { ^self.active. } - #method resume: process + method resume: process { self primitiveFailed. @@ -396,45 +396,45 @@ } " - #method yield + method yield { self primitiveFailed } " - #method signal: semaphore after: secs + method signal: semaphore after: secs { self primitiveFailed. } - #method signal: semaphore after: secs and: nanosecs + method signal: semaphore after: secs and: nanosecs { self primitiveFailed. } - #method unsignal: semaphore + method unsignal: semaphore { self primitiveFailed. } - "#method signal: semaphore onInput: file + "method signal: semaphore onInput: file { }" - "#method signal: semaphore onOutput: file + "method signal: semaphore onOutput: file { }" - #method return: object to: context + method return: object to: context { self primitiveFailed. } - #method sleepFor: secs + method sleepFor: secs { ## ----------------------------------------------------- ## put the calling process to sleep for given seconds. @@ -445,7 +445,7 @@ s wait. } - #method sleepFor: secs and: nanosecs + method sleepFor: secs and: nanosecs { ## ----------------------------------------------------- ## put the calling process to sleep for given seconds. diff --git a/stix/kernel/Stdio.st b/stix/kernel/Stdio.st index 8851ac7..4bf8d38 100644 --- a/stix/kernel/Stdio.st +++ b/stix/kernel/Stdio.st @@ -1,44 +1,44 @@ -#class(#byte) Stdio(Object) from 'stdio' +class(#byte) Stdio(Object) from 'stdio' { - #dcl(#class) in out err. + dcl(#class) in out err. (* * The following methods are generated by the module. - * #method(#class) _newInstSize { } - * #method open: name for: mode { } - * #method close { } + * method(#class) _newInstSize { } + * method open: name for: mode { } + * method close { } *) - #method(#class) new: size + method(#class) new: size { ## ignore the specified size ^(super new: (self _newInstSize)) } - #method(#class) new + method(#class) new { ^(super new: (self _newInstSize)) } - #method(#class) open: name for: mode + method(#class) open: name for: mode { ^(self new) open: name for: mode } (* --------------------- - #method(#class) stdin + method(#class) stdin { self.in isNil ifTrue: [ self.in := ^(super new) open: 0 for: 'r' ]. ^self.in. } - #method(#class) stdout + method(#class) stdout { self.out isNil ifTrue: [ self.out := ^(super new) open: 1 for: 'w' ]. ^self.out. } - #method(#class) stderr + method(#class) stderr { self.err isNil ifTrue: [ self.err := ^(super new) open: 2 for: 'w' ]. ^self.err. @@ -46,37 +46,36 @@ ------------------------ *) (* - #method format: fmt with: ... + method format: fmt with: ... { } *) - #method format (fmt) + method format (fmt) { - | a b c ubound | + | a b c | 'THIS IS FORMAT' dump. fmt dump. thisContext temporaryCount dump. - ubound := thisContext vargCount - 1. - 0 to: ubound do: [:k | + 0 priorTo: (thisContext vargCount) do: [:k | (thisContext vargAt: k) dump. ]. } } -#extend Stdio +extend Stdio { - #method xxxx + method xxxx { self basicSize dump. } } -#class(#byte) Stdio2(Stdio) +class(#byte) Stdio2(Stdio) { - #method(#class) new + method(#class) new { ##self prohibited ##raise exception. prohibited... diff --git a/stix/kernel/Stix.st b/stix/kernel/Stix.st index a9ece74..dd72460 100644 --- a/stix/kernel/Stix.st +++ b/stix/kernel/Stix.st @@ -1,343 +1,23 @@ #include 'Apex.st'. -#include 'Class.st'. -#include 'Boolean.st'. - -######################################################################################### -#class Magnitude(Object) -{ -} - -#class Association(Magnitude) -{ - #dcl key value. - - #method(#class) key: key value: value - { - ^self new key: key value: value - } - #method key: key value: value - { - self.key := key. - self.value := value. - } - - #method key - { - ^self.key - } - - #method value - { - ^self.value - } -} - -#class Character(Magnitude) -{ - ## #method basicSize - ## { - ## ^0 - ## } -} - -#class Number(Magnitude) -{ - #method + aNumber - { - - self primitiveFailed. - } - - #method - aNumber - { - - self primitiveFailed. - } - - #method * aNumber - { - - self primitiveFailed. - } - - #method quo: aNumber - { - - self primitiveFailed. - } - - #method rem: aNumber - { - - self primitiveFailed. - } - - #method // aNumber - { - - self primitiveFailed. - } - - #method \\ aNumber - { - - self primitiveFailed. - } - - #method = aNumber - { - - self primitiveFailed. - } - - #method ~= aNumber - { - - self primitiveFailed. - } - - #method < aNumber - { - - self primitiveFailed. - } - - #method > aNumber - { - - self primitiveFailed. - } - - #method <= aNumber - { - - self primitiveFailed. - } - - #method >= aNumber - { - - self primitiveFailed. - } - - #method negated - { - - ^0 - self. - } - - #method bitAt: index - { - - ^(self bitShift: index negated) bitAnd: 1. - } - - #method bitAnd: aNumber - { - - self primitiveFailed. - } - - #method bitOr: aNumber - { - - self primitiveFailed. - } - - #method bitXor: aNumber - { - - self primitiveFailed. - } - - #method bitInvert - { - - ^-1 - self. - } - - #method bitShift: aNumber - { - (* positive number for left shift. - * negative number for right shift *) - - - self primitiveFailed. - } - - #method asString - { - ^self printStringRadix: 10 - } - - #method printStringRadix: aNumber - { - - self primitiveFailed. - } - - #method to: 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 to: end do: aBlock - { - ^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 - { - self < 0 ifTrue: [^self negated]. - ^self. - } - - #method sign - { - self < 0 ifTrue: [^-1]. - self > 0 ifTrue: [^1]. - ^0. - } -} - -#class Integer(Number) -{ - #method timesRepeat: aBlock - { - 1 to: self by: 1 do: [ :count | aBlock value ]. - } -} - -#class SmallInteger(Integer) -{ - ## #method basicSize - ## { - ## ^0 - ## } - - #method asError - { - - } - - #method asCharacter - { - - } -} - -#class(#liword) LargeInteger(Integer) -{ -} - -#class(#liword) LargePositiveInteger(LargeInteger) -{ - #method abs - { - ^self. - } - - #method sign - { - ^1. - } -} - -#class(#liword) LargeNegativeInteger(LargeInteger) -{ - #method abs - { - ^self negated. - } - - #method sign - { - ^-1. - } -} - -######################################################################################### - -#include 'Collect.st'. - -#class(#pointer) CompiledMethod(Object) -{ - ## #dcl owner name preamble preamble_data_1 preamble_data_2 ntmprs nargs code source. - #dcl owner name preamble preamble_data_1 preamble_data_2 ntmprs nargs source. - - #method preamble - { - ^self.preamble - } - - #method preambleCode - { - ^(self.preamble bitAnd: 16rFF) bitShift: -2. - } - - #method owner - { - ^self.owner - } - - #method name - { - ^self.name - } -} - #include 'Context.st'. #include 'Except.st'. +#include 'Class.st'. +#include 'Boolean.st'. +#include 'Magnitu.st'. +#include 'Collect.st'. #include 'Process.st'. -#class FFI(Object) -{ - #dcl name handle funcs. - #method(#class) new: aString +class FFI(Object) +{ + dcl name handle funcs. + + method(#class) new: aString { ^self new open: aString. } - #method open: aString + method open: aString { self.funcs := Dictionary new. self.name := aString. @@ -353,13 +33,13 @@ ^self. } - #method close + method close { self privateClose: self.handle. self.handle := nil. } - #method call: aFunctionName withSig: aString withArgs: anArray + method call: aFunctionName withSig: aString withArgs: anArray { | f | @@ -375,23 +55,23 @@ f isNil ifTrue: [ self error: 'No such function' ]. ^self privateCall: f withSig: aString withArgs: anArray } - #method privateOpen: aString + method privateOpen: aString { ^nil. ## TODO: Error signal: 'can not open' } - #method privateClose: aHandle + method privateClose: aHandle { } - #method privateCall: aSymbol withSig: aString withArgs: anArray + method privateCall: aSymbol withSig: aString withArgs: anArray { } - #method privateGetSymbol: aString in: aHandle + method privateGetSymbol: aString in: aHandle { ^nil. diff --git a/stix/kernel/generr.st b/stix/kernel/generr.st index 5f744f8..e6f098c 100644 --- a/stix/kernel/generr.st +++ b/stix/kernel/generr.st @@ -1,8 +1,8 @@ #include 'Stix.st'. -#class MyObject(Object) +class MyObject(Object) { - #method(#class) main + method(#class) main { | errmsgs synerrmsgs f | @@ -72,7 +72,8 @@ 'undefined class' 'duplicate class' 'contradictory class definition' - '#dcl not allowed' + 'wrong class name' + 'dcl not allowed' 'wrong method name' 'duplicate method name' 'duplicate argument name' @@ -109,7 +110,7 @@ f close. } - #method(#class) emitMessages: errmsgs named: name on: f + method(#class) emitMessages: errmsgs named: name on: f { | c prefix | prefix := name & '_'. @@ -134,7 +135,7 @@ f puts: S'};\n'. } - #method(#class) printString: s prefix: prefix index: index on: f + method(#class) printString: s prefix: prefix index: index on: f { | c | c := s size - 1. diff --git a/stix/kernel/test-001.st b/stix/kernel/test-001.st index a0f6934..64d9bc3 100644 --- a/stix/kernel/test-001.st +++ b/stix/kernel/test-001.st @@ -9,35 +9,35 @@ ## use #extend to extend a class ## using #class for both feels confusing. -#extend Apex +extend Apex { } -#extend SmallInteger +extend SmallInteger { - #method getTrue: anInteger + method getTrue: anInteger { ^anInteger + 9999. } - #method inc + method inc { ^self + 1. } } -#class TestObject(Object) +class TestObject(Object) { - #dcl(#class) Q R. - #dcl(#classinst) a1 a2. + dcl(#class) Q R. + dcl(#classinst) a1 a2. } -#class MyObject(TestObject) +class MyObject(TestObject) { #declare(#classinst) t1 t2. - #method(#class) xxxx + method(#class) xxxx { | g1 g2 | t1 dump. @@ -47,17 +47,17 @@ ^self xxxx. } - #method(#class) zzz + method(#class) zzz { 'zzzzzzzzzzzzzzzzzz' dump. ^self. } - #method(#class) yyy + method(#class) yyy { ^[123456789 dump. ^200]. } - #method(#class) main + method(#class) main { 'START OF MAIN' dump. ['1111111' dump. '111111111' dump. '22222222222' dump. diff --git a/stix/kernel/test-002.st b/stix/kernel/test-002.st index 06d0ff7..4011f7a 100644 --- a/stix/kernel/test-002.st +++ b/stix/kernel/test-002.st @@ -9,35 +9,35 @@ ## use #extend to extend a class ## using #class for both feels confusing. -#extend Apex +extend Apex { } -#extend SmallInteger +extend SmallInteger { - #method getTrue: anInteger + method getTrue: anInteger { ^anInteger + 9999. } - #method inc + method inc { ^self + 1. } } -#class TestObject(Object) +class TestObject(Object) { - #dcl(#class) Q R. - #dcl(#classinst) a1 a2. + dcl(#class) Q R. + dcl(#classinst) a1 a2. } -#class MyObject(TestObject) +class MyObject(TestObject) { #declare(#classinst) t1 t2. - #method(#class) xxxx + method(#class) xxxx { | g1 g2 | t1 dump. @@ -47,17 +47,17 @@ ^self xxxx. } - #method(#class) zzz + method(#class) zzz { 'zzzzzzzzzzzzzzzzzz' dump. ^self. } - #method(#class) yyy + method(#class) yyy { ^[123456789 dump. ^200]. } - #method(#class) main2 + method(#class) main2 { 'START OF MAIN2' dump. ##[thisContext dump. ^100] newProcess resume. @@ -70,14 +70,14 @@ 'EDN OF MAIN2' dump. } - #method(#class) main1 + method(#class) main1 { 'START OF MAIN1' dump. self main2. 'END OF MAIN1' dump. } - #method(#class) main + method(#class) main { 'START OF MAIN' dump. self main1. diff --git a/stix/kernel/test-003.st b/stix/kernel/test-003.st index fa0ef3a..efda704 100644 --- a/stix/kernel/test-003.st +++ b/stix/kernel/test-003.st @@ -9,35 +9,35 @@ ## use #extend to extend a class ## using #class for both feels confusing. -#extend Apex +extend Apex { } -#extend SmallInteger +extend SmallInteger { - #method getTrue: anInteger + method getTrue: anInteger { ^anInteger + 9999. } - #method inc + method inc { ^self + 1. } } -#class TestObject(Object) +class TestObject(Object) { - #dcl(#class) Q R. - #dcl(#classinst) a1 a2. + dcl(#class) Q R. + dcl(#classinst) a1 a2. } -#class MyObject(TestObject) +class MyObject(TestObject) { #declare(#classinst) t1 t2. - #method(#class) xxxx + method(#class) xxxx { | g1 g2 | t1 dump. @@ -47,7 +47,7 @@ ^self xxxx. } - #method(#class) main + method(#class) main { 'START OF MAIN' dump. 'EDN OF MAIN' dump. diff --git a/stix/kernel/test-004.st b/stix/kernel/test-004.st index 3899fd7..cf35e82 100644 --- a/stix/kernel/test-004.st +++ b/stix/kernel/test-004.st @@ -9,35 +9,35 @@ ## use #extend to extend a class ## using #class for both feels confusing. -#extend Apex +extend Apex { } -#extend SmallInteger +extend SmallInteger { - #method getTrue: anInteger + method getTrue: anInteger { ^anInteger + 9999. } - #method inc + method inc { ^self + 1. } } -#class TestObject(Object) +class TestObject(Object) { - #dcl(#class) Q R. - #dcl(#classinst) a1 a2. + dcl(#class) Q R. + dcl(#classinst) a1 a2. } -#class MyObject(TestObject) +class MyObject(TestObject) { #declare(#classinst) t1 t2. - #method(#class) xxxx + method(#class) xxxx { | g1 g2 | t1 dump. @@ -47,7 +47,7 @@ ^self xxxx. } - #method(#class) main + method(#class) main { 'START OF MAIN' dump. Processor activeProcess terminate. diff --git a/stix/kernel/test-005.st b/stix/kernel/test-005.st index 45420b6..ba3c9d7 100644 --- a/stix/kernel/test-005.st +++ b/stix/kernel/test-005.st @@ -9,50 +9,50 @@ ## use #extend to extend a class ## using #class for both feels confusing. -#extend Apex +extend Apex { } -#extend SmallInteger +extend SmallInteger { - #method getTrue: anInteger + method getTrue: anInteger { ^anInteger + 9999. } - #method inc + method inc { ^self + 1. } } -#class TestObject(Object) +class TestObject(Object) { - #dcl(#class) Q R. - #dcl(#classinst) t1 t2. + dcl(#class) Q R. + dcl(#classinst) t1 t2. } -#class MyObject(TestObject) +class MyObject(TestObject) { - #dcl(#class) C B A. + dcl(#class) C B A. - #method getTrue + method getTrue { ^true. } - #method getTrue: anInteger + method getTrue: anInteger { ^ anInteger } - #method getFalse + method getFalse { ^false } - #method yyy: aBlock + method yyy: aBlock { | a | a := aBlock value. @@ -62,14 +62,14 @@ ##a := Stix.MyCOM.HashTable new. } - #method xxx: aBlock + method xxx: aBlock { | a | a := self yyy: aBlock. 'KKKKKKKKKKKKKKKKKKKKKKKKKKKKK' dump. ^a. } - #method(#class) main2 + method(#class) main2 { | a b c sum | @@ -139,7 +139,7 @@ ##a dump. } - #method(#class) main55 + method(#class) main55 { |a b c| @@ -148,7 +148,7 @@ ## [ b < 5 ] whileTrue: [ b dump. b := b + 1 ]. } - #method(#class) getTen + method(#class) getTen { ^10 } @@ -158,7 +158,7 @@ " this sample demonstrates what happens when a block context returns to the origin's caller after the caller has already returned. " - #method(#class) xxxx + method(#class) xxxx { | g1 g2 | t1 dump. @@ -168,7 +168,7 @@ t1 := t1 + 1. self xxxx } - #method(#class) yyyy + method(#class) yyyy { |c1| t1 := 1. @@ -177,14 +177,14 @@ 999 dump. ^c1. } - #method(#class) main66 + method(#class) main66 { self yyyy. t2 := t2 value. "can t2 return? it should return somewhere into the method context of yyy. but it has already terminated" t2 dump. } - #method(#class) mainj + method(#class) mainj { |k1| t1 := 1. @@ -195,7 +195,7 @@ } ## ---------------------------------------------------------------------- - #method(#class) main22 + method(#class) main22 { |a b c d e f g h i j k sum | @@ -224,31 +224,31 @@ [self getTen] value dump. } - #method(#class) abc + method(#class) abc { } - #method(#class) a: a b: b c: c + method(#class) a: a b: b c: c { c dump. } - #method(#class) a: a b: b c: c d: d e: e f: f g: g h: h + method(#class) a: a b: b c: c d: d e: e f: f g: g h: h { h dump. } - #method(#class) a: a b: b c: c d: d e: e f: f g: g + method(#class) a: a b: b c: c d: d e: e f: f g: g { g dump. } - #method(#class) getABlock + method(#class) getABlock { ^ [ 'a block returned by getABlock' dump. "^ self"] } - #method(#class) main + method(#class) main { " | ffi | @@ -502,12 +502,12 @@ self represents the receiver. that is bc->origin->receiver which is mc1->receive -------------------------------------------------------------------------------- -#method ifTrue: trueBlock +method ifTrue: trueBlock { ^trueBlock value. } -#method whileTrue: aBlock +method whileTrue: aBlock { (self value) ifTrue: [aBlock value. self whileTrue: aBlock]. } diff --git a/stix/kernel/test-006.st b/stix/kernel/test-006.st index 5a8ee94..e9905bd 100644 --- a/stix/kernel/test-006.st +++ b/stix/kernel/test-006.st @@ -9,59 +9,59 @@ ## use #extend to extend a class ## using #class for both feels confusing. -#extend Apex +extend Apex { } -#extend SmallInteger +extend SmallInteger { - #method getTrue: anInteger + method getTrue: anInteger { ^anInteger + 9999. } - #method inc + method inc { ^self + 1. } } -#class TestObject(Object) +class TestObject(Object) { - #dcl(#class) Q R. - #dcl(#classinst) t1 t2. + dcl(#class) Q R. + dcl(#classinst) t1 t2. } -#class MyObject(TestObject) +class MyObject(TestObject) { - #dcl(#class) C B A. + dcl(#class) C B A. - #method getTrue + method getTrue { ^true. } - #method getTrue: anInteger + method getTrue: anInteger { ^ anInteger } - #method getFalse + method getFalse { ^false } - #method a { ^ 10 } - #method b { ^ 20 } - #method c { ^ 30 } + method a { ^ 10 } + method b { ^ 20 } + method c { ^ 30 } - #method(#class) a: a b: b c: c + method(#class) a: a b: b c: c { ^ a + b + c. } - #method(#class) getBlock + method(#class) getBlock { | a | a := 7777777. @@ -73,7 +73,7 @@ ^[self a: a b: 3 c: ([[[^6] value] value ] value)]. } - #method(#class) main + method(#class) main { " | k | diff --git a/stix/kernel/test-007.st b/stix/kernel/test-007.st index 2ad0084..ca68222 100644 --- a/stix/kernel/test-007.st +++ b/stix/kernel/test-007.st @@ -9,59 +9,59 @@ ## use #extend to extend a class ## using #class for both feels confusing. -#extend Apex +extend Apex { } -#extend SmallInteger +extend SmallInteger { - #method getTrue: anInteger + method getTrue: anInteger { ^anInteger + 9999. } - #method inc + method inc { ^self + 1. } } -#class TestObject(Object) +class TestObject(Object) { - #dcl(#class) Q R. - #dcl(#classinst) t1 t2. + dcl(#class) Q R. + dcl(#classinst) t1 t2. } -#class MyObject(TestObject) +class MyObject(TestObject) { - #dcl(#class) C B A. + dcl(#class) C B A. - #method getTrue + method getTrue { ^true. } - #method getTrue: anInteger + method getTrue: anInteger { ^ anInteger } - #method getFalse + method getFalse { ^false } - #method a { ^ 10 } - #method b { ^ 20 } - #method c { ^ 30 } + method a { ^ 10 } + method b { ^ 20 } + method c { ^ 30 } - #method(#class) a: a b: b c: c + method(#class) a: a b: b c: c { ^ a + b + c. } - #method(#class) main + method(#class) main { | p p2 | 'START OF MAIN' dump. diff --git a/stix/kernel/test-008.st b/stix/kernel/test-008.st index cc704a2..283ad53 100644 --- a/stix/kernel/test-008.st +++ b/stix/kernel/test-008.st @@ -9,35 +9,35 @@ ## use #extend to extend a class ## using #class for both feels confusing. -#extend Apex +extend Apex { } -#extend SmallInteger +extend SmallInteger { - #method getTrue: anInteger + method getTrue: anInteger { ^anInteger + 9999. } - #method inc + method inc { ^self + 1. } } -#class TestObject(Object) +class TestObject(Object) { - #dcl(#class) Q R. - #dcl(#classinst) a1 a2. + dcl(#class) Q R. + dcl(#classinst) a1 a2. } -#class MyObject(TestObject) +class MyObject(TestObject) { #declare(#classinst) t1 t2 t3. - #method(#class) xxxx + method(#class) xxxx { | g1 g2 | t1 dump. @@ -48,7 +48,7 @@ ^self xxxx. } - #method(#class) main + method(#class) main { t3 := ['1111' dump. ^20.]. t1 := 1. diff --git a/stix/kernel/test-009.st b/stix/kernel/test-009.st index be36d26..daba64b 100644 --- a/stix/kernel/test-009.st +++ b/stix/kernel/test-009.st @@ -9,43 +9,43 @@ ## use #extend to extend a class ## using #class for both feels confusing. -#extend Apex +extend Apex { } -#extend SmallInteger +extend SmallInteger { - #method getTrue: anInteger + method getTrue: anInteger { ^anInteger + 9999. } - #method inc + method inc { ^self + 1. } } -#class TestObject(Object) +class TestObject(Object) { - #dcl(#class) Q R. - #dcl(#classinst) a1 a2. + dcl(#class) Q R. + dcl(#classinst) a1 a2. } -#class MyObject(TestObject) +class MyObject(TestObject) { #declare(#classinst) t1 t2. - #method(#class) main2 + method(#class) main2 { 'START OF MAIN2' dump. t1 value. 'END OF MAIN2' dump. } - #method(#class) main1 + method(#class) main1 { 'START OF MAIN1' dump. self main2. @@ -54,7 +54,7 @@ } - #method(#class) main + method(#class) main { 'START OF MAIN' dump. t1 := ['BLOCK #1' dump. ^100]. diff --git a/stix/kernel/test-010.st b/stix/kernel/test-010.st index dbbf14b..093f486 100644 --- a/stix/kernel/test-010.st +++ b/stix/kernel/test-010.st @@ -9,55 +9,55 @@ ## use #extend to extend a class ## using #class for both feels confusing. -#extend Apex +extend Apex { } -#extend SmallInteger +extend SmallInteger { - #method getTrue: anInteger + method getTrue: anInteger { ^anInteger + 9999. } - #method inc + method inc { ^self + 1. } } -#class TestObject(Object) +class TestObject(Object) { - #dcl(#class) Q R. - #dcl(#classinst) a1 a2. + dcl(#class) Q R. + dcl(#classinst) a1 a2. - #method test999 + method test999 { ^self.Q } } -#class B.TestObject(Object) +class B.TestObject(Object) { - #dcl(#class) Q R. - #dcl(#classinst) a1 a2. + dcl(#class) Q R. + dcl(#classinst) a1 a2. - #method test000 + method test000 { ^self.Q } } -#pooldic ABC +pooldic ABC { #KKK := 20. } -#class MyObject(TestObject) +class MyObject(TestObject) { - #method(#class) main111 + method(#class) main111 { | s3 | s3 := Semaphore new. @@ -67,7 +67,7 @@ } - #method(#class) main987 + method(#class) main987 { |t1 t2 s1 s2 s3| @@ -112,7 +112,7 @@ } - #method(#class) aaa_123 + method(#class) aaa_123 { | v1 | v1 := [ @@ -130,7 +130,7 @@ ]. ^v1 } - #method(#class) main + method(#class) main { | v1 | 'START OF MAIN' dump. @@ -171,7 +171,7 @@ 'END OF MAIN' dump. } - #method(#class) main22222 + method(#class) main22222 { |t1 t2 s1 s2 s3| @@ -211,7 +211,7 @@ 'END OF MAIN' dump. } - #method(#class) test_semaphore_heap + method(#class) test_semaphore_heap { | sempq a | sempq := SemaphoreHeap new. diff --git a/stix/kernel/test-011.st b/stix/kernel/test-011.st index 1ccb91f..ec3f224 100644 --- a/stix/kernel/test-011.st +++ b/stix/kernel/test-011.st @@ -9,35 +9,35 @@ ## use #extend to extend a class ## using #class for both feels confusing. -#extend Apex +extend Apex { } -#extend SmallInteger +extend SmallInteger { - #method getTrue: anInteger + method getTrue: anInteger { ^anInteger + 9999. } - #method inc + method inc { ^self + 1. } } -#class TestObject(Object) +class TestObject(Object) { - #dcl(#class) Q R. - #dcl(#classinst) a1 a2. + dcl(#class) Q R. + dcl(#classinst) a1 a2. } -#class MyObject(TestObject) +class MyObject(TestObject) { - #method(#class) main2 + method(#class) main2 { | k q | 'BEGINNING OF main2' dump. @@ -56,12 +56,12 @@ 'END OF main2' dump. } - #method(#class) raise_exception + method(#class) raise_exception { Exception signal: 'bad exceptinon'. } - #method(#class) test3 + method(#class) test3 { | k j g_ex | j := 20. @@ -90,7 +90,7 @@ 'END OF TEST3' dump. } - #method(#class) test4_1 + method(#class) test4_1 { | k j | j := 20. @@ -113,7 +113,7 @@ 'END OF TEST4_1' dump. } - #method(#class) test4 + method(#class) test4 { 'BEGINNING OF TEST4' dump. [ self test4_1 ] on: Exception do: [:ex | 'Excepton in test4_1' dump. ex messageText dump. ex resume]. @@ -121,7 +121,7 @@ } - #method(#class) test5 + method(#class) test5 { | k j | 'BEGINNING OF TEST5' dump. @@ -142,7 +142,7 @@ 'END OF TEST5' dump. } - #method(#class) test11 + method(#class) test11 { ## exception is raised in a new process. it can't be captured ## by an exception handler of a calling process. @@ -157,7 +157,7 @@ 'END OF test11' dump. } - #method(#class) test12 + method(#class) test12 { 'BEGINNING OF test12' dump. [ @@ -174,7 +174,7 @@ 'END OF test12' dump. } - #method(#class) main + method(#class) main { '>>>>> BEGINNING OF MAIN' dump. diff --git a/stix/kernel/test-013.st b/stix/kernel/test-013.st index b010a2f..1b7223f 100644 --- a/stix/kernel/test-013.st +++ b/stix/kernel/test-013.st @@ -9,55 +9,55 @@ ## use #extend to extend a class ## using #class for both feels confusing. -#extend Apex +extend Apex { } -#extend SmallInteger +extend SmallInteger { - #method getTrue: anInteger + method getTrue: anInteger { ^anInteger + 9999. } - #method inc + method inc { ^self + 1. } } -#class TestObject(Object) +class TestObject(Object) { - #dcl(#class) Q R. - #dcl(#classinst) a1 a2. + dcl(#class) Q R. + dcl(#classinst) a1 a2. - #method test999 + method test999 { ^self.Q } } -#class B.TestObject(Object) +class B.TestObject(Object) { - #dcl(#class) Q R. - #dcl(#classinst) a1 a2. + dcl(#class) Q R. + dcl(#classinst) a1 a2. - #method test000 + method test000 { ^self.Q } } -#pooldic ABC +pooldic ABC { #KKK := 20. } -#class MyObject(TestObject) +class MyObject(TestObject) { - #method(#class) main + method(#class) main { | v1 v2 | System logNl: 'START OF MAIN'. diff --git a/stix/kernel/test-014.st b/stix/kernel/test-014.st index f43bc59..d414b75 100644 --- a/stix/kernel/test-014.st +++ b/stix/kernel/test-014.st @@ -9,58 +9,58 @@ ## use #extend to extend a class ## using #class for both feels confusing. -#extend Apex +extend Apex { } -#extend SmallInteger +extend SmallInteger { - #method getTrue: anInteger + method getTrue: anInteger { ^anInteger + 9999. } - #method inc + method inc { ^self + 1. } } -#class TestObject(Object) +class TestObject(Object) { - #dcl(#class) Q R. - #dcl(#classinst) a1 a2. + dcl(#class) Q R. + dcl(#classinst) a1 a2. - #method test999 + method test999 { ^self.Q } } -#class B.TestObject(Object) +class B.TestObject(Object) { - #dcl(#class) Q R. - #dcl(#classinst) a1 a2. + dcl(#class) Q R. + dcl(#classinst) a1 a2. - #method test000 + method test000 { ^self.Q } } -#pooldic ABC +pooldic ABC { #KKK := 20. } -#pooldic SRX.ABC +pooldic SRX.ABC { #JJJ := 1000. } -#class MyConsole(Console) +class MyConsole(Console) { - #method box: origin corner: corner + method box: origin corner: corner { | tmp | self setCursor: origin. @@ -88,11 +88,11 @@ } } -#class MyObject(TestObject) +class MyObject(TestObject) { - #dcl(#pooldic) ABC SRX.ABC. + dcl(#pooldic) ABC SRX.ABC. - #method(#class) main + method(#class) main { | v1 v2 | @@ -190,23 +190,26 @@ (v1 := self t001(20)) isError ifTrue: [('t001 Error 333....' & v1 asInteger asString) dump]. error(9999) dump. error(9999) asInteger dump. + + v2 := (16rFFFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF) basicAt: 1 put: 1; yourself. + v2 dump. } - #method(#class) varg_test() + method(#class) varg_test() { 0 to: (thisContext vargCount - 1) do: [:k | (thisContext vargAt: k) dump. ]. ^999 } - #method(#class) varg_test2(a,b,c) + method(#class) 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) varg_test3(a,b,c,d,e,f) { 0 to: (thisContext vargCount - 1) do: [:k | (thisContext vargAt: k) dump. @@ -215,7 +218,7 @@ ^f } - #method(#class) t001(a) + method(#class) t001(a) { a isNil ifTrue: [^error(10)]. (a = 20) ifTrue: [^error]. @@ -230,9 +233,9 @@ } } -#extend MyObject +extend MyObject { - #method(#class) main2 + method(#class) main2 { System logNl: KKK. System logNl: SRX.ABC.JJJ. diff --git a/stix/lib/bigint.c b/stix/lib/bigint.c index ddaf5fc..72215b6 100644 --- a/stix/lib/bigint.c +++ b/stix/lib/bigint.c @@ -324,12 +324,12 @@ int stix_inttooow (stix_t* stix, stix_oop_t x, stix_oow_t* w) if (v < 0) { *w = -v; - return -1; + return -1; /* negative number negated - kind of an error */ } else { *w = v; - return 1; + return 1; /* zero or positive number */ } } diff --git a/stix/lib/comp.c b/stix/lib/comp.c index e812420..37b9755 100644 --- a/stix/lib/comp.c +++ b/stix/lib/comp.c @@ -76,24 +76,24 @@ static struct voca_t } vocas[] = { { 5, { '#','b','y','t','e' } }, { 10, { '#','c','h','a','r','a','c','t','e','r' } }, + { 5, { 'c','l','a','s','s' } }, { 6, { '#','c','l','a','s','s' } }, { 10, { '#','c','l','a','s','s','i','n','s','t' } }, - { 4, { '#','d','c','l' } }, - { 8, { '#','d','e','c','l','a','r','e' } }, + { 3, { 'd','c','l' } }, + { 7, { 'd','e','c','l','a','r','e' } }, { 6, { 'e','n','s','u','r','e', } }, { 5, { 'e','r','r','o','r' } }, { 9, { 'e','x','c','e','p','t','i','o','n' } }, - { 7, { '#','e','x','t','e','n','d' } }, + { 6, { 'e','x','t','e','n','d' } }, { 5, { 'f','a','l','s','e' } }, { 4, { 'f','r','o','m' } }, { 9, { '#','h','a','l','f','w','o','r','d' } }, { 8, { '#','i','n','c','l','u','d','e' } }, { 7, { '#','l','i','w','o','r','d' } }, - { 5, { '#','m','a','i','n' } }, - { 7, { '#','m','e','t','h','o','d' } }, - { 4, { '#','m','t','h' } }, + { 6, { 'm','e','t','h','o','d' } }, { 3, { 'n','i','l' } }, { 8, { '#','p','o','i','n','t','e','r' } }, + { 7, { 'p','o','o','l','d','i','c' } }, { 8, { '#','p','o','o','l','d','i','c' } }, { 10, { 'p','r','i','m','i','t','i','v','e',':' } }, { 4, { 's','e','l','f' } }, @@ -112,10 +112,11 @@ static struct voca_t enum voca_id_t { - VOCA_BYTE, - VOCA_CHARACTER, + VOCA_BYTE_S, + VOCA_CHARACTER_S, VOCA_CLASS, - VOCA_CLASSINST, + VOCA_CLASS_S, + VOCA_CLASSINST_S, VOCA_DCL, VOCA_DECLARE, VOCA_ENSURE, @@ -124,22 +125,21 @@ enum voca_id_t VOCA_EXTEND, VOCA_FALSE, VOCA_FROM, - VOCA_HALFWORD, - VOCA_INCLUDE, - VOCA_LIWORD, - VOCA_MAIN, + VOCA_HALFWORD_S, + VOCA_INCLUDE_S, + VOCA_LIWORD_S, VOCA_METHOD, - VOCA_MTH, VOCA_NIL, - VOCA_POINTER, + VOCA_POINTER_S, VOCA_POOLDIC, + VOCA_POOLDIC_S, VOCA_PRIMITIVE_COLON, VOCA_SELF, VOCA_SUPER, VOCA_THIS_CONTEXT, VOCA_THIS_PROCESS, VOCA_TRUE, - VOCA_WORD, + VOCA_WORD_S, VOCA_VBAR, VOCA_GT, @@ -279,6 +279,30 @@ static int is_reserved_word (const stix_oocs_t* ucs) return 0; } +static int is_restricted_word (const stix_oocs_t* ucs) +{ + /* not fully reserved. but restricted in a certain context */ + + static int rw[] = + { + VOCA_CLASS, + VOCA_DCL, + VOCA_DECLARE, + VOCA_EXTEND, + VOCA_METHOD, + VOCA_POOLDIC, + VOCA_FROM + }; + int i; + + for (i = 0; i < STIX_COUNTOF(rw); i++) + { + if (is_word(ucs, rw[i])) return 1; + } + + return 0; +} + static int begin_include (stix_t* stix); static int end_include (stix_t* stix); @@ -2535,21 +2559,21 @@ static int compile_class_level_variables (stix_t* stix) /* process variable modifiers */ GET_TOKEN (stix); - if (is_token_symbol(stix, VOCA_CLASS)) + if (is_token_symbol(stix, VOCA_CLASS_S)) { - /* #dcl(#class) */ + /* dcl(#class) */ dcl_type = VAR_CLASS; GET_TOKEN (stix); } - else if (is_token_symbol(stix, VOCA_CLASSINST)) + else if (is_token_symbol(stix, VOCA_CLASSINST_S)) { - /* #dcl(#classinst) */ + /* dcl(#classinst) */ dcl_type = VAR_CLASSINST; GET_TOKEN (stix); } - else if (is_token_symbol(stix, VOCA_POOLDIC)) + else if (is_token_symbol(stix, VOCA_POOLDIC_S)) { - /* #dcl(#pooldic) - import a pool dictionary */ + /* dcl(#pooldic) - import a pool dictionary */ dcl_type = VAR_GLOBAL; /* this is not a real type. use for branching below */ GET_TOKEN (stix); } @@ -2922,35 +2946,18 @@ static int compile_method_primitive (stix_t* stix) { /* a built-in primitive function is not found * check if it is a primitive function identifier */ -#if 0 - const stix_ooch_t* us; - us = stix_findoochar (tptr, tlen, '_'); - if (us > tptr && us < tptr + tlen - 1) - { - stix_oow_t lit_idx; - /* the symbol literal contains an underscore. - * and it is neither the first nor the last character */ - if (add_symbol_literal(stix, TOKEN_NAME(stix), 1, &lit_idx) >= 0 && - STIX_OOI_IN_METHOD_PREAMBLE_INDEX_RANGE(lit_idx)) - { - stix->c->mth.pftype = 2; /* named primitive */ - stix->c->mth.pfnum = lit_idx; - break; - } - } -#else stix_oow_t lit_idx; - if (add_symbol_literal(stix, TOKEN_NAME(stix), 1, &lit_idx) >= 0 && + if (stix_findoochar (tptr, tlen, '.') && + add_symbol_literal(stix, TOKEN_NAME(stix), 1, &lit_idx) >= 0 && STIX_OOI_IN_METHOD_PREAMBLE_INDEX_RANGE(lit_idx)) { - stix->c->mth.pftype = 2; /* named primitive */ + /* external named primitive containing a period. */ + stix->c->mth.pftype = 2; stix->c->mth.pfnum = lit_idx; break; } -#endif - /* wrong primitive number */ set_syntax_error (stix, STIX_SYNERR_PFID, TOKEN_LOC(stix), TOKEN_NAME(stix)); return -1; @@ -4671,9 +4678,9 @@ static int compile_method_definition (stix_t* stix) /* process method modifiers */ GET_TOKEN (stix); - if (is_token_symbol(stix, VOCA_CLASS)) + if (is_token_symbol(stix, VOCA_CLASS_S)) { - /* #method(#class) */ + /* method(#class) */ stix->c->mth.type = STIX_METHOD_CLASS; GET_TOKEN (stix); } @@ -4837,7 +4844,7 @@ static int __compile_class_definition (stix_t* stix, int extend) * variable-modifier := "(" (#class | #classinst)? ")" * variable-list := identifier* * - * method-definition := (#mth | #method) method-modifier? method-actual-definition + * method-definition := method method-modifier? method-actual-definition * method-modifier := "(" (#class | #instance)? ")" * method-actual-definition := method-name "{" method-tempraries? method-primitive? method-statements* "}" * @@ -4853,44 +4860,44 @@ static int __compile_class_definition (stix_t* stix, int extend) GET_TOKEN (stix); - if (is_token_symbol(stix, VOCA_BYTE)) + if (is_token_symbol(stix, VOCA_BYTE_S)) { - /* #class(#byte) */ + /* class(#byte) */ stix->c->cls.flags |= CLASS_INDEXED; stix->c->cls.indexed_type = STIX_OBJ_TYPE_BYTE; GET_TOKEN (stix); } - else if (is_token_symbol(stix, VOCA_CHARACTER)) + else if (is_token_symbol(stix, VOCA_CHARACTER_S)) { - /* #class(#character) */ + /* class(#character) */ stix->c->cls.flags |= CLASS_INDEXED; stix->c->cls.indexed_type = STIX_OBJ_TYPE_CHAR; GET_TOKEN (stix); } - else if (is_token_symbol(stix, VOCA_HALFWORD)) + else if (is_token_symbol(stix, VOCA_HALFWORD_S)) { - /* #class(#halfword) */ + /* class(#halfword) */ stix->c->cls.flags |= CLASS_INDEXED; stix->c->cls.indexed_type = STIX_OBJ_TYPE_HALFWORD; GET_TOKEN (stix); } - else if (is_token_symbol(stix, VOCA_WORD)) + else if (is_token_symbol(stix, VOCA_WORD_S)) { - /* #class(#word) */ + /* class(#word) */ stix->c->cls.flags |= CLASS_INDEXED; stix->c->cls.indexed_type = STIX_OBJ_TYPE_WORD; GET_TOKEN (stix); } - else if (is_token_symbol(stix, VOCA_POINTER)) + else if (is_token_symbol(stix, VOCA_POINTER_S)) { - /* #class(#pointer) */ + /* class(#pointer) */ stix->c->cls.flags |= CLASS_INDEXED; stix->c->cls.indexed_type = STIX_OBJ_TYPE_OOP; GET_TOKEN (stix); } - else if (is_token_symbol(stix, VOCA_LIWORD)) + else if (is_token_symbol(stix, VOCA_LIWORD_S)) { - /* #class(#biatom) */ + /* class(#liword) */ stix->c->cls.flags |= CLASS_INDEXED; stix->c->cls.indexed_type = STIX_OBJ_TYPE_LIWORD; GET_TOKEN (stix); @@ -4913,6 +4920,15 @@ static int __compile_class_definition (stix_t* stix, int extend) return -1; } +#if 0 + if (TOKEN_TYPE(stix) == STIX_IOTOK_IDENT && is_restricted_word (TOKEN_NAME(stix))) + { + /* wrong class name */ + set_syntax_error (stix, STIX_SYNERR_CLASSNAME, TOKEN_LOC(stix), TOKEN_NAME(stix)); + return -1; + } +#endif + /* copy the class name */ if (set_class_fqn(stix, TOKEN_NAME(stix)) <= -1) return -1; stix->c->cls.fqn_loc = stix->c->tok.loc; @@ -5115,13 +5131,12 @@ static int __compile_class_definition (stix_t* stix, int extend) stix_oop_char_t pds; /* when a class is extended, a new variable cannot be added */ - if (is_token_symbol(stix, VOCA_DCL) || is_token_symbol(stix, VOCA_DECLARE)) + if (is_token_word(stix, VOCA_DCL) || is_token_word(stix, VOCA_DECLARE)) { set_syntax_error (stix, STIX_SYNERR_DCLBANNED, TOKEN_LOC(stix), TOKEN_NAME(stix)); return -1; } - #ifdef MTHDIC /* use the method dictionary of an existing class object */ stix->c->cls.mthdic_oop[STIX_METHOD_INSTANCE] = stix->c->cls.self_oop->mthdic[STIX_METHOD_INSTANCE]; @@ -5182,9 +5197,9 @@ static int __compile_class_definition (stix_t* stix, int extend) { /* a new class including an internally defined class object */ - while (is_token_symbol(stix, VOCA_DCL) || is_token_symbol(stix, VOCA_DECLARE)) + while (is_token_word(stix, VOCA_DCL) || is_token_word(stix, VOCA_DECLARE)) { - /* variable definition. #dcl or #declare */ + /* variable definition. dcl or declare */ GET_TOKEN (stix); if (compile_class_level_variables(stix) <= -1) return -1; } @@ -5197,9 +5212,9 @@ static int __compile_class_definition (stix_t* stix, int extend) } } - while (is_token_symbol(stix, VOCA_MTH) || is_token_symbol(stix, VOCA_METHOD)) + while (is_token_word(stix, VOCA_METHOD)) { - /* method definition. #mth or #method */ + /* method definition. method */ GET_TOKEN (stix); if (compile_method_definition(stix) <= -1) return -1; } @@ -5478,7 +5493,7 @@ static int compile_stream (stix_t* stix) while (TOKEN_TYPE(stix) != STIX_IOTOK_EOF) { - if (is_token_symbol(stix, VOCA_INCLUDE)) + if (is_token_symbol(stix, VOCA_INCLUDE_S)) { /* #include 'xxxx' */ GET_TOKEN (stix); @@ -5489,21 +5504,21 @@ static int compile_stream (stix_t* stix) } if (begin_include(stix) <= -1) return -1; } - else if (is_token_symbol(stix, VOCA_CLASS)) + else if (is_token_word(stix, VOCA_CLASS)) { - /* #class Selfclass(Superclass) { } */ + /* class Selfclass(Superclass) { } */ GET_TOKEN (stix); if (compile_class_definition(stix, 0) <= -1) return -1; } - else if (is_token_symbol(stix, VOCA_EXTEND)) + else if (is_token_word(stix, VOCA_EXTEND)) { - /* #extend Selfclass {} */ + /* extend Selfclass {} */ GET_TOKEN (stix); if (compile_class_definition(stix, 1) <= -1) return -1; } - else if (is_token_symbol(stix, VOCA_POOLDIC)) + else if (is_token_word(stix, VOCA_POOLDIC)) { - /* #pooldic SharedPoolDic { #ABC := 20. #DEFG := 'ayz' } */ + /* pooldic SharedPoolDic { #ABC := 20. #DEFG := 'ayz' } */ GET_TOKEN (stix); if (compile_pooldic_definition(stix) <= -1) return -1; } diff --git a/stix/lib/err.c b/stix/lib/err.c index e59e6b5..6c4718b 100644 --- a/stix/lib/err.c +++ b/stix/lib/err.c @@ -97,32 +97,33 @@ static stix_ooch_t synerrstr_26[] = {'w','r','o','n','g',' ','d','i','r','e','c' static stix_ooch_t synerrstr_27[] = {'u','n','d','e','f','i','n','e','d',' ','c','l','a','s','s','\0'}; static stix_ooch_t synerrstr_28[] = {'d','u','p','l','i','c','a','t','e',' ','c','l','a','s','s','\0'}; static stix_ooch_t synerrstr_29[] = {'c','o','n','t','r','a','d','i','c','t','o','r','y',' ','c','l','a','s','s',' ','d','e','f','i','n','i','t','i','o','n','\0'}; -static stix_ooch_t synerrstr_30[] = {'#','d','c','l',' ','n','o','t',' ','a','l','l','o','w','e','d','\0'}; -static stix_ooch_t synerrstr_31[] = {'w','r','o','n','g',' ','m','e','t','h','o','d',' ','n','a','m','e','\0'}; -static stix_ooch_t synerrstr_32[] = {'d','u','p','l','i','c','a','t','e',' ','m','e','t','h','o','d',' ','n','a','m','e','\0'}; -static stix_ooch_t synerrstr_33[] = {'d','u','p','l','i','c','a','t','e',' ','a','r','g','u','m','e','n','t',' ','n','a','m','e','\0'}; -static stix_ooch_t synerrstr_34[] = {'d','u','p','l','i','c','a','t','e',' ','t','e','m','p','o','r','a','r','y',' ','v','a','r','i','a','b','l','e',' ','n','a','m','e','\0'}; -static stix_ooch_t synerrstr_35[] = {'d','u','p','l','i','c','a','t','e',' ','v','a','r','i','a','b','l','e',' ','n','a','m','e','\0'}; -static stix_ooch_t synerrstr_36[] = {'d','u','p','l','i','c','a','t','e',' ','b','l','o','c','k',' ','a','r','g','u','m','e','n','t',' ','n','a','m','e','\0'}; -static stix_ooch_t synerrstr_37[] = {'c','a','n','n','o','t',' ','a','s','s','i','g','n',' ','t','o',' ','a','r','g','u','m','e','n','t','\0'}; -static stix_ooch_t synerrstr_38[] = {'u','n','d','e','c','l','a','r','e','d',' ','v','a','r','i','a','b','l','e','\0'}; -static stix_ooch_t synerrstr_39[] = {'u','n','u','s','a','b','l','e',' ','v','a','r','i','a','b','l','e',' ','i','n',' ','c','o','m','p','i','l','e','d',' ','c','o','d','e','\0'}; -static stix_ooch_t synerrstr_40[] = {'i','n','a','c','c','e','s','s','i','b','l','e',' ','v','a','r','i','a','b','l','e','\0'}; -static stix_ooch_t synerrstr_41[] = {'a','m','b','i','g','u','o','u','s',' ','v','a','r','i','a','b','l','e','\0'}; -static stix_ooch_t synerrstr_42[] = {'w','r','o','n','g',' ','e','x','p','r','e','s','s','i','o','n',' ','p','r','i','m','a','r','y','\0'}; -static stix_ooch_t synerrstr_43[] = {'t','o','o',' ','m','a','n','y',' ','t','e','m','p','o','r','a','r','i','e','s','\0'}; -static stix_ooch_t synerrstr_44[] = {'t','o','o',' ','m','a','n','y',' ','a','r','g','u','m','e','n','t','s','\0'}; -static stix_ooch_t synerrstr_45[] = {'t','o','o',' ','m','a','n','y',' ','b','l','o','c','k',' ','t','e','m','p','o','r','a','r','i','e','s','\0'}; -static stix_ooch_t synerrstr_46[] = {'t','o','o',' ','m','a','n','y',' ','b','l','o','c','k',' ','a','r','g','u','m','e','n','t','s','\0'}; -static stix_ooch_t synerrstr_47[] = {'t','o','o',' ','l','a','r','g','e',' ','b','l','o','c','k','\0'}; -static stix_ooch_t synerrstr_48[] = {'w','r','o','n','g',' ','p','r','i','m','i','t','i','v','e',' ','f','u','n','c','t','i','o','n',' ','n','u','m','b','e','r','\0'}; -static stix_ooch_t synerrstr_49[] = {'w','r','o','n','g',' ','p','r','i','m','i','t','i','v','e',' ','f','u','n','c','t','i','o','n',' ','i','d','e','n','t','i','f','i','e','r','\0'}; -static stix_ooch_t synerrstr_50[] = {'w','r','o','n','g',' ','m','o','d','u','l','e',' ','n','a','m','e','\0'}; -static stix_ooch_t synerrstr_51[] = {'#','i','n','c','l','u','d','e',' ','e','r','r','o','r','\0'}; -static stix_ooch_t synerrstr_52[] = {'w','r','o','n','g',' ','n','a','m','e','s','p','a','c','e',' ','n','a','m','e','\0'}; -static stix_ooch_t synerrstr_53[] = {'w','r','o','n','g',' ','p','o','o','l',' ','d','i','c','t','i','o','n','a','r','y',' ','n','a','m','e','\0'}; -static stix_ooch_t synerrstr_54[] = {'d','u','p','l','i','c','a','t','e',' ','p','o','o','l',' ','d','i','c','t','i','o','n','a','r','y',' ','n','a','m','e','\0'}; -static stix_ooch_t synerrstr_55[] = {'l','i','t','e','r','a','l',' ','e','x','p','e','c','t','e','d','\0'}; +static stix_ooch_t synerrstr_30[] = {'w','r','o','n','g',' ','c','l','a','s','s',' ','n','a','m','e','\0'}; +static stix_ooch_t synerrstr_31[] = {'#','d','c','l',' ','n','o','t',' ','a','l','l','o','w','e','d','\0'}; +static stix_ooch_t synerrstr_32[] = {'w','r','o','n','g',' ','m','e','t','h','o','d',' ','n','a','m','e','\0'}; +static stix_ooch_t synerrstr_33[] = {'d','u','p','l','i','c','a','t','e',' ','m','e','t','h','o','d',' ','n','a','m','e','\0'}; +static stix_ooch_t synerrstr_34[] = {'d','u','p','l','i','c','a','t','e',' ','a','r','g','u','m','e','n','t',' ','n','a','m','e','\0'}; +static stix_ooch_t synerrstr_35[] = {'d','u','p','l','i','c','a','t','e',' ','t','e','m','p','o','r','a','r','y',' ','v','a','r','i','a','b','l','e',' ','n','a','m','e','\0'}; +static stix_ooch_t synerrstr_36[] = {'d','u','p','l','i','c','a','t','e',' ','v','a','r','i','a','b','l','e',' ','n','a','m','e','\0'}; +static stix_ooch_t synerrstr_37[] = {'d','u','p','l','i','c','a','t','e',' ','b','l','o','c','k',' ','a','r','g','u','m','e','n','t',' ','n','a','m','e','\0'}; +static stix_ooch_t synerrstr_38[] = {'c','a','n','n','o','t',' ','a','s','s','i','g','n',' ','t','o',' ','a','r','g','u','m','e','n','t','\0'}; +static stix_ooch_t synerrstr_39[] = {'u','n','d','e','c','l','a','r','e','d',' ','v','a','r','i','a','b','l','e','\0'}; +static stix_ooch_t synerrstr_40[] = {'u','n','u','s','a','b','l','e',' ','v','a','r','i','a','b','l','e',' ','i','n',' ','c','o','m','p','i','l','e','d',' ','c','o','d','e','\0'}; +static stix_ooch_t synerrstr_41[] = {'i','n','a','c','c','e','s','s','i','b','l','e',' ','v','a','r','i','a','b','l','e','\0'}; +static stix_ooch_t synerrstr_42[] = {'a','m','b','i','g','u','o','u','s',' ','v','a','r','i','a','b','l','e','\0'}; +static stix_ooch_t synerrstr_43[] = {'w','r','o','n','g',' ','e','x','p','r','e','s','s','i','o','n',' ','p','r','i','m','a','r','y','\0'}; +static stix_ooch_t synerrstr_44[] = {'t','o','o',' ','m','a','n','y',' ','t','e','m','p','o','r','a','r','i','e','s','\0'}; +static stix_ooch_t synerrstr_45[] = {'t','o','o',' ','m','a','n','y',' ','a','r','g','u','m','e','n','t','s','\0'}; +static stix_ooch_t synerrstr_46[] = {'t','o','o',' ','m','a','n','y',' ','b','l','o','c','k',' ','t','e','m','p','o','r','a','r','i','e','s','\0'}; +static stix_ooch_t synerrstr_47[] = {'t','o','o',' ','m','a','n','y',' ','b','l','o','c','k',' ','a','r','g','u','m','e','n','t','s','\0'}; +static stix_ooch_t synerrstr_48[] = {'t','o','o',' ','l','a','r','g','e',' ','b','l','o','c','k','\0'}; +static stix_ooch_t synerrstr_49[] = {'w','r','o','n','g',' ','p','r','i','m','i','t','i','v','e',' ','f','u','n','c','t','i','o','n',' ','n','u','m','b','e','r','\0'}; +static stix_ooch_t synerrstr_50[] = {'w','r','o','n','g',' ','p','r','i','m','i','t','i','v','e',' ','f','u','n','c','t','i','o','n',' ','i','d','e','n','t','i','f','i','e','r','\0'}; +static stix_ooch_t synerrstr_51[] = {'w','r','o','n','g',' ','m','o','d','u','l','e',' ','n','a','m','e','\0'}; +static stix_ooch_t synerrstr_52[] = {'#','i','n','c','l','u','d','e',' ','e','r','r','o','r','\0'}; +static stix_ooch_t synerrstr_53[] = {'w','r','o','n','g',' ','n','a','m','e','s','p','a','c','e',' ','n','a','m','e','\0'}; +static stix_ooch_t synerrstr_54[] = {'w','r','o','n','g',' ','p','o','o','l',' ','d','i','c','t','i','o','n','a','r','y',' ','n','a','m','e','\0'}; +static stix_ooch_t synerrstr_55[] = {'d','u','p','l','i','c','a','t','e',' ','p','o','o','l',' ','d','i','c','t','i','o','n','a','r','y',' ','n','a','m','e','\0'}; +static stix_ooch_t synerrstr_56[] = {'l','i','t','e','r','a','l',' ','e','x','p','e','c','t','e','d','\0'}; static stix_ooch_t* synerrstr[] = { synerrstr_0, synerrstr_1, synerrstr_2, synerrstr_3, synerrstr_4, synerrstr_5, synerrstr_6, synerrstr_7, @@ -131,7 +132,8 @@ static stix_ooch_t* synerrstr[] = synerrstr_24, synerrstr_25, synerrstr_26, synerrstr_27, synerrstr_28, synerrstr_29, synerrstr_30, synerrstr_31, synerrstr_32, synerrstr_33, synerrstr_34, synerrstr_35, synerrstr_36, synerrstr_37, synerrstr_38, synerrstr_39, synerrstr_40, synerrstr_41, synerrstr_42, synerrstr_43, synerrstr_44, synerrstr_45, synerrstr_46, synerrstr_47, - synerrstr_48, synerrstr_49, synerrstr_50, synerrstr_51, synerrstr_52, synerrstr_53, synerrstr_54, synerrstr_55 + synerrstr_48, synerrstr_49, synerrstr_50, synerrstr_51, synerrstr_52, synerrstr_53, synerrstr_54, synerrstr_55, + synerrstr_56 }; #endif /* END: GENERATED WITH generr.st */ diff --git a/stix/lib/exec.c b/stix/lib/exec.c index 74e6c15..0cc9997 100644 --- a/stix/lib/exec.c +++ b/stix/lib/exec.c @@ -1171,7 +1171,7 @@ TODO: overcome this problem } /* ------------------------------------------------------------------------- */ -static int pf_dump (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_dump (stix_t* stix, stix_ooi_t nargs) { stix_ooi_t i; @@ -1185,7 +1185,7 @@ static int pf_dump (stix_t* stix, stix_ooi_t nargs) } STIX_STACK_SETRETTORCV (stix, nargs); /* ^self */ - return 1; /* success */ + return STIX_PF_SUCCESS; } static void log_char_object (stix_t* stix, stix_oow_t mask, stix_oop_char_t msg) @@ -1226,7 +1226,7 @@ start_over: } } -static int pf_log (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_log (stix_t* stix, stix_ooi_t nargs) { stix_oop_t msg, level; stix_oow_t mask; @@ -1289,10 +1289,10 @@ static int pf_log (stix_t* stix, stix_ooi_t nargs) } STIX_STACK_SETRETTORCV (stix, nargs); /* ^self */ - return 1; + return STIX_PF_SUCCESS; } -static int pf_identical (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_identical (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, arg, b; @@ -1304,10 +1304,10 @@ static int pf_identical (stix_t* stix, stix_ooi_t nargs) b = (rcv == arg)? stix->_true: stix->_false; STIX_STACK_SETRET (stix, nargs, b); - return 1; + return STIX_PF_SUCCESS; } -static int pf_not_identical (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_not_identical (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, arg, b; @@ -1319,10 +1319,40 @@ static int pf_not_identical (stix_t* stix, stix_ooi_t nargs) b = (rcv != arg)? stix->_true: stix->_false; STIX_STACK_SETRET (stix, nargs, b); - return 1; + return STIX_PF_SUCCESS; } -static int pf_class (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_equal (stix_t* stix, stix_ooi_t nargs) +{ + stix_oop_t rcv, arg, b; + + STIX_ASSERT (stix, nargs == 1); + + rcv = STIX_STACK_GETRCV(stix, nargs); + arg = STIX_STACK_GETARG(stix, nargs, 0); + + b = (rcv == arg)? stix->_true: stix->_false; + + STIX_STACK_SETRET (stix, nargs, b); + return STIX_PF_SUCCESS; +} + +static stix_pfrc_t pf_not_equal (stix_t* stix, stix_ooi_t nargs) +{ + stix_oop_t rcv, arg, b; + + STIX_ASSERT (stix, nargs == 1); + + rcv = STIX_STACK_GETRCV(stix, nargs); + arg = STIX_STACK_GETARG(stix, nargs, 0); + + b = (rcv != arg)? stix->_true: stix->_false; + + STIX_STACK_SETRET (stix, nargs, b); + return STIX_PF_SUCCESS; +} + +static stix_pfrc_t pf_class (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, c; @@ -1332,10 +1362,10 @@ static int pf_class (stix_t* stix, stix_ooi_t nargs) c = STIX_CLASSOF(stix, rcv); STIX_STACK_SETRET (stix, nargs, c); - return 1; /* success */ + return STIX_PF_SUCCESS; } -static int pf_basic_new (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_basic_new (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, obj; @@ -1345,17 +1375,17 @@ static int pf_basic_new (stix_t* stix, stix_ooi_t nargs) if (STIX_CLASSOF(stix, rcv) != stix->_class) { /* the receiver is not a class object */ - return 0; + return STIX_PF_FAILURE; } obj = stix_instantiate (stix, rcv, STIX_NULL, 0); - if (!obj) return -1; + if (!obj) return STIX_PF_HARD_FAILURE; STIX_STACK_SETRET (stix, nargs, obj); - return 1; /* success */ + return STIX_PF_SUCCESS; } -static int pf_basic_new_with_size (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_basic_new_with_size (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, szoop, obj; stix_oow_t size; @@ -1366,14 +1396,14 @@ static int pf_basic_new_with_size (stix_t* stix, stix_ooi_t nargs) if (STIX_CLASSOF(stix, rcv) != stix->_class) { /* the receiver is not a class object */ - return 0; + return STIX_PF_FAILURE; } szoop = STIX_STACK_GETARG(stix, nargs, 0); if (stix_inttooow (stix, szoop, &size) <= 0) { /* integer out of range or not integer */ - return 0; + return STIX_PF_FAILURE; } /* stix_instantiate() ignores size if the instance specification @@ -1383,34 +1413,30 @@ static int pf_basic_new_with_size (stix_t* stix, stix_ooi_t nargs) obj = stix_instantiate (stix, rcv, STIX_NULL, size); if (!obj) { - return -1; /* hard failure */ + return STIX_PF_HARD_FAILURE; } STIX_STACK_SETRET (stix, nargs, obj); - return 1; /* success */ + return STIX_PF_SUCCESS; } -static int pf_ngc_new (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_ngc_new (stix_t* stix, stix_ooi_t nargs) { - int n; +/* TODO: implement this. + * if NGC is allowed for non-OOP objects, GC issues get very simple. +* +* also allow NGC code in non-safe mode. in safe mode, ngc_new is same as normal new. +* ngc_dispose should not do anything in safe mode. */ + return pf_basic_new (stix, nargs); - n = pf_basic_new (stix, nargs); - if (n <= 0) return n; - - return 1; } -static int pf_ngc_new_with_size (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_ngc_new_with_size (stix_t* stix, stix_ooi_t nargs) { - int n; - - n = pf_basic_new_with_size (stix, nargs); - if (n <= 0) return n; - - return 1; + return pf_basic_new_with_size (stix, nargs); } -static int pf_ngc_dispose (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_ngc_dispose (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv; @@ -1420,26 +1446,24 @@ static int pf_ngc_dispose (stix_t* stix, stix_ooi_t nargs) stix_freemem (stix, rcv); STIX_STACK_SETRET (stix, nargs, stix->_nil); - return 1; /* success */ + return STIX_PF_SUCCESS; } -static int pf_shallow_copy (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_shallow_copy (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, obj; STIX_ASSERT (stix, nargs == 0); - rcv = STIX_STACK_GETRCV (stix, nargs); obj = stix_shallowcopy (stix, rcv); - if (!obj) return -1; + if (!obj) return STIX_PF_HARD_FAILURE; - /* emulate 'pop receiver' and 'push result' */ STIX_STACK_SETRET (stix, nargs, obj); - return 1; /* success */ + return STIX_PF_SUCCESS; } -static int pf_basic_size (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_basic_size (stix_t* stix, stix_ooi_t nargs) { /* return the number of indexable fields */ @@ -1456,14 +1480,14 @@ static int pf_basic_size (stix_t* stix, stix_ooi_t nargs) else { sz = stix_oowtoint (stix, STIX_OBJ_GET_SIZE(rcv)); - if (!sz) return -1; /* hard failure */ + if (!sz) return STIX_PF_HARD_FAILURE; /* hard failure */ } STIX_STACK_SETRET(stix, nargs, sz); - return 1; + return STIX_PF_SUCCESS; } -static int pf_basic_at (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_basic_at (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, pos, v; stix_oow_t idx; @@ -1474,19 +1498,19 @@ static int pf_basic_at (stix_t* stix, stix_ooi_t nargs) if (!STIX_OOP_IS_POINTER(rcv)) { /* the receiver is a special numeric object, not a normal pointer */ - return 0; + return STIX_PF_FAILURE; } pos = STIX_STACK_GETARG(stix, nargs, 0); if (stix_inttooow (stix, pos, &idx) <= 0) { /* negative integer or not integer */ - return 0; + return STIX_PF_FAILURE; } if (idx >= STIX_OBJ_GET_SIZE(rcv)) { /* index out of range */ - return 0; + return STIX_PF_FAILURE; } switch (STIX_OBJ_GET_FLAGS_TYPE(rcv)) @@ -1505,8 +1529,8 @@ static int pf_basic_at (stix_t* stix, stix_ooi_t nargs) break; case STIX_OBJ_TYPE_WORD: - /* TODO: LargeInteger if the word is too large */ - v = STIX_SMOOI_TO_OOP(((stix_oop_word_t)rcv)->slot[idx]); + v = stix_oowtoint (stix, ((stix_oop_word_t)rcv)->slot[idx]); + if (!v) return STIX_PF_HARD_FAILURE; break; case STIX_OBJ_TYPE_OOP: @@ -1515,14 +1539,14 @@ static int pf_basic_at (stix_t* stix, stix_ooi_t nargs) default: stix->errnum = STIX_EINTERN; - return -1; + return STIX_PF_HARD_FAILURE; } STIX_STACK_SETRET (stix, nargs, v); - return 1; + return STIX_PF_SUCCESS; } -static int pf_basic_at_put (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_basic_at_put (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, pos, val; stix_oow_t idx; @@ -1533,7 +1557,7 @@ static int pf_basic_at_put (stix_t* stix, stix_ooi_t nargs) if (!STIX_OOP_IS_POINTER(rcv)) { /* the receiver is a special numeric object, not a normal pointer */ - return 0; + return STIX_PF_FAILURE; } pos = STIX_STACK_GETARG(stix, nargs, 0); val = STIX_STACK_GETARG(stix, nargs, 1); @@ -1541,12 +1565,12 @@ static int pf_basic_at_put (stix_t* stix, stix_ooi_t nargs) if (stix_inttooow (stix, pos, &idx) <= 0) { /* negative integer or not integer */ - return 0; + return STIX_PF_FAILURE; } if (idx >= STIX_OBJ_GET_SIZE(rcv)) { /* index out of range */ - return 0; + return STIX_PF_FAILURE; } if (STIX_OBJ_GET_CLASS(rcv) == stix->_symbol) @@ -1554,7 +1578,7 @@ static int pf_basic_at_put (stix_t* stix, stix_ooi_t nargs) /* TODO: disallow change of some key kernel objects???? */ /* TODO: is it better to introduct a read-only mark in the object header instead of this class check??? */ /* read-only object */ /* TODO: DEVISE A WAY TO PASS a proper error from the primitive handler to STIX */ - return 0; + return STIX_PF_FAILURE; } switch (STIX_OBJ_GET_FLAGS_TYPE(rcv)) @@ -1563,7 +1587,7 @@ static int pf_basic_at_put (stix_t* stix, stix_ooi_t nargs) if (!STIX_OOP_IS_SMOOI(val)) { /* the value is not a character */ - return 0; + return STIX_PF_FAILURE; } /* TOOD: must I check the range of the value? */ ((stix_oop_char_t)rcv)->slot[idx] = STIX_OOP_TO_SMOOI(val); @@ -1573,7 +1597,7 @@ static int pf_basic_at_put (stix_t* stix, stix_ooi_t nargs) if (!STIX_OOP_IS_CHAR(val)) { /* the value is not a character */ - return 0; + return STIX_PF_FAILURE; } ((stix_oop_char_t)rcv)->slot[idx] = STIX_OOP_TO_CHAR(val); break; @@ -1582,7 +1606,7 @@ static int pf_basic_at_put (stix_t* stix, stix_ooi_t nargs) if (!STIX_OOP_IS_SMOOI(val)) { /* the value is not a number */ - return 0; + return STIX_PF_FAILURE; } /* if the small integer is too large, it will get truncated */ @@ -1590,14 +1614,17 @@ static int pf_basic_at_put (stix_t* stix, stix_ooi_t nargs) break; case STIX_OBJ_TYPE_WORD: - /* TODO: handle LargeInteger */ - if (!STIX_OOP_IS_SMOOI(val)) + { + stix_oow_t w; + + if (stix_inttooow (stix, val, &w) <= 0) { - /* the value is not a number */ - return 0; + /* the value is not a number, out of range, or negative */ + return STIX_PF_FAILURE; } - ((stix_oop_word_t)rcv)->slot[idx] = STIX_OOP_TO_SMOOI(val); + ((stix_oop_word_t)rcv)->slot[idx] = w; break; + } case STIX_OBJ_TYPE_OOP: ((stix_oop_oop_t)rcv)->slot[idx] = val; @@ -1605,15 +1632,15 @@ static int pf_basic_at_put (stix_t* stix, stix_ooi_t nargs) default: stix->errnum = STIX_EINTERN; - return -1; + return STIX_PF_HARD_FAILURE; } /* TODO: return receiver or value? */ STIX_STACK_SETRET (stix, nargs, val); - return 1; + return STIX_PF_SUCCESS; } -static int pf_hash (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_hash (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv; stix_oow_t hv; @@ -1662,7 +1689,7 @@ static int pf_hash (stix_t* stix, stix_ooi_t nargs) default: /* STIX_OBJ_TYPE_OOP, ... */ STIX_DEBUG1 (stix, " Cannot hash an object of type %d\n", type); - return 0; + return STIX_PF_FAILURE; } break; } @@ -1670,10 +1697,10 @@ static int pf_hash (stix_t* stix, stix_ooi_t nargs) hv %= STIX_SMOOI_MAX; STIX_STACK_SETRET (stix, nargs, STIX_SMOOI_TO_OOP(hv)); - return 1; + return STIX_PF_SUCCESS; } -static int pf_exceptionize_error (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_exceptionize_error (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv; @@ -1685,16 +1712,16 @@ static int pf_exceptionize_error (stix_t* stix, stix_ooi_t nargs) /* the receiver is a special numeric object, not a normal pointer. * excceptionization is not supported for small integers, characters, and errors. * first of all, methods of these classes must not return errors */ - return 0; + return STIX_PF_FAILURE; } // TODO: ....... // STIX_OBJ_SET_FLAGS_EXTRA (rcv, xxx); STIX_STACK_SETRETTORCV (stix, nargs); - return 1; + return STIX_PF_SUCCESS; } -static int pf_context_goto (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_context_goto (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv; stix_oop_t pc; @@ -1711,7 +1738,7 @@ static int pf_context_goto (stix_t* stix, stix_ooi_t nargs) { STIX_LOG2 (stix, STIX_LOG_PRIMITIVE | STIX_LOG_ERROR, "Error(%hs) - invalid receiver, not a method context - %O\n", __PRIMITIVE_NAME__, rcv); - return 0; + return STIX_PF_FAILURE; } pc = STIX_STACK_GETARG(stix, nargs, 0); @@ -1719,7 +1746,7 @@ static int pf_context_goto (stix_t* stix, stix_ooi_t nargs) { STIX_LOG1 (stix, STIX_LOG_PRIMITIVE | STIX_LOG_ERROR, "Error(%hs) - invalid pc\n", __PRIMITIVE_NAME__); - return 0; + return STIX_PF_FAILURE; } ((stix_oop_context_t)rcv)->ip = pc; @@ -1727,10 +1754,10 @@ static int pf_context_goto (stix_t* stix, stix_ooi_t nargs) STIX_ASSERT (stix, nargs + 1 == 2); STIX_STACK_POPS (stix, 2); /* pop both the argument and the receiver */ - return 1; + return STIX_PF_SUCCESS; } -static int __block_value (stix_t* stix, stix_oop_context_t rcv_blkctx, stix_ooi_t nargs, stix_ooi_t num_first_arg_elems, stix_oop_context_t* pblkctx) +static stix_pfrc_t __block_value (stix_t* stix, stix_oop_context_t rcv_blkctx, stix_ooi_t nargs, stix_ooi_t num_first_arg_elems, stix_oop_context_t* pblkctx) { /* prepare a new block context for activation. * the receiver must be a block context which becomes the base @@ -1764,7 +1791,7 @@ static int __block_value (stix_t* stix, stix_oop_context_t rcv_blkctx, stix_ooi_ STIX_ASSERT (stix, STIX_OBJ_GET_SIZE(rcv_blkctx) > STIX_CONTEXT_NAMED_INSTVARS); STIX_LOG2 (stix, STIX_LOG_PRIMITIVE | STIX_LOG_ERROR, "Error(%hs) - re-valuing of a block context - %O\n", __PRIMITIVE_NAME__, rcv_blkctx); - return 0; + return STIX_PF_FAILURE; } STIX_ASSERT (stix, STIX_OBJ_GET_SIZE(rcv_blkctx) == STIX_CONTEXT_NAMED_INSTVARS); @@ -1773,7 +1800,7 @@ static int __block_value (stix_t* stix, stix_oop_context_t rcv_blkctx, stix_ooi_ STIX_LOG4 (stix, STIX_LOG_PRIMITIVE | STIX_LOG_ERROR, "Error(%hs) - wrong number of arguments to a block context %O - expecting %zd, got %zd\n", __PRIMITIVE_NAME__, rcv_blkctx, STIX_OOP_TO_SMOOI(rcv_blkctx->method_or_nargs), actual_arg_count); - return 0; + return STIX_PF_FAILURE; } /* the number of temporaries stored in the block context @@ -1787,7 +1814,7 @@ static int __block_value (stix_t* stix, stix_oop_context_t rcv_blkctx, stix_ooi_ stix_pushtmp (stix, (stix_oop_t*)&rcv_blkctx); blkctx = (stix_oop_context_t) stix_instantiate (stix, stix->_block_context, STIX_NULL, local_ntmprs); stix_poptmp (stix); - if (!blkctx) return -1; + if (!blkctx) return STIX_PF_HARD_FAILURE; #if 0 /* shallow-copy the named part including home, origin, etc. */ @@ -1834,12 +1861,12 @@ static int __block_value (stix_t* stix, stix_oop_context_t rcv_blkctx, stix_ooi_ blkctx->sender = stix->active_context; *pblkctx = blkctx; - return 1; + return STIX_PF_SUCCESS; } -static int pf_block_value (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_block_value (stix_t* stix, stix_ooi_t nargs) { - int x; + stix_pfrc_t x; stix_oop_context_t rcv_blkctx, blkctx; rcv_blkctx = (stix_oop_context_t)STIX_STACK_GETRCV(stix, nargs); @@ -1848,17 +1875,17 @@ static int pf_block_value (stix_t* stix, stix_ooi_t nargs) /* the receiver must be a block context */ STIX_LOG2 (stix, STIX_LOG_PRIMITIVE | STIX_LOG_ERROR, "Error(%hs) - invalid receiver, not a block context - %O\n", __PRIMITIVE_NAME__, rcv_blkctx); - return 0; + return STIX_PF_FAILURE; } x = __block_value (stix, rcv_blkctx, nargs, 0, &blkctx); - if (x <= 0) return x; /* hard failure and soft failure */ + if (x <= STIX_PF_FAILURE) return x; /* hard failure and soft failure */ SWITCH_ACTIVE_CONTEXT (stix, (stix_oop_context_t)blkctx); - return 1; + return STIX_PF_SUCCESS; } -static int pf_block_new_process (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_block_new_process (stix_t* stix, stix_ooi_t nargs) { /* create a new process from a block context. * the receiver must be be a block. @@ -1875,7 +1902,7 @@ static int pf_block_new_process (stix_t* stix, stix_ooi_t nargs) { /* too many arguments */ /* TODO: proper error handling */ - return 0; + return STIX_PF_FAILURE; } if (nargs == 1) @@ -1887,7 +1914,7 @@ static int pf_block_new_process (stix_t* stix, stix_ooi_t nargs) { /* the only optional argument must be an OOP-indexable * object like an array */ - return 0; + return STIX_PF_FAILURE; } num_first_arg_elems = STIX_OBJ_GET_SIZE(xarg); @@ -1899,7 +1926,7 @@ static int pf_block_new_process (stix_t* stix, stix_ooi_t nargs) /* the receiver must be a block context */ STIX_LOG2 (stix, STIX_LOG_PRIMITIVE | STIX_LOG_ERROR, "Error(%hs) - invalid receiver, not a block context - %O\n", __PRIMITIVE_NAME__, rcv_blkctx); - return 0; + return STIX_PF_FAILURE; } /* this primitive creates a new process with a block as if the block @@ -1914,29 +1941,29 @@ static int pf_block_new_process (stix_t* stix, stix_ooi_t nargs) blkctx->sender = (stix_oop_context_t)stix->_nil; proc = make_process (stix, blkctx); - if (!proc) return -1; /* hard failure */ /* TOOD: can't this be treated as a soft failure? */ + if (!proc) return STIX_PF_HARD_FAILURE; /* hard failure */ /* TOOD: can't this be treated as a soft failure? */ /* __block_value() has popped all arguments and the receiver. * PUSH the return value instead of changing the stack top */ STIX_STACK_PUSH (stix, (stix_oop_t)proc); - return 1; + return STIX_PF_SUCCESS; } -static int pf_process_resume (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_process_resume (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv; STIX_ASSERT (stix, nargs == 0); rcv = STIX_STACK_GETRCV(stix, nargs); - if (STIX_CLASSOF(stix,rcv) != stix->_process) return 0; + if (STIX_CLASSOF(stix,rcv) != stix->_process) return STIX_PF_FAILURE; resume_process (stix, (stix_oop_process_t)rcv); /* TODO: error check */ /* keep the receiver in the stack top */ - return 1; + return STIX_PF_SUCCESS; } -static int pf_process_terminate (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_process_terminate (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv; STIX_ASSERT (stix, nargs == 0); @@ -1944,71 +1971,71 @@ static int pf_process_terminate (stix_t* stix, stix_ooi_t nargs) /* TODO: need to run ensure blocks here.. * when it's executed here. it does't have to be in Exception>>handleException when there is no exception handler */ rcv = STIX_STACK_GETRCV(stix, nargs); - if (STIX_CLASSOF(stix,rcv) != stix->_process) return 0; + if (STIX_CLASSOF(stix,rcv) != stix->_process) return STIX_PF_FAILURE; terminate_process (stix, (stix_oop_process_t)rcv); /* keep the receiver in the stack top */ - return 1; + return STIX_PF_SUCCESS; } -static int pf_process_yield (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_process_yield (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv; STIX_ASSERT (stix, nargs == 0); rcv = STIX_STACK_GETRCV(stix, nargs); - if (STIX_CLASSOF(stix,rcv) != stix->_process) return 0; + if (STIX_CLASSOF(stix,rcv) != stix->_process) return STIX_PF_FAILURE; yield_process (stix, (stix_oop_process_t)rcv); /* keep the receiver in the stack top */ - return 1; + return STIX_PF_SUCCESS; } -static int pf_process_suspend (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_process_suspend (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv; STIX_ASSERT (stix, nargs == 0); rcv = STIX_STACK_GETRCV(stix, nargs); - if (STIX_CLASSOF(stix,rcv) != stix->_process) return 0; + if (STIX_CLASSOF(stix,rcv) != stix->_process) return STIX_PF_FAILURE; suspend_process (stix, (stix_oop_process_t)rcv); /* keep the receiver in the stack top */ - return 1; + return STIX_PF_SUCCESS; } -static int pf_semaphore_signal (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_semaphore_signal (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv; STIX_ASSERT (stix, nargs == 0); rcv = STIX_STACK_GETRCV(stix, nargs); - if (STIX_CLASSOF(stix,rcv) != stix->_semaphore) return 0; + if (STIX_CLASSOF(stix,rcv) != stix->_semaphore) return STIX_PF_FAILURE; signal_semaphore (stix, (stix_oop_semaphore_t)rcv); /* keep the receiver in the stack top */ - return 1; + return STIX_PF_SUCCESS; } -static int pf_semaphore_wait (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_semaphore_wait (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv; STIX_ASSERT (stix, nargs == 0); rcv = STIX_STACK_GETRCV(stix, nargs); - if (STIX_CLASSOF(stix,rcv) != stix->_semaphore) return 0; + if (STIX_CLASSOF(stix,rcv) != stix->_semaphore) return STIX_PF_FAILURE; await_semaphore (stix, (stix_oop_semaphore_t)rcv); /* keep the receiver in the stack top */ - return 1; + return STIX_PF_SUCCESS; } -static int pf_processor_schedule (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_processor_schedule (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, arg; @@ -2019,14 +2046,14 @@ static int pf_processor_schedule (stix_t* stix, stix_ooi_t nargs) if (rcv != (stix_oop_t)stix->processor || STIX_CLASSOF(stix,arg) != stix->_process) { - return 0; + return STIX_PF_FAILURE; } resume_process (stix, (stix_oop_process_t)arg); /* TODO: error check */ - return 1; + return STIX_PF_SUCCESS; } -static int pf_processor_add_timed_semaphore (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_processor_add_timed_semaphore (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, sec, nsec; stix_oop_semaphore_t sem; @@ -2037,7 +2064,7 @@ static int pf_processor_add_timed_semaphore (stix_t* stix, stix_ooi_t nargs) if (nargs == 3) { nsec = STIX_STACK_GETARG (stix, nargs, 2); - if (!STIX_OOP_IS_SMOOI(nsec)) return 0; + if (!STIX_OOP_IS_SMOOI(nsec)) return STIX_PF_FAILURE; } else nsec = STIX_SMOOI_TO_OOP(0); @@ -2045,9 +2072,9 @@ static int pf_processor_add_timed_semaphore (stix_t* stix, stix_ooi_t nargs) sem = (stix_oop_semaphore_t)STIX_STACK_GETARG(stix, nargs, 0); rcv = STIX_STACK_GETRCV(stix, nargs); - if (rcv != (stix_oop_t)stix->processor) return 0; - if (STIX_CLASSOF(stix,sem) != stix->_semaphore) return 0; - if (!STIX_OOP_IS_SMOOI(sec)) return 0; + if (rcv != (stix_oop_t)stix->processor) return STIX_PF_FAILURE; + if (STIX_CLASSOF(stix,sem) != stix->_semaphore) return STIX_PF_FAILURE; + if (!STIX_OOP_IS_SMOOI(sec)) return STIX_PF_FAILURE; if (STIX_OOP_IS_SMOOI(sem->heap_index) && sem->heap_index != STIX_SMOOI_TO_OOP(-1)) @@ -2058,7 +2085,7 @@ static int pf_processor_add_timed_semaphore (stix_t* stix, stix_ooi_t nargs) /* Is this more desired??? STIX_STACK_SETRET (stix, nargs, stix->_false); - return 1; + return STIX_PF_SUCCESS; */ } @@ -2075,19 +2102,19 @@ static int pf_processor_add_timed_semaphore (stix_t* stix, stix_ooi_t nargs) STIX_LOG3 (stix, STIX_LOG_PRIMITIVE | STIX_LOG_ERROR, "Error(%hs) - time (%ld) out of range(0 - %zd) when adding a timed semaphore\n", __PRIMITIVE_NAME__, (unsigned long int)ft.sec, (stix_ooi_t)STIX_SMOOI_MAX); - return 0; + return STIX_PF_FAILURE; } sem->heap_ftime_sec = STIX_SMOOI_TO_OOP(ft.sec); sem->heap_ftime_nsec = STIX_SMOOI_TO_OOP(ft.nsec); - if (add_to_sem_heap (stix, sem) <= -1) return -1; + if (add_to_sem_heap (stix, sem) <= -1) return STIX_PF_HARD_FAILURE; STIX_STACK_SETRETTORCV (stix, nargs); /* ^self */ - return 1; + return STIX_PF_SUCCESS; } -static int pf_processor_remove_semaphore (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_processor_remove_semaphore (stix_t* stix, stix_ooi_t nargs) { /* remove a semaphore from processor's signal scheduling */ @@ -2102,8 +2129,8 @@ static int pf_processor_remove_semaphore (stix_t* stix, stix_ooi_t nargs) /* TODO: remove a semaphore from IO handler if it's registered... * remove a semaphore from XXXXXXXXXXXXXX */ - if (rcv != (stix_oop_t)stix->processor) return 0; - if (STIX_CLASSOF(stix,sem) != stix->_semaphore) return 0; + if (rcv != (stix_oop_t)stix->processor) return STIX_PF_FAILURE; + if (STIX_CLASSOF(stix,sem) != stix->_semaphore) return STIX_PF_FAILURE; if (STIX_OOP_IS_SMOOI(sem->heap_index) && sem->heap_index != STIX_SMOOI_TO_OOP(-1)) @@ -2114,10 +2141,10 @@ static int pf_processor_remove_semaphore (stix_t* stix, stix_ooi_t nargs) } STIX_STACK_SETRETTORCV (stix, nargs); /* ^self */ - return 1; + return STIX_PF_SUCCESS; } -static int pf_processor_return_to (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_processor_return_to (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, ret, ctx; @@ -2127,10 +2154,10 @@ static int pf_processor_return_to (stix_t* stix, stix_ooi_t nargs) ret = STIX_STACK_GETARG(stix, nargs, 0); ctx = STIX_STACK_GETARG(stix, nargs, 1); - if (rcv != (stix_oop_t)stix->processor) return 0; + if (rcv != (stix_oop_t)stix->processor) return STIX_PF_FAILURE; if (STIX_CLASSOF(stix, ctx) != stix->_block_context && - STIX_CLASSOF(stix, ctx) != stix->_method_context) return 0; + STIX_CLASSOF(stix, ctx) != stix->_method_context) return STIX_PF_FAILURE; STIX_STACK_POPS (stix, nargs + 1); /* pop arguments and receiver */ /* TODO: verify if this is correct? does't it correct restore the stack pointer? @@ -2144,10 +2171,10 @@ static int pf_processor_return_to (stix_t* stix, stix_ooi_t nargs) STIX_STACK_PUSH (stix, ret); SWITCH_ACTIVE_CONTEXT (stix, (stix_oop_context_t)ctx); - return 1; + return STIX_PF_SUCCESS; } -static int pf_integer_add (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_integer_add (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, arg, res; @@ -2157,13 +2184,13 @@ static int pf_integer_add (stix_t* stix, stix_ooi_t nargs) arg = STIX_STACK_GETARG(stix, nargs, 0); res = stix_addints (stix, rcv, arg); - if (!res) return (stix->errnum == STIX_EINVAL? 0: -1); /* soft or hard failure */ + if (!res) return (stix->errnum == STIX_EINVAL? STIX_PF_FAILURE: STIX_PF_HARD_FAILURE); STIX_STACK_SETRET (stix, nargs, res); - return 1; + return STIX_PF_SUCCESS; } -static int pf_integer_sub (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_integer_sub (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, arg, res; @@ -2173,13 +2200,13 @@ static int pf_integer_sub (stix_t* stix, stix_ooi_t nargs) arg = STIX_STACK_GETARG(stix, nargs, 0); res = stix_subints (stix, rcv, arg); - if (!res) return (stix->errnum == STIX_EINVAL? 0: -1); /* soft or hard failure */ + if (!res) return (stix->errnum == STIX_EINVAL? STIX_PF_FAILURE: STIX_PF_HARD_FAILURE); STIX_STACK_SETRET (stix, nargs, res); - return 1; + return STIX_PF_SUCCESS; } -static int pf_integer_mul (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_integer_mul (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, arg, res; @@ -2189,13 +2216,13 @@ static int pf_integer_mul (stix_t* stix, stix_ooi_t nargs) arg = STIX_STACK_GETARG(stix, nargs, 0); res = stix_mulints (stix, rcv, arg); - if (!res) return (stix->errnum == STIX_EINVAL? 0: -1); /* soft or hard failure */ + if (!res) return (stix->errnum == STIX_EINVAL? STIX_PF_FAILURE: STIX_PF_HARD_FAILURE); STIX_STACK_SETRET (stix, nargs, res); - return 1; + return STIX_PF_SUCCESS; } -static int pf_integer_quo (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_integer_quo (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, arg, quo; @@ -2205,14 +2232,14 @@ static int pf_integer_quo (stix_t* stix, stix_ooi_t nargs) arg = STIX_STACK_GETARG(stix, nargs, 0); quo = stix_divints (stix, rcv, arg, 0, STIX_NULL); - if (!quo) return (stix->errnum == STIX_EINVAL? 0: -1); /* soft or hard failure */ + if (!quo) return (stix->errnum == STIX_EINVAL? STIX_PF_FAILURE: STIX_PF_HARD_FAILURE); /* TODO: STIX_EDIVBY0 soft or hard failure? */ STIX_STACK_SETRET (stix, nargs, quo); - return 1; + return STIX_PF_SUCCESS; } -static int pf_integer_rem (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_integer_rem (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, arg, quo, rem; @@ -2222,14 +2249,14 @@ static int pf_integer_rem (stix_t* stix, stix_ooi_t nargs) arg = STIX_STACK_GETARG(stix, nargs, 0); quo = stix_divints (stix, rcv, arg, 0, &rem); - if (!quo) return (stix->errnum == STIX_EINVAL? 0: -1); /* soft or hard failure */ + if (!quo) return (stix->errnum == STIX_EINVAL? STIX_PF_FAILURE: STIX_PF_HARD_FAILURE); /* TODO: STIX_EDIVBY0 soft or hard failure? */ STIX_STACK_SETRET (stix, nargs, rem); - return 1; + return STIX_PF_SUCCESS; } -static int pf_integer_quo2 (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_integer_quo2 (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, arg, quo; @@ -2239,14 +2266,14 @@ static int pf_integer_quo2 (stix_t* stix, stix_ooi_t nargs) arg = STIX_STACK_GETARG(stix, nargs, 0); quo = stix_divints (stix, rcv, arg, 1, STIX_NULL); - if (!quo) return (stix->errnum == STIX_EINVAL? 0: -1); /* soft or hard failure */ + if (!quo) return (stix->errnum == STIX_EINVAL? STIX_PF_FAILURE: STIX_PF_HARD_FAILURE); /* TODO: STIX_EDIVBY0 soft or hard failure? */ STIX_STACK_SETRET (stix, nargs, quo); - return 1; + return STIX_PF_SUCCESS; } -static int pf_integer_rem2 (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_integer_rem2 (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, arg, quo, rem; @@ -2256,14 +2283,14 @@ static int pf_integer_rem2 (stix_t* stix, stix_ooi_t nargs) arg = STIX_STACK_GETARG(stix, nargs, 0); quo = stix_divints (stix, rcv, arg, 1, &rem); - if (!quo) return (stix->errnum == STIX_EINVAL? 0: -1); /* soft or hard failure */ + if (!quo) return (stix->errnum == STIX_EINVAL? STIX_PF_FAILURE: STIX_PF_HARD_FAILURE); /* TODO: STIX_EDIVBY0 soft or hard failure? */ STIX_STACK_SETRET (stix, nargs, rem); - return 1; + return STIX_PF_SUCCESS; } -static int pf_integer_negated (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_integer_negated (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, res; @@ -2272,13 +2299,13 @@ static int pf_integer_negated (stix_t* stix, stix_ooi_t nargs) rcv = STIX_STACK_GETRCV(stix, nargs); res = stix_negateint (stix, rcv); - if (!res) return (stix->errnum == STIX_EINVAL? 0: -1); /* soft or hard failure */ + if (!res) return (stix->errnum == STIX_EINVAL? STIX_PF_FAILURE: STIX_PF_HARD_FAILURE); STIX_STACK_SETRET (stix, nargs, res); - return 1; + return STIX_PF_SUCCESS; } -static int pf_integer_bitat (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_integer_bitat (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, arg, res; @@ -2288,13 +2315,13 @@ static int pf_integer_bitat (stix_t* stix, stix_ooi_t nargs) arg = STIX_STACK_GETARG(stix, nargs, 0); res = stix_bitatint (stix, rcv, arg); - if (!res) return (stix->errnum == STIX_EINVAL? 0: -1); /* soft or hard failure */ + if (!res) return (stix->errnum == STIX_EINVAL? STIX_PF_FAILURE: STIX_PF_HARD_FAILURE); STIX_STACK_SETRET (stix, nargs, res); - return 1; + return STIX_PF_SUCCESS; } -static int pf_integer_bitand (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_integer_bitand (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, arg, res; @@ -2304,13 +2331,13 @@ static int pf_integer_bitand (stix_t* stix, stix_ooi_t nargs) arg = STIX_STACK_GETARG(stix, nargs, 0); res = stix_bitandints (stix, rcv, arg); - if (!res) return (stix->errnum == STIX_EINVAL? 0: -1); /* soft or hard failure */ + if (!res) return (stix->errnum == STIX_EINVAL? STIX_PF_FAILURE: STIX_PF_HARD_FAILURE); STIX_STACK_SETRET (stix, nargs, res); - return 1; + return STIX_PF_SUCCESS; } -static int pf_integer_bitor (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_integer_bitor (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, arg, res; @@ -2320,13 +2347,13 @@ static int pf_integer_bitor (stix_t* stix, stix_ooi_t nargs) arg = STIX_STACK_GETARG(stix, nargs, 0); res = stix_bitorints (stix, rcv, arg); - if (!res) return (stix->errnum == STIX_EINVAL? 0: -1); /* soft or hard failure */ + if (!res) return (stix->errnum == STIX_EINVAL? STIX_PF_FAILURE: STIX_PF_HARD_FAILURE); STIX_STACK_SETRET (stix, nargs, res); - return 1; + return STIX_PF_SUCCESS; } -static int pf_integer_bitxor (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_integer_bitxor (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, arg, res; @@ -2336,13 +2363,13 @@ static int pf_integer_bitxor (stix_t* stix, stix_ooi_t nargs) arg = STIX_STACK_GETARG(stix, nargs, 0); res = stix_bitxorints (stix, rcv, arg); - if (!res) return (stix->errnum == STIX_EINVAL? 0: -1); /* soft or hard failure */ + if (!res) return (stix->errnum == STIX_EINVAL? STIX_PF_FAILURE: STIX_PF_HARD_FAILURE); STIX_STACK_SETRET (stix, nargs, res); - return 1; + return STIX_PF_SUCCESS; } -static int pf_integer_bitinv (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_integer_bitinv (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, res; @@ -2351,13 +2378,13 @@ static int pf_integer_bitinv (stix_t* stix, stix_ooi_t nargs) rcv = STIX_STACK_GETRCV(stix, nargs); res = stix_bitinvint (stix, rcv); - if (!res) return (stix->errnum == STIX_EINVAL? 0: -1); /* soft or hard failure */ + if (!res) return (stix->errnum == STIX_EINVAL? STIX_PF_FAILURE: STIX_PF_HARD_FAILURE); STIX_STACK_SETRET (stix, nargs, res); - return 1; + return STIX_PF_SUCCESS; } -static int pf_integer_bitshift (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_integer_bitshift (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, arg, res; @@ -2367,13 +2394,13 @@ static int pf_integer_bitshift (stix_t* stix, stix_ooi_t nargs) arg = STIX_STACK_GETARG(stix, nargs, 0); res = stix_bitshiftint (stix, rcv, arg); - if (!res) return (stix->errnum == STIX_EINVAL? 0: -1); /* soft or hard failure */ + if (!res) return (stix->errnum == STIX_EINVAL? STIX_PF_FAILURE: STIX_PF_HARD_FAILURE); STIX_STACK_SETRET (stix, nargs, res); - return 1; + return STIX_PF_SUCCESS; } -static int pf_integer_eq (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_integer_eq (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, arg, res; @@ -2383,13 +2410,13 @@ static int pf_integer_eq (stix_t* stix, stix_ooi_t nargs) arg = STIX_STACK_GETARG(stix, nargs, 0); res = stix_eqints (stix, rcv, arg); - if (!res) return (stix->errnum == STIX_EINVAL? 0: -1); /* soft or hard failure */ + if (!res) return (stix->errnum == STIX_EINVAL? STIX_PF_FAILURE: STIX_PF_HARD_FAILURE); STIX_STACK_SETRET (stix, nargs, res); - return 1; + return STIX_PF_SUCCESS; } -static int pf_integer_ne (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_integer_ne (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, arg, res; @@ -2399,13 +2426,13 @@ static int pf_integer_ne (stix_t* stix, stix_ooi_t nargs) arg = STIX_STACK_GETARG(stix, nargs, 0); res = stix_neints (stix, rcv, arg); - if (!res) return (stix->errnum == STIX_EINVAL? 0: -1); /* soft or hard failure */ + if (!res) return (stix->errnum == STIX_EINVAL? STIX_PF_FAILURE: STIX_PF_HARD_FAILURE); STIX_STACK_SETRET (stix, nargs, res); - return 1; + return STIX_PF_SUCCESS; } -static int pf_integer_lt (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_integer_lt (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, arg, res; @@ -2415,13 +2442,13 @@ static int pf_integer_lt (stix_t* stix, stix_ooi_t nargs) arg = STIX_STACK_GETARG(stix, nargs, 0); res = stix_ltints (stix, rcv, arg); - if (!res) return (stix->errnum == STIX_EINVAL? 0: -1); /* soft or hard failure */ + if (!res) return (stix->errnum == STIX_EINVAL? STIX_PF_FAILURE: STIX_PF_HARD_FAILURE); STIX_STACK_SETRET (stix, nargs, res); - return 1; + return STIX_PF_SUCCESS; } -static int pf_integer_gt (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_integer_gt (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, arg, res; @@ -2431,13 +2458,13 @@ static int pf_integer_gt (stix_t* stix, stix_ooi_t nargs) arg = STIX_STACK_GETARG(stix, nargs, 0); res = stix_gtints (stix, rcv, arg); - if (!res) return (stix->errnum == STIX_EINVAL? 0: -1); /* soft or hard failure */ + if (!res) return (stix->errnum == STIX_EINVAL? STIX_PF_FAILURE: STIX_PF_HARD_FAILURE); STIX_STACK_SETRET (stix, nargs, res); - return 1; + return STIX_PF_SUCCESS; } -static int pf_integer_le (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_integer_le (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, arg, res; @@ -2447,13 +2474,13 @@ static int pf_integer_le (stix_t* stix, stix_ooi_t nargs) arg = STIX_STACK_GETARG(stix, nargs, 0); res = stix_leints (stix, rcv, arg); - if (!res) return (stix->errnum == STIX_EINVAL? 0: -1); /* soft or hard failure */ + if (!res) return (stix->errnum == STIX_EINVAL? STIX_PF_FAILURE: STIX_PF_HARD_FAILURE); STIX_STACK_SETRET (stix, nargs, res); - return 1; + return STIX_PF_SUCCESS; } -static int pf_integer_ge (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_integer_ge (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, arg, res; @@ -2463,13 +2490,13 @@ static int pf_integer_ge (stix_t* stix, stix_ooi_t nargs) arg = STIX_STACK_GETARG(stix, nargs, 0); res = stix_geints (stix, rcv, arg); - if (!res) return (stix->errnum == STIX_EINVAL? 0: -1); /* soft or hard failure */ + if (!res) return (stix->errnum == STIX_EINVAL? STIX_PF_FAILURE: STIX_PF_HARD_FAILURE); STIX_STACK_SETRET (stix, nargs, res); - return 1; + return STIX_PF_SUCCESS; } -static int pf_integer_inttostr (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_integer_inttostr (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, arg, str; stix_ooi_t radix; @@ -2479,18 +2506,18 @@ static int pf_integer_inttostr (stix_t* stix, stix_ooi_t nargs) rcv = STIX_STACK_GETRCV(stix, nargs); arg = STIX_STACK_GETARG(stix, nargs, 0); - if (!STIX_OOP_IS_SMOOI(arg)) return 0; /* soft failure */ + if (!STIX_OOP_IS_SMOOI(arg)) return STIX_PF_FAILURE; radix = STIX_OOP_TO_SMOOI(arg); - if (radix < 2 || radix > 36) return 0; /* soft failure */ + if (radix < 2 || radix > 36) return STIX_PF_FAILURE; str = stix_inttostr (stix, rcv, radix); if (!str) return (stix->errnum == STIX_EINVAL? 0: -1); STIX_STACK_SETRET (stix, nargs, str); - return 1; + return STIX_PF_SUCCESS; } -static int pf_smooi_as_character (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_smooi_as_character (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv; stix_ooi_t ec; @@ -2498,15 +2525,15 @@ static int pf_smooi_as_character (stix_t* stix, stix_ooi_t nargs) STIX_ASSERT (stix, nargs == 0); rcv = STIX_STACK_GETRCV(stix, nargs); - if (!STIX_OOP_IS_SMOOI(rcv)) return 0; + if (!STIX_OOP_IS_SMOOI(rcv)) return STIX_PF_FAILURE; ec = STIX_OOP_TO_SMOOI(rcv); if (ec < 0) ec = 0; STIX_STACK_SETRET (stix, nargs, STIX_CHAR_TO_OOP(ec)); - return 1; + return STIX_PF_SUCCESS; } -static int pf_smooi_as_error (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_smooi_as_error (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv; stix_ooi_t ec; @@ -2514,15 +2541,15 @@ static int pf_smooi_as_error (stix_t* stix, stix_ooi_t nargs) STIX_ASSERT (stix, nargs == 0); rcv = STIX_STACK_GETRCV(stix, nargs); - if (!STIX_OOP_IS_SMOOI(rcv)) return 0; + if (!STIX_OOP_IS_SMOOI(rcv)) return STIX_PF_FAILURE; ec = STIX_OOP_TO_SMOOI(rcv); if (ec < 0) ec = 0; STIX_STACK_SETRET (stix, nargs, STIX_ERROR_TO_OOP(ec)); - return 1; + return STIX_PF_SUCCESS; } -static int pf_error_as_character (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_error_as_character (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv; stix_ooi_t ec; @@ -2530,15 +2557,15 @@ static int pf_error_as_character (stix_t* stix, stix_ooi_t nargs) STIX_ASSERT (stix, nargs == 0); rcv = STIX_STACK_GETRCV(stix, nargs); - if (!STIX_OOP_IS_ERROR(rcv)) return 0; + if (!STIX_OOP_IS_ERROR(rcv)) return STIX_PF_FAILURE; ec = STIX_OOP_TO_ERROR(rcv); STIX_ASSERT (stix, STIX_IN_SMOOI_RANGE(ec)); STIX_STACK_SETRET (stix, nargs, STIX_CHAR_TO_OOP(ec)); - return 1; + return STIX_PF_SUCCESS; } -static int pf_error_as_integer (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_error_as_integer (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv; stix_ooi_t ec; @@ -2546,15 +2573,15 @@ static int pf_error_as_integer (stix_t* stix, stix_ooi_t nargs) STIX_ASSERT (stix, nargs == 0); rcv = STIX_STACK_GETRCV(stix, nargs); - if (!STIX_OOP_IS_ERROR(rcv)) return 0; + if (!STIX_OOP_IS_ERROR(rcv)) return STIX_PF_FAILURE; ec = STIX_OOP_TO_ERROR(rcv); STIX_ASSERT (stix, STIX_IN_SMOOI_RANGE(ec)); STIX_STACK_SETRET (stix, nargs, STIX_SMOOI_TO_OOP(ec)); - return 1; + return STIX_PF_SUCCESS; } -static int pf_error_as_string (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_error_as_string (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, ss; stix_ooi_t ec; @@ -2563,7 +2590,7 @@ static int pf_error_as_string (stix_t* stix, stix_ooi_t nargs) STIX_ASSERT (stix, nargs == 0); rcv = STIX_STACK_GETRCV(stix, nargs); - if (!STIX_OOP_IS_ERROR(rcv)) return 0; + if (!STIX_OOP_IS_ERROR(rcv)) return STIX_PF_FAILURE; ec = STIX_OOP_TO_ERROR(rcv); STIX_ASSERT (stix, STIX_IN_SMOOI_RANGE(ec)); @@ -2571,13 +2598,13 @@ static int pf_error_as_string (stix_t* stix, stix_ooi_t nargs) /* TODO: error string will be mostly the same.. do i really have to call makestring every time? */ s = stix_errnumtoerrstr (ec); ss = stix_makestring (stix, s, stix_countoocstr(s)); - if (!ss) return -1; + if (!ss) return STIX_PF_HARD_FAILURE; STIX_STACK_SETRET (stix, nargs, ss); - return 1; + return STIX_PF_SUCCESS; } -static int pf_ffi_open (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_ffi_open (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, arg; void* handle; @@ -2590,13 +2617,13 @@ static int pf_ffi_open (stix_t* stix, stix_ooi_t nargs) if (!STIX_ISTYPEOF(stix, arg, STIX_OBJ_TYPE_CHAR)) { /* TODO: more info on error */ - return 0; + return STIX_PF_FAILURE; } if (!stix->vmprim.dl_open) { /* TODO: more info on error */ - return 0; + return STIX_PF_FAILURE; } @@ -2605,17 +2632,17 @@ static int pf_ffi_open (stix_t* stix, stix_ooi_t nargs) if (!handle) { /* TODO: more info on error */ - return 0; + return STIX_PF_FAILURE; } STIX_STACK_POP (stix); /* TODO: how to hold an address? as an integer???? or a byte array? fix this not to loose accuracy*/ STIX_STACK_SETTOP (stix, STIX_SMOOI_TO_OOP(handle)); - return 1; + return STIX_PF_SUCCESS; } -static int pf_ffi_close (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_ffi_close (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, arg; void* handle; @@ -2629,17 +2656,17 @@ static int pf_ffi_close (stix_t* stix, stix_ooi_t nargs) if (!STIX_OOP_IS_SMOOI(arg)) { /* TODO: more info on error */ - return 0; + return STIX_PF_FAILURE; } STIX_STACK_POP (stix); handle = (void*)STIX_OOP_TO_SMOOI(arg); /* TODO: how to store void* ???. fix this not to loose accuracy */ if (stix->vmprim.dl_close) stix->vmprim.dl_close (stix, handle); - return 1; + return STIX_PF_SUCCESS; } -static int pf_ffi_call (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_ffi_call (stix_t* stix, stix_ooi_t nargs) { #if defined(USE_DYNCALL) stix_oop_t rcv, fun, sig, args; @@ -2654,19 +2681,19 @@ static int pf_ffi_call (stix_t* stix, stix_ooi_t nargs) if (!STIX_OOP_IS_SMOOI(fun)) /* TODO: how to store pointer */ { /* TODO: more info on error */ - return 0; + return STIX_PF_FAILURE; } if (!STIX_ISTYPEOF(stix, sig, STIX_OBJ_TYPE_CHAR) || STIX_OBJ_GET_SIZE(sig) <= 0) { STIX_DEBUG0 (stix, "FFI: wrong signature...\n"); - return 0; + return STIX_PF_FAILURE; } if (STIX_CLASSOF(stix,args) != stix->_array) /* TODO: check if arr is a kind of array??? or check if it's indexed */ { /* TODO: more info on error */ - return 0; + return STIX_PF_FAILURE; } { @@ -2680,7 +2707,7 @@ STIX_DEBUG0 (stix, "FFI: wrong signature...\n"); arr = (stix_oop_oop_t)args; dc = dcNewCallVM (4096); - if (!dc) return -1; /* TODO: proper error handling */ + if (!dc) return STIX_PF_HARD_FAILURE; /* TODO: proper error handling */ STIX_DEBUG1 (stix, "FFI: CALLING............%p\n", f); /*dcMode (dc, DC_CALL_C_DEFAULT); @@ -2798,7 +2825,7 @@ STIX_DEBUG2 (stix, "CALL ERROR %d %d\n", dcGetError (dc), DC_ERROR_UNSUPPORTED_M if (!s) { dcFree (dc); - return -1; /* TODO: proper error h andling */ + return STIX_PF_HARD_FAILURE; /* TODO: proper error h andling */ } STIX_STACK_SETTOP (stix, s); @@ -2813,13 +2840,13 @@ STIX_DEBUG2 (stix, "CALL ERROR %d %d\n", dcGetError (dc), DC_ERROR_UNSUPPORTED_M dcFree (dc); } - return 1; + return STIX_PF_SUCCESS; #else - return 0; + return STIX_PF_FAILURE; #endif } -static int pf_ffi_getsym (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_ffi_getsym (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, hnd, fun; void* sym; @@ -2833,30 +2860,30 @@ static int pf_ffi_getsym (stix_t* stix, stix_ooi_t nargs) if (!STIX_OOP_IS_SMOOI(hnd)) /* TODO: how to store pointer */ { /* TODO: more info on error */ - return 0; + return STIX_PF_FAILURE; } if (!STIX_ISTYPEOF(stix,fun,STIX_OBJ_TYPE_CHAR)) { STIX_DEBUG0 (stix, "wrong function name...\n"); - return 0; + return STIX_PF_FAILURE; } if (!stix->vmprim.dl_getsym) { - return 0; + return STIX_PF_FAILURE; } sym = stix->vmprim.dl_getsym (stix, (void*)STIX_OOP_TO_SMOOI(hnd), ((stix_oop_char_t)fun)->slot); if (!sym) { - return 0; + return STIX_PF_FAILURE; } /* TODO: how to hold an address? as an integer???? or a byte array? */ STIX_STACK_SETRET (stix, nargs, STIX_SMOOI_TO_OOP(sym)); - return 1; + return STIX_PF_SUCCESS; } #define MAX_NARGS STIX_TYPE_MAX(stix_ooi_t) @@ -2876,6 +2903,8 @@ static pf_t pftab[] = { 1, 1, pf_identical, "_identical" }, { 1, 1, pf_not_identical, "_not_identical" }, + { 1, 1, pf_equal, "_equal" }, + { 1, 1, pf_not_equal, "_not_equal" }, { 0, 0, pf_class, "_class" }, { 0, 0, pf_basic_new, "_basic_new" }, @@ -3077,8 +3106,8 @@ static int start_method (stix_t* stix, stix_oop_method_t method, stix_oow_t narg stix_pushtmp (stix, (stix_oop_t*)&method); n = pftab[pfnum].handler (stix, nargs); stix_poptmp (stix); - if (n <= -1) return -1; /* hard primitive failure */ - if (n >= 1) break; /* primitive ok */ + if (n <= STIX_PF_HARD_FAILURE) return -1; + if (n >= STIX_PF_SUCCESS) break; } /* soft primitive failure */ @@ -3137,12 +3166,12 @@ static int start_method (stix_t* stix, stix_oop_method_t method, stix_oow_t narg n = handler (stix, nargs); stix_poptmp (stix); - if (n <= -1) + if (n <= STIX_PF_HARD_FAILURE) { STIX_DEBUG2 (stix, "Hard failure indicated by primitive function %p - return code %d\n", handler, n); return -1; /* hard primitive failure */ } - if (n >= 1) break; /* primitive ok*/ + if (n >= STIX_PF_SUCCESS) break; /* primitive ok*/ /* soft primitive failure */ STIX_DEBUG1 (stix, "Soft failure indicated by primitive function %p\n", handler); diff --git a/stix/lib/stix.h b/stix/lib/stix.h index 57b3159..af7d382 100644 --- a/stix/lib/stix.h +++ b/stix/lib/stix.h @@ -747,8 +747,16 @@ struct stix_cb_t * ========================================================================= */ #define STIX_MOD_NAME_LEN_MAX 120 +enum stix_pfrc_t +{ + STIX_PF_HARD_FAILURE = -1, + STIX_PF_FAILURE = 0, + STIX_PF_SUCCESS = 1 +}; +typedef enum stix_pfrc_t stix_pfrc_t; + /* primitive function implementation type */ -typedef int (*stix_pfimpl_t) ( +typedef stix_pfrc_t (*stix_pfimpl_t) ( stix_t* stix, stix_ooi_t nargs ); @@ -1088,6 +1096,7 @@ enum stix_synerrnum_t STIX_SYNERR_CLASSUNDEF, /* undefined class */ STIX_SYNERR_CLASSDUP, /* duplicate class */ STIX_SYNERR_CLASSCONTRA, /* contradictory class */ + STIX_SYNERR_CLASSNAME, /* wrong class name */ STIX_SYNERR_DCLBANNED, /* #dcl not allowed */ STIX_SYNERR_MTHNAME, /* wrong method name */ STIX_SYNERR_MTHNAMEDUP, /* duplicate method name */ diff --git a/stix/lib/syntax.txt b/stix/lib/syntax.txt index 065eaf0..3cba1b1 100644 --- a/stix/lib/syntax.txt +++ b/stix/lib/syntax.txt @@ -30,7 +30,7 @@ variable-definition := (#dcl | #declare) variable-modifier? variable-list "." variable-modifier := "(" (#class | #classinst)? ")" variable-list := identifier* -method-definition := (#mth | #method) method-modifier? method-actual-definition +method-definition := #method method-modifier? method-actual-definition method-modifier := "(" (#class | #instance) ")" method-actual-definition := method-name "{" method-tempraries? method-primitive? method-statements* "}" diff --git a/stix/mod/console.c b/stix/mod/console.c index 6da3511..f9574f2 100644 --- a/stix/mod/console.c +++ b/stix/mod/console.c @@ -48,7 +48,7 @@ struct console_t }; /* ------------------------------------------------------------------------ */ -static int pf_open (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_open (stix_t* stix, stix_ooi_t nargs) { #if defined(_WIN32) HANDLE h; @@ -119,10 +119,10 @@ static int pf_open (stix_t* stix, stix_ooi_t nargs) #endif STIX_STACK_SETRET (stix, nargs, STIX_SMOOI_TO_OOP((stix_oow_t)con)); - return 1; + return STIX_PF_SUCCESS; } -static int pf_close (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_close (stix_t* stix, stix_ooi_t nargs) { #if defined(_WIN32) HANDLE h; @@ -139,10 +139,10 @@ static int pf_close (stix_t* stix, stix_ooi_t nargs) stix_freemem (stix, con); STIX_STACK_SETRETTORCV (stix, nargs); - return 1; + return STIX_PF_SUCCESS; } -static int pf_write (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_write (stix_t* stix, stix_ooi_t nargs) { console_t* con; stix_oop_char_t oomsg; @@ -157,7 +157,7 @@ static int pf_write (stix_t* stix, stix_ooi_t nargs) if (STIX_CLASSOF(stix,oomsg) != stix->_string) { /* TODO: invalid message */ - return 0; + return STIX_PF_FAILURE; } ucspos = 0; @@ -171,7 +171,7 @@ static int pf_write (stix_t* stix, stix_ooi_t nargs) if (n != -2 || ucslen <= 0) { stix_seterrnum (stix, STIX_EECERR); - return -1; + return STIX_PF_HARD_FAILURE; } } @@ -182,10 +182,10 @@ static int pf_write (stix_t* stix, stix_ooi_t nargs) } STIX_STACK_SETRETTORCV (stix, nargs); /* TODO: change return code */ - return 1; + return STIX_PF_SUCCESS; } -static int pf_clear (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_clear (stix_t* stix, stix_ooi_t nargs) { console_t* con; @@ -194,10 +194,10 @@ static int pf_clear (stix_t* stix, stix_ooi_t nargs) write (con->fd, con->clear, strlen(con->clear)); STIX_STACK_SETRETTORCV (stix, nargs); - return 1; + return STIX_PF_SUCCESS; } -static int pf_setcursor (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_setcursor (stix_t* stix, stix_ooi_t nargs) { console_t* con; stix_oop_oop_t point; @@ -209,44 +209,16 @@ static int pf_setcursor (stix_t* stix, stix_ooi_t nargs) /* TODO: error check, class check, size check.. */ if (STIX_OBJ_GET_SIZE(point) != 2) { - return 0; + return STIX_PF_FAILURE; } cup = tiparm (con->cup, STIX_OOP_TO_SMOOI(point->slot[1]), STIX_OOP_TO_SMOOI(point->slot[0])); write (con->fd, cup, strlen(cup)); /* TODO: error check */ STIX_STACK_SETRETTORCV (stix, nargs); - return 1; + return STIX_PF_SUCCESS; } - -#if 0 -static int pf_setcursorto (stix_t* stix, stix_ooi_t nargs) -{ - console_t* con; - stix_oop_oop_t point; - char* cup; - - rcv = STIX_STACK_GETRCV(stix, nargs); - con = STIX_OOP_TO_SMOOI( - - con = STIX_OOP_TO_SMOOI(STIX_STACK_GETARG(stix, nargs, 0)); - point = STIX_STACK_GETARG(stix, nargs, 1); - -/* TODO: error check, class check, size check.. */ - if (STIX_OBJ_GET_SIZE(point) != 2) - { - return 0; - } - - cup = tiparm (con->cup, STIX_OOP_TO_SMOOI(point->slot[1]), STIX_OOP_TO_SMOOI(point->slot[0])); - write (con->fd, cup, strlen(cup)); /* TODO: error check */ - - STIX_STACK_SETRETTORCV (stix, nargs); - return 1; -} -#endif - /* ------------------------------------------------------------------------ */ typedef struct fnctab_t fnctab_t; diff --git a/stix/mod/stdio.c b/stix/mod/stdio.c index 10f910b..82766fe 100644 --- a/stix/mod/stdio.c +++ b/stix/mod/stdio.c @@ -39,14 +39,14 @@ struct stdio_t FILE* fp; }; -static int pf_newinstsize (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_newinstsize (stix_t* stix, stix_ooi_t nargs) { stix_ooi_t newinstsize = STIX_SIZEOF(stdio_t) - STIX_SIZEOF(stix_obj_t); STIX_STACK_SETRET (stix, nargs, STIX_SMOOI_TO_OOP(newinstsize)); - return 1; + return STIX_PF_SUCCESS; } -static int pf_open (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_open (stix_t* stix, stix_ooi_t nargs) { stix_oop_char_t name; stix_oop_char_t mode; @@ -84,14 +84,14 @@ static int pf_open (stix_t* stix, stix_ooi_t nargs) } STIX_STACK_SETRETTORCV (stix, nargs); - return 1; + return STIX_PF_SUCCESS; reterr: STIX_STACK_SETRETTOERROR (stix, nargs); - return 1; + return STIX_PF_SUCCESS; } -static int pf_close (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_close (stix_t* stix, stix_ooi_t nargs) { stdio_t* rcv; @@ -103,17 +103,17 @@ static int pf_close (stix_t* stix, stix_ooi_t nargs) } STIX_STACK_SETRETTORCV (stix, nargs); - return 1; + return STIX_PF_SUCCESS; } -static int pf_gets (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_gets (stix_t* stix, stix_ooi_t nargs) { /* return how many bytes have been written.. */ STIX_STACK_SETRETTORCV (stix, nargs); - return 1; + return STIX_PF_SUCCESS; } -static int __pf_puts (stix_t* stix, stix_ooi_t nargs, stix_oow_t limit) +static stix_pfrc_t __pf_puts (stix_t* stix, stix_ooi_t nargs, stix_oow_t limit) { stdio_t* rcv; stix_ooi_t i; @@ -181,19 +181,19 @@ static int __pf_puts (stix_t* stix, stix_ooi_t nargs, stix_oow_t limit) } STIX_STACK_SETRETTORCV (stix, nargs); - return 1; + return STIX_PF_SUCCESS; reterr: STIX_STACK_SETRETTOERROR (stix, nargs); - return 1; + return STIX_PF_SUCCESS; } -static int pf_putc (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_putc (stix_t* stix, stix_ooi_t nargs) { return __pf_puts (stix, nargs, 1); } -static int pf_puts (stix_t* stix, stix_ooi_t nargs) +static stix_pfrc_t pf_puts (stix_t* stix, stix_ooi_t nargs) { return __pf_puts (stix, nargs, STIX_TYPE_MAX(stix_oow_t)); }