Files
hak/src/kernel.hcl

182 lines
3.3 KiB
HCL
Raw Normal View History

2024-07-23 23:50:29 +09:00
class Apex {
fun(#class) basicNew(size) {
2024-08-10 14:42:21 +09:00
return (core.basicNew self size)
2024-08-03 10:40:44 +09:00
}
2024-08-08 01:52:50 +09:00
fun(#class) respondsTo(mth) {
2024-08-10 14:42:21 +09:00
return (core.classRespondsTo self mth)
2024-08-08 01:52:50 +09:00
}
fun respondsTo(mth) {
2024-08-10 14:42:21 +09:00
return (core.instRespondsTo self mth)
2024-08-08 01:52:50 +09:00
}
fun primAt(pos) {
return (core.primAt self pos)
}
fun primtAtPut(pos value) {
return (core.primAtPut self pos value)
}
2024-08-08 01:52:50 +09:00
fun basicAt(pos) {
2024-08-10 14:42:21 +09:00
return (core.basicAt self pos)
2024-08-08 01:52:50 +09:00
}
2024-08-10 14:42:21 +09:00
fun basicAtPut(pos value) {
return (core.basicAtPut self pos value)
}
fun basicSize() {
return (core.basicSize self)
2024-08-08 01:52:50 +09:00
}
2024-07-05 00:53:37 +09:00
}
class Object: Apex {
2024-07-05 00:53:37 +09:00
}
class(#uncopyable #varying #limited #final) Class: Apex [
2024-08-08 01:52:50 +09:00
_name
_mdic
_spec
_selfspec
_superclass
_nivars_super
_ibrand
_ivarnames
_cvarnames
] {
fun name() {
2024-08-10 14:42:21 +09:00
##return (core.className self)
2024-08-08 01:52:50 +09:00
return _class
}
2024-07-05 00:53:37 +09:00
2024-08-08 01:52:50 +09:00
fun instanceVariableNames() {
## TODO: this still returns nil as the acutal manipulation of the field has not been implemented
return _ivarnames
}
2024-07-05 00:53:37 +09:00
2024-08-08 01:52:50 +09:00
fun classVariableNames() {
## TODO: this still returns nil as the acutal manipulation of the field has not been implemented
return _cvarnames
}
2024-07-05 00:53:37 +09:00
}
class Collection: Object {
2024-08-08 01:52:50 +09:00
fun length() {
2024-08-10 14:42:21 +09:00
return (core.basicSize self)
2024-08-08 01:52:50 +09:00
}
2024-07-23 23:50:29 +09:00
}
class IndexedCollection: Collection {
2024-08-08 01:52:50 +09:00
fun slice(index count) {
return (core.slice self index count)
}
2024-07-05 00:53:37 +09:00
2024-08-08 01:52:50 +09:00
fun at(index) {
2024-08-10 14:42:21 +09:00
return (core.basicAt self index)
2024-08-08 01:52:50 +09:00
}
2024-07-05 00:53:37 +09:00
2024-08-08 01:52:50 +09:00
fun atPut(index value) {
2024-08-10 14:42:21 +09:00
return (core.basicAtPut self index value)
2024-08-08 01:52:50 +09:00
}
}
class FixedSizedCollection: IndexedCollection {
fun(#class) new(size) {
2024-08-08 01:52:50 +09:00
| obj iv |
2024-08-10 14:42:21 +09:00
obj := (core.basicNew self size)
2024-08-08 01:52:50 +09:00
if (self:respondsTo "initValue") { ## TODO: change "initValue" to a symbol once supported
i := 0
iv := (self:initValue)
while (< i size) { ## TODO: change to i < size after having implemented these methods on integer/smallintger
2024-08-10 14:42:21 +09:00
core.basicAtPut obj i iv
i := (+ i 1) ## TODO: change to i + 1 ## TODO: change to i < size after having implemented these methods on integer/smallintger
2024-08-08 01:52:50 +09:00
}
}
return obj
}
2024-07-05 00:53:37 +09:00
2024-08-08 01:52:50 +09:00
##fun ::initValue() {
## return nil
##}
2024-07-29 19:15:12 +09:00
}
class(#varying) Array: FixedSizedCollection {
2024-07-16 00:15:28 +09:00
}
class(#char #varying) String: FixedSizedCollection {
fun(#class) initValue() {
2024-08-08 01:52:50 +09:00
##return '\0'
return ' '
}
}
2024-07-05 00:53:37 +09:00
2024-07-29 19:15:12 +09:00
k := "abcdefghijklmn"
2024-07-05 00:53:37 +09:00
printf "string length %d\n" ("aaaa":length)
2024-07-29 19:15:12 +09:00
printf "substring [%s]\n" (k:slice 5 6)
try {
printf "substring [%c]\n" (k:at 13)
k:atPut 14 'A'
printf "[%s]\n" k
} catch (e) {
printf "EXCEPTION %O\n" e
}
k := #[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15]
try {
k:atPut 2 'A'
printf "%O\n" k
} catch (e) {
printf "EXCEPTION %O\n" e
}
k := #b[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15]
try {
k:atPut 2 -10
printf "%O\n" k
} catch (e) {
printf "EXCEPTION %O\n" e
}
k := (Array:new 10)
k:atPut 3 "hello"
printf "%O\n" k
2024-08-08 01:52:50 +09:00
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)
2024-08-08 16:30:15 +09:00
##printf "%O\n" #"abcdefg"
2024-08-10 14:42:21 +09:00
printf "----------------------------------------\n"
k := #[1 2 3]
printf "%O\n" (k:basicAt 2)
class Z: Object [ a b c ] {
fun(#classinst) new() {
2024-08-10 14:42:21 +09:00
self.a := 10
self.b := 20
self.c := 30
}
}
##k := (Z:basicNew 0)
k := (Z:new)
2024-08-10 14:42:21 +09:00
printf "%O\n" (k:basicAt 2)