Files
hak/src/kernel.hcl

99 lines
1.4 KiB
HCL
Raw Normal View History

2024-07-23 23:50:29 +09:00
class Apex {
fun :: basicNew(size) {
2024-08-03 10:40:44 +09:00
return (core.basic_new self size)
}
2024-07-05 00:53:37 +09:00
}
2024-07-23 23:50:29 +09:00
class Object :: Apex {
2024-07-05 00:53:37 +09:00
}
2024-07-23 23:50:29 +09:00
class Collection :: Object {
2024-07-05 00:53:37 +09:00
}
2024-07-23 23:50:29 +09:00
class IndexedCollection :: Collection {
2024-07-05 00:53:37 +09:00
}
class FixedSizedCollection :: IndexedCollection {
2024-07-05 00:53:37 +09:00
}
2024-07-23 23:50:29 +09:00
class Array :: FixedSizedCollection {
2024-08-03 10:40:44 +09:00
fun :: new(size) {
return (core.basic_new self size)
}
2024-07-23 23:50:29 +09:00
}
class String :: FixedSizedCollection {
2024-07-05 00:53:37 +09:00
}
fun Collection:length() {
return (core.length self)
2024-07-05 00:53:37 +09:00
}
fun Collection:slice(index count) {
return (core.slice self index count)
}
fun Collection:at(index) {
return (core.get self index)
2024-07-05 00:53:37 +09:00
}
2024-07-29 19:15:12 +09:00
fun Collection:atPut(index value) {
return (core.put self index value)
}
2024-07-16 00:15:28 +09:00
fun Class:name() {
return (core.class_name self)
}
2024-07-23 23:50:29 +09:00
##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)
## }
##}
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