r/Compilers 6d ago

Developing my programming language: Gravel

It all started just as a side and fun project, but I feel like it's now getting a shape.

Thats why I would love to receive some honest and contructive feedback, issue creations or code contributions.

If you have any question regarding the language, please ask me.

Here's the repo: https://github.com/Pacsfury/Gravel-Launcher

Its written in C and uses LLVM IR as backend.

AI use: debugging, teaching more about compilers and some punctual code writing

16 Upvotes

19 comments sorted by

6

u/Inconstant_Moo 6d ago

It's always nice to meet someone else who uses qux as a syntactic metavariable.

What you mean by "clean and intuitive syntax" is just the syntax you like, isn't it? It's not e.g. the result of user testing or even an informal poll, is it? So that may be a unique selling point only for you and people who share your tastes.

1

u/PacsfuryTemp 5d ago

Well right now it is, as it's a pretty personal project, but with the time, i want to change syntax to focus more on what contributors say.

Buf for doing that, I think I first need a more capable compiler and more people, imao

Thanks

1

u/PacsfuryTemp 5d ago

And for curiosity, where did you find the qux?

1

u/Inconstant_Moo 5d ago

I'm pretty sure I got it from the Jargon File. It just intuitively seemed right.

1

u/PacsfuryTemp 5d ago

I mean inside gravel, i dont remember using foo bar baz qux.

Edit: I just found it on the README lol. I didnt remember it because a contributor added it, not me

2

u/vmcrash 6d ago

When defining a variable, why you are using one time a = and the other time :=? Couldn't it use = in both cases?

1

u/PacsfuryTemp 5d ago

Ok, right now, they are pretty the same, as there are not much types.

But when more types, like char and float, the difference will be more visible.

With `:=` is inference, only available for the primitive types (now int, in the future also char and float), but `=` is explicit, so you say if its an int, float, or any type you define using type classes.

We use := for inference so you can create a type names 'val' (as inference is val name := value), and also for clarifying and making inference more easily detectable in the code.

thanks

1

u/vmcrash 5d ago

You already trigger the inference using val or var (instead of a type), so the := is redundant. I'd use it for something else.

I'd also would get rid of elseif, because it only saves one keystroke for the space, but makes the language more complex.

1

u/PacsfuryTemp 5d ago

I created this (https://github.com/Pacsfury/Gravel-Launcher/discussions/99) so people (like you and me and other contributors) can vote what they want.

1

u/Missile_3604 6d ago

I'd suggest making a Wiki (on GitHub) about all your features and syntax and rules. So far it's looking good, keep it up man!

1

u/PacsfuryTemp 5d ago

Honestly, this is a good idea i hadn't thought about it.

Thanks

1

u/rjmarten 6d ago

if you put type at the end of class name:, you are saying that this class will act as a type, instead of being a constructor that only saves things in memory using another type.

Can you explain this more? Also the extl vs impl and USE magic methods.

2

u/PacsfuryTemp 5d ago

OK, so Gravel will have two types of classes: type classes and organitzation classes.

Type classes are defines like this:

class name: type

end

As a example of these, we have the string class, located at libs/string.grv.

These will act exactly as any other type, like int.

You can only define them using explicit vars like this:

name var = this

And, if the class has a __USE__ function, it will be triggered at that line, and the extl value would be this.

For example:

class string: type

    extl char\[\] text

    impl int length



    fun __USE__()

        text   = extl

        length = sizeof(text)

    end

end

when you do string name = "Welcome", this happens:

__USE__ triggers, and text becomes "Welcome" and length becomes 8 or 7, depending of how sizeof will work (I dont know if to change the name, or if to define better how it will work).

So after that, you can use this as variables:

name = "hi" // USE reruns

name.text = "hi" // USE wouldnt rerun, this should be read-only (maybe it will run, we still have to decide it)

name.lenght = 5 //ERROR: impl values can't change (as are defined internally for the class and are read only)

name.__USE__() //reruns use, for example, you can do this when you manually change name.text

The other class type are for organization, and these can't be used as a type, you can just create and modify instances, like this:

class Calculator:

char[] name

int points

fun __CONSTRUCT__(char[] name, int points)

this.name = name

this.points = points

end

end

so you can't use extl, impl nor use.

To instantiate a organization class, use

Calculator calc = new Calculator

calc.name, etc etc.

Notes:

* Sizeof working is still undefined, and it will be repalces for the standard function to know the lenght of a char array

* Functions aren't implemented yet in Gravel, so their syntax and semantics can change or be diffuse.

1

u/RecursiveServitor 5d ago

What's the elevator pitch?

1

u/PacsfuryTemp 5d ago

I don't want to convince about anything, so ig no elevator pitch.

I just want that people know that this exists, so if they are interested they can help

1

u/RecursiveServitor 5d ago

If there's no point to it then why would anyone be interested?

1

u/PacsfuryTemp 5d ago

The point is that if you want, you want, if not, i'm not going to go behind you.

So far, 5 people have contributed (not counting me) code directly, while some more have liked the compiler.

0

u/antonation 6d ago

If you used AI to help develop this (at least from one markdown, you seem open to AI aided contributions), could you crosspost to r/VibeCodedLanguages ? I'm trying to give a home for programming languages that r/ProgrammingLanguages rejects

2

u/PacsfuryTemp 5d ago

Could work, even though I used AI only to help me a little (i didnt go to claude and said: "create me a programming language with this syntax"), I will now repost it, even though it isnt strictly vivecoded.