annotate lab1/keiko.mli @ 0:bfdcc3820b32

Basis
author Mike Spivey <mike@cs.ox.ac.uk>
date Thu, 05 Oct 2017 08:04:15 +0100
parents
children
rev   line source
0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
1 (* common/keiko.mli *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
2 (* Copyright (c) 2017 J. M. Spivey *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
3
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
4 (* |codelab| -- type of code labels *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
5 type codelab = int
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
6
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
7 (* |label| -- allocate a code label *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
8 val label : unit -> codelab
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
9
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
10 (* |op| -- type of picoPascal operators *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
11 type op = Plus | Minus | Times | Div | Mod | Eq
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
12 | Uminus | Lt | Gt | Leq | Geq | Neq | And | Or | Not
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
13
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
14 (* op_name -- map an operator to its name *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
15 val op_name : op -> string
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
16
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
17 (* |code| -- type of intermediate instructions *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
18 type code =
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
19 CONST of int (* Push constant (value) *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
20 | GLOBAL of string (* Push global address (name) *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
21 | LOCAL of int (* Push local adddress (offset) *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
22 | LOADW (* Load word *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
23 | STOREW (* Store word *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
24 | LOADC (* Load character *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
25 | STOREC (* Store character *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
26 | MONOP of op (* Perform unary operation (op) *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
27 | BINOP of op (* Perform binary operation (op) *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
28 | OFFSET (* Add address and offset *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
29 | LABEL of codelab (* Set code label *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
30 | JUMP of codelab (* Unconditional branch (dest) *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
31 | JUMPC of op * codelab (* Conditional branch (op, dest) *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
32 | PCALL of int (* Call procedure *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
33 | PCALLW of int (* Proc call with result (nargs) *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
34 | RETURNW (* Return from procedure *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
35 | BOUND of int (* Bounds check *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
36 | CASEJUMP of int (* Case jump (num cases) *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
37 | CASEARM of int * codelab (* Case value and label *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
38 | PACK (* Pack two values into one *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
39 | UNPACK (* Unpack one value into two *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
40 | DUP
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
41 | POP
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
42
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
43 | LDGW of string (* Load Global Word (name) *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
44 | STGW of string (* Store Global Word (name) *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
45 | LDLW of int (* Load Local Word (offset) *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
46 | STLW of int (* Store Local Word (offset) *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
47 | LDNW of int (* Load word with offset *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
48 | STNW of int (* Store word with offset *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
49
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
50 | LINE of int
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
51 | SEQ of code list
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
52 | NOP
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
53
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
54 (* |fInst| -- format an instruction for |printf| *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
55 val fInst : code -> Print.arg
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
56
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
57 (* |canon| -- flatten a code sequence *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
58 val canon : code -> code
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
59
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
60 (* |output| -- output a code sequence *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
61 val output : code -> unit