added respondsTo and related functions
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
133
src/kernel.hcl
133
src/kernel.hcl
@ -1,67 +1,105 @@
|
||||
class Apex {
|
||||
fun :: basicNew(size) {
|
||||
fun ::basicNew(size) {
|
||||
return (core.basic_new self size)
|
||||
}
|
||||
|
||||
fun ::respondsTo(mth) {
|
||||
return (core.cresp_to self mth)
|
||||
}
|
||||
|
||||
fun respondsTo(mth) {
|
||||
return (core.iresp_to self mth)
|
||||
}
|
||||
|
||||
fun basicAt(pos) {
|
||||
return (core.get self index)
|
||||
}
|
||||
|
||||
fun basicAtPut(index value) {
|
||||
return (core.put self index value)
|
||||
}
|
||||
}
|
||||
|
||||
class Object :: Apex {
|
||||
}
|
||||
|
||||
class Class :: Apex [
|
||||
_name
|
||||
_mdic
|
||||
_spec
|
||||
_selfspec
|
||||
_superclass
|
||||
_nivars_super
|
||||
_ibrand
|
||||
_ivarnames
|
||||
_cvarnames
|
||||
] {
|
||||
fun name() {
|
||||
##return (core.class_name self)
|
||||
return _class
|
||||
}
|
||||
|
||||
fun instanceVariableNames() {
|
||||
## TODO: this still returns nil as the acutal manipulation of the field has not been implemented
|
||||
return _ivarnames
|
||||
}
|
||||
|
||||
fun classVariableNames() {
|
||||
## TODO: this still returns nil as the acutal manipulation of the field has not been implemented
|
||||
return _cvarnames
|
||||
}
|
||||
}
|
||||
|
||||
class Collection :: Object {
|
||||
fun length() {
|
||||
return (core.length self)
|
||||
}
|
||||
}
|
||||
|
||||
class IndexedCollection :: Collection {
|
||||
fun slice(index count) {
|
||||
return (core.slice self index count)
|
||||
}
|
||||
|
||||
fun at(index) {
|
||||
return (core.get self index)
|
||||
}
|
||||
|
||||
fun atPut(index value) {
|
||||
return (core.put self index value)
|
||||
}
|
||||
}
|
||||
|
||||
class FixedSizedCollection :: IndexedCollection {
|
||||
fun ::new(size) {
|
||||
| obj iv |
|
||||
obj := (core.basic_new self size)
|
||||
if (self:respondsTo "initValue") { ## TODO: change "initValue" to a symbol once supported
|
||||
i := 0
|
||||
iv := (self:initValue)
|
||||
while (i < size) {
|
||||
core.put obj i iv
|
||||
i := (i + 1)
|
||||
}
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
##fun ::initValue() {
|
||||
## return nil
|
||||
##}
|
||||
}
|
||||
|
||||
class Array :: FixedSizedCollection {
|
||||
fun :: new(size) {
|
||||
return (core.basic_new self size)
|
||||
}
|
||||
}
|
||||
|
||||
class String :: FixedSizedCollection {
|
||||
fun ::initValue() {
|
||||
##return '\0'
|
||||
return ' '
|
||||
}
|
||||
}
|
||||
|
||||
fun Collection:length() {
|
||||
return (core.length self)
|
||||
}
|
||||
|
||||
fun Collection:slice(index count) {
|
||||
return (core.slice self index count)
|
||||
}
|
||||
|
||||
fun Collection:at(index) {
|
||||
return (core.get self index)
|
||||
}
|
||||
|
||||
fun Collection:atPut(index value) {
|
||||
return (core.put self index value)
|
||||
}
|
||||
|
||||
fun Class:name() {
|
||||
return (core.class_name self)
|
||||
}
|
||||
|
||||
##class String:: Array [a b c] {
|
||||
##}
|
||||
|
||||
##class String:: Array [
|
||||
## monaco
|
||||
## duncan
|
||||
## falcon
|
||||
## deuce
|
||||
## canival
|
||||
## pebble
|
||||
## godzilla
|
||||
##] {
|
||||
## fun Collection:slice(index count) {
|
||||
## return (arr.slice self index count)
|
||||
## }
|
||||
##}
|
||||
|
||||
|
||||
k := "abcdefghijklmn"
|
||||
printf "string length %d\n" ("aaaa":length)
|
||||
@ -96,3 +134,16 @@ try {
|
||||
k := (Array:new 10)
|
||||
k:atPut 3 "hello"
|
||||
printf "%O\n" k
|
||||
|
||||
printf "[%O]\n" (String:new 5)
|
||||
printf "[%O]\n" (String:basicNew 5)
|
||||
|
||||
printf "[%O]\n" (String:respondsTo "new")
|
||||
printf "[%O]\n" (String:respondsTo "newx")
|
||||
printf "[%O]\n" (" ":respondsTo "new")
|
||||
printf "[%O]\n" (" ":respondsTo "length")
|
||||
|
||||
##printf "[%O]\n" (String:classVariableNames)
|
||||
##printf "[%O]\n" (String:instanceVariableNames)
|
||||
|
||||
printf "%O\n" #"abcdefg"
|
||||
|
Reference in New Issue
Block a user