I just finished the first version of Frak, my interpreter for the brainf*ck language. At present, the program is only capable of executing brainf*ck programs that require less than 30000 bytes of memory. I plan on adjusting the interpreter eventually so that it becomes capable of managing its own memory.

Building Frak

$ git clone http://git.annwfn.net/Frak.git
$ cd Frak
$ mkdir build
$ cd build
$ cmake ../
$ make

Using Frak

$ frak Hello.f
Hello World!

More information

You can get the source from my git repository.

See the official Wikipedia page about Brainf*ck. Although I have not added a proper licence yet, I lean towards releasing the code under the MIT Licence.

Posted late Tuesday evening, July 1st, 2014 Tags:

I recently discovered a new plague on the internet—Scraper Sites and their brethren. While I can live with the fact that their bots are actively marketing my "valuable content" (cue laughter) as their own, I draw the line at stealing my traffic. Although the amount they steal by hotlinking my images is comparatively small, I still consider it a matter of principle to fight these sites. Foremost, the internet is a place for information. By displaying publicly-available information in a very confusing and haphazard way (most of the "people search engines" out there do not even attempt to check the names for correctness), they only confuse people.

I will not let this stand, so I devised a way of blacklisting these sites and serving them different content instead of the images they attempted to access. Assuming you have an Apache webserver with mod_rewrite installed, place the following in either your .htaccess file or one of the vhost configuration files in /etc/apache2/sites-available:

<IfModule mod_rewrite.c>
        RewriteEngine on
        RewriteCond %{REQUEST_FILENAME} !hotlinking\.png$
        RewriteCond %{HTTP_REFERER} ^http://(www\.)?.*(-|.)?example\.org.*$ [NC,OR]
        RewriteCond %{HTTP_REFERER} ^http://(www\.)?.*(-|.)?example\.com.*$ [NC]
        RewriteRule \.(gif|jpg|jpeg|png)$ /images/hotlinking.png [R,L]

This snippet rewrites any image requests that come from a subdomain of example.org or example.com to the file in /images/hotlinking.png. The first condition ensures that the rewriting does not pertain to the hotlinking.png itself. You do not necessarily need this condition if all your images are placed in a single folder and you place the hotlinking.png one outside of it.

Note that I only explicitly deny hotlinking to those who want to make a quick buck. I have absolutely no problem with other people hotlinking my content—I consider this a mark of honour and will gladly take their additional traffic. Hence, I cannot wholeheartedly recommend that you block any referrer that does not come from your own domain.

Happy internetting.

Posted Wednesday evening, July 9th, 2014 Tags:

One of the new features in C++11 is the ability to declare variables (or even functions) to be a constant expression that can be evaluated at compile time. Not only does this make the code easier to read, it also offers increased performance while still being very maintainable.

I was thus very surprised to find out that, according to one of our group members, constexpr stopped working—the code had apparently compiled on a personal machine but it would not compile in our production environment at university. We used the following test program to trace down the culprit:

#include <cmath>

int main(int, char**)
  constexpr double a = 2.0;
  constexpr double b = std::sqrt(a);

  return 0;

And indeed, using our CMake build environment, gcc would prove unwilling to compile the code, responding with a very terse error message:

constexpr.cc: In function ‘int main(int, char**)’:
constexpr.cc:6:35: error: ‘sqrt(2.0e+0)’ is not a constant expression
   constexpr double b = std::sqrt(a);

After the initial bafflement about this seemingly incorrect compiler error message, I happened to take a closer look at the compiler flags of our build environment. The culprit then turned out to be -frounding-math. This flag instructs the compiler that floating point rounding behaviour might change at runtime, so naturally, an expression such as std::sqrt(2.0) is not a constant expression any more. Thus, I learned that:

$ g++ -std=c++11 constexpr.cc
$ ./a.out # Yay
$ g++ -std=c++11 -frounding-math constexpr.cc
constexpr.cc: In function ‘int main(int, char**)’:
constexpr.cc:6:35: error: ‘sqrt(2.0e+0)’ is not a constant expression
   constexpr double b = std::sqrt(a);

Having lost a sizeable chunk of my daily sanity on this bug, I was of course interested in tracing done its cause. The culprit turned out to be CGAL. For reasons that are not completely clear to my addled mind, the CGAL module for CMake decides to set the CXX_COMPILE_FLAGS globally, regardless of whether a file actually uses CGAL or not. The personal computer where the code was tested first did not have a working installation of CGAL, so of course the code compiled correctly.

Lessons learned: Check the compile flags and be wary around CMake modules (though I have to point out that it is the implementation of the module that caused the problems, not CMake per se; quite the opposite—I am a very fond user of CMake).

Posted late Tuesday evening, July 15th, 2014 Tags:

I finally found some time for updating the archives. The page for each year now shows every valuable article of that period. Plus the other stuff I wrote. This was surprisingly easy using ikiwiki:

[[!calendar  type=year year=2006 pages="blog/posts/*/*"]]
[[!inline  pages="blog/posts/2006/*" archive=yes]]

I also added an addendum to my article on the film Codebreaker—Alan Turing has been pardoned by the British government. About time!

Posted mid-morning Monday, July 28th, 2014 Tags: