Publish a post about compiler error reporting & change links to own git forge

This commit is contained in:
Konstantin Nazarov 2024-09-12 00:12:15 +01:00
parent 06d41801d8
commit 83b7cc0385
Signed by: knazarov
GPG key ID: 4CFE0A42FA409C22
21 changed files with 69 additions and 22 deletions

View file

@ -1,7 +1,7 @@
# My personal website # My personal website
This is source code for [knazarov.com](https://knazarov.com), my personal website. This is source code for [knazarov.com](https://knazarov.com), my personal website.
It is written mostly in bash, and uses [markdown.awk](https://git.sr.ht/~knazarov/markdown.awk) to convert It is written mostly in bash, and uses [markdown.awk](https://git.knazarov.com/knazarov/markdown.awk) to convert
markdown posts and pages to HTML. markdown posts and pages to HTML.
The site has very minimal CSS (about 110 lines) that should be enough to display fine in most browsers The site has very minimal CSS (about 110 lines) that should be enough to display fine in most browsers

View file

@ -3,7 +3,7 @@ X-Note-Id: 19a3f09f-467c-4ba5-ba58-fd954cd931ea
Subject: A fuzzy launcher I use for the last 2 years Subject: A fuzzy launcher I use for the last 2 years
X-Slug: a_fuzzy_launcher_i_use X-Slug: a_fuzzy_launcher_i_use
About 2 years ago, I decided to write [my own launcher](https://git.sr.ht/~knazarov/q.sh). About 2 years ago, I decided to write [my own launcher](https://git.knazarov.com/knazarov/q.sh).
It's been originally for [Yabai](https://github.com/koekeishiya/yabai) It's been originally for [Yabai](https://github.com/koekeishiya/yabai)
WM, which is a tiling WM for the mac. I wrote it because at the time there were no satisfactory replacements to dmenu/rofi WM, which is a tiling WM for the mac. I wrote it because at the time there were no satisfactory replacements to dmenu/rofi
that suited my personal needs. Right now I use it with Linux, because it's fully portable. that suited my personal needs. Right now I use it with Linux, because it's fully portable.
@ -28,4 +28,4 @@ To be fair, some other people have come to roughly the same idea.
See [sway-launcher-desktop](https://github.com/Biont/sway-launcher-desktop) for example. I just don't think that other people See [sway-launcher-desktop](https://github.com/Biont/sway-launcher-desktop) for example. I just don't think that other people
went as far as to add prefix commands and extensibility. went as far as to add prefix commands and extensibility.
If you want to read through the code, you can find it [here](https://git.sr.ht/~knazarov/q.sh). If you want to read through the code, you can find it [here](https://git.knazarov.com/knazarov/q.sh).

View file

@ -21,7 +21,7 @@ all the basic options may be hard for NixOS novices. So if for some reason you c
feel free to peruse. feel free to peruse.
Note that nixpkgs tend to evolve, and it may stop working for you if you're reading this a long time after the post has been Note that nixpkgs tend to evolve, and it may stop working for you if you're reading this a long time after the post has been
made. Hopefully, by that time my Nix configuration will be available at [git.sr.ht/~knazarov](https://git.sr.ht/~knazarov/). made. Refer to the latest configuration in [git.knazarov.com/knazarov/nixos](https://git.knazarov.com/knazarov/nixos).
``` ```
{ config, pkgs, ... }: { config, pkgs, ... }:

View file

@ -17,7 +17,7 @@ rewrite that has lots of things implemented natively, and which shares those nat
The common part now lives in the [Rust SDK](https://github.com/matrix-org/matrix-rust-sdk), that would be a reference The common part now lives in the [Rust SDK](https://github.com/matrix-org/matrix-rust-sdk), that would be a reference
implementation of the client from now on. implementation of the client from now on.
I've configured the new sliding-sync [on my server](https://git.sr.ht/~knazarov/nixos/tree/master/item/nodes/knazarovcom/configuration.nix) I've configured the new sliding-sync [on my server](https://git.knazarov.com/knazarov/nixos/src/branch/master/nodes/knazarovcom/configuration.nix)
and Element X connected to it without any major issues (except maybe slow initial history sync). The app feels a lot and Element X connected to it without any major issues (except maybe slow initial history sync). The app feels a lot
snappier overall. snappier overall.

View file

@ -36,7 +36,7 @@ lexical scope, source code location, or any other custom metadata. You can "pack
syntax objects if you want to really fiddle with a low-level representation. Scheme also uses syntax objects if you want to really fiddle with a low-level representation. Scheme also uses
syntax objects for hygienic macro system, but that's out of scope for me right now. syntax objects for hygienic macro system, but that's out of scope for me right now.
Since I want [Valeri](https://git.sr.ht/~knazarov/valeri) to be friendly, I've taken a stab Since I want [Valeri](https://git.knazarov.com/knazarov/valeri) to be friendly, I've taken a stab
at implementing syntax objects. To play with them in the REPL, you can do as follows: at implementing syntax objects. To play with them in the REPL, you can do as follows:
``` ```

View file

@ -3,7 +3,7 @@ X-Note-Id: 175bdac4-8655-4b75-8205-f44b7311daa0
Subject: First real program compiled with Valeri Subject: First real program compiled with Valeri
X-Slug: first_real_program_compiled_with_valeri X-Slug: first_real_program_compiled_with_valeri
I've reached my first significant milestone with [Valeri](https://git.sr.ht/~knazarov/valeri). I've reached my first significant milestone with [Valeri](https://git.knazarov.com/knazarov/valeri).
It can now compile something useful to bytecode and then execute it in the virtual machine. It can now compile something useful to bytecode and then execute it in the virtual machine.
As an example, I've implemented a simple recursive factorial function: As an example, I've implemented a simple recursive factorial function:

View file

@ -75,4 +75,4 @@ It reads almost plain English, doesn't it? This is due to most of the existing s
And best of all, NixOS has good integration with [sops](https://github.com/getsops/sops) that allows you to store secrets And best of all, NixOS has good integration with [sops](https://github.com/getsops/sops) that allows you to store secrets
in an encrypted form in a git repository, and easily reference them in the configuration. in an encrypted form in a git repository, and easily reference them in the configuration.
If you're interested, my NixOS configuration can be found [here](https://git.sr.ht/~knazarov/nixos). If you're interested, my NixOS configuration can be found [here](https://git.knazarov.com/knazarov/nixos).

View file

@ -6,7 +6,7 @@ X-Slug: i_now_host_my_own_videos
Today I've launched a separate server that contains my own PeerTube instance: [videos.knazarov.com](https://videos.knazarov.com). Today I've launched a separate server that contains my own PeerTube instance: [videos.knazarov.com](https://videos.knazarov.com).
All videos that I produce will be mirrored there, because I care about giving people an alternative to centralized platforms. All videos that I produce will be mirrored there, because I care about giving people an alternative to centralized platforms.
If you're curious how this is set up, here's [a link to the configuration repo](https://git.sr.ht/~knazarov/nixos/tree/master/item/nodes/videos/configuration.nix). If you're curious how this is set up, here's [a link to the configuration repo](https://git.knazarov.com/knazarov/nixos/src/branch/master/nodes/videos/configuration.nix).
The most interesting part that's not mentioned in the [official wiki article](https://nixos.wiki/wiki/PeerTube) on NixOS is the The most interesting part that's not mentioned in the [official wiki article](https://nixos.wiki/wiki/PeerTube) on NixOS is the
security. The way the article does this will keep the world-readable plain-text passwords in the configuration on the security. The way the article does this will keep the world-readable plain-text passwords in the configuration on the
filesystem. My approach is to use SOPS and use a principle of minimal access permissions, and as such I've figured out how filesystem. My approach is to use SOPS and use a principle of minimal access permissions, and as such I've figured out how

View file

@ -0,0 +1,49 @@
X-Date: 2024-09-11T22:46:56Z
X-Note-Id: 430f7fd9-a6fc-4250-977d-bd15846a4e6a
Subject: Reporting errors from the compilation phase
X-Slug: reporting_errors_from_the_compilation_phase
Latest changes to [Valeri](https://git.knazarov.com/knazarov/valeri) have introduced
significant improvements to error reporting, not only within the parser, but also
within the compiler. Where previously the compiler will error out with a cryptic
"compilation error", it now explains what went wrong and where.
As an example, let's input an incorrect expression in the REPL:
```
valeri> (let (("x" 1)) x)
<stdin>:1:8 Syntax error: Binding name must be a symbol
```
As you can see, it shows you that the error happened in `<stdin>` at a specific
location, and that it is because you specified a variable binding that is not a
symbol.
The same happens when you write the expression to the file, and call the file.
But additionally it will show you the filename:
```
./valeri error_report.vli
error_report.vli:1:8 Syntax error: Binding name must be a symbol
```
There aren't that many syntax errors that you can make in a real program, because
only special forms get this type of treatment (such as function definitions, conditions,
comparison, etc). But it's already quite a bit better than what you may find in other
Lisp flavors. For example, if you do this in Guile:
```
scheme@(guile-user)> (let (("x" 1)) x)
While compiling expression:
Syntax error:
unknown file:1:0: let: bad let in form (let (("x" 1)) x)
```
Alright, it is a "bad let", but why? I guess the poor error reporting in this case is
due to the fact that in Scheme a lot of basic operations like "let" are actually "lowered"
to more primitive things such as lambdas. And this lowering is performed by macros, and
not by special-purpose handlers in the compiler.
I'm sure the error reporing will become 10x harder when I make it to implementing macros.
But as it stands right now, I'm happy with the current implementation for the purpose
of writing simple programs.

View file

@ -89,4 +89,4 @@ So, how fast is this approach? In my preliminary tests, a simple loop from 1 to
takes 0.7 seconds to complete. Which is plenty fast, considering that the VM implementation is naive and has never been takes 0.7 seconds to complete. Which is plenty fast, considering that the VM implementation is naive and has never been
seriously optimized. seriously optimized.
The code for the experimental version can be found [here](https://git.sr.ht/~knazarov/lisp.experimental). The code for the experimental version can be found [here](https://git.knazarov.com/knazarov/valeri).

View file

@ -3,7 +3,7 @@ X-Note-Id: 8bb59a7f-ed5e-4407-b703-d592746e5ca8
Subject: Valeri now has a REPL Subject: Valeri now has a REPL
X-Slug: valeri_now_has_a_repl X-Slug: valeri_now_has_a_repl
If you run [Valeri](https://git.sr.ht/~knazarov/valeri) without any arguments, If you run [Valeri](https://git.knazarov.com/knazarov/valeri) without any arguments,
it now drops you into a REPL, where you can type something like this: it now drops you into a REPL, where you can type something like this:
``` ```

View file

@ -3,7 +3,7 @@ X-Note-Id: b5ba6437-5fe2-4d01-8dc5-3efe8587e728
Subject: Valeri REPL became actually useful (and keeps state) Subject: Valeri REPL became actually useful (and keeps state)
X-Slug: valeri_repl_became_useful X-Slug: valeri_repl_became_useful
[Valeri](https://git.sr.ht/~knazarov/valeri) REPL has progressed to a state where it can [Valeri](https://git.knazarov.com/knazarov/valeri) REPL has progressed to a state where it can
run multiple sequential statements that can refer to each other's variable and function run multiple sequential statements that can refer to each other's variable and function
bindings. A few examples: bindings. A few examples:

View file

@ -49,5 +49,3 @@ $3 = " ;; Immediate operations (64-bit signed int)
``` ```
Now, this is much better! We can see that the `cursor` object represents a string, and contains assembly code. The `source prettyprint.py` here is an instruction to GDB to load my pretty-printer. Now, this is much better! We can see that the `cursor` object represents a string, and contains assembly code. The `source prettyprint.py` here is an instruction to GDB to load my pretty-printer.
The code of the pretty-printer is not yet fully complete, but you can find it here: [prettyprint.py](https://git.sr.ht/~knazarov/lisp.experimental/tree/master/item/prettyprint.py)

View file

@ -3,7 +3,7 @@ X-Note-Id: 4c9287dc-53f7-4a1d-8bd8-9edbff143200
Subject: VM progress update: flexible arena, ASAN and gcov Subject: VM progress update: flexible arena, ASAN and gcov
X-Slug: vm_progress_update_arena_asan_gcov X-Slug: vm_progress_update_arena_asan_gcov
This is another post in the series where I talk about what's new in the [virtual machine](https://git.sr.ht/~knazarov/lisp.experimental) This is another post in the series where I talk about what's new in the [virtual machine](https://git.knazarov.com/knazarov/valeri)
I'm working on. I'm working on.
Today let's discuss memory allocation. In a typical garbage-collected language, the memory that is allocated for the language objects Today let's discuss memory allocation. In a typical garbage-collected language, the memory that is allocated for the language objects

View file

@ -116,4 +116,4 @@ After ironing out the basics, I would probably work on the dynamic linking and i
a C FFI. This is needed to give the code executing in the virtual machine ability to call a C FFI. This is needed to give the code executing in the virtual machine ability to call
external functions (like filesystem access, network and others). external functions (like filesystem access, network and others).
As usual, the experimental code can be found [here](https://git.sr.ht/~knazarov/lisp.experimental). As usual, the experimental code can be found [here](https://git.knazarov.com/knazarov/valeri).

View file

@ -3,7 +3,7 @@ X-Note-Id: 3a07c153-0d26-402e-b0b4-626dfdcf38fc
Subject: VM progress update: data segment and constants Subject: VM progress update: data segment and constants
X-Slug: vm_progress_update_data_segment_and_constants X-Slug: vm_progress_update_data_segment_and_constants
Today I'd like to introduce another addition to the [virtual machine](https://git.sr.ht/~knazarov/lisp.experimental) Today I'd like to introduce another addition to the [virtual machine](https://git.knazarov.com/knazarov/valeri)
I'm working on: the data segment. I'm working on: the data segment.
Let's first take a look at why this is necessary. Here's a piece of assembly code that multiplies 2 by 2: Let's first take a look at why this is necessary. Here's a piece of assembly code that multiplies 2 by 2:

View file

@ -81,4 +81,4 @@ also be returned as a "frozen pointer", just with an adjusted offset from the st
So far, I've implemented most of the required data structures, but haven't finished the access layer completely, So far, I've implemented most of the required data structures, but haven't finished the access layer completely,
so no transparent load/stores yet. Stay tuned for the updates. so no transparent load/stores yet. Stay tuned for the updates.
The code for the experimental version can be found [here](https://git.sr.ht/~knazarov/lisp.experimental). The code for the experimental version can be found [here](https://git.knazarov.com/knazarov/valeri).

View file

@ -65,5 +65,5 @@ The API is in place, so the next step would be to add a few instructions to the
that can call memory allocations, and write an inefficient merge sort (the one that would that can call memory allocations, and write an inefficient merge sort (the one that would
copy sub-ranges). copy sub-ranges).
As usual, the code can be found [here](https://git.sr.ht/~knazarov/lisp.experimental) As usual, the code can be found [here](https://git.knazarov.com/knazarov/valeri)
(note that it's experimental, so don't expect any clarity). (note that it's experimental, so don't expect any clarity).

View file

@ -93,4 +93,4 @@ Resolving this problem took a bit of thinking, but eventually I've formulated th
It seems to fit nicely into the whole idea of making the language simple, and doesn't require any custom implementation if you need to use your data structures as keys in dictionaries. Of course, using red-black trees is not without disadvantages: they are slower than hash tables, and would take more memory. But as of now, I feel that this is a good tradeoff to make. It seems to fit nicely into the whole idea of making the language simple, and doesn't require any custom implementation if you need to use your data structures as keys in dictionaries. Of course, using red-black trees is not without disadvantages: they are slower than hash tables, and would take more memory. But as of now, I feel that this is a good tradeoff to make.
At the time of writing this post, I've finished a simple implementation of a red-black tree in C, and plugged it into the dictionary implementation of my language. As usual, you can find the code [here](https://git.sr.ht/~knazarov/lisp.experimental). At the time of writing this post, I've finished a simple implementation of a red-black tree in C, and plugged it into the dictionary implementation of my language. As usual, you can find the code [here](https://git.knazarov.com/knazarov/valeri).

View file

@ -42,4 +42,4 @@ If you need a practical guide, take a look at [Crafting Interpreters](https://cr
If you look for inspiration, check out this video: [The most beautiful program ever written](https://www.youtube.com/watch?v=OyfBQmvr2Hc) If you look for inspiration, check out this video: [The most beautiful program ever written](https://www.youtube.com/watch?v=OyfBQmvr2Hc)
My own in-progress programming language can be found [here](https://git.sr.ht/~knazarov/lisp.experimental). My own in-progress programming language can be found [here](https://git.knazarov.com/knazarov/valeri).

View file

@ -91,7 +91,7 @@ sops file-with-secrets.yaml
SOPS has integrations with NixOS (which I care about the most), with Ansible (for provisioning servers), with AWS and other tools. SOPS has integrations with NixOS (which I care about the most), with Ansible (for provisioning servers), with AWS and other tools.
It looks as if [Hashicorp Vault](https://www.hashicorp.com/products/vault) was reduced to a set of simple core principles. It looks as if [Hashicorp Vault](https://www.hashicorp.com/products/vault) was reduced to a set of simple core principles.
If you're interested, [here are some of my personal passwords](https://git.sr.ht/~knazarov/nixos/tree/master/item/secrets.yaml) If you're interested, [here are some of my personal passwords](https://git.knazarov.com/knazarov/nixos/src/branch/master/secrets.yaml)
stored as a SOPS-encrypted file. stored as a SOPS-encrypted file.
It is also possible to use GPG for encrypting the passwords stored with [pass](https://www.passwordstore.org/) because it uses It is also possible to use GPG for encrypting the passwords stored with [pass](https://www.passwordstore.org/) because it uses