News for hackers. Stuff that matters.
Re:Show HN: Minimal Fibers by backpropaganda on Friday May 18, 2018 @10:30PM (#17106311)
Slightly OT, but do people know of any good small language which compiles to C? I'm not looking for big languages like C++, Nim, or Rust, but something which is essentially just C, but with some minimal modernization, such as perhaps being able to import modules, and doing away with header files.
Re:Show HN: Minimal Fibers by bgongfu on Friday May 18, 2018 @10:34PM (#17106320)
Cixl? :)

I realize the Forth & Lisp heritage might be a bit hard on the brain for those who haven't been exposed before, but what you're asking for is otherwise more or less what Cixl is aiming for.

https://github.com/basic-gongfu/cixl#compiling

Re:Show HN: Minimal Fibers by enriquto on Saturday May 19, 2018 @02:49AM (#17106934)
Wow, cixl is a great thing! I love the Dijkstra quote against complexity that serves as inspiration for the language. However, you find this :

> To build Cixl yourself, you'll need a reasonably modern GCC and CMake installed.

I was very taken aback by this. Really? Why do you really need to depend on the cmake monstrosity? It's just a few lines of C without dependencies that they are distributing!

If there is something about cixl that will scare people is the ridiculous dependence on cmake, not its clean syntax.

Re:Show HN: Minimal Fibers by bgongfu on Saturday May 19, 2018 @07:35AM (#17107440)
I hear you; I'm not overly excited with CMake either, or the C build system story in general.

I spent several years trying to bend regular make into something I was happy with; then I spent several years on top of that using Rake, since at least it allowed me to say what I mean in a sane language. Compared to Rake, CMake is at least semi-standard, provides some kind of macro for most things I want to do, and mostly stays out of my way.

But you definitely have a point when it comes to simplicity and project fit. If someone would be willing to step up and help translate the makefile into something that doesn't look horrible, I'd be more than happy to let it go. Otherwise we'll have to wait until I get enough round tuits, which could take a while given how much remains to be done in Cixl.

Re:Show HN: Minimal Fibers by enriquto on Saturday May 19, 2018 @02:34PM (#17109080)
Often it is disheartening to bend make to your bidding. But cixl has a neatly arranged tree and the makefile to build it is trivial. The following lines suffice (and by running 'make test -j' you compile everything in parallel and run all the tests) :

    CFLAGS   = -Isrc -O2
    LDLIBS   = -ldl -lm

    SRC      = $(shell ls src/cixl/*.c src/cixl/lib/*.c)
    OBJ      = $(SRC:%.c=%.o)

    src/main : src/main.o $(OBJ)

    clean    : ; $(RM) $(OBJ) src/main

    test: src/main ; for i in tests/*; do ./src/main<$$i; done

would you accept such a patch in your project?
Re:Show HN: Minimal Fibers by bgongfu on Saturday May 19, 2018 @04:07PM (#17109505)
Not bad; my make-fu was never that spectacular to begin with and it hasn't been aging well, this helps me a lot.

Sure thing, if you feel like giving the entire makefile the same treatment I'd be delighted to accept it.

Thanks for taking the time!

Re:Show HN: Minimal Fibers by exikyut on Saturday May 19, 2018 @02:59AM (#17106957)
What's so bad about cmake? The first time I ever used it, I was very pleasantly impressed by the percentage system.

I take it that cmake tried to tackle autotools, partially succeeded, and partly succumbed to autotools' all-devouring complexity? :)

Re:Show HN: Minimal Fibers by enriquto on Saturday May 19, 2018 @03:30AM (#17107002)
I just do not understand its point. Cmakefiles are much, much uglier than makefiles. And it takes several steps to compile a program, instead of a single one. And it seems larger than the operating system itself.

I do not know what is "the percentage system", but I doubt it can be so wonderful to make me forget about all the other unnecessary problems.

It may be justified to use cmake when it is really needed. But the cixl interpreter can be built by a five-line makefile.

Re:Show HN: Minimal Fibers by exikyut on Saturday May 19, 2018 @06:12AM (#17107281)
Ah, I see, a bit more tentativity has been filed away for when I finally check it out.

I was regarding how it outputs progress indication, like

  [ 16%] Building C object ...
  [ 91%] Linking C executable ...
etc (many lines elided). Back on the slow machine I was using when I was very new to Linux, progress indication ("how soon can I stop freaking out about this maybe not working") was very nice to have :D

But (10 years on) I can understand it being icky to use. I guess, ugly as it is, it's a little more structured than automake is, and maybe that's its redeeming quality.

Maybe build systems are the dead-centre of a "sour spot" (opposite of sweet spot) in computer science, with no truly nice solutions out there? (Genuinely curious. The exponential profusion of JS build systems suggests it's rather hard to solve.)

The only explanation I have is that

- Maybe the author is used to cmake

- Maybe this project has Big Goals And Ventures™ syndrome - and, hence, all the enterprise build systems. (Hopefully not, it looks kinda nice)

Re:Show HN: Minimal Fibers by enriquto on Saturday May 19, 2018 @07:15AM (#17107388)
> Maybe build systems are the dead-centre of a "sour spot" (opposite of sweet spot) in computer science, with no truly nice solutions out there?

I think it's the opposite. It is a very, very sweet spot for which many essentially perfect solutions exist. Then, it attracts all kinds of extreme bikeshedding and produces the monsters we see here and there.

Re:Show HN: Minimal Fibers by exikyut on Saturday May 19, 2018 @08:58AM (#17107712)
Ooh, okay.

What do you think are the best/"essentially perfect" solution(s)?

(Said as someone who just figured out his first Makefile a couple days ago :P)

Re:Show HN: Minimal Fibers by enriquto on Saturday May 19, 2018 @02:37PM (#17109091)
make is essentially perfect for compiling small and moderately sized projects
Re:Show HN: Minimal Fibers by backpropaganda on Saturday May 19, 2018 @05:39AM (#17107235)
Yeah, the syntax is pretty out-of-the-world for me, but I'll give it a go. Thanks!
Re:Show HN: Minimal Fibers by bgongfu on Saturday May 19, 2018 @04:11PM (#17109524)
If you're serious about writing code; I strongly recommend learning some C, Forth & Common Lisp to get an idea of what's possible. Once you have those under your belt, appearances matter less and Cixl will look less crazy banana.
Re:Show HN: Minimal Fibers by panic on Saturday May 19, 2018 @12:41AM (#17106694)
Ion (https://github.com/pervognsen/bitwise/tree/master/ion) is a relatively new language with round-trippable conversion to C as a design goal.
Re:Show HN: Minimal Fibers by exikyut on Saturday May 19, 2018 @02:57AM (#17106953)
Ooooh, bitwise looks really interesting...
Re:Show HN: Minimal Fibers by exikyut on Saturday May 19, 2018 @02:55AM (#17106947)
Hmm. How would you do away with header files in a simple way if you wanted something similarly-scoped to C? Have the compiler vacuum in every source file at once to pick up all references, then discard via dead code elimination? That'd kill incremental compilation :/

(I'm genuinely curious about the answer to this question - I'm also looking for something similar to C)

Re:Show HN: Minimal Fibers by backpropaganda on Saturday May 19, 2018 @05:38AM (#17107233)
Incremental compilation creates .o files for every compiled .c file, and so it could also create a .h file at the same time (perhaps fused in the .o file).
Re:Show HN: Minimal Fibers by exikyut on Saturday May 19, 2018 @06:16AM (#17107289)
Ooooh, duh. Takes notes
Re:Show HN: Minimal Fibers by dom96 on Saturday May 19, 2018 @04:03AM (#17107075)
Nim is small enough to be used for this purpose. You can easily use it as a nice layer on top of C.

Why do you consider it too big?

Re:Show HN: Minimal Fibers by backpropaganda on Saturday May 19, 2018 @05:33AM (#17107227)
I haven't looked at Nim in detail, but since Nim does garbage collection, it didn't read to me like a thin layer over C. For instance, is it possible to instantiate a struct on the stack? I'd also have liked the compiled C code to be readable, which if I'm not mistaken, Nim doesn't do.
Re:Show HN: Minimal Fibers by dom96 on Saturday May 19, 2018 @05:54AM (#17107251)
> For instance, is it possible to instantiate a struct on the stack?

Yeah, it is. You can easily avoid the GC as long as you don't mind managing memory yourself (unfortunately this means that you cannot use the stdlib either, or at least parts of it, if you disable the GC with the `--gc:none` flag you'll get warning messages from the compiler about procs that need the GC which is nice).

> I'd also have liked the compiled C code to be readable, which if I'm not mistaken, Nim doesn't do.

Yeah, that's one thing that Nim definitely doesn't do. I don't think there are many languages that do. It would be an interesting experiment to see how pretty you could make the generated C by either fixing things in the compiler or just running a C formatter on it.

Re:Show HN: Minimal Fibers by backpropaganda on Saturday May 19, 2018 @06:12AM (#17107282)
> unfortunately this means that you cannot use the stdlib either

This is the kind of friction I expect from a language which uses GC, for my usecase. I think it might make sense for Nim to support a GC-less stdlib for people who do not want GC in their code.

Re:Show HN: Minimal Fibers by theprotocol on Sunday May 20, 2018 @04:25AM (#17111807)
This is giving me D flashbacks.
Re:Show HN: Minimal Fibers by steveklabnik on Friday May 18, 2018 @10:46PM (#17106354)
I think you want Zig!
Re:Show HN: Minimal Fibers by backpropaganda on Saturday May 19, 2018 @06:10AM (#17107279)
Zig looks amazing! Thank you! While it doesn't compile to C, you read my mind that I actually wanted a C replacement rather than compile to C.
Re:Show HN: Minimal Fibers by steveklabnik on Saturday May 19, 2018 @09:05AM (#17107732)
Great! Yeah, that's what I was guessing, glad that I guessed correctly.
Re:Show HN: Minimal Fibers by bgongfu on Friday May 18, 2018 @10:49PM (#17106362)
Isn't Zig based on LLVM rather than compiled to C?
Re:Show HN: Minimal Fibers by steveklabnik on Saturday May 19, 2018 @09:04AM (#17107727)
Yes, I didn’t assume that was the highest order bit here.
Re:Show HN: Minimal Fibers by jitl on Saturday May 19, 2018 @01:52AM (#17106826)
Zig explicitly does not depend on the C stdlib
Re:Show HN: Minimal Fibers by steveklabnik on Saturday May 19, 2018 @09:05AM (#17107731)
Yeah, this is true, I was responding mostly to the semantics aspect rather than that part.