Powered by Starship v1.3
Activation energy
Aug 14 2024
2:03 PM

Hey yall. Been a while :P

My schedule has been kinda strange ever since coming back from road trip - firstly I started a project with some friends over that trip, SARA, which took up a decent portion of my first few days back. Then I had to deal with some school related stuff, and got involved with a new project after that... and all in all I haven't had had as much time to work on contest recently, or update this blog.

Finally decided to allocate a block of time to updating blog, so here we are! (hence the title)

Also, now that most of the projects I've been working on are at reasonably complete stages, I can talk a bit about them here! This is a short overview of what I've been up to recently:


SARA - Spatial Analysis of Router Activity

Essentially a script to log router signal strength and GPS location and then use collected data to estimate real location of the router. This is actually a project I've been thinking about conceptually for a log time, but only recently learned the tools to make it happen!

SARA source code isn't public and probably won't ever be, (also there are a couple things about it that I can't say here), but it's essentially an objective-c command line script that hooks CoreLocation and MobileWiFi (private apple framework) to collect data. It runs on my jailbroken iphone. (2016 SE, ios 13.4.1)

I actually did a little bit of field testing at a local university and the geolocation module is accurate to a couple meters. Signal strength isn't very fine-grained, but can get a good read from surprisingly far away, as utilization of internal apple frameworks let me remove the software filters to wifid.

This project kinda stagnated due to a couple reasons.


CBAS

Recently I discovered CBAS, a really interesting programming language:

At the most basic level, it's a low-level language that transpiles to C. It's also really portable: the interpreter/compiler is written in C99, and emitted C is as well, I believe. It implements object oriented features like classes with methods, constructors, destructors, etc.

But CBAS is way more than just a wrapper on top of C. From the ground up it's built with metaprogramming in mind. Similar to Rust's procedural macro system, CBAS code (when declared codegen) is able to directly manipulate the syntax tree of the interpreter/compiler. This essentially means that new features and constructs can be added without touching the compiler at all. In fact, the CBAS source is written mostly in CBAS itself, and the compiler is very minimal.

Not only are high level constructs like templating and type deduction implemented through metaprogramming, but the standard library has tons of metaprogramming structures that build off of each other. Using them, creating more powerful constructs is very streamlined.

Visit the codeberg repo for a better explanation than mine! :P


So, what have I been doing with this?

Standard CBAS has tons of compile-time utilities, but not a whole lot of work on the emitted C side. I decided to implement somewhat of my own usermode standard library. I'ts far from complete, but it essentially already serves as a complete replacement of C for all of my use cases. never touching c again :towers:

My standard library is on github here. Most of what I've worked on is I/O: I implemented my own buffered input reading system that not only is safe, respecting buffer sizes, but also uses an (although still quite janky) type deduction system that sort of accomplishes what c++ std::cin does, without dealing with function overloading at all. Furthermore, it's faster than both c and c++ stdio. It's very similar to the fgets() based superfastio that you might've seen on chinese contest templates.

Here's a little demo of what CBAS + my custom DSL looks like:

#include <iframe>   // wow, that's me!
@cgmain
fn pub main -> int:
int n; float f; char[10] s; // @poll will respect buffer size and read at most 9 chars. char* p; // as this isn't an array, @poll will allocate a new buffer // to store the string. (CBAS stores array len in datatype)
@poll n f s p; // reads into the vars, respecting type. it is that easy!
@fmt f/n s[3]; // output too :D
free(p); // not strictly necessary as we will exit
end

(I haven't gotten around to writing a formatting script for this, but it should be easy)

I also have a string datatype similar to c++ std::string, a @poll-like construct to read & format from a string instead of stdin, and more!

In the near future, I'll add template structures like vector, set, etc, but even in its current state it is enough to replace C in my normal usage situations. Seeing that this transpiles to C, and is faster in terms of I/O, I could maybe use this for contest, depending on whether or not it's deemed "excessive" for a template :thonk:


Time balancing, though..

Tradeoffs had to be made in order to work on all of these projects recently, especially CBAS. I didn't end up practicing much contest recently, or updating blog. This will become increasingly unsustainable once school starts, and I'll probably have to switch to lower-activation-energy task management.

p.s. jason you can talk to me whenever you want - I'm not actually very busy but it's rather an activation energy thing :P

tags: programming life