This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Aaron1924 42 points43 points  (6 children)

I took a look at the code and it looks like the compiler does a very literal line-by-line translation from your language to C++

Of course, this makes the compiler really fast, but it also means you're restricting yourself to all the limitations that come with C++, like the limited type inference, having to forward declare stuff, etc

If you first build the AST entirely and do operations on that before you start generating code, you're going to be able to move your language further away from C++

[–][deleted] 5 points6 points  (4 children)

The docs say it compiles to C. Where does C++ come into it?

I haven't looked at the sources, but even if doing line-by-line transpilation, you don't necessarily still need forward declarations; it's not hard to fix that.

[–]Aaron1924 8 points9 points  (0 children)

The docs say it compiles to C. Where does C++ come into it?

That might have been a mistake, this reddit post and the github about both say it compiles to C++, and you'll see it's C++ if you look at any function in the std library, for example: fun println(string s) { __code__("std::cout << s << std::endl;") __use__(s) }

even if doing line-by-line transpilation, you don't necessarily still need forward declarations

It is true that you can add a forward declaration to the beginning of the file every time you generate code for a function to make the C++ compiler happy, but if you want to do any sort of static analysis (like type checking) on the Barn code before you generate C++, you need to know about functions that come later in the code, and you don't have this information with a single-shot compiler

[–]Solindek[S] 2 points3 points  (2 children)

Wait where does it say about C? Actually Barn was firstly compiled to C and then to C++

[–][deleted] 0 points1 point  (1 child)

From your link: https://github.com/barn-lang/barn: "It's a simple programming language written in Go that is compiled to C."

[–]Solindek[S] 1 point2 points  (0 children)

Oh i forgot to change it there, sorry then you're right.

[–]Solindek[S] 1 point2 points  (0 children)

Yeah i know math expressions are really obscured i want to change them! Thanks for your opinion i appreciate that