Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> Programming language that compiles into a x86 ELF executable.

> a compiler somewhat resembling C

> Add new or borrow from other language(s) features ontop of C, deviate away from just C

  function strlen(const char *s)
This does not appear to be a C compiler. The title should reflect this.


The main goal at the moment is to create a C compiler, the function keyword there is just a placeholder for the time being. At the moment anything returned is just mov'd into the EAX register and then stored in a local variable if called that way.


If you're looking for C-like languages to study look up the plan 9 Alef language. It was a concurrent C-like that was designed to replace C until they realized its better off as a C library which is what plan 9's thread(2) is. It's mostly extinct but survives:

http://doc.cat-v.org/plan_9/2nd_edition/papers/alef/

https://seh.dev/go-legacy/


Worth pointing out Plan9's C was itself sort of its own language. I think it was a strict subset, but I can't remember all the details. The preprocessor was much simpler, that much I remember.


Not exactly a subset, there were at least the anonymous struct/union members that partially made it into C11 much later.

But then if we look beyond the syntax almost any C implementation is “its own language” in that it defines behaviour the standard doesn’t specify, and frequently also changes behaviour the standard does, if in minor ways. Like how the Windows ABI forces a noncompliant wchar_t.

(Even if we look at the preprocessor, the classic algorithm implemented in most places [that I can’t be bothered to find a link for] in fact expands more than the standard strictly guarantees, e.g. you can sometimes get recursive expansion out of it by creative use of token pasting,—I remember reading the ANSI committee thought the case was too “perverse” and didn’t specify anything [no link here as well, sorry... poke me again if you actually care about this]. The standalone preprocessor mcpp has warnings about this specification hole, but other implementations don’t as far as I know. And you’d think the preprocessor, an almost purely syntactic thing, wouldn’t have implementation differences worth keeping around.)


Yes, Plan 9 c has its own C library which does not follow ANSI/ISO though it is very similar to ISO C. Its syntax is pretty much c89 and the useful bits of c99. To build ANSI/POSIX you use the APE (ANSI/POSIX Environment) compilers and libraries which are built in. It's only reason for existing is to help with porting Unix baggage.

The compiler is kencc which is why it is different. Plan 9 also still uses a.out for binary images.


Looks really interesting, thanks for sharing this.

I'm not sure whether I'll incorporate everything from C or just make it compatible with C and behind the scenes do things differently e.g instead of carrying const char */string pointers everywhere always carry the length of said data structure along with it. Or for instance push an additional pointer on the stack for memory zones, where an allocator is always present and knows it's context, sort of like __thiscall with class methods for this->.


Oh, is _this_ where the inspiration for Go came from? It would explain a lot.


Yes. Even before Alef, Newsqueak (01989) was almost identical to Golang, and of course Alef, Limbo, etc., descend from Newsqueak.


And if the idea is to extend C in some direction, that is what the language I’m working on does: C3 (http://www.c3-lang.org)


Actually they realized Alef was useless without a GC, hence why Limbo on Inferno, Plan 9's sucessor was GC based.

Below taken from https://en.wikipedia.org/wiki/Alef_(programming_language):

Alef appeared in the first and second editions of Plan 9, but was abandoned during development of the third edition.[1][2] Rob Pike later explained Alef's demise by pointing to its lack of automatic memory management, despite Pike's and other people's urging Winterbottom to add garbage collection to the language;[3] also, in a February 2000 slideshow, Pike noted: "…although Alef was a fruitful language, it proved too difficult to maintain a variant language across multiple architectures, so we took what we learned from it and built the thread library for C."[4]


If you are exploring alternatives to the stdlib, you might commit yourself to no zero terminated strings and see where it takes you. A fundamental data type with a pointer, a length and a capacity does a lot to stop buffer overflows.


To replace C-style strings you only need the length! You also get cheap substrings which is such a common operation that it alone IMO makes it worth taking this route.


Can't edit my original reply anymore, but fair point, I've changed the keyword 'function' in the AST to a function return type instead. There's no error handling done yet to check whether the variable receiving the function return data matches the function return type, but it's on my todo list.

https://github.com/riicchhaarrd/ocean/commit/0618e0810c8d437...

Then again in C it would work aswell if you type casted the types.

  const char *f()
  {
      return (const char*)123;
  }

  int main()
  {
      int i = (int)f();
      return 0;
  }


Yeesh. This is probably the most pedantic comment I've read on HN.

Contributes absolutely nothing to the conversation, here.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: