GithubHelp home page GithubHelp logo

casc-lang / yakou Goto Github PK

View Code? Open in Web Editor NEW
38.0 2.0 2.0 2.03 MB

An experimental JVM Language inspired by Rust.

Kotlin 100.00%
programming-language casc compiler jvm-languages bytecode-compiler rust-like go-like v-like

yakou's People

Contributors

chaosunity avatar siongsng avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

yakou's Issues

Antlr wired parsing bug

"a" + java::lang::Integer::toString(1)

This will cuase parsing error somehow, require further investigation at toString(1)

Deprecate phase Check (Prelude)

Summary

Check (Prelude) is used to emit compiled unchecked files into bytecode and load it in current compilation process, this is needed because ClassWriter::getCommonType(String, String) from ASM lib requires types already exists in JVM environment. But we can override it by checking caching to make sure class exists with our internal type table.

Pros:

By profiling our compiler, it seems it has some relatively heavy performance penalty from ClassLoader::defineClass(byte[]). With this proposal, we can reduce lots of time on compilation.

Cons:

Our typing system needs to be refined so no cached class will be requested to ClassLoader::loadClass(String) calling and throws exception.

Current status

  • Implement type symbol table lookup in CommonClassWriter::getCommonType
  • Remove phase Check (Prelude)
  • Stablize cached class registeration (including separating JVM-loaded class and cached class)

Access modifier

public in default.

Java CASC
public pub
protected prot
private priv
Kotlin CASC
internal intl

Function java::util::Arrays#fill(f64[], f64) does not exist in current context

use java::util::Arrays as Arr

class Donut

impl Donut {
    fn main(args: [str]) {
        k := 0
        A, B, i, j := 0
        z := [f64; 1760]{}
        b := [char; 1760]{}
        System.out.println("\u001b[2J")
        for ;; {
            Arr.fill(b, ' ')
            Arr.fill(z, 0D)
            for mut j := 0D; 6.28 > j; j = j + 0.07 {
                for mut i := 0D; 6.28 > i; i = i + 0.02 {
                    c, e, f, h, D, l, m, n, t :=
                        Math.sin(i),
                        Math.cos(j),
                        Math.sin(A),
                        Math.sin(j),
                        Math.cos(A),
                        d + 2,
                        1 / (c * h * e + f * g + 5),
                        Math.cos(i),
                        Math.cos(B),
                        Math.sin(B),
                        c * h * g - f * e

                }
            }
        }
    }
}

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

  1. To declare a non-companion function, add self keyword in parameter list like rust does:
impl Main {
    pub fn hello(self, s: str[]) {
        //...
    }
}
  1. Vice versa, declare companion function without self in parameter list:
impl Main {
    pub fn hello(s: str[]) {
        //...
    }
}
  1. 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");
    }
}

Revamp CASC Compiler

I. Discard ANTLR

Reason:
Although ANTLR can greatly provides huge development assistance on lex-parse units, but there are still some big cons come along with: Proper error message is hard to implement, Heavily depends on ANTLR library (not very fine since might encounters some unknown library-internal bugs, thus causes compiler errors even syntax is fine). Therefore, we are going to revamp lex-parse unit manually.

II. Enhance code quality

Reason:
Currently, few parts of entire compiler has either TODO or comment, which is not very developer friendly when others want to either contribute CASC compiler unit or take it as an education source, plus there's tons of improper OOP design, which could end up with even creator himself (which is me lol) doesn't actually know how it works.

You can track this issue's progress in branch Revamp. Before this issue being resolved, all other issue are temporarily not in progress.

Note: This Issue's finish date is TBA, and there'll be some minor syntax changes as well.

Revamp array syntax

Current array syntax will conflict with identifier call in BNF grammar, to avoid this, we will introduce Rust's solution:

a := [i32; 3] // array declaration
b := [; 3]{ 1, 2, 3 } // array initialization (no type)
c := [i32; 3]{ 1, 2, 3 } // array initialization
d := [[i32; 3]; 3] // multidimensional array declaration
// and so on

This syntax will greatly makes lots of works easier.

Additionally, we might change array type's syntax (Not final syntax):

i32[]
// into:
[i32]

Proper diagnostic system

There are several problem may occurs unexpected issue, need to implement a proper diagnostic system in order to terminate entire compilation as long as there are something went wrong.

  • [] Use object class to store diagnostic info.
  • [] Terminate when there are problems in lexing / parsing / analyzing / emitting phase.

More For Loop Options

infinite loop:

for {
    //...
}

detailed loop:

for (i := 1; i < 10; i++) {
    //...
}

predicate loop:

for i < 10 {
    //...
}

Enhance secondary constructor

  1. Detect circular secondary constructor call then terminate compilation
  2. Since secondary constructor must implement primary or another secondary one, move the self call into a parsing rule.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.