GithubHelp home page GithubHelp logo

c4's Introduction

Hi, I'm Silver

I write code. Mostly in Zig at the moment, but occasionally I'll sprinkle in some other languages here or there. My specific interests vary over time, but at present I seem to be focusing mostly on graphics and game programming.

Contact me

  • Email: silver [at] squirl [dot] dev
  • Discord: silversquirl

c4's People

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

c4's Issues

Global variables don't work

What went wrong?

Global variables currently act as declarations only, without actually allocating any space for the variable.

What caused it?

var foo I32

pub fn main() I32 {
	foo += 3
	return 0
}

Debug info

What new feature would you like to see?

Debugging symbols in the compiled ELF object.

What problems would this feature address?

Would help with diagnosing issues with programs; currently one has to step through instructions and guess where they are.

How do you think this feature should be implemented?

I'm not aware of any feature in qbe that would allow implementing this. Perhaps a patch is required.

Struct as return type causes QBE type error

What went wrong?

Expected a compiled binary, got a QBE type error undefined type :w. Adding multiple fields to the struct gives type errors for :w2+.

What caused it?

type Foo struct {
    n I32
}

fn test() Foo {

}

Better compiler errors

A list of improvements to the error outputs, in order of importance:

  1. positional information for type errors
  2. show source snippets for syntax and type errors
  3. GNU standard error message labels for compatibility with tooling such as editor/linter plugins
  4. output a message to wrap QBE errors to distinguish them from compiler errors (and possibly dump the line of QBE source that the error comes from)

Constants

What new feature would you like to see?

A way to define names for constant values. Some thought needs to be put into how enums work in relation to this (one option is something similar to Go's iota).

What problems would this feature address?

Avoids magic numbers. Variables aren't ideal because they are stored in the data segment and require pointer indirection, rather than being immediates.

How do you think this feature should be implemented?

const foo = 3

QBE error: unknown keyword `jz`

What went wrong?

QBE fails to parse the emitted IR due to an invalid keyword jz.

What caused it?

I'm not sure of the exact circumstances that generate a jz instruction, but the following code errors as described:

fn strcmp(a [I8], b [I8]) I32 {
    var i [I8]
    for i = 0; [a + i] != 0; i += 1 {
        if [a + i] != [b + i] {
            return 0
        }
    }
    return [a + i] == 0 && [b + i] == 0
}

Declaration and initialisation syntax

What new feature would you like to see?

Syntax for declaring then initializing a variable:

var foo I32 = 5

What problems would this feature address?

Code verbosity

How do you think this feature should be implemented?

This can be desugared easily to two lines:

var foo I32
foo = 5

Cannot return Bool type

What went wrong?

QBE doesnt allow returning bytes or half words, meaning the type Bool cannot be used as a function return type

What caused it?

fn test() Bool { }

Switch statement

Purely syntactic (no performance benefit) until I either patch qbe to support indirect jumps or write a different backend

Character literals

What new feature would you like to see?

C-style character literals, such as 'a' or '\n'.

What problems would this feature address?

Lots of string manipulation currently requires comparing to ascii values which harms readability.

How do you think this feature should be implemented?

Add a new lexer token that desugars to an integer literal.

`sizeof`

What new feature would you like to see?

A sizeof operator/macro that computes the size of a type at compile time.

What problems would this feature address?

Allocating space on the heap for composite types is currently not easy, since structs can have arbitrary sizes. Estimating the size will become impossible if #6 is implemented.

How do you think this feature should be implemented?

Likely as an operator, but replaced by a numerical constant at compile time.

Indexing by differing types gives incorrect type error

What went wrong?

Indexing an array by a type should be a special case in the type checker. For example, indexing a [I8] with an I32 is currently not possible with [x + i] due to type checking of the + operator.

What caused it?

var x [I8]
var i I32
[x + i]

Type declarations are order-dependent

What went wrong?

Type aliases and wrappers are order dependent, disallowing recursive types, including recursive pointers.

What caused it?
The following is invalid:

type Foo = Bar
type Bar = Foo

as is:

type Foo = [Bar]
type Bar = Foo

Type system fails to check dereferenced type definition

What went wrong?

Dereferencing a value with type of an alias gives an incorrect type error Dereference of non-pointer type.

What caused it?

Changing Alias to [I8] in the function signature will fix the bug.

type Alias [I8]

fn test(x Alias) I32 {
    _ = [x + 2]
}

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.