CASC-Lang / Yakou

An experimental JVM Language inspired by Rust.
38 stars 2 forks source link

Remove `comp` function declaration block in `impl` block, replace it with `comp` statement block #28

Closed ChAoSUnItY closed 2 years ago

ChAoSUnItY commented 2 years ago
  1. To declare a non-companion function, add self keyword in parameter list like rust does:
    impl Main {
    pub fn hello(self, s: str[]) {
        //...
    }
    }
  2. Vice versa, declare companion function without self in parameter list:
    impl Main {
    pub fn hello(s: str[]) {
        //...
    }
    }
  3. Treat companion block in impl block like Java's static block
    impl Main {
    comp {
        System.out.println("Hello");
    }
    }

    The above example does the same thing as the following Java code:

    class Main {
    static {
        System.out.println("Hello");
    }
    }