×

Poking Technology's video: Hjalfi writes a compiler

@Hjalfi writes a compiler
In which yr hmbl svt spends a few hours recreating a multi-month-long project of last year, smaller, better and simpler. Livecoding time! And today I'm writing a compiler. This is a prototype for an alternate take on code generation for my Cowgol programming language (http://cowlark.com/cowgol). This is an Ada-inspired strongly-typed programming language for very small systems, such as 8-bit machines, intended to be self-hosted on such systems (although realistically you'll cross compile). Cowgol works, but is achingly slow, and in this video I'm experimenting with a drastically simplified code generation model to see whether I can eliminate 95% of the complexity and produce something which works nearly as well but is much smaller and faster. It's an utterly simple one-pass compiler, using flex and yacc for the lexer and parser, and a stack-based intermediate language with a few basic heuristics to generate runnable 8080 code. Everything has been sacrificed for the sake of simplicity. Did it work? Watch the video and find out. The code's all BSD 2-clause open source and you can find it (although I've been tinkering with it since the video) at https://github.com/davidgiven/cowgol/tree/master/tinycowc. And yes, I'm aiming it at CP/M. It was done in one sitting, with two breaks for tea and dinner respectively. The clock on my status bar is accurate. List of interesting timestamps follows: - 00:06:33 First trivial program runs (just a ret statement) - 00:37:30 Symbol table, variable declarations skeleton (but no code generated) - 00:44:05 Symbol lookups and simple types - 00:50:02 Variable declarations code generation works - 00:59:51 Constant value propagation and lazy coercion to a concrete type - 01:05:55 Addition operator works with constants - 01:08:32 Variables can be looked up, addition operator generates code - 01:17:10 Proper memory storage for variables - 01:19:10 Running code - 01:31:10 Subtraction works - 01:47:01 Simple subroutine definitions work (you can't call them) - 01:51:45 Calling simple subroutines works (with no parameters) - 01:59:37 Infinite loops work - 02:03:17 Variable assignment works - 02:03:39 TEA BREAK - 02:29:32 8-bit types work - 02:32:40 Tangential lecture on subroutines in a non-recursive language - 02:37:10 Start diversion on TOS optimisation - 03:11:47 Old Cowgol vs New Cowgol - 03:30:40 Pointer types and pointer arithmetic works - 03:41:46 Dereferencing pointers on read works - 03:50:35 Give up on TOS optimisation --- too complex and I was getting it wrong anyway - 04:05:30 Tangential lector on comparing Old Cowgol and New Cowgol - 04:32:03 Hacked up conditionals and while...end while loop work (maybe) - 04:41:05 Dereferencing pointers on write works - 04:43:08 Comparison of Old Cowgol and New Cowgol generated code - 04:59:02 DINNER BREAK - 04:59:03 Plan next stages and problem summary - 05:02:30 Start work on virtual stack implementation - 05:37:50 Virtual stack works, is highly successful - 05:50:30 Lots of microoptimisations done, do another comparison - 05:57:00 Start implementing subroutine parameters - 06:47:50 Start debugging the Horrible Yacc Problemâ„¢ - 07:03:26 Stop debugging the Horrible Yacc Problemâ„¢ and just brute force it - 07:07:51 Calling subroutines with parameters works - 07:32:29 String constants work - 07:33:53 Type inference works - 07:42:35 Extern subroutine declarations work - 07:50:24 if...then...end if works - 07:57:02 break works - 08:11:40 'Hello, world!' works - 08:16:20 Bedtime

172

29
Poking Technology
Subscribers
3.2K
Total Post
174
Total Views
109.6K
Avg. Views
1.3K
View Profile
This video was published on 2019-07-16 02:04:13 GMT by @hjalfi on Youtube. Poking Technology has total 3.2K subscribers on Youtube and has a total of 174 video.This video has received 172 Likes which are higher than the average likes that Poking Technology gets . @hjalfi receives an average views of 1.3K per video on Youtube.This video has received 29 comments which are higher than the average comments that Poking Technology gets . Overall the views for this video was lower than the average for the profile.

Other post by @hjalfi