James Livesey

@jthecoder
19 Followers
74 Following
68 Posts
Writing code to change the world Β· Age 21 Β· Software Engineering Apprentice at the BBC, working on @liveg in spare time
Websitehttps://jamesl.me
Twitterhttps://twitter.com/jthecoder
GitHubhttps://github.com/James-Livesey

I was very hesitant to see if I could even return a list from a procedure.

By some miracle, that also works too! And also note the local scoping of `i` in that `for` loop! 😲

Oh yeah, and the good ending is, it works now!

It wasn't a problem with that function itself. What was the problem is that my code was littered with calls to `catto_appendCharToString`, and I was throwing away its return value in each case.

You'll notice in the function declaration that I return the value of `CATTO_REALLOC` β€” AKA `realloc`.

Oh dear.

At first, I thought it would be an issue with my memory allocator again β€” it could possibly be returning the wrong memory addresses or overwriting areas of memory it shouldn't.

Nope, it turns out it's a problem with my use of this function here...

I clicked on 'run' multiple times. Looks like atto didn't work...

(Each line in this console output should be exactly the same.)

Why on Earth is it printing `yoyo`???

Back to the drawing board then. 🫀

I wanted to see how well atto could cope with returning strings from procedures.

(For context, to return something from a procedure, you have to store the return value into a parameter variable, which is basically given by reference.)

So I wrote a simple program to return the string `"yo"` with the value of `n` appended to it.

If you call `free` multiple times for a contiguous set of memory blocks, then the next call to `malloc` will attempt to stitch together those individual free blocks into a larger free block before attempting allocation.

Here's a hastily-drawn diagram to show you what I mean.

For a bit of background, I've been trying to get a web version of my atto programming language working correctly with all sorts of advanced features, like procedures with scoped variables.

It works by running catto (my C implementation of atto) in a WebAssembly module, which is then wrapped with JavaScript.

(Sounds a bit ridiculous given that the original atto was written in JavaScript, but I want to ensure that the behaviour of atto is consistent across platforms.)

Happy Christmas Eve Eve! I've been working on building another new #BASIC interpreter (https://github.com/devicefuture/catto) and wrote a little program that draws a Christmas tree. The same program works with a few minor edits on my #Amstrad CPC 464 too!
GitHub - devicefuture/catto: A C runtime library for the atto programming language. 😺πŸ–₯️

A C runtime library for the atto programming language. 😺πŸ–₯️ - devicefuture/catto

GitHub

Anyone else looking forward to the leap second in 2025? I've been working on a project that relies on timekeeping and I just had to implement it...

Then naturally I had to make it work across timezones 😳