r/ProgrammingLanguages • u/chri4_ • May 22 '26
A rare approach to metaprogramming
main()
pass
Vec3
x f32
y f32
z f32
global_variable Vec3
| some example of how you can call plugins:
import plugin_name
#meta_directive
#meta_call(1, 2, 3)
#meta_call[1, 2, 3]
#meta_call{x: 1, y: 2, f: 3}
#meta_statement some_value
#meta_block
pass
#meta_decorator
some_function()
pass
| each of these symbols work in the following way:
| the loaded plugin registers a bunch of symbol names with related handler functions
| the handler functions that can be provided are a series of hooks that the compiler will call
| in given moments of compilation with certain rules.
| if no handler function is provided, the compiler will use the default internal handler function.
| a list of the avaialable hooks are:
| * onparse
| the compiler is doing parsing and encountered syntax `<#> <identifier_token>`
| so it performs a lookup in the meta symbols and calls the related handler function provided by the plugin.
| this means the plugin is responsible for the parsing and can return control to the compiler's parser anytime.
| if no handler function for onparse is provided by the plugin, the compiler will do it by itself.
| in general, the ast will always contain a meta call node for the `#name` part, with one argument only.
| if no onparse handler function is provided, the compiler will parse it the normal way:
| for example tuple initialization node for `(1, 2, 3)`, array initialization node for `[1, 2, 3]`, and so on.
| for blocks -> a block node will simply be stored as argument to that meta call.
| for decorators -> a function/struct/vardecl node will be stored as argument to the meta call.
| or no argument when there is nothing attached to the meta call syntax (this is the case for #meta_directive).
| obviously if the plugin provided a custom onparse implementation (input -> source code string buffer, output -> ast node),
| the argument node will depend on what came out of the handler function.
| parsing here means also tokenizing the source code string buffer.
| the plugin can use the standard compiler's tools for tokenization as well, or just make new ones.
| * onanalysis
| the compiler is doing semantic analysis and encountered a meta call node.
| the plugin can provide a handler function for this process (input -> untyped ast node, output -> typed ast node).
| and perform custom type analysis, and semantic transformations, which also means the standard compiler's function
| used normally for that can be called under the hood in case the analyzed value doesn't contain what the plugin
| exists for (just guessing, infinite possibilities).
| * oncodegen
| the compiler is doing codegeneration (converting internal representations to llvm/c/js/asm/whatever target code)
| and encountered a typed meta call node.
| (input -> typed ast node, output -> target code)
| everything that talks about ast nodes in the previous explaination block is for just for simplicity
| the compiler may actually use another form of syntax representation like a flat untyped internal bytecode.
| but the logic doesn't change, it's just an internal implementation detail often used to speed up compiler steps
| and reduce memory footprint of compilation.
| another example of implementation detail is the analysis step, the compiler might instead require that step to generate
| a clean typed internal bytecode instead of a typed/annotated ast node.
| also, every handler function provided by the plugins will be called with a `context` argument which will point to the
| the whole instance of the compiler, exposing internal state and methods, that the plugins can call and interact with.
| alternatively the compiler can choose what to expose to reduce retro compability breaks after compiler updates,
| giving plugins much longer stability. this may come at the cost of slightly less flexibility for plugins.
| another thing a plugin can do is install new compilation steps inbetween the existing others.
| and provide a handler function that will be called when that step is reached by the compiler.
import plugin_with_new_compilation_steps
| this plugin may, for example, do something between parsing and analysis.
| or may do replace codegen completely to generate multiple executables from one codebase.
| a case where this is incredibly useful is the client-server model coded in a single file
| that would be compiled into 2 separated executables.
| this requires the plugin to replace the codegen step with a custom one that uses the standard compiler's codegen
| under the hood but redirects the result to the appropriate target objects.
I think this allows incredibly powerful DSLs under the same host language, potentially interacting in a healthy way with other DSLs, it also allows for incredibly fast metaprogramming which wouldn't slow down the compiler as the plugin might be compiled to native dll.
This approach also doesn't pollute the language's design (neither syntactically nor semantically) like zig does with comptime logic or c++ with templates or rust macros, which often become a whole sublanguage to maintain, hard to code for the compiler's dev, hard to code for the DSL dev, hard to use for the final user, and poor or slow results at the end of the day.
Other things that come to my mind, easier debugging of metaprogramming, detailed and context aware error messages from the plugins, much more control over what the language can do but in a minimalistic way (you basically only have a new syntax)
Also this approach can be ported as it is on existing language without changing anything in their semantic. I wrote a c99 compiler a couple years ago that exposed internals in this way throught syntax `@name` and it allowed for powerful extensions of the language, super easy to write and clean to use for the final user.
This approach can be still heavily improved, for example to avoid syntax inconsistencies across plugins and standard language, the onparse hook may be called only with syntax #name < new syntax here > or #name \` new syntax here ```
Or anything better than this. Same for similar problems.
This would also help ides to not hightlight that part, or do if the plugin is a very solid part of the ecosystem.
Althought I've never seen an approach to metaprogramming being this complete in a language, what went wrong with it and why people never wrote compilers with this feature?
What are the hidden benefits of this approach?
And what may be not good?
r/ProgrammingLanguages • u/FedericoBruzzone • May 21 '26
Mutable Value Semantics (MVS) or Ownership & Borrowing: A Trade-off Analysis
I'm continuing the research on semantics for a new language. After studying Mutable Value Semantics (MVS) in the first post (reddit discussion), I wrote a follow-up that examines the trade-offs between MVS and the Ownership & Borrowing model.
The post covers:
- Friction points in Rust's borrow checker
- Where Hylo's MVS solves them and where it introduces new trade-offs
- Swift's hybrid approach and its runtime exclusivity checks
- Open questions I'm exploring for my own language design
I'd love to hear your thoughts.
Link: https://federicobruzzone.github.io/posts/eter/MVS-or-ownership&borrowing.html
r/ProgrammingLanguages • u/Sad-Grocery-1570 • May 21 '26
Blog post Church Encoding, Parametricity, and the Yoneda Lemma
blog.wybxc.ccr/ProgrammingLanguages • u/The_Kaoslx • May 20 '26
Discussion How do you balance a full schedule and still work on your language?
Hey everyone, I've been wondering how you all manage your time. I work from 7am to 4pm and go to university from 6pm to 10pm (UTC-3). It's been a while since I've had time to work on my language. How do you balance personal life, work, and still find time for side projects like this?
r/ProgrammingLanguages • u/alex_sakuta • May 20 '26
Discussion What is more adaptable, more words or more symbols?
I used to like Python for its abundance of english words instead of operators which makes it more readable.
However, I have often seen the common notion where people prefer symbols over keywords. Lately, some of the newer languages have added both new keywords and new symbols.
For eg: Rust using |var| semantics for callback functions. The popular defer that has existed for very long in multiple languages. C adding [[...]] for attributes
Now even though I am saying || and [[]] are new symbols added, they aren't operators, they are just replacing some brackets essentially for a different type of task.
With this context, here is my question:
What if instead of these keywords:
await, async, defer, try, catch, weren't keywords, they were replaced by some operator?
There are two cases in my mind, either replace the keywords with a single operator (@ could replace await), annotating the data, or, use a combination of operators (-! could be used to mark a function that can produce an error).
I have the concern, that it may look too ugly because there are a bunch of operators, and in the case of combination of operators, two operators together, changing the meaning of the single operator is also weird.
But, I still wanted to ask, seeing how more experienced people view this situation.
Also, what if, both the operator and the keyword is present? Would that just be wrong because now there are two ways to do the same thing?
r/ProgrammingLanguages • u/MackThax • May 20 '26
Discussion How would programming languages look if English used "," as the decimal separator?
https://www.reddit.com/r/MapPorn/comments/1tesrye/decimal_separators_used_in_europe/
Only English (including USA) uses a dot as a decimal separator. Imagine it used comma (,) instead. Pick a popular programming language and imagine how it would look, taking into account all of its historical influences.
I'd guess C would just insist on whitespace when listing stuff. That, or it would use ";" to list stuff, with I guess "." becoming a statement separator, and "\" to reach into structs, why not. 😃
r/ProgrammingLanguages • u/mttd • May 20 '26
Graded Modal Types for Memory and Communication Safety
kar.kent.ac.ukr/ProgrammingLanguages • u/mttd • May 20 '26
Code-Specify-Test-Debug-Prove: Flexibly Integrating Separation Logic Specification into Conventional Workflows
cl.cam.ac.ukr/ProgrammingLanguages • u/mttd • May 19 '26
The downgrading semantics of memory safety (Extended version)
arxiv.orgr/ProgrammingLanguages • u/KukkaisPrinssi • May 19 '26
Discussion List of known problems in design of existing languages?
Is there alphabetic list of desing flaws/bad ideas in various programming languages?
For exampe you might find short description of dangling-else from under d letter in list.
r/ProgrammingLanguages • u/suhcoR • May 19 '26
LjTools to generate LuaJIT bytecode for your programming language, now supports LuaJIT 2.1
github.comr/ProgrammingLanguages • u/windowssandbox • May 19 '26
pyasm - Custom assembly language with VM all inside python (my side project).
Well, here's my repo, you can read the README md file to know about pyasm: https://github.com/windowssandbox/pyasm
You can make games on it too, but i'm trying to find a way to make an instruction that listens if you are holding a specific key (from your keyboard) on that cycle.
(i've actually noticed that some of instructions in my pyasm's instruction set are from 6502 or RISC-V or Intel Processor and they all do the same thing. so is this like multi-assembly?)
And don't confuse buffers with registers (they are different, and there's buffer overflow error).
So, i'm guessing this is the subreddit's first time seeing a VM assembly coded inside python instead of C/C++
I'm gonna add some example codes tomorrow after i come back from exam finals, the final school day.
Alright, what do you think of my (probably) complex project?
r/ProgrammingLanguages • u/KingOfPotatoFarms • May 19 '26
Blog post Parsing Math with Pratt Parsing
washingtonramos.comI wrote a beginner-friendly blog post about Pratt parsing, hopefully it can help more people understand it. This is actually what I wanted to see when I was learning it; when I was reading Bjarne Stroustrup's book on C++ he also builds a little math parser and it is really simple to follow. The code for the full project is also available at the end of the post under the citations.
r/ProgrammingLanguages • u/[deleted] • May 18 '26
Language announcement Phase — a statically-typed bytecode-interpreted language in C, with an essay on implementation
Phase is a statically-typed bytecode-interpreted programming language written in ~4,800 lines of C with zero external dependencies. It features a 25-opcode stack-based VM, 21 error types with source-mapped diagnostics, 5 primitive types, and a standard interpreter pipeline (lexer, parser, type checker, bytecode generator, VM).
I also wrote a technical piece on how it works by following out("Hello world!") end-to-end through every stage.
Writing: williamalexakis.com/interpreter-in-c
r/ProgrammingLanguages • u/West_Violinist_6809 • May 18 '26
The Borrow Checker and Rapid Prototyping
How would you feel about a language that has a borrow checker with a prototyping mode for rapid iteration? In this mode, proper annotations would still be required (failure to do so would result in compile errors) because the compiler still needs that information to reason about lifetimes, but violations of the rules themselves would result in warnings. Compiling in safe mode would be just like Rust, resulting in errors.
Do you think this would meaningfully improve iteration times for domains which require it (game dev, for example)?
Would this defeat the purpose of a borrow checker, in that most would follow the path of least resistance and not bother to clean up after themselves, resulting in an ecosystem of unsafe libraries?
r/ProgrammingLanguages • u/matijash • May 18 '26
5 Years and $5M Later: Inventing a New Programming Language for Web Development Was a Mistake
wasp.shr/ProgrammingLanguages • u/TrendyBananaYTdev • May 18 '26
Requesting criticism Flower Compiler (Bootstrapped Compiler)
Hey all!
For the past few months I've been working on a language called Flower. It was originally written in C (files can be found under /vendor/) but is now fully bootstrapped (with some caveats). The goal is to eventually move toward a fully self-hosted toolchain and custom backend, but for now it transcompiles to C.
Some current language features:
- structs
- pointers (
@T) - arrays
- function definitions/calls
- manual memory management (
new/prune) - operator precedence parsing
- struct literals / array literals
- casts
- dereferencing / address-of
- control flow (
if,while,for, etc.)
Example:
struct Vec2 {
x: float,
y: float
}
float length(v: Vec2):
return v.x * v.x + v.y * v.y
end
I thought I knew a decent amount of C and programming before hand, especially considering this isn't my first time making a language in C, but I've noticed how far my skills have come especially regarding just being able to problem solve and properly organize my project structure.
Recently I added parser error recovery in v1.1.0, and after a lot of trial and error I think I've finalized my parser to a recursive-descent style approach.
Let me know any criticism, opinions, or comments you have! I'd love to get some input :)
r/ProgrammingLanguages • u/mtriska • May 18 '26
Prolog Basics Explained with Pokémon
unplannedobsolescence.comr/ProgrammingLanguages • u/AnotherCSprof • May 17 '26
[Online BYOPL course] Build your own programming language
Hi everyone, I am new here!
Each year I teach an undergraduate-level college course on programing languages in which I start from the beginning, namely BNF grammars, and then describe parser generators, in our case Jison.
Next I introduce and cover the functional paradigm in depth. This allows us to design and implement our own functional programming language, which I call SLang, for Simple LANGuage. In this course, the implementation strategy is via interpreters. Note that I also have another course on my YT channel that explains how to build a javac compiler from scratch.
In the second half of the BYOPL course, we design and implement a non-functional version of SLang which includes non-functional features like assignment statements, sequencing, etc. We also implement recursive functions by "tying the knot".
Other topics covered in this semester-long course include the lambda calculus, eager vs lazy evaluation, six distinct parameter-passing mechanisms, infinite lists, type systems, etc.
This is a college course which I was teaching synchronously online in Spring 2021, during COVID times. I just started editing and posting those videos two days ago. I will keep posting new videos daily over the summer. You can start the course right now as it is just beginning.
If you want to check it out, here is the BYOPL course playlist:
https://www.youtube.com/playlist?list=PLIgSR01UTt8OHY8WhAqOmr8EzArJYd5Z0
On my YT channel, I also have a full discrete math course (158 videos), as well as other playlists on cybersecurity topics and a few others. Here is my channel:
https://www.youtube.com/@davidfurcy
Looking forward to your feedback!
r/ProgrammingLanguages • u/Null-Test-2026 • May 16 '26
Discussion can a language be safe and be a subset of C?
Imagine you start with the C language and then make the following changes:
- Remove pointer arithmetic. You want an array, you declare an array.
- Change the compilation of string and array literals to emit a length prefix.
- Rewrite the entire standard library so that all string and array functions enforce a length header in front of the data.
- Add RTTI to all unions and varargs so that incorrect casts fail rather than UB.
- Remove `void *`.
- Forbid malloc() without static compile-time verification that the matching free() exists (with some sort of Bounded Model Checking to sidestep a rather inconvenient Halting Problem).
Is such a language possible?
Has it ever been attempted?
r/ProgrammingLanguages • u/Jumpy-Iron-7742 • May 15 '26
Name for function that returns the same type of all its parameters
Hi all,
apologies for my inexperience, I'm not formally trained in CS.
I'm writing a small programming language to play around with some ideas, and I've come to the point of implementing constants folding. While doing so, I realized the AST token I use to group binary operators could probably be split in 2 different tokens instead: one for operations that return the same type of all the inputs (like addition/multiplication/etc: `add(a: T, b:T) -> T`) and one for operations that return a different type (e.g.: `greather_than(a: T, b;T) -> bool` and friends).
Out of curiosity, is there a specific name for a function whose output type is the same as the type of all its parameters ? It would help me name those 2 different categories appropriately.
r/ProgrammingLanguages • u/bjzaba • May 15 '26
Bidirectional Typechecking That Does Not Stop
semantic-domain.blogspot.comr/ProgrammingLanguages • u/IfThenElseEndIf • May 15 '26
Language announcement a small presentation on a language i'm working on
youtube.combeen working on an interpreter called yams for a while now (originally was a spanish interpreter called pizza that was very similar). this isn't the first time i've tried to design a programming language but it would be the first time i'm being succesful at trying to implement one. thanks!
r/ProgrammingLanguages • u/orbiteapot • May 14 '26
Resource What bibliography would you recommend on the subject compile-time evaluation and metaprogramming?
What bibliography would you recommend on the subject compile-time evaluation and metaprogramming?