annotate modules/ast.tp @ 246:8c81afd6d2d3

Refactor some of the AST node object constructors into a separate AST module
author Michael Pavone <pavone@retrodev.com>
date Mon, 06 Jan 2014 19:41:35 -0800
parents
children b76f683d076e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
246
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1 {
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2 _binary <- 0
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
3 _string <- 1
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
4 _int <- 2
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
5
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
6 #{
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
7 binary <- { _binary }
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
8 stringlit <- { _string }
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
9 intlit <- { _int }
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
10
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
11
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
12 binaryOp:withArgs <- :opname :_left _right {
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
13 #{
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
14 nodeType <- { _binary }
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
15 left <- _left
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
16 op <- opname
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
17 right <- _right
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
18
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
19 leftAssociative? <- {
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
20 op != "|"
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
21 }
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
22 stringIndent <- :indent {
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
23 (left stringIndent: indent) . " " . op . (right stringIndent: indent)
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
24 }
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
25 string <- {
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
26 stringIndent: ""
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
27 }
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
28 }
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
29 }
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
30
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
31 stringLit <- :_val {
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
32 #{
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
33 nodeType <- { _string }
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
34 val <- _val
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
35 stringIndent <- :indent {
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
36 "\"" . val . "\""
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
37 }
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
38 string <- {
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
39 stringIndent: ""
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
40 }
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
41 }
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
42 }
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
43
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
44 intLit:withBits:andBase:signed? <- :_val :_bits :_base :_signed? {
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
45 #{
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
46 nodeType <- { _int }
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
47 val <- _val
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
48 base <- _base
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
49 bits <- _bits
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
50 signed? <- _signed?
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
51 stringIndent <- :indent {
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
52 suffix <- ""
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
53 if: bits != 32 || (not: signed?) {
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
54 suffix <- (if: signed? {"i"} else: {"u"}) . bits
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
55 }
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
56 if: base = 16 {
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
57 "0x" . (hex: val) . suffix
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
58 } else: {
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
59 if: base = 2 {
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
60 str <- "0b"
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
61 i <- bits - 1
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
62 printzero <- false
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
63 while: { i >= 0 } do: {
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
64 str <- str . (if: (lshift: 1 by: i) and val > 0 {
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
65 printzero <- true
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
66 "1"
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
67 } else: {
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
68 if: printzero {"0"} else: {""}
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
69 })
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
70 i <- i - 1
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
71 }
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
72 str . suffix
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
73 } else: {
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
74 (string: val) . suffix
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
75 }
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
76 }
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
77 }
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
78 string <- {
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
79 stringIndent: ""
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
80 }
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
81 }
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
82 }
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
83 }
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
84 }