• Stars
    star
    247
  • Rank 158,339 (Top 4 %)
  • Language
    TypeScript
  • Created almost 4 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Source code for the book Compiling to Assembly from Scratch https://keleshev.com/cas

Compiling to Assembly from Scratch

This repository contains source code from the book Compiling to Assembly from Scratch, plus ports to other langauges (currently Python, OCaml, and Rust)

Structure

  • part-1 folder contains the baseline compiler from Part I of the book.
  • part-2 folder contains the extended compiler from Part II of the book.
  • contrib folder is for various other versions of the compiler. Contributions are welcome.

Running the code

The book's compilers are wirtten in TypeScript, so you need to install the TypeScript compiler. TypeScript compiles to JavaScript, so you need Node to run it in a non-browser environment (however, it works in browser too).

On Rasperry Pi

Install Node and TypeScript:

$ sudo apt-get install npm
$ sudo npm install -g typescript

Now you've got everything necessary to run the compiler's test suite. No emulation or cross-assembling necessary.

$ make CC=gcc RUN=''

On x86-64 Linux

This assumes apt-get package manager.

Install TypeScript (and Node, as a dependency):

$ sudo apt-get install npm
$ sudo npm install -g typescript

Install GCC toolchain that targets 32-bit ARM:

$ sudo apt-get install gcc-arm-linux-gnueabihf

Install QEMU emulator:

$ sudo apt-get install qemu-user-static

Run baseline compiler's test suite:

$ make CC='arm-linux-gnueabihf-gcc -static' RUN='qemu-arm-static'

In the browser

Minimal browser playground is available as well.

cd part-2
make ../docs/build.js
open ../docs/index.html

Contribution

You are welcome to contribute your version of the book's compiler. Make a pull request into the contrib directory.

More Repositories

1

schema

Schema validation just got Pythonic
Python
2,830
star
2

mini

Mini: Interpreter and a programming language implemented in Python
Python
145
star
3

rome

A practical Roman numerals implementation (also an example of Python project structure)
Python
73
star
4

version

Semantic versioning (SemVer) implementation for Python
Python
50
star
5

misra-c

MISRA-C:2004 simplest rules checker
C
25
star
6

docopt-dispatch

Dispatch from command-line arguments to functions
Python
20
star
7

value

Value object pattern implementation
Python
17
star
8

vi-gang-sign

SVG rendition of the original vi gang sign
10
star
9

Terminal.ml

Templating library for styling terminal text and type-safe variable substitution
OCaml
8
star
10

ask-me-about-api-design

Me giving you advice on API design in your open-source project: create an issue to start discussion
8
star
11

little-scheme

Just another Scheme implementation (with fexprs)
C
7
star
12

Integers.ml

Pure OCaml emulation of {u,}int{8,16,32} integers
OCaml
6
star
13

monads

Implementation of monads from the original monad paper in OCaml and F#
OCaml
6
star
14

TankYou

Gameplay experiment in using WE/SD controls. Play:
Elm
6
star
15

peg.rb

Parsing Expression Grammar (PEG) imeplementation
Ruby
5
star
16

tau

Tau—time series database
Python
5
star
17

kcats

kcats -- stack-based programming language.
C
4
star
18

trash

Safe `rm` substitute for OS X
Python
3
star
19

Arrow

OCaml
3
star
20

docopt.ml

Work in progress…
OCaml
3
star
21

stupid.h

C library
C
2
star
22

keleshev.com

My homepage
HTML
2
star
23

monorepo

OCaml
1
star
24

little-schemer

JavaScript
1
star
25

new.keleshev.com

OCaml
1
star
26

migrate.ml

OCaml
1
star
27

dotfiles

Vim Script
1
star
28

signature

Helper for multi-signature funcitons
Python
1
star
29

kci

Kinda C Interpreter
Python
1
star
30

keleshev-com

My old App Engine website.
Python
1
star
31

dumpcenter

DumpCenter: Centralized distributed process-communication client-server system
Python
1
star