Wednesday, May 27, 2015

Recursive Structs in LLVM experiments, using Clang


You don't get enough science in computer science, like with the whole experimental method.

I'm (currently?) using LLVMlite (https://github.com/numba/llvmlite) in my compiler project. Some things you might want to do aren't well covered in the LLVMlite documentation, or even in the LLVM documentation.

Case in point, I'd like to be able to generate code for something like this:

  Ship bar;
  bar.pos.y = 7;
  bar.vel.y = 3;
  bar.pos.y += bar.vel.y;

I haven't been making a lot of progress lately (you'd know), trying to wrap my head around what I'd even need to keep track of for that to work, including most recently thinking that I'd need to be able to walk the tree to create a path of element offsets, keep track of l-vals and r-vals, and some sort of stack of symbol tables.

But then I recalled that I had used Clang before to figure out how they do things.

  clang -S -emit-llvm teststruct.c 

I just pointed that commandline at some C that does what I want, and it spits out LLVM instructions that I can use as a reference.

For example, some of the instructions generated for the above code is:

  %10 = getelementptr inbounds %struct.Ship* %bar, i32 0, i32 0
  %11 = getelementptr inbounds %struct.Vec2f* %10, i32 0, i32 1
  %12 = load i32* %11, align 4
  %13 = add nsw i32 %12, %9
  store i32 %13, i32* %11, align 4
 
So, there you go. Just get the element pointer, then get the element pointer, and then bam, put the thing in the thing. That's it.

Reverse engineering. One of my top several favorite kinds of engineering.

Sunday, May 3, 2015

SIFF 2015 Scheduling, Part 3 of the epic trilogy(?)

In the prior post, I had been publishing the showing times into CSV, which I was pulling in to Google Sheets.

Seems like a more natural way to show a sequence of things in time might be a calendar app, so I poked around with the Google Docs API.




I started off with the Python Quickstart: https://developers.google.com/google-apps/calendar/quickstart/python which walked through getting the client secret and OAuth bits. I then followed (cut-and-pasted) examples from https://developers.google.com/google-apps/calendar/v3/reference/events/insert to put the showings into a calendar.

If you'd like to see the calendar, maybe because you're going to SIFF and want to see the movies in a different format than siff.net provides, that's cool - check out this link: https://www.google.com/calendar/embed?src=18j890v2366vkfpcn9nhn3828k%40group.calendar.google.com&ctz=America/Los_Angeles

There's a few problems, including Unicode still giving me grief, which I'm currently avoiding by just dropping the movies that have difficult accents. I might want to watch a movie about sake, but if it's "saké", then it's a problem. Also, some of the special programs have pages that are formatted a little differently, leading to at least one event ostensibly screening at "Buy".

I may continue to tinker, or maybe I walk away from it - it's plenty useful as it is now for me. If it's useful to you, that's groovy, as well.




SIFF 2015 - Movie 0 : Song of the Sea

I've already posted about the geekery of pulling data off the siff.net webpage and putting it into CSV or Google Calendar format. That continues.

Today, while I wasn't doing that, I was actually watching a movie at SIFF. I always think it's a bit confusing to the uninitiated, but SIFF is an organization that runs, amongst other things,  the Seattle International Film Festival event. Which is also called SIFF. SIFF, the organization, also shows films year-round. As well as during the festival.

So, today, I went to the SIFF Uptown cinema to watch a movie that's not part of the festival. Is that all clear? Did it need to be? Probably not, but that's why I'm not numbering it as a festival movie. A pre-festival movie.

http://www.siff.net/cinema/song-of-the-sea

An animated movie out of Ireland, this is the story of a family whose mother disappears under mysterious and possibly tragic circumstances right about the time of the birth of the daughter. And then the daughter turns out to be a "selkie", which is like a were-seal, I guess. I read stats for them in a Monster's Manual at some point.

This was done by the same team that did "The Secret of Kells", which I enjoyed, which was a story about calligraphers in the middle ages. Or, a kid apprenticed to calligraphers. Big eyes, very flat shapes - reminded me a whole lot of Genndy Tartakovsky's "Samurai Jack" style. And "Song of the Sea" has a lot of the same style.

One thing bothered me when I looked at the description: it's described as a movie about a boy who discovers his sister is a selkie. Is it really that, or is it a movie about a girl who is a selkie? Turns out, the description is probably a little more apt. It's about the boy's adventures, tugging his supernatural sister around. You see the rest of the family, but clearly the boy is the focus. But why is that? Isn't the interesting character the girl?

Random other observation: how do the Irish learn how to pronounce things? The girl's name is "Saoirse", pronounced "seer-shuh". It's their language, they can do what they want, but wow.

Some peril, no dirty language as far as I can recall. Seems appropriate for kids.

SIFF 2015 Scheduling (Part 2/???)

My efforts to get SIFF schedule data into a format useful to me continues.

Earlier, I had collected the movies that I had already manually tagged on SIFF's website that I might be interested in. There was some data that I didn't have in that original pass, like running time of the movies, so I proceeded to spider the full 2015 festival schedule:


Before I go on, let me encourage anybody that is inspired to do any sort of crawling of a website to be considerate, perhaps rate-limiting your requests - it's easy to imagine a script getting out of hand and inadvertently becoming a "denial of service" bot. And presumably, you don't want that.

So, you can see above that I've pulled the different showing data for each movie, and each showing is its own line in my new spreadsheet. That's handy.

You will also see that the movie "Décor" got mangled in the process. I fought with unicode and encodings and decodings and python 2 vs python 3 and I gave up. What's worse is that you don't see "Paco de Lucía: A Journey", because the URL for the movie is non-ascii, which I guess is fine, except that it broke my stuff. So I skipped that movie altogether. Maybe that's a tip for webmasters that want to discourage lazy hackers: throw in some accented characters, and hope that unicode is too much work to bother with.

I'm assured that Python 3 gets the unicode stuff right, and if I were to start all over again right now, I might use Python 3, but how many of the libraries I depend upon currently support Python 3? (Some, I imagine. Probably not all.)

Also, while I'm here, I'll mention that I appreciate that the midnight showings are listed as 11:55pm showings. That's unambiguous and easy to understand.


Next up: Hm, I don't know - I was thinking of jamming all of this information into a Google Calendar, which could be pretty useful. A whole new set of APIs to wrestle with, which isn't entirely a bad thing. I've got the start time, duration, and location - all of which would make for useful values in a schedule.

Saturday, May 2, 2015

SIFF 2015 Scheduling (Part 1?)


It's time for the 2015 Seattle International Film Festival. Last year, I saw somewhere around 30 movies. This year, I think I might be able to do around 50. I've put some hurdles in my way like deciding to go into work most of the days of the festival, and maybe I won't see the midnight movies like I might have when I was younger.

I spent some time going through SIFF's festival website, and got somewhat impatient and frustrated with what it provided me, so I pulled down the data of movies I was (somewhat?) interested in.


SIFF's website lets you add movies to "MySIFF", which is then presented in one page of scrapable HTML. I used the Python "Beautiful Soup" tool to find the appropriate chunk of data inside the HTML file, then I carved out individual chunks of data that I wanted to track. I bundled those bits back up and sent everything out to a CSV file, which Google Sheets (or "Google Docs Spreadsheets", as I call it) was happy to import.

I did a tiny bit of special-case formatting in my script so that the movie "808" renders as a string instead of an integer. I didn't special-case that movie, but I did recognize that there might be titles that get interpreted as integers.

Next Up(?) - constraint satisfaction to help me understand when I should see a particular screening of a movie (movie A conflicts with movie B now, but movie A is only showing now, but movie B has no conflicts next Tuesday, therefore, movie A is the better option now).