annotate code/README @ 36:c0b3922646d8

Fill in readme
author Michael Pavone <pavone@retrodev.com>
date Sat, 26 Jul 2014 03:18:10 -0700
parents 360862a3f3e3
children ea6a0709373f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
36
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
1 Team: Rhope Burn
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
2 Language: Quiche
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
3 Members: Michael Pavone, William Morgan
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
4
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
5 HOW TO BUILD:
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
6
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
7 To build our Lambda-man AI, you first need to build the lmc compiler. lmc is
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
8 written in a WIP language called Quiche. The steps to get a Quiche toolchain
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
9 setup are as follows:
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
10
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
11 1) Make a local clone of hg repo: http://rhope.retrodev.com/repos/tabletprog
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
12 2) Make sure the d8 Javascript shell (built from Chrome's v8) is in your path
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
13 -- see this page for instructions on how to build d8:
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
14 https://developers.google.com/v8/build
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
15 3) Install the Boehm GC development package (libgc-dev on Debian derivatives)
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
16 3) Install gcc if it is not already present
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
17
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
18 Once you have the toolchain in place, navigate to the Quiche repo clone in a
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
19 terminal and execute the following command.
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
20
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
21 ./compile PATH/TO/lmc.tp
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
22
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
23 If all goes well an executable named lmc will be produced at PATH/TO/lmc. This
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
24 program takes a .lm file as an argument and produces "GCC" assembly code on
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
25 stdout.
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
26
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
27 ABOUTE QUICHE:
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
28
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
29 Quiche (previously called TP) is a language I (Michael Pavone) work on in my
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
30 spare time. It draws rather heavily from Smalltalk with a smattering of
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
31 influence from other languages. In theory, it's reason for existence is to be
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
32 a good target for a structured editor on mobile devices. In practice, I'd
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
33 probably be better served targeting an existing language, but that's not nearly
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
34 as much fun.
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
35
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
36 The current implementation is a quick and dirty bootstrap compiler written in
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
37 Javascript that produces C code. A self-hosted compiler is in progress.
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
38
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
39 A Quiche program is made up of one or more modules. At runtime, a module is
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
40 just a plain object. Only one module is allowed per source file. The top level
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
41 of a Quiche source file is required to either be an object literal or a lambda
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
42 that returns an object. After all modules used are initialized, execution
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
43 starts in the main method of the main module. Currently, the names of all
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
44 available modules occupy the top level of the symbol table; however, this will
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
45 change in the self-hosted compiler.
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
46
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
47 QUICHE SYNTAX:
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
48
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
49 To make reading lmc's code a bit easier, here is a quick primer on Quiche's
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
50 syntax.
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
51
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
52 line comment: //
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
53 block comment: /* */
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
54 assignment: foo <- bar
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
55 list literal: [1 2 3 4]
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
56 array literal: #[1 2 3 4]
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
57 string literal "foo bar"
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
58 lambda: :arg {
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
59 arg + 1
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
60 }
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
61 object literal: #{
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
62 foo <- "blah blah"
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
63 bar <- :val {
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
64 foo <- val . " blah"
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
65 }
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
66 }
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
67 method invokation/function application:
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
68 someval someFunOrMeth
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
69 someFunOrMeth: someval
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
70 some: val1 Fun: val2 OrMeth: val3
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
71 some:Fun:OrMeth: val1 val2 val3
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
72 operators:
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
73 +,-,/,* -- basic arithmetic
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
74 =,!=,>=,<= -- comparison
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
75 and,or,xor -- bitwise
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
76 % -- modulus
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
77 . -- concatenation
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
78 | -- cons
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
79
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
80 ABOUT LMC:
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
81
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
82 lmc implements a subset of Quiche for the LamCo General Compute Coprocessor. It
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
83 uses the parser, ast and symbols modules from the work in progress self-hosted
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
84 compiler. Object literals are not supported apart from the top-level object
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
85 that represents the module. That object is used to populate the global
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
86 environment. Closures are properly supported; however, some elements that are
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
87 implemented using closures in the normal Quiche compiler (namely if:else and
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
88 while:do) are instead implemented as special forms that do not introduce a new
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
89 scope. Array literals are used for producing tuples as the GCC does not really
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
90 support the former and Quiche does not currently support the latter.
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
91
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
92 Tail call optimization is notcurrently implemented; however, while:do is
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
93 implemented using TSEL so we were able to do without.
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
94
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
95 LIGHTNING ROUND SOLUTION:
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
96
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
97 Our lightning round solution is relatively simple. Each step, we do a breadth
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
98 first search for something desirable (pellet, power pellet, fruit or fright
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
99 mode ghost). Cells occupied by normal mode ghosts and their immediate neighbors
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
100 are marked as walls to provide simple avoidance behavior.
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
101
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
102 We translate the grid to a tree format to provide more efficient lookup. An
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
103 identically dimensioned tree is used for keeping track of visited nodes for our
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
104 search.
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
105
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
106 This seems to work surprisingly well given how simple it is. I'm a bit
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
107 concerned about our cycle usage when the nearest "good" thing is far away,
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
108 hopefully that will not be an issue.
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
109
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
110 We noticed that the "undefined" input to main appears to be the ghost code, but
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
111 we did not have time to take advantage of it for the lightning round.
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
112
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
113 The code for this AI is located in dotScanner.lm
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
114
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
115 OTHER FILES:
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
116
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
117 test.lm - random collection of syntax for exercising parts of the compiler
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
118 simple.lm - picks each direction in order every 4 turns
c0b3922646d8 Fill in readme
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
119 mike00.lm - test program for developing library functions