Python and C killer seekers rejoice

Flux is a new language that combines the performance and power of C with the readability of Python. Flux resembles the C-family of languages. It is neither C, nor a derivative of C. It has a fundamentally different type system while still being C ABI compatible.

I named it after flux paste used in soldering.

https://github.com/kvthweatt/Flux

Here's reversing bits:

```

#import "standard.fx";

using standard::io::console;

def main() -> int { byte x = 55;

    x[0``7] = x[7``0];

    println(int(x));

    return 0;
};

```

You can take bit slices of bit slices as well like `[x``y][a``b]`

Flux has seamless FFI with C, everything is stack allocated by default including pointers, and everything is zero initialized by default. You can opt-in to uninitialized declaration like:

`int x = noinit;`

You can also assign arbitrary bytes to a function pointer, and if its valid machine code for your arch, you can execute that function. Example:

```

#import "standard.fx";

def main() -> int { byte[] some_bytecode = [0x48, 0x31, 0xC0, 0xC3]; // xor rax,rax ; ret

    def{}\* fp()->void = @some_bytecode;

    fp();

    return 0;
};

```

Flux has macros, and contracts, and the ability to put contracts on operators:

```

#import "standard.fx";

using standard::io::console;

contract NonZero(a,b) { assert(a != 0, "a must be nonzero"); assert(b != 0, "b must be nonzero"); };

operator(int x, i32 y)[+] -> int : NonZero(a,b) { return x+y; };

def main() -> int { 0 + 4; // runtime error

    return 0;
};

```

C:

```

len_block[0] = (byte)((aad_bits >> 56) & 0xFF);

len_block[1] = (byte)((aad_bits >> 48) & 0xFF);

len_block[2] = (byte)((aad_bits >> 40) & 0xFF);

len_block[3] = (byte)((aad_bits >> 32) & 0xFF);

len_block[4] = (byte)((aad_bits >> 24) & 0xFF);

len_block[5] = (byte)((aad_bits >> 16) & 0xFF);

len_block[6] = (byte)((aad_bits >> 8) & 0xFF);

len_block[7] = (byte)( aad_bits & 0xFF);

len_block[8] = (byte)((cipher_bits >> 56) & 0xFF);

len_block[9] = (byte)((cipher_bits >> 48) & 0xFF);

len_block[10] = (byte)((cipher_bits >> 40) & 0xFF);

len_block[11] = (byte)((cipher_bits >> 32) & 0xFF);

len_block[12] = (byte)((cipher_bits >> 24) & 0xFF);

len_block[13] = (byte)((cipher_bits >> 16) & 0xFF);

len_block[14] = (byte)((cipher_bits >> 8) & 0xFF);

len_block[15] = (byte)( cipher_bits & 0xFF);

```

Flux equivalent

```

len_block[0..7] = (byte[8])(u64)aad_bits;

len_block[8..15] = (byte[8])(u64)cipher_bits;

```

Reworking a loop:

```

for (i = 0; i < 4; i++) { hash[i] = (byte)((ctx.state[0] >> (24 - i * 8)) & 0xFF);

    hash[i + 4] = (byte)((ctx.state[1] >> (24 - i \* 8)) & 0xFF);

    hash[i + 8] = (byte)((ctx.state[2] >> (24 - i \* 8)) & 0xFF);

    hash[i + 12] = (byte)((ctx.state[3] >> (24 - i \* 8)) & 0xFF);

    hash[i + 16] = (byte)((ctx.state[4] >> (24 - i \* 8)) & 0xFF);

    hash[i + 20] = (byte)((ctx.state[5] >> (24 - i \* 8)) & 0xFF);

    hash[i + 24] = (byte)((ctx.state[6] >> (24 - i \* 8)) & 0xFF);

    hash[i + 28] = (byte)((ctx.state[7] >> (24 - i \* 8)) & 0xFF);
};

```

Turns into:

```

hash[0..3] = (byte[4])ctx.state[0];

hash[4..7] = (byte[4])ctx.state[1];

hash[8..11] = (byte[4])ctx.state[2];

hash[12..15] = (byte[4])ctx.state[3];

hash[16..19] = (byte[4])ctx.state[4];

hash[20..23] = (byte[4])ctx.state[5];

hash[24..27] = (byte[4])ctx.state[6];

hash[28..31] = (byte[4])ctx.state[7];

```

Would love to take questions and see if anyone finds it useful for anything.

1 points | by kvthweatt 1 hour ago

0 comments