Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/kinderjosh/quad-c

Quad C is my own dialect of C written from scratch. It can achieve memory safety through an optional garbage collector, otherwise memory must be manually freed. It currently only targets Linux x86_64.
https://github.com/kinderjosh/quad-c

assembly assembly-language compiler nasm programming-language templeos terry-davis

Last synced: about 1 month ago
JSON representation

Quad C is my own dialect of C written from scratch. It can achieve memory safety through an optional garbage collector, otherwise memory must be manually freed. It currently only targets Linux x86_64.

Awesome Lists containing this project

README

        

# Quad C

Quad C is my own dialect of C written from scratch, featuring a custom backend. It can achieve memory safety through an optional garbage collector, otherwise memory must be manually freed. It currently only targets Linux x86_64.

> [!WARNING]
> Quad C is still in development, expect bugs and missing features.

## Examples

Hello world:

```c
#import "lib/core.qc"

void main() {
puts("Hello world!\n");
}
```

Greet the user:

```c
#import "lib/core.qc"

void main() {
puts("What is your name? ");
char *name = gets(64); // Returns a malloc'd string, 64 byte capacity

puts("Hello, ");
puts(name);
puts("!\n");

free(name, 64); // Free all 64 bytes
}
```

Optionally, with garbage collection:

```c
#import "lib/core.qc"

void main() {
enable_garbage_collection(); // Garbage collector turned on, 16384 byte capacity by default

puts("What is your name? ");
char *name = gets(64); // Returns a malloc'd string, 64 byte capacity

puts("Hello, ");
puts(name);
puts("!\n");

// DO NOT FREE OTHERWISE IT WILL FREE TWICE
// the garbage collector does it for you

collect_garbage(); // Garbage collector frees all malloc'd memory
}
```

## Installation

### Dependencies

- g++
- make
- nasm

```bash
$ git clone https://github.com/kinderjosh/quad-c.git
$ cd quad-c
$ make
```

Check it works by compiling and running hello world:

```console
$ ./qcc fun/hello.qc
$ ./a.out
```

## Usage

```
usage: ./qcc [options]
options:
-c compile to only an object file
-o place the output into
-S compile to only an assembly file
-S-imports compile to only an assembly file, with imported files included
```

## License

[BSD 2-Clause](./LICENSE)