Alex Carney

Creating a CPython Extension

Previously, as part of my exploration into how programming languages are implemented, I wrote a very simple AST evaluator that knew how to add and multiply floats together. Since constructing these ASTs by hand is quite painful I thought it would be fun to come up with a frontend to my “programming language” which could do it for me.

Now your typical frontend would be some kind of parser built into the compiler/interpreter. However, while I’m definitely interested in parsing I don’t quite feel like tackling that just yet. Instead I’m going to have Python be the frontend and embed my toy language into it via a CPython Extension


Evaluating a Simple Abstract Syntax Tree

Programming languages and their implementation is a topic I’ve been interested in for a long time and I thought it would be worth trying to get a bit more hands on and play with some of the ideas in this space. Choosing a topic somewhat at random I’ve chosen to take a look at implementing an Abstract Syntax Tree (AST).


Learning Vulkan: Enumerating Physical Devices

Being an API for talking to GPUs and other compute devices every Vulkan program starts off by looking for an appropriate physical device to use. In this post I write a little C program that initialises the Vulkan API and lists out the available devices in the system.

$ vkdevice
Device Name:            Intel(R) HD Graphics 520 (Skylake GT2)
  Type:                 Integrated GPU
  Vendor ID:            32902
  Device ID:            6422
  API Version:          v1.1.102
  Driver Version:       v19.3.1

Learning Vulkan: Overview

I have always been interested in graphics and have on numerous occasions tried to dip my toe into the world of OpenGL and more recently Vulkan. However I have never been able to get past the “Hello, World” of these technologies - drawing a triangle on screen, I think mostly becuase I never really had a goal in mind once I got that far…

But that’s (hopefully) about to change! What better excuse than a new decade to jump back into this world for the 100th time and try to get to all those interesting ideas I see people playing with all the time!



A CPython extension that embeds the simple-ast program into Python. >>> import ccalc >>> expression = (ccalc.Literal(1) + 2) * 3 >>> expression Multiply<Plus<Literal<1.0>, Literal<2.0>>, Literal<3.0>> >>> ccalc.eval_ast(expression) 9.0 Building It’s probably worth creating a virtual environment to work in .cli-command::before { content: "$ "; } python -m venv .env Assuming you have a C compiler available, building the extension is as easy as running the following command More...

Simple AST

A simple C program that can construct and evaluate a simple Abstract Syntax Tree (AST). The AST represents a toy “programming language” that only knows how to add and multiply floating point numbers together. $ ./simple-ast * + 1.00 2.00 3.00 Example 1: 9.00 + 1.00 * 2.00 3.00 Example 2: 7.00 Building Having no real dependencies beyond the standard library this program can be compiled with just a C compiler More...

Writing Makefiles

Pattern Rules A pattern rule can be used to define a generic recipe for turning a file of type X into a file a type Y for example, compiling program.c into program.o. A pattern rule can be defined as follows %.o: %.c $(CC) -c $(CFLAGS) $< -o $@ %.o/%.c Will match files of the form *.o and *.c respectively $< can be used to reference all the dependencies of the target, in this case the *. More...