News for hackers. Stuff that matters.
Re:Making a programming language using Rust by harikb on Sunday November 08, 2020 @04:57PM (#25029466)
Part zero made me chuckle! Whenever I start a project I go through the same motion of trying to find a good name for it. I am sure it is not rational, but somehow I would hate the project myself if the name doesn’t feel right.
Re:Making a programming language using Rust by emmanueloga_ on Sunday November 08, 2020 @05:18PM (#25029644)
I decided to pick a naming theme and name every new experiment folder accordingly. Works pretty well, surprisingly as/if your project evolves you tend to find connections with the (randomly picked) name.

I'm using sea creatures lately :-).

Re:Making a programming language using Rust by harshitaneja on Sunday November 08, 2020 @06:06PM (#25029949)
I am going to try this. Naming is hard.
Re:Making a programming language using Rust by bGl2YW5j on Sunday November 08, 2020 @06:30PM (#25030077)
Def fun for personal projects, but when it comes to work, I've been on projects made up of multiple services with the silliest, vaguest names ever; all this did was made it impossible to remember what each service actually did! Such a hassle.
Re:Making a programming language using Rust by freeopinion on Sunday November 08, 2020 @06:58PM (#25030222)
I know, right? I can never keep C and D straight in my head. I think I'd be ok if it wasn't for R. It's all so confusing.
Re:Making a programming language using Rust by chrismorgan on Monday November 09, 2020 @01:33AM (#25031971)
If I can’t immediately decide on a good name, I like to take a single word (or occasionally as many as three) that describes it, and take the initial (or initials) and use that as a code name. That way I know I’ve got to change it, and avoid the risk of retaining a bad name because of inertia. One project I have going at present is code named “B”. Some previous examples have been “ABC”, “C” and “V”.
Re:Making a programming language using Rust by billconan on Sunday November 08, 2020 @08:56PM (#25030720)
I'm also implementing my own language using rust. I got stuck at code generation.

I'm new to llvm IR. it is more assembly than I thought. my language is similar to javascript. I found it's difficult to map it to llvm IR.

Re:Making a programming language using Rust by siraben on Sunday November 08, 2020 @09:26PM (#25030860)
If your langauge is functional (has closures), I would recommend checking out[0] which is a full end-to-end tutorial on compiling a functional language to C and could be adapted to LLVM, using Haskell as the implementation language.

Basically the only slightly non-trivial step is closure conversion[1] which lifts free (AKA "captured" in C++ terminology) variables from a closure, which lets you encode closures faithfully in a first-order language with structs.

[0] https://github.com/jozefg/pcf/

[1] http://lampwww.epfl.ch/teaching/archive/advanced_compiler/20...

Re:Making a programming language using Rust by caditinpiscinam on Sunday November 08, 2020 @10:05PM (#25031077)
Any tips on implementing tail-call optimization when compiling to C? (or llvm)?
Re:Making a programming language using Rust by sinistersnare on Monday November 09, 2020 @12:04AM (#25031630)
If you translate your language to use Continuation Passing Style [0], then you get tail-calls for every function, which effectively obviates the stack.

This technique is used by functional language compilers, see Compiling With Continuations for more info on the underlying theory

[0]: https://en.wikipedia.org/wiki/Continuation-passing_style

[1]: https://books.google.com/books/about/Compiling_with_Continua...

Re:Making a programming language using Rust by siraben on Monday November 09, 2020 @04:38AM (#25033042)
> then you get tail-calls for every function, which effectively obviates the stack.

This is true, however CPS moves the work from the stack to the heap, so a deep enough recursion would exhaust the heap instead. Using a trampoline[0] in conjunction with CPS ensure constant stack usage for tail-recursive functions.

[0] https://en.wikipedia.org/wiki/Trampoline_(computing)

Re:Making a programming language using Rust by siraben on Sunday November 08, 2020 @10:26PM (#25031184)
That is a good question. Although tail-call is easy to describe and understand I've haven't implemented it myself. I'd also appreciate pointers to resources.
Re:Making a programming language using Rust by siraben on Sunday November 08, 2020 @10:29PM (#25031195)
Oh, I completely forgot about[0], which talks about TCO in the imperative context (but applies to functional languages as well)!

[0] https://dspace.mit.edu/bitstream/handle/1721.1/5753/AIM-443....

Re:Making a programming language using Rust by Joker_vD on Monday November 09, 2020 @06:25AM (#25033632)
See also [0], which talks about how Chicken SCHEME (which compiles to portable C) does it.

[0] https://www.more-magic.net/posts/internals-gc.html#managing-...

Re:Making a programming language using Rust by ratww on Sunday November 08, 2020 @10:19PM (#25031148)
The easy way is by using goto.
Re:Making a programming language using Rust by hardwaregeek on Sunday November 08, 2020 @09:24PM (#25030846)
Code generation is pretty hard. I'd start by generating arithmetic from your AST. Then focus on getting a simple function to compile. Don't worry if this requires a lot of hard coding. Once you get to the harder concepts like closures, consider making a secondary IR that simplifies code gen. I have a typed AST representation that desugars various concepts like first class functions, destructuring, etc.

I'm actually compiling to WebAssembly but it's the same principles

Re:Making a programming language using Rust by billconan on Sunday November 08, 2020 @11:12PM (#25031388)
I also want to generate webassembly. I compared the option of generating wasm directly with using llvm. The wasm spec is hard to read without enough examples.

My current approach is writing my runtime in c or c++, and put most logic there. And I will try to generate c code first, and compile the c code using clang and learn from the generated IR.

I kinda want to write the runtime also in rust, but I don't know if linking will be a problem.

Re:Making a programming language using Rust by hardwaregeek on Monday November 09, 2020 @10:06AM (#25035492)
Agreed that the WebAssembly spec is a pain to read. I mostly used this outdated doc: https://github.com/WebAssembly/design/blob/master/BinaryEnco...

Generating C seems like a good middle ground. I also considered that. Frankly though code generation is hard regardless because you’re gonna have some abstractions that just don’t lower nicely.

Writing the runtime in Rust might work but ownership might get in the way.

Happy to talk about this more if you want. Shoot me an email

Re:Making a programming language using Rust by txdv on Monday November 09, 2020 @04:58AM (#25033162)
You might want generate assembly yourself, even if it is in the most inefficient way.

I found myself that LLVM has a very high barrier to use.

Re:Making a programming language using Rust by muglug on Monday November 09, 2020 @01:09AM (#25031880)
Quite apart from the very good content, this guide is also incredibly beautiful.

It’s wonderful to see a programming guide that has thought hard about typography (and Freight works great here).

Re:Making a programming language using Rust by chrismorgan on Monday November 09, 2020 @01:40AM (#25032001)
I find font-family stacks to regularly be a source of amusement and/or bafflement. Here’s this site’s main one:

  font-family: freight-text, Iowan Old Style, Georgia, system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, sans-serif;
I… what? The web-font serif, then a macOS (I think?) serif, then a Windows serif, then… system-ui stuff which is almost always sans-serif, then sans-serif fallbacks. This is a bizarre mixture.

This immediately makes much more sense:

  font-family: freight-text, Iowan Old Style, Georgia, serif;
And I tend to think just this would be better:

  font-family: freight-text, serif;
Also, one other rule that I can’t let pass by without comment:

  letter-spacing: .01em;
Bumping letter-spacing is always risky: the designer chose the spacing they did for a reason. Pretty much the only circumstances you should do it are (a) very specific display purposes (that is, headings and the likes—typically 0.2em or more) and (b) all caps (typically something like 0.07ex). Body text letter-spacing bumps are almost always a bad idea. In this case, it’s even already using a fairly wide font. (Well, so long as freight-text is used. I really wish all font properties (font-, letter-spacing, &c.*) could be varied by font availability, so that you could do things like bump font-size if you use your own web font with smaller metrics than the likely fallback font.)
Re:Making a programming language using Rust by xixixao on Monday November 09, 2020 @01:32AM (#25031970)
It might make sense to stretch the code blocks, to avoid horizontal scrolling which is quite annoying when reading code. Similar to photos breaking out of the text column on various sites.
Re:Making a programming language using Rust by chrismorgan on Monday November 09, 2020 @01:45AM (#25032017)
Also on the topic of horizontal scrolling, `overflow: scroll` is almost never what you want, because it causes scrollbars to be drawn even if unneeded. >99.99999% of the time you want `overflow: auto` which draws scrollbars only if needed.
Re:Making a programming language using Rust by rvdca on Monday November 09, 2020 @02:49AM (#25032308)
Apart from the very detailed rust content, your RSS feed is broken : I wanted to subscribe but I couldn't; a shame.
Re:Making a programming language using Rust by pedro1976 on Monday November 09, 2020 @03:21AM (#25032526)
Not the perfect feed, but at least a working one [0]. Disclaimer: I develop a tool to transform markup to feed, completely automated [1]

[0] https://rssproxy.migor.org/api/feed?url=https%3A%2F%2Farzg.g...

[1] https://github.com/damoeb/rss-proxy