Giter VIP home page Giter VIP logo

a-compiler's People

Contributors

simmsb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

pombredanne

a-compiler's Issues

Bug: Possible to return arrays from functions

Hi, when writing programs and compiling with this compiler, I have found that it is possible to declare functions returning arrays.
For example:

fn a() -> [u1@4] {
	return {1, 2, 3, 4};
}

fn main() {
	var x := a();

	std.printf("%u1 %u1 %u1 %u1\n", x[0], x[1], x[2], x[3]);
}

This appears to function, presumably because the size of the array 1 * 4 fits into a register size.

However, the following:

fn a() -> [u1@5] {
	return {1, 2, 3, 4};
}

fn main() {
	var x := a();

	std.printf("%u1 %u1 %u1 %u1\n", x[0], x[1], x[2], x[3]);
}

(Note the array size changed to 5)

Produces an assertion exception:

~/dev/wewcompiler/objects/base.py", line 551, in get_register
    assert size in (1, 2, 4, 8)
AssertionError

After looking through your code it seems like the best place to apply a fix would be here:

https://github.com/nitros12/A-Compiler/blob/61783d3072015927b38e8293e2a0a3333c017229/wewcompiler/objects/types.py#L198-L200

Improve typechecking in array literals

This shouldn't compile:

var a := {x, y}; // this should fail to typecheck
fn x(l: u8, b: s4, n: *u8) {}
fn y() -> u8 {}
fn main() {}

Function types shouldn't implicitly cast, if they are (or are we even checking?)

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.