On Programmer Archaeology

Brit Butler

(use arrow keys or PgUp/PgDown to move slides)

I've become known by the wrong name...
and it's my own fault.

Just a lisper?

Ideas > Tools

"Tools are only worthwhile in the service of ideas."

A Programmer Archaeologist

"Over thousands of years, the machine memories have been filled with programs that can help. But like Brent says, many of those programs are lies, all of them are buggy, and only the top-level ones are precisely appropriate for our needs."

Sound familiar?

The Inherent Complexity in Software

At 50 lines/page, Storyville is 185k or *10* 370-page books.

No one knows how to solve it. Especially me.
Though historically we've tried a number of things ...

Every program is part of some other program and rarely fits.

-- Alan Perlis, Epigrams on Programming

My definition of Programmer Archaeology

Know Your Damn History

Let's mine history! ... at JSConf?

Another example: @bigthingist used mark+sweep GC algos to manage retail fashion site.

In many ways, this is equivalent to knowing and having an interest in CS...but the lens of archaeology is more fun. :)

Revenge of the Smalltalkers?

Why didn't old tech win if it was so great?

Alan Kay - Programming and Scaling talk, Dr. Dobbs interview, etc

"...But nowadays people are reinventing the flat tire."

A broken record. Crank or genius? Why keep saying it?

Lisp and Smalltalk failed for a reason, presumably.

Alright, proof is in the pudding. What's he building?

Steps for the Reinvention of Computing, VPRI

5 year project funded by the NSF.

First thought: What a pretentious jerk!

Second thought: Well...what are their results?

An entire OS+Office Suite in 20,000 lines of code. W.T.F.

Even if it isn't backwards compatible with /anything/ ... ... HOW?!?

Metaprogramming, the Compiler as a Service pattern

OMETA - Technology from the 60s!!!
[extended with Inheritance and PEGs]
Parsing as a weapon: Compiler as parser series in lieu of IR.

See appendices of 2007 STEPS report for further examples.

[Like OMETA->JS in 75 lines and Prolog->JS in 100 lines.]

Burn the Libraries

'We should burn all libraries and allow to remain only that which everyone knows by heart' - Hugo Ball

Interview question: 'Write as much of jQuery as possible in 45 minutes from scratch.'

The antithesis of using past solutions.

Why not?

What's the lesson?

Tests define 'satisfactory code'. By using them, we are less trapped in the past.

My Open Source Talk makes it clear how this would help promote competition and diversity.

MustacheJS has a specs repo in JSON.

... but it's not quite clear how to apply this to the 6502.
And it wasn't my goal to. :)

Enter cl-6502

Let's emulate one.....with Lisp!


Goals: Definition

Goals: Status

Why Lisp? (or, a few good points)

A Culture of Metaprogramming

Still fairly unique to Lisp culturally...because metaprogramming and source transformation is usually INSANE AND FROUGHT WITH DANGER.

Non-paren alternatives in Dynamic and Static langs exist: Template Haskell, Camlp4, Dylan, Factor, Io

Thus far, no parens == no culture of metaprogramming.

Fear not, I will explain macro usage carefully.

On emulators, portability, and methods of emulation

It's basically a VM, duh. Simulate hardware and run a program inside the simulated hardware.

Portability thinking seems to be: Write it in C. After all, C compilers are ported everywhere.

I stayed with interpretation for simplicity's sake. Crawl, then walk. For a great overview, see this paper.

Enter the 6502

Addressing Modes, or Pointers redux

None of this "Declare a variable" nonsense.

6502 has 13 addressing modes. No instruction supports every mode. Indirect mode only used by one instruction.

Some opcodes use address, some use byte at address.

Get ready to poop your pampers

The following code has been rated GH-MA*
* - [Github Mature]

An executable spec, or Enter defopcode

Remember when I said I'll Explain?

A Defopcode Aside

On dispatch strategies

Which method goes with this byte in the array?

Wound up doing dispatch via opcodes just like a switch/case interpreter...

But using Lisp's EQL-specialized methods! \o/

On Assembly and Disassembly

Once you have an opcodes array full of metadata, disassembly is *trivial*.

Assembly is more involved even though I was lazy and didn't write a proper parser, just regexes. Still not so bad.

2-pass assembler. First sets labels, second resolves uses.

Supports labels, constants, comments. Here's a small example.

Interesting hurdles

Decimal mode - Dodged that bullet. Not in the NES! ;)
Sadly, no language can make decimal mode pretty.

Status bits - Sort of ad-hoc and messy. No defaults for you!

Relative addressing - Oh God, Oh God.

Emulator hurdles

Truthfully, CPU emulation isn't so bad. Whole systems are what's complicated.

What's next?

Emulation as a Service!

Maybe build crazy dev tools on top a la Frodo Redpill.

No promises! ;)

The Dichotomy at the Bottom

Biologists vs Logicians

Late-bound metaprogramming vs Static verification

On Abstraction

Civilization advances by extending the number of important operations which we can perform without thinking about them.
- Alfred North Whitehead

We are living now, not in the delicious intoxication induced by the early successes of science, but in a rather grisly morning-after, [where we have]... improved the means for achieving deteriorated ends.
- Aldous Huxley

There must be a middle place between abstraction and childishness where one can talk seriously about serious things.
Czeslaw Milosz, Second Space


Slides Source