# absolute minimum. classes which the compiler depends on. # void type Unit Unit #[ctype 'bool', cstdinclude 'stdbool.h'] Bool #[clit 'false'] False #[clit 'true'] True #[ctype 'uint8_t', cstdinclude 'stdint.h', bytes '1'] U8 #[ctype 'uint16_t', cstdinclude 'stdint.h', bytes '2'] U16 #[ctype 'uint32_t', cstdinclude 'stdint.h', bytes '4'] U32 #[ctype 'uint64_t', cstdinclude 'stdint.h', bytes '8'] U64 # ???? #[ctype 'size_t', cstdinclude 'stddef.h', bytes '8'] Size #[ctype 'int8_t', cstdinclude 'stdint.h', bytes '1'] I8 #[ctype 'int16_t', cstdinclude 'stdint.h', bytes '2'] I16 #[ctype 'int32_t', cstdinclude 'stdint.h', bytes '4'] I32 #[ctype 'int64_t', cstdinclude 'stdint.h', bytes '8'] I64 #[ctype 'float', bytes '4'] F32 #[ctype 'double', bytes '8'] F64 # Is this too much voodoo? I'm basically only using it for Ints # class Int <= Eq, Ord, Addition, Subtraction, Multiplication, Division #[actual-pointer-type] Ptr a: a # Strings n shii # currently only used in @argv and @panic. # if/when we remove it from there, we will delegate it to the Cnile module. #[ctype 'const char*'] ConstStr # define it here for use in StrView. # (BUT BEFORE IT WAS PRETTY COOL WE DIDN'T DEPEND ON Slice necessarily bruh, BUT NOW WE'VE MADE IT PART OF PRELUDE) Slice a ptr Ptr a count Size StrView contents Slice U8 # stolen from Str std module. used in string interpolation StrConcat l r StrConcat l r StrCase c1 c2 # big hack for alternative string representations. (ex: Maybe) # honestly, we can just do the same thing as with iterators, where we define custom datatypes for this specific function. # But, I'll keep StrCase for now. StrCase1 c1 StrCase2 c2 # TODO: Move it to Char? # basically a slice doe # ref: Swift's Character. # I have the perfect opportunity to support Characters with grapheme clusters. # Also, scalar values (in Rust for example) need to be "compressed": https://www.mathly.fr/images/utf8encoding.png # (which I don't really care about.) Char ptr Ptr U8 # makes it 64 bit alignmed anyway, so whatevs. num-bytes Size # all of it is basically a slice. # my array type bruh Array ^count a # funny experiment-ahh class class FromChar: Char from-charlike (ptr Ptr U8, num-bytes Size) -> _ # im more likely to throw out this class. # it's not like haskell, where the default String datatype is just bad for high performance - StrView is a reasonable default which should not be changed. # we can just use conversion functions for them anyway. # otoh, FromChar can convert to StrView and ConstStr, so this is kinda funny. class FromString: StrView from-string (ptr Ptr U8, num-bytes Size) -> _ # Equality class Eq eq (_, _) -> Bool # Ord Ordering LT EQ GT class Ord cmp (_, _) -> Ordering class FromIntegral: I32 from-integral(Size) -> _ # numeric ops yooo class Addition op-add (_, _) -> _ class Subtraction op-sub (_, _) -> _ class Multiplication op-mul (_, _) -> _ class Division op-div (_, _) -> _ class Negation op-neg (_) -> _ # Index class Indexable # Key # Elem elem-get (self _, key key) -> elem # problem: no autodereferencing so either we choose List (pass by reference) or Slice/Vector (pass by value) # so, in case of pass by value: # Slice: slice[0] # List: list&[0] # in case of pass by reference: # Slice: (&slice)[0] # List: list[0] # List construction (but actually Array bruhhhhhh) class ListLike: Array # type Elem # maybe take in pointer to it? from-listlike (arr Ptr (Array count elem)) -> _ # List decostruction ListSpread spread NoSpread UnassignedSpread AssignedSpread (Ptr spread) class ListDecon # Elem <- dependent type # simulates list deconstruction. the implementing classes can have two behaviors: # 1. Range - does not actually store anything, so write to the ptr like lp <&&= ... # 2. Slice - actually has inner state and we might want to take references to it. In this case hijack the pointer by lp <&= slice.ptr. deconstruct (self _, lp Ptr (Ptr elem), lc Size, spread ListSpread spread, rp Ptr (Ptr elem), rc Size) -> Bool # correct type would be (_, Slice elem, Maybe (Maybe (Ptr _), Slice elem)), but the current one is easier to call from the iterpreter. # Iter and IntoIter is directly used by `for .. in` loop. Maybe a None Just a class IntoIter into-iter (self _) -> itershit class Iter next (self Ptr _) -> Maybe item # this might be generated at compile time bruv. thats why im keeping it here. # Also, instead of Tuple, Treeple, Quantuple use Tuple2, Tuple3, etc. It'll be easier to parse. Tuple2 a b Tuple2 a b Tuple3 a b c Tuple3 a b c Tuple4 a b c d Tuple4 a b c d Either e a Left e Right a ##### INSTANCES !!!! ####### # Num inst FromIntegral I64 from-integral (x): @cast(x) inst FromIntegral I32 from-integral (x): @cast(x) inst FromIntegral U32 from-integral (x): @cast(x) inst FromIntegral U16 from-integral (x): @cast(x) inst FromIntegral I8 from-integral (x): @cast(x) inst FromIntegral U8 from-integral (x): @cast(x) inst FromIntegral U64 from-integral (x): @cast(x) inst FromIntegral Size from-integral (x): x inst FromIntegral F32 from-integral (x): @size-f32(x) inst FromIntegral F64 from-integral (x): @size-f64(x) # FromChar # inst FromChar Char instance is in Prim # ^^^^ ^^^^^^^^ word duplication for grepping! inst FromChar ConstStr from-charlike (ptr, _): @cast(ptr) as ConstStr inst FromChar StrView from-charlike (ptr, count): StrView { contents: Slice { ptr, count } } # FromChar Char instance in std/Char.kkc # FromString inst FromString ConstStr from-string (ptr, _): @cast(ptr) as ConstStr inst FromString StrView from-string (ptr, count): StrView { contents: Slice { ptr, count } } # for all lists and stuff. instead of offsetting a pointer, it calls the inner function. inst Indexable Ptr elem-get (Ptr(self), k): self elem-get(k) # Eq inst Eq Ordering eq (l, r): @memeq(l, r) inst Eq Unit eq (l, r): True inst Eq I64 eq (l, r): @memeq(l, r) inst Eq I32 eq (l, r): @memeq(l, r) inst Eq U32 eq (l, r): @memeq(l, r) inst Eq U8 eq (l, r): @memeq(l, r) inst Eq U16 eq (l, r): @memeq(l, r) inst Eq Size eq (l, r): @memeq(l, r) inst Eq Bool eq (l, r): @memeq(l, r) inst Eq U64 eq (l, r): @u64-cmp(l, r) == EQ # tryin sumtin noo inst Eq Maybe eq (l, r) case Tuple2(l, r) Tuple2(None, None) return True Tuple2(Just(l), Just(r)) return l == r _ return False inst Eq Ptr eq (Ptr(l), Ptr(r)): l == r inst Ord I64 cmp (l, r) return @i64-cmp(l, r) inst Ord I32 cmp (l, r): @i32-cmp(l, r) inst Ord U32 cmp (l, r): @u32-cmp(l, r) inst Ord U8 cmp (l, r): @u8-cmp(l, r) inst Ord F32 cmp (l, r): @f32-cmp(l, r) inst Ord F64 cmp (l, r): @f64-cmp(l, r) inst Ord Size cmp (l, r): @size-cmp(l, r) inst Ord U64 cmp (l, r): @u64-cmp(l, r) # ops ## Int inst Addition I64 op-add (l, r): @i64-add(l, r) inst Subtraction I64 op-sub (l, r): @i64-sub(l, r) inst Multiplication I64 op-mul (l, r): @i64-mul(l, r) inst Division I64 op-div (l, r): @i64-div(l, r) inst Negation I64 op-neg (l): @i64-sub(0, l) # I32 inst Addition I32 op-add (l, r): @i32-add(l, r) inst Subtraction I32 op-sub (l, r): @i32-sub(l, r) inst Multiplication I32 op-mul (l, r): @i32-mul(l, r) inst Division I32 op-div (l, r): @i32-div(l, r) inst Negation I32 op-neg (x): @i32-sub(0, x) # :) # U32 inst Addition U32 op-add (l, r): @u32-add(l, r) inst Subtraction U32 op-sub (l, r): @u32-sub(l, r) inst Multiplication U32 op-mul (l, r): @u32-mul(l, r) inst Division U32 op-div (l, r): @u32-div(l, r) # U8 inst Addition U8 op-add (l, r): @u8-add(l, r) inst Subtraction U8 op-sub (l, r): @u8-sub(l, r) inst Multiplication U8 op-mul (l, r): @u8-mul(l, r) inst Division U8 op-div (l, r): @u8-div(l, r) ## Size inst Addition Size op-add (l, r): @size-add(l, r) inst Subtraction Size op-sub (l, r): @size-sub(l, r) inst Multiplication Size op-mul (l, r): @size-mul(l, r) inst Division Size op-div (l, r): @size-div(l, r) ## U64 inst Addition U64 op-add (l, r): @u64-add(l, r) inst Subtraction U64 op-sub (l, r): @u64-sub(l, r) inst Multiplication U64 op-mul (l, r): @u64-mul(l, r) inst Division U64 op-div (l, r): @u64-div(l, r) ## F32 inst Addition F32 op-add (l, r): @f32-add(l, r) inst Subtraction F32 op-sub (l, r): @f32-sub(l, r) inst Multiplication F32 op-mul (l, r): @f32-mul(l, r) inst Division F32 op-div (l, r): @f32-div(l, r) ## F64 inst Addition F64 op-add (l, r): @f64-add(l, r) inst Subtraction F64 op-sub (l, r): @f64-sub(l, r) inst Multiplication F64 op-mul (l, r): @f64-mul(l, r) inst Division F64 op-div (l, r): @f64-div(l, r) inst ListLike Array from-listlike (self Ptr (Array n a)): self& # experimental: cool typeclasses class Int into-int (self _) -> I64 class UInt into-uint (self _) -> Size clamp-uint (self _) -> Size