Skip to content

Latest commit

 

History

History
54 lines (46 loc) · 2.55 KB

log.org

File metadata and controls

54 lines (46 loc) · 2.55 KB

Lonnrot Development Log

Change Log

Friday April 9th, 2021

Started work on actual coursework. Added lexemes, syntax and railroad diagrams. There is still prose to be written to clarify the diagrams (e.g. the anyChar terminal literally means any char, and hence it doesn’t have a production rule, etc.)

This includes:

  • The bibliography file
  • The overall structure of the report in LaTeX

Work on the first compilers and interpreters was done (i.e. Abscond, Blackmail, Con). I decided a Makefile would make the whole iterative process a bit less tedious.

This includes:

  • The C runtime (so far, it only prints the result of running the program)
  • The parsing from:
    • Source -> AST -> x86 AST -> NASM
  • An interpreter for the Source AST
  • A Makefile to compile the runtime and link it to the result of compiling the source

Friday April 16th, 2021

For this deliverable, I have implemented up to Dupe, which means that there is an implementation of AST operations for

  • if
  • zero? as a primitive

And now we have booleans and integers as distinct types both in the interpreter and in the runtime (i.e. running a program that produces a boolean will correctly print the symbols #t and #f instead of their integer representations)

Likewise, I’ve been studying about CEK machines and Continuation Passing Style. Methods inspired by Ghuloum’s and Dybvig’s literature on compiler nanopasses compile to x86; to make it more interesting (i.e. as opposed to mindlessly following one tutorial) it might be worthwhile trying to use one such IR besides the AST.

Notes

Calling Racket to run a file as a program (for the interpreter)

To run the interpeter (interp.rkt), one has to run racket -t "interp.rkt" -m <file_name>. Details on the flags is found in the Racket Reference, in section 18.1. For now, a TLDR is that -t uses the main function in interp.rkt to evaluate (-m) the results of calling (main <file_name>). This is what we would alias to something like lonnrot-i <file> (i.e. like ghci). This is the same for the compiler, but we would instead provide compile-file.rkt.

Compiling the runtime object file

To produce the runtime object file, we run gcc -m64 -c -o main.o main.c. This main.o is then linked with the results of the entry function, i.e. the results of compiling our source code.

Putting it together

To assemble the result of compiling our source (i.e. the resulting NASM code) into an object file, we use nasm -f elf64 -o <file>.o <file>.s. The result of this is then linked to the runtime with gcc main.o <file>.o -o <file>.run.