From fb690237e763d8875c6bdac6173c1983a562be43 Mon Sep 17 00:00:00 2001 From: SpookyDervish Date: Fri, 10 Jul 2026 10:25:37 +1000 Subject: [PATCH] update docs and add a ton of info --- chookspace/docs.html | 259 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 250 insertions(+), 9 deletions(-) diff --git a/chookspace/docs.html b/chookspace/docs.html index f345232..d57c17d 100644 --- a/chookspace/docs.html +++ b/chookspace/docs.html @@ -52,6 +52,19 @@
  • While-Loops
  • For-Loops
  • +
  • Structs
  • + +
  • Arrays
  • + +
  • Enums
  • @@ -84,6 +97,12 @@

    Comet is still very, VERY early in development! Here be dragons!

    +
    +

    Warning

    +

    The Comet docs are written with the expectation that you have used + another programming language before. Comet is not designed for beginner programmers. +

    +
    @@ -95,12 +114,11 @@

    Building From Source

    Note

    -

    Comet is not entirely supported on Windows yet. (due to - argp)

    +

    Comet is not entirely supported on Windows yet, please + use Comet inside WSL for the best experience.

    To build comet, you first have to get the repo. Make sure you have Git and LLVM installed before anything else. Once you + href="https://git-scm.com/install/">Git installed before anything else. Once you have git installed, type these commands in a terminal to clone the repository, build Comet, and install it:

    git clone https://chookspace.com/comet/comet &&
    @@ -130,10 +148,11 @@ sudo make install
    import io
     
     func main() -> int {
    -    io.print("Hello, World!")
    +    io.println("Hello, World!")
     }

    -

    Save this to a file called "helloWorld.comet". We can compile this program to an executable file with the following command:

    +

    Save this to a file called "helloWorld.comet". We can compile this program to an executable + file with the following command:

    cometc helloWorld.comet -o helloWorld.cvm

    And then we can run our program on the Comet VM:

    comet helloWorld.cvm
    @@ -158,7 +177,7 @@ func main() -> int {

    Built-in Types

    Comet has a few built in types:

    - +
    +
    +

    Structs

    +

    Structs are like classes in most other programming languages. Structs are required to have a + constructor, but they can also have fields, methods, and a destructor.

    +

    To define a struct, you just use the following syntax:

    +
    struct StructName { /* every word in your struct should always start with a capital letter! */
    +    int myField = 123 /* you define fields like variables, and you can give them an optional default value */
    +    readonly int value /* the keyword "readonly" means code outside this struct can't change the value of this field,
    +                          but they can still read it. */
     
    +    init(int value) {
    +        /*
    +            this is where the code for your constructor goes. your constructor can take arguments like a normal function.
    +            you are automatically given the "self" variable, and can change the value of fields with the '.' operator 
    +        */
    +        self.value = value
    +    }
    +
    +    destroy {
    +        /*
    +            you can optionally have a destructor to clean up used memory.
    +
    +            the destructor is called when you use the drop keyword on your struct, more on that later!
    +        */
    +        ...
    +    }
    +}
    +
    +func main() -> int {
    +    StructName test = new StructName(16) /* we create a new instance of StructName and pass args to its constructor */
    +    return test.value /* We get the field called "value" */
    +}
    +
    +
    +

    Field Attributes

    +
      +
    • private - Any code outside of this struct can't read or write to this field
    • +
    • protected - Any code outside of this struct or its children can't read or write to this + field
    • +
    • readonly - Any code outside of this struct can't write to this field, but they can read + it
    • +
    • public (default) - Any code can read or write to this field
    • +
    +
    +
    +
    +

    Inheritance

    +

    Structs can inherit from eachother, and thus get all the fields and methods of their parent. + Here is an example of inheritance:

    +
    import io
    +                            
    +struct Animal {
    +    protected int age = 0 /* The "protected" keyword makes it so code outside of this class or
    +                             its children can't access the age field */
    +
    +    init() {
    +
    +    }
    +
    +    func speak() {
    +        io.println("...")
    +    }
    +}
    +
    +struct Dog : Animal { /* Inherit from the Animal struct */
    +    string owner
    +
    +    init(string owner) {
    +        super(self) /* Call the parent struct's constructor */
    +
    +        /* Then set our own fields */
    +        self.owner = owner
    +    }
    +
    +    override func speak() { /* We change what the parent struct's "speak" method does! */
    +        io.println("Woof! Hello, %s!", self.owner)
    +    }
    +}
    +
    +func main() -> int {
    +    Animal animal = new Animal()
    +    animal.speak() /* "..." */
    +    
    +    Dog dog = new Dog("Bob")
    +    dog.speak() /* "Woof! Hello, Bob!" */
    +}
    +
    +
    +
    +

    Generics

    +

    What if we wanted to make a struct that needs a field that can be any type? For example, a + list struct. We can do that with generics! See the example below:

    +
    import io
    +                            
    +struct MyStruct <T1, T2> {
    +        T1 someValue /* T1 and T2 are types that can be anything */
    +        T2 someOtherValue
    +
    +        init(T1 a, T2 b) {
    +            self.someValue = a
    +            self.someOtherValue = b
    +        }
    +    }
    +
    +    func main() -> int {
    +        MyStruct<int, float> test = new MyStruct<int, float>(123, 0.456) /* We've created a new instance of MyStruct with our custom types! */
    +        return test.someValue /* if we defined our generic struct with any type other than an int, this return statement would error */
    +    }
    +
    +
    +
    +

    Drop Statement

    +

    When you're done with your struct, you can free its memory with the drop statement. This also + calls the destructor of the struct.

    +
    import io
    +                            
    +struct Foo {
    +    int x
    +
    +    init(int x) {
    +        self.x = x
    +    }
    +
    +    destroy {
    +        io.println("Destructor called!")
    +    }
    +}
    +
    +func main() -> int {
    +    Foo foo = new Foo(123)
    +    io.println("%n", foo.x)
    +
    +    drop foo /* call destructor and free memory */
    +
    +    return 0
    +}
    +
    +

    Just remember to not call drop twice on the same thing!

    +
    +
    + +
    +

    Arrays

    +

    Arrays allow you to define a list of something, like a list of integers or a list of strings. + Arrays are indexed starting at 0. Array syntax in Comet is a bit different to other programming + languages:

    +
    func main() -> int {
    +    int[3] myArray = new int[3] /* create an array (list) of 3 integers */
    +    myArray:0 = 2 /* set the first integer to 2 */
    +    myArray:1 = 8 /* set the second integer to 8 */
    +    myArray:2 = 3 /* and so on... */
    +
    +    int something = myArray:1 /* get the second value in the array */
    +    drop myArray /* you can drop arrays and free their memory like how you can free structs */
    +
    +    return something /* returns 8 */
    +}
    +
    +

    You can also define array literals:

    +
    func main() -> int {
    +    int[3] myArray = [1, 2, 3]
    +
    +    return myArray:0
    +}
    +
    +

    '#' Operator

    +

    you can get the length of an array with + the '#' operator. Because strings are also arrays, you can use the '#' operator on them too! For example:

    +
    import io
    +                        
    +func main() -> int {
    +    int[3] myArray = [1, 2, 3]
    +    io.println("Array length: %n", #myArray) /* "Array length: 3" */
    +
    +    string myString = "hi there!"
    +    io.println("String length: %n", #myArray) /* "String length: 9" */
    +
    +    return 0
    +}
    +
    +

    '*' Syntax

    +

    If you don't know the size of an array at compile time, you can use the '*' syntax. If you have a + function that takes an array of a fixed size, that function enforces that the array being passed + to it must also be the same fixed size. You can use the '*' syntax to allow a function to take + an array of any size. The following is an example that uses both star syntax and the '#' operator:

    +
    func sum(int[*] arr) -> int { /* take an array of * size (any size) */
    +    int sum = 0
    +
    +    for int i in 0 .. #arr { /* loop over every number in the array */
    +        sum += arr:i /* add the current number to the sum */
    +    }
    +
    +    return sum
    +}
    +
    +func main() -> int {
    +    int[3] myNumbers = [4, 5, 6]
    +    return sum(myNumbers) /* because the function takes an array of any size, this is valid */
    +}
    +
    +
    + +
    +

    Enums

    +

    Enums allow you to define a category of something, like a colour. Enums can be treated like + integers because enum items are indexed starting at 0 and increasing at each value. Example + usage of enums:

    +
    import io
    +
    +enum Colour {
    +    Red, /* 0 */
    +    Green, /* 1 */
    +    Blue /* 2 */
    +    /* and so on if you add more items... */
    +}
    +
    +func main() -> int {
    +    Colour myColour = Colour.Green
    +    io.println("%n", myColour) /* "1" */
    +    return myColour
    +}
    +
    +