C++ Compiler Targets The Web

It is a common problem these days. You have a piece of code in C or C++. Maybe it is older code. Or maybe you prefer prototyping your ideas using C. But, inevitably, someone now wants your code to run in a Web browser. The options for making this happen have expanded quite a bit lately and one possibility is Cheerp, an open-source compiler that handles up to C++ 17 and can output to WebAssembly, JavaScript, or asm.js.

The compiler is free to use for GPLv2 projects. If you aren’t open yourself, it looks like you have to cut a deal to use Cheerp with its maker, Learning Technologies.

Continue reading “C++ Compiler Targets The Web”

Learn Compilers Online From Cornell

It sounds like the start of a joke, but what’s the difference between taking Cornell’s CS6120 online and in-person? The instructor, [Adrian Samspon] notes that the real class has deadlines, an end-of-semester project, and a discussion board that is only open to real-life students. He also notes that you only earn “imagination credits.”

Still, this is a great opportunity to essentially audit a PhD-level computer science class on a fascinating topic. The course consists of videos, papers, and open source projects using LLVM and a custom internal representation based on JSON that is made for the class. It is all open source, too. You do however need access to the papers, some of which are behind paywalls. Your local library can help if you can’t otherwise find copies of the papers.

Continue reading “Learn Compilers Online From Cornell”

All You’ve Ever Wanted To Know About Compilers

They say that in order to understand recursion, you must first understand recursion. Once you master that concept, you might decide that it’s time to write your own compiler that can compile itself as a fun side project. According to [Warren] aka [DoctorWkt], who documented every step of writing this C compiler from scratch, a true compiler will be able to do that.

Some of the goals for the project included self-compiling, focusing on a real hardware platform, practicality, and simplicity. [Warren] outlines a lot of the theory of compilers as well, including all the lexical, grammar, and semantic analysis and then the final translation into assembly language, but really focuses on making this compiler one for practical use rather than just a theoretical implementation. He focuses on Intel x86-64 and 32-bit ARM platforms too, which are widely available.

This project is a long read and very thoroughly documented at around 100,000 words, so if you’ve ever been interested in compilers this is a great place to start. There are a lot of other great compiler tools floating around too, like the Compiler Explorer which shows you generated code as you write in a higher level language.

[via Hackaday.io]

Tony Brooker And Autocode – The First High-level Language

The field of computer science has undeniably changed the world for virtually every single person by now. Certainly for you as Hackaday reader, but also for everyone around you, whether they’re working in the field themselves, or are simply enjoying the fruits of convenience it bears. What was once a highly specialized niche field for a few chosen people has since grown into a discipline that not only created one of the biggest industry in modern times, but also revolutionized every other industry, some a few times over.

The fascinating part about all this is the relatively short time span it took to get here, and with that the privilege to live in an era where some of the pioneers and innovators, the proverbial giants whose shoulders every one of us is standing on, are still among us. Sadly, one of them, [Tony Brooker], a pioneer of the early programming language concept known as Autocode, passed away in November. Reaching the remarkable age of 94, the truly sad part however is that this might be the first time you hear his name, and there’s a fair chance you never heard of Autocode either.

But Autocode was probably the first high-level computer language, and as such played a fundamental role in the development of whatever you’re coding in today. So to honor the memory of [Tony Brooker], let’s remember the work he did with Autocode, and the leap in computer science history that it represented.

Continue reading “Tony Brooker And Autocode – The First High-level Language”

Peek Into The Compiler’s Code — Lots Of Compilers

We don’t know what normal people argue about, but we know we spend a lot of time arguing about the best microcontroller, which editor is the best, and what language or compiler does the best job. The problem with all those compilers is getting them loaded and digging into the generated code. If you too spend your time thinking about those things, you ought to have a look at [Matt Godbolt’s] Compiler Explorer. We know that hosting an IDE-like web page and compiling code is old hat — although [Matt’s] site has been around quite some time. But [Matt’s] doing it differently. The code you build on the left hand pane shows up as assembly language on the right hand side.

There are plenty of options, too. For example, here’s a bit of C code from the site’s example:

int square(int num) {
   return num * num;
}

Here’s the corresponding assembly from gcc 9.2 for x86-64:

square:
  push rbp
  mov rbp, rsp
  mov DWORD PTR [rbp-4], edi
  mov eax, DWORD PTR [rbp-4]
  imul eax, eax
  pop rbp
  ret

Continue reading “Peek Into The Compiler’s Code — Lots Of Compilers”

Python And The Internet Of Things Hack Chat

Join us Wednesday at noon Pacific time for the Python and the Internet of Things Hack Chat!

Opinions differ about what the most-used programming language in right now is, but it’s hard to deny both the popularity and versatility of Python. In the nearly 30 years since it was invented it has grown from niche language to full-blown development environment that seems to be everywhere these days. That includes our beloved microcontrollers now with MicroPython, and Adafruit’s CircuitPython, greatly lowering the bar for entry-level hackers and simplifying and speeding development for old hands and providing a path to a Python-powered Internet of Things.

The CircuitPython team from Adafruit Industries – Dan Halbert​, Kattni Rembor​, Limor “Ladyada” Fried​, Phillip Torrone​, and Scott Shawcroft – will drop by the Hack Chat to answer all your questions about Python and the IoT. Join us as we discuss:

  • How CircuitPython came to be;
  • The range of IoT products that support Python;
  • Getting started with Python on IoT devices; and
  • What’s on the horizon for a Python-powered IoT?

And as extra enticement, we’ll be giving away five free one-year passes to ​Adafruit.io​! We’ll draw five names at random from the list of Hack Chat attendees. Stop by for a chance to win. And, the Adafruit team will be streaming video live during the Hack Chat as well.

You are, of course, encouraged to add your own questions to the discussion. You can do that by leaving a comment on the Python and the Internet of Things Hack Chat and we’ll put that in the queue for the Hack Chat discussion.

join-hack-chatOur Hack Chats are live community events on the Hackaday.io Hack Chat group messaging. This week we’ll be sitting down on Wednesday, April 3, at noon, Pacific time. If time zones have got you down, we have a handy time zone converter.

Click that speech bubble to the right, and you’ll be taken directly to the Hack Chat group on Hackaday.io. You don’t have to wait until Wednesday; join whenever you want and you can see what the community is talking about.

Want a quick peek at what’s possible with CircuitPython? Check out this PyPortal event countdown timer that just happens to be counting down the hours till the next Hack Chat.

ESP8266 Gets Its Game On With Open Source Engine

This is likely not to come as much of a shock to you, but the ESP8266 is pretty popular. At this point, we’re more surprised when a project that hits the tip line doesn’t utilize this incredibly cheap WiFi-enabled microcontroller. If you’re making a gadget that needs to connect to the Internet, there’s a good chance some member of the ESP family is going to be a good choice. But is it a one-trick MCU?

ESP Little Game Engine Logo

Well, judging by software frameworks like the “Little Game Engine” created by [Igor], it looks like the ESP is expanding its reach into offline projects as well. While it might not turn the ESP8266 into a next-gen gaming powerhouse, we’ve got to admit that the demos shown off so far are pretty impressive. When paired with a couple of buttons and a TFT display such as the ILI9341, the ESP could make for a particularly pocket-friendly game system.

The game engine that [Igor] has developed provides the programmer with a virtual screen resolution of 128×128, a background layer, and 32 sprites which offer built-in tricks like collision detection and rotation. All while running at a respectable 20 frames per second. This environment is ideal for the sort of 2D scrolling games that dominated the 8 and 16-bit era of gaming, and as seen in the video after the break, it can even pull off a fairly decent clone of “Flappy Bird”.

In addition, [Igor] created an online emulator and compiler which allows you to develop games using his engine right in your web browser. You can load up a selection of example programs and execute them to see what the engine is capable of, then try your hand at developing your own game before ever having to put the hardware together. Incidentally, the performance of this online development environment is fantastic; with even the fairly complex “Flappy Bird” example code compiling and starting in the emulator nearly instantaneously.

This isn’t the first handheld game we’ve seen powered by the ESP8266, but it would be fair to say this one is a generational leap over its predecessors. Of course, if you really want to start throwing around some pixels, you might want to make the leap to the ESP32; which is the heart of the incredibly awesome (and tiny) PocketSprite.

Continue reading “ESP8266 Gets Its Game On With Open Source Engine”