*Update on the Mu computer's memory-safe language*

Progress has been slow over the holiday season because I've been working on a paper about Mu for 2020.programming-conference.or

But functions can now return outputs.

```
fn foo a: int -> result/eax: int {
result <- copy a
increment result
}
```

Project page: github.com/akkartik/mu#readme

Sources for the memory-safe language, now at 5kLoC: akkartik.github.io/mu/html/app

Caveats: no checking yet, only int types supported.

*Update on the Mu computer's memory-safe language*

Still no type-checking or memory-safety, but we can now write any programs with int variables.

There's still no 'var' keyword, so we can't define local variables yet. But that's not insurmountable; just pass in extra arguments for any space you want on the stack 😀

```
result <- factorial n 0 0 0
```

Show thread

*Update on the Mu computer's memory-safe language*

Basic language is done! Here's factorial. (Compare mastodon.social/@akkartik/1027.)

Still todo:
- user-defined types
- type checking and memory-safety

In other words, I'm about a third of the way there 😂 More detailed todo list: lobste.rs/s/pv8jpr/what_are_yo

(More details on the Mu project: akkartik.name/post/mu-2019-1. Repo: github.com/akkartik/mu)

Show thread

A brief timeline of the Mu computing stack

Jul 6, 2014: commit 0, tree-based interpreter for a statement-oriented language (github.com/akkartik/mu)

Jul 19, 2017: commit 3930, start of SubX machine code (akkartik.name/post/mu-2019-1)

Sep 20, 2018: started building SubX in SubX (mastodon.social/@akkartik/1007)

Jul 24, 2019: SubX in SubX done, commit 5461 (mastodon.social/@akkartik/1024)

Oct 2, 2019: started designing the Mu memory-safe language (akkartik.name/post/mu-2019-2)

Oct 29: started akkartik.github.io/mu/html/app

Show thread

I'll be in Porto, Portugal on Mar 24 to present a paper on Mu at the Convivial Computing Salon: 2020.programming-conference.or

Hoping for some great conversation and disagreements.

Show thread

*Update on the Mu computer's memory-safe language*

Mu just got its first couple of non-integer types: addresses and arrays. As a result, the factorial app can _finally_ run its tests based on command-line args.

akkartik.github.io/mu/html/app

Addresses are accessed using a '*' operator. Arrays are accessed using an 'index' instruction that takes an address (addr array T) and returns an address (addr T).

Literal indexes aren't supported yet.

Open q: indexing arrays of non-power-of-2 element sizes.

Show thread

*Update on the Mu computer's memory-safe language*

Still no type-checking or memory-safety, but we have partial support for arrays and product types. Still several sharp edges:

- can't index an array with a literal
- can't index an array with non-power-of-2-sized elements
- can allocate but not use arrays/records on the stack

My todo list is growing. But work per item is shrinking. Hopefully there's an asymptote.

(More details: akkartik.name/post/mu-2019-1. Repo: github.com/akkartik/mu)

Show thread

*Update on the Mu computer's memory-safe language*

Arrays and product types are now done. Any remaining rough edges are working as intended 😄 Only hex literals, for example.

What's left? Actually making it safe.

Complexity outlay so far: 16k lines of code, but only 6.5k if you exclude tests. Tests get _very_ repetitive in machine code. Hopefully we won't need another 15k LoC.

Example program: akkartik.github.io/mu/html/app

(More details: akkartik.name/post/mu-2019-2. Repo: github.com/akkartik/mu)

Show thread

The Mu compiler summarized in one page: akkartik.github.io/mu/html/mu_

More details: akkartik.name/akkartik-convivi

Repo: github.com/akkartik/mu

(Brief update since there isn't much to report: I'm working on safe heap allocations as described in the paper. But it's slow going because of life and the need to unwind some past decisions.)

Show thread

I'm back from a death march.

Mu is a safe language built in machine code, translating almost 1:1 to machine code. A key check is for use-after-free errors, using a second address type (akkartik.name/akkartik-convivi, section 4.4)

I spent the last 2 months switching all of Mu's implementation to this scheme. It was a tough time: lobste.rs/s/vcx5vu/what_are_yo. But now I know it works (with 10-15% slowdown), and Mu functions calling low-level libraries should behave unsurprisingly.

github.com/akkartik/mu

Show thread

I'm starting to build some simple apps in Mu, my memory-safe language that translates 1:1 to machine code.

Today I built a program to print a file to screen: akkartik.github.io/mu/html/app

Experience report: github.com/akkartik/mu/commit/

Also:
- I fixed a bug in the process: github.com/akkartik/mu/commit/
- I wished I already had clobbered-variable warnings.
- I wished I had type checks.

All in all, this language isn't ready for others yet. I'm constantly inspecting the code generated by the translator.

Show thread

A new day, a new app

A text-mode paginator for text files. Think `more`, but no ncurses, no termbox, no libc, just Linux syscalls.

2-minute demo video: archive.org/details/akkartik-2

App sources: akkartik.github.io/mu/html/app

Repo: github.com/akkartik/mu

Show thread

It's amazing how much you can do layout-wise with just plain text. Pictured in this toot:

Alice in Wonderland by Lewis Carroll

Poems by e e cummings (en.wikipedia.org/wiki/E._E._Cu)

Show thread

My text-mode paginator for text files implemented all the way up from machine code now supports a tiny subset of Markdown syntax. Screenshots below.

The code is terribly ugly, and there are zero tests. But it did help flush out three bugs in Mu. Next steps:

- Build out the compiler checks I missed the most.
- Implement a fake screen and keyboard so I can write tests for this app.
- Throw the app away and redo it right.

(Background: akkartik.name/akkartik-convivi. Repo: github.com/akkartik/mu)

Show thread

Why do programming languages require us to specify what modules we use? I think that stuff is easy to deduce. Even in machine code.

archive.org/details/akkartik-2

cc @s_ol

Show thread

I spent the last few days implementing a 'byte' type in Mu.

For the most part, Mu is exclusively 32-bit. No long/short nonsense here. However, I do like strings. Eventually even UTF-8 strings. So, minimal byte support. Mostly they behave like 32-bit values. You can't store them on the stack. (Because x86 reasons.)

As a test, I built a little calculator app: akkartik.github.io/mu/html/app. This app also shows off multiple return values.

Read more: github.com/akkartik/mu

cc @s_ol

Show thread

*Update on the Mu computer's memory-safe language*

Mu now checks all function calls.

Pass in the wrong type = error.
Save a result to the wrong type = error.
Save a result to the wrong register = error.

There are automated tests for error messages.

I estimate this change protects against 60% of the most common mistakes. Checking the most recent variable in a register should provide another 20%. And I hopefully have TODOs for the remainder to gradually whack away.

github.com/akkartik/mu

Show thread

*Update on the Mu computer's memory-safe language*

Mu now checks for most variable accesses if the variable is still live, and it's register hasn't been clobbered by some other variable. The extra-burdensome parts of programming in Mu are hopefully now not very burdensome.

Next up: testable syscalls for screen and keyboard. But I might take a break first. My RSI has been acting up.

github.com/akkartik/mu

Show thread
Follow

@akkartik oh no! take care of yourself, RSI is priority #1

· · Web · 0 · 0 · 1
Sign in to participate in the conversation
- = > NerdCulture < = -

All friendly creatures are welcome. Be excellent to each other, live humanism, no nazis, no hate speech. Not only for nerds, but the domain is somewhat cool. ;) No bots in general! (only with prior permission)