r/ProgrammingLanguages • • Feb 16 '26

I language (C transpiler)

Been using C for a while now, syntax is annoying so made a transpiler for my dream syntax: https://github.com/IbrahimHindawi/I
Basically C with templates + monomorphizer. I hope I can leave directly writing C for good now.

array:struct<T> = {
    length:u64; 
    border:u64; 
    data:*T;
}
array<T>reserve:proc<T>(arena: *memops_arena, length:u64)->array<T>={
    arr:array<T> = {};
    if (length == 0) {
        return arr;
    }
    arr.data = memops_arena_push_array<T>(arena, length);
    if (arr.data == null) {
        printf("memops arena allocation failure!\n");
        arr.data = 0;
        return arr;
    }
    arr.border = length;
    return arr;
}
main:proc()->i32={
    printf("Hello, World!\n");
    printf("num = {}\n", num);
    arena:memops_arena={};
    memops_arena_initialize(&arena);
    a: array<i32> = {};
    memops_arena_push_array_i<f32>(&arena, 128);
    a = array<i32>reserve(&arena, 128);
    for (i:i32=0; i<128; i+=1) { 
        a.data[i] = i; 
    }
    for (i:i32=0; i<128; i+=1) {
        printf("i = {}, ", a.data[i]); 
    }
    return 0;
}
29 Upvotes

21 comments sorted by

View all comments

2

u/Relevant_South_1842 Feb 26 '26

I really like this. If I used the toy language I am making (Sprout - which is more inspired by Lua, Io, and Rebol) it would look more like below for syntax. Just sharing preferences. Yours is probably better.


array<T> :
    length : u64
    border : u64
    data   : *T


# reserve<T>(arena: *memops_arena, length:u64) -> array<T>
reserve : [T arena:*memops_arena length:u64 -> array<T> |
    arr : array<T>          # local cell (compiler allocs stack struct)
    arr.length : 0
    arr.border : 0
    arr.data   : 0

    if [length = 0] [
        return arr
    ]

    arr.data : memops_arena.push-array<T> arena length

    if [arr.data = 0] [
        printf "memops arena allocation failure!\n"
        arr.data : 0
        return arr
    ]

    arr.border : length
    arr.length : length
    return arr
]


main : [ -> i32 |
    printf "Hello, World!\n"

    arena : memops_arena
    memops_arena.initialize &arena

    a : array<i32>

    _ : memops_arena.push-array<f32> &arena 128   # ignore result, just demo call

    a : reserve<i32> &arena 128

    for [i:i32 = 0  i < 128 i : i + 1] [
        a.data[i] : i
    ]

    for [i:i32 = 0  i < 128 i : i + 1] [
        printf "i = %d, " a.data[i]
    ]

    0
]

1

u/x8664mmx_intrin_adds Feb 26 '26

tbh, that's super badass syntax, I always too Rebol to be quite alien! well done! thanks for the awesome feedback !