Coder Social home page Coder Social logo

c1c's Introduction

c1c

A compiler for .c1 files - they're just regular C files, except array indexes start at 1.

Motivation

Do you ever feel the need to torture a software engineer? The c1 programming language is the perfect fit for you!

How to install

Just download c1c and add it to your path. There's a linux executable in the repo, or you can build the compiler from source (c1c.c).

Note: You need to have gcc installed for the compiler to work.

Usage

Just execute c1c test.c1 to compile the given file to an executable.

Options

There's the option to provide a custom start index for arrays using the --start-index option. It's not limited to integer values, so you can even let your arrays start at 0.5 or pi. How awesome is that!

Warning: Almost all array start indexes are permitted, except 0. Because that would be crazy. Also, your indexes are casted to ints.

Examples

Here's a simple program that's supposed to be compiled using an array start index of 1:

#include <stdio.h>

int main(void) {
  int a[] = { 2, 3, 1 };
  printf("Element is %d.\n", a[a[3]]);
}

Output with array start of 1: Element is 2.

Output with array start of 2: Element is 3.

You can find the file in the repo as test.c1.


Disclaimer: Do not use this compiler in a production environment. In fact, just don't use it at all. I do not support array indexes starting at 1. Of course, pi is the only correct start index.

c1c's People

Contributors

marcelgarus avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

c1c's Issues

c1c crashes with error "free(): invalid next size (fast): 0x00007fffd618e7d0"

I tried compiling the test.c1 program from the repository and c1c crashed with the following backtrace:

*** Error in `./c1c': free(): invalid next size (fast): 0x00007fffd618e7d0 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x70bfb)[0x7f943d8d0bfb]
/lib/x86_64-linux-gnu/libc.so.6(+0x76fc6)[0x7f943d8d6fc6]
/lib/x86_64-linux-gnu/libc.so.6(+0x7780e)[0x7f943d8d780e]
./c1c(+0x122e)[0x7f943e00122e]
./c1c(+0xfc6)[0x7f943e000fc6]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf1)[0x7f943d8802e1]
./c1c(+0xaba)[0x7f943e000aba]
======= Memory map: ========
7f9438000000-7f9438021000 rw-p 00000000 00:00 0
7f9438021000-7f943c000000 ---p 00000000 00:00 0
7f943d640000-7f943d656000 r-xp 00000000 00:00 534852             /lib/x86_64-linux-gnu/libgcc_s.so.1
7f943d656000-7f943d657000 ---p 00016000 00:00 534852             /lib/x86_64-linux-gnu/libgcc_s.so.1
7f943d657000-7f943d855000 ---p 00000017 00:00 534852             /lib/x86_64-linux-gnu/libgcc_s.so.1
7f943d855000-7f943d856000 r--p 00015000 00:00 534852             /lib/x86_64-linux-gnu/libgcc_s.so.1
7f943d856000-7f943d857000 rw-p 00016000 00:00 534852             /lib/x86_64-linux-gnu/libgcc_s.so.1
7f943d860000-7f943d9f5000 r-xp 00000000 00:00 534827             /lib/x86_64-linux-gnu/libc-2.24.so
7f943d9f5000-7f943d9fd000 ---p 00195000 00:00 534827             /lib/x86_64-linux-gnu/libc-2.24.so
7f943d9fd000-7f943dbf5000 ---p 0000019d 00:00 534827             /lib/x86_64-linux-gnu/libc-2.24.so
7f943dbf5000-7f943dbf9000 r--p 00195000 00:00 534827             /lib/x86_64-linux-gnu/libc-2.24.so
7f943dbf9000-7f943dbfb000 rw-p 00199000 00:00 534827             /lib/x86_64-linux-gnu/libc-2.24.so
7f943dbfb000-7f943dbff000 rw-p 00000000 00:00 0
7f943dc00000-7f943dc22000 r-xp 00000000 00:00 534805             /lib/x86_64-linux-gnu/ld-2.24.so
7f943dc22000-7f943dc23000 r-xp 00022000 00:00 534805             /lib/x86_64-linux-gnu/ld-2.24.so
7f943de23000-7f943de24000 r--p 00023000 00:00 534805             /lib/x86_64-linux-gnu/ld-2.24.so
7f943de24000-7f943de25000 rw-p 00024000 00:00 534805             /lib/x86_64-linux-gnu/ld-2.24.so
7f943de25000-7f943de26000 rw-p 00000000 00:00 0
7f943df00000-7f943df02000 rw-p 00000000 00:00 0
7f943df10000-7f943df11000 rw-p 00000000 00:00 0
7f943df20000-7f943df23000 rw-p 00000000 00:00 0
7f943e000000-7f943e001000 r-xp 00000000 00:00 1446759            /home/clemens/c1c/c1c
7f943e001000-7f943e002000 r-xp 00001000 00:00 1446759            /home/clemens/c1c/c1c
7f943e201000-7f943e202000 r--p 00001000 00:00 1446759            /home/clemens/c1c/c1c
7f943e202000-7f943e203000 rw-p 00002000 00:00 1446759            /home/clemens/c1c/c1c
7fffd618e000-7fffd61af000 rw-p 00000000 00:00 0                  [heap]
7fffdccbd000-7fffdd4bd000 rw-p 00000000 00:00 0                  [stack]
7fffdda28000-7fffdda29000 r-xp 00000000 00:00 0                  [vdso]
Aborted (core dumped)

I am using GCC 6.3.0 on WSL (Debian).

Support custom step sizes

It would be nice to be able to configure custom step sizes.
For example, one might want to access array elements like this:

int a[] = { 1, 2, 3 };
printf("%d %d %d", a[2.1], a[2.2], a[2.3]);
// Expected output: 1 2 3

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.