21 comments

  • ridiculous_fish9 hours ago
    I was curious how defer is implemented. `defer` in Go is famously function-scoped, not lexically-scoped. This means that the number of actively-deferred statements is unbounded, which implies heap allocation.<p>The answer is that Solod breaks with Go semantics here: it just makes defer block-scoped (and unavailable in for&#x2F;if blocks, which I don&#x27;t quite get).<p><a href="https:&#x2F;&#x2F;github.com&#x2F;solod-dev&#x2F;solod&#x2F;blob&#x2F;main&#x2F;doc&#x2F;spec.md#defer" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;solod-dev&#x2F;solod&#x2F;blob&#x2F;main&#x2F;doc&#x2F;spec.md#def...</a>
    • hmry9 hours ago
      What&#x27;s the point if it&#x27;s incompatible? The README suggests using go&#x27;s testing toolchain and type checker, but that&#x27;s unreliable if the compiled code has different behavior than the tested code. That&#x27;s like testing and typechecking your code in a C++ compiler but then for production you run it through a C compiler.<p>Would have been a lot more useful if it tried to match the Go behavior and threw a compiler error if it couldn&#x27;t, e.g. when you defer in a loop.<p>Is this just for people who prefer Go syntax over C syntax?
    • tgv1 hour ago
      As long as you exclude defers in a loop, this can be done statically: count the maximum number of defers in a function, and add an array of that size + counter at the function entrance. That would make it a strict subset.
    • crowdyriver5 hours ago
      tbh I&#x27;d rather have this behaviour, defer should&#x27;ve been lexically scoped from the beginning.
    • 17186274407 hours ago
      &gt; This means that the number of actively-deferred statements is unbounded, which implies heap allocation.<p>In C you can allocate dynamically on the stack using alloca or a VLA.
      • kleiba7 hours ago
        But also: <a href="https:&#x2F;&#x2F;stackoverflow.com&#x2F;a&#x2F;1018865" rel="nofollow">https:&#x2F;&#x2F;stackoverflow.com&#x2F;a&#x2F;1018865</a>
  • Retr0id11 hours ago
    I don&#x27;t really &quot;get&quot; the sweet-spot being targeted here. You don&#x27;t get channels, goroutines, or gc, so aside from syntax and spatial memory safety you&#x27;re not really inheriting much from Go. There is also no pathway to integrate with existing Go libraries.<p>Spatial memory safety <i>is</i> nice but it&#x27;s the temporal safety that worries me most, in nontrivial C codebases.
    • tidwall10 hours ago
      Looks to me like having the ability to write Go syntax and interop directly with C is the plus.
      • Retr0id10 hours ago
        I do like Go&#x27;s syntax but I can&#x27;t help thinking the best language for C interop is C.
        • AdieuToLogic10 hours ago
          &gt; I do like Go&#x27;s syntax but I can&#x27;t help thinking the best language for C interop is C.<p>SWIG[0] is a viable option for incorporating C code as well.<p>0 - <a href="https:&#x2F;&#x2F;swig.org&#x2F;Doc4.4&#x2F;Go.html#Go" rel="nofollow">https:&#x2F;&#x2F;swig.org&#x2F;Doc4.4&#x2F;Go.html#Go</a>
          • stevekemp9 hours ago
            I love how SWIG is still around! I first used it about 30 years ago to integrate with Perl, then later with Java.
      • whateveracct8 hours ago
        Go&#x27;s syntax is basically C tho lol<p>what&#x27;s the benefit? for loops?
    • cocodill7 hours ago
      I guess there is no point except Anton is having fun do it.
  • 0xmrpeter8 hours ago
    The claim that no goroutines makes this pointless isn&#x27;t quite right. Migrated 50 services off Docker Compose using Nomad and half of them had zero concurrency needs. A safe Go-syntax C target is actually useful for that layer.
  • tidwall11 hours ago
    &quot;To keep things simple, there are no channels, goroutines, closures, or generics.&quot;<p>I wonder if it could be integrated with <a href="https:&#x2F;&#x2F;github.com&#x2F;tidwall&#x2F;neco" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;tidwall&#x2F;neco</a>, which has Go-like coroutines, channels, and synchronization methods.
  • MYEUHD10 hours ago
    Related and currently on the front page: <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=47627595">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=47627595</a>
  • voidUpdate5 hours ago
    I&#x27;m reminded of the tools in programs like Ghidra or IDA which can take assembly code and convert it into a C-like language. If you could create one of those tools that also takes in the source file so that it names things somewhat reasonably, could you create an anything to C translator? As long as the original file compiles to assembly, that is
    • circuit104 hours ago
      I once used Ghidra to decompile a hand-written ARM assembly floating point library and compile the result to a different architecture, and it was significantly faster than GCC’s built in methods…<p>But in general this kind of thing is very unreliable for any non-trivial code without a lot of manual work, so a better approach could be to compile to WebAssembly which can be translated into C
      • voidUpdate4 hours ago
        It may be easier if you also have the original source file (I&#x27;ve not don&#x27;t much decompilation myself, only seen other people doing it), as more of a custom solution rather than using an existing system
  • leecommamichael2 hours ago
    If this sounds good to you, you would like the Odin programming language.
  • remywang9 hours ago
    Anton also wrote the fantastic codapi [1] for embedding executable code snippets with wasm<p>[1]: <a href="https:&#x2F;&#x2F;codapi.org&#x2F;" rel="nofollow">https:&#x2F;&#x2F;codapi.org&#x2F;</a>
  • joshuahart4 hours ago
    Interesting approach. What was the main motivation for targeting C specifically instead of something like LLVM or WASM as an intermediate?
    • nulltrace3 hours ago
      Biggest reason is usually the toolchain. Debuggers, sanitizers, profilers all just work when your target is C. Go through LLVM and you get similar optimization but now you own the backend. With C, gcc and clang handle that part.
  • xentripetal5 hours ago
    Somewhat similar language, <a href="https:&#x2F;&#x2F;vlang.io" rel="nofollow">https:&#x2F;&#x2F;vlang.io</a><p>It’s a mix of go and rust syntax that translates to C
  • weitzj6 hours ago
    Love it. And from my experience the need for Go Routines is not that urgent.<p>Sure when I started Go there were Go routines plastered everywhere. And now I think harder: “do I really need a go routine here?”
  • numlock867 hours ago
    &gt; So supports structs, methods, interfaces, slices, multiple returns, and defer.<p>&gt; To keep things simple, there are no channels, goroutines, closures, or generics.<p>Sure, slices and multiple return values are nice, but it&#x27;s not what makes Go good. When people think about Go they usually think about channels and goroutines. YMMV<p>While I do kind of get what the appeal and target audience is supposed to be, I absolutely don&#x27;t get why you&#x27;d choose a subset and still have it behave differently than the Go counterpart. For me that destroys the whole purpose of the project.
  • jimgill6 hours ago
    Might this help in memory leaks in go ... what will happen to the code that translated to pointers ....wrong conversation...CODE CRASH??
  • Surac6 hours ago
    I seem too stupid. Why not use C11 in the first place? Can anyone explain?
  • matthewmueller7 hours ago
    Love the design considerations here!
  • vaughan7 hours ago
    We need this for TypeScript.
  • WalterBright6 hours ago
    Translating code to C usually results in some nearly unreadable code. I submit the C++ to C translator, cfront, as evidence. I&#x27;ve looked into using C as a target backend now and then, but always &quot;noped&quot; out of it.<p>I was pleasantly surprised to discover, however, that C code can be readily translated to D.
    • Someone4 hours ago
      I don’t think that’s a valid comparison. It compares two entirely different cases.<p>In general, if the guts of Foo are similar to those of Bar, translating Foo to Bar is fairly easy.<p>If Foo has additional guts, as in the C++-to-ℂ translator, translating those parts can lead to hard to read code.<p>In the C-to-D translator case, it’s not Foo that has additional guts, though, but Bar.<p>Then, a reasonable 1:1 transaction is easy. Doing it in idiomatic style can still be hard, though. For example D has garbage collection, classes and inheritance. I doubt the readily translation of C to D will replace C equivalents (e.g. a garbage collector written in C that’s part of the code) by those where possible.
  • Onavo10 hours ago
    Does it work with the preprocessor?
  • MegagramEnjoyer9 hours ago
    This is a bit too barebones. At least bring goroutines dude
  • Sarthakofficial7 hours ago
    [flagged]
  • melodyogonna4 hours ago
    [dead]