TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

I wrote my own “proper” programming language (2020)

93 点作者 upmind4 个月前

8 条评论

Timwi4 个月前
I&#x27;m so excited to see that the idea of creating new programming languages is getting more popular. There is definitely a lot of space in which to explore more creativity; we haven&#x27;t even remotely begun to scratch the surface of what&#x27;s possible!<p>I just wish more tooling existed that was language-agnostic so that it&#x27;s easier to get off the ground with something “serious”. I&#x27;m talking debuggers, parse-tree-aware diffs, autocompletion like Intellisense, etc.
评论 #42812444 未加载
评论 #42812654 未加载
评论 #42811776 未加载
评论 #42817331 未加载
评论 #42811994 未加载
norir4 个月前
This is one way to write a compiler. One of the large tradeoffs made is extensive use of libraries on both the front and backends. It&#x27;s a practical choice but also means that the compiler itself is also likely somewhat slow. Targeting LLVM alone is a choice that will guarantee that code gen is slow (you pay for a lot of unneeded complexity in llvm with every compile).<p>When you master the principles of parsing, it is straightforward to do in any language by hand with good performance. It is easy to write a function in any language that takes a range string, such as &quot;_a-zA-Z&quot; and returns a table of size 256 with 65-90, 95 and 97-122 set to 1 and the rest set to zero. You can build your parser easily on top of these tables (this is not necessarily optimal but it is more than good enough when you are starting).<p>For the backend, you can target another language that you already know. It could be javascript, c or something else. This will be much easier than targeting llvm.<p>Start with hello world and build up the functionality you need. In no more than 10k lines of code (and typically significantly less), you can achieve self hosting. Then you can rewrite the compiler in itself. By this point you have identified the parts of the language you like and the parts that you don&#x27;t or are not carrying weight. This is the point at which maybe it makes sense to target llvm or write a custom assembly backend.<p>The beauty of this approach is you keep the language small from the beginning without relying on a huge pile of dependencies. For a small compiler, you do not need concurrency or other fancy features because the programs it compiles are almost definitionally small.<p>Now you have a language that is optimized for writing compilers that you understand intimately. You can use it to design a new language that has the fancy things you want like data race protection. Repeat the same process as before except this time you start with concurrent hello world and build in the data race protection from the beginning.
atan24 个月前
I probably won&#x27;t create a &quot;proper&quot; programming language but this topic fascinates me. As someone that never even took a compilers class in college I was really happy with the content I found at pikuma.com. The course really helped me understand how a simple programming language works. I&#x27;m sure others might benefit from it too.
评论 #42812432 未加载
dunham4 个月前
I wrote my own language last year[1], ending the year by doing Advent of Code in it, and then translated it to itself in early January (so it&#x27;s now self-hosted). I wanted to see if I could learn how to write a dependent typed language, wanted it to be self hosted, and able to run in a browser.<p>It&#x27;s perhaps not a &quot;proper&quot; language because I targeted Javascript. So I didn&#x27;t have to write the back half of the compiler. Since it&#x27;s dependent typed, I had plenty of work to do with dependent pattern matching, solving implicits, a typeclass-like mechanism, etc.<p>Next I may do a proper backend, or I may concentrate on the front end stuff (experiment with tighter editor integration, add LSP instead of the ad hoc extension that I currently have, or maybe turn it into a query-based compiler). Lots of directions I could go in.<p>At the moment, I&#x27;m looking into lambda-lifting the `where` clauses (I had punted lambda lifting to JS), and adding tail call optimization. I lost Idris&#x27; TCO when I self-hosted, so I currently have to run the self-hosted version in `bun` (JavaScriptCore does TCO).<p>[1]: <a href="https:&#x2F;&#x2F;github.com&#x2F;dunhamsteve&#x2F;newt">https:&#x2F;&#x2F;github.com&#x2F;dunhamsteve&#x2F;newt</a>
pyrale4 个月前
I&#x27;d be interested to understand the design choices behind using protobuf as an interface with LLVM: in my reasoning, it may be more performant, but that serialization step is a very small part of compute, and the serialization format is unusable by humans. For debug purposes, it&#x27;d have been nice to have a more human-friendly format. Did the project have other constraints?
评论 #42811367 未加载
评论 #42812026 未加载
mistrial94 个月前
there was a guy on a large science team that wrote the &quot;programming language&quot; for that system.. there was a system of dispatch for &quot;verbs&quot; in the system, and it was large.. there were maybe 20 full time engineers building other parts, all the time. The guy who wrote the &quot;language&quot; was a sports guy with a swim background. For years, five days a week, he would get up before dawn and train swimming, then he would arrive at work at 9am and work on the code system.. every day.. for years. It was admirable in a way but also slavish
gjadi4 个月前
His progression is wild. Going from top Cambridge graduate in 2021 to Staff Eng at META in 3y. Nice!
fjfaase4 个月前
If you want to design your own language, you might want to start with IParse Studio, an interactive online parser that parses input according a grammer at every keystroke returning a parse tree, if the input can be parsed according the grammar.<p>Once you have the grammar, you can use it with IParse developed in C++, which produces an abstract parse tree.<p>IParse has a build-in scanner for C like terminals, which are now used in many languages. You can implement your own scanner. IParse also has an unparser, which allows you to generate pretty printed output with just some annotations in the grammar.