annotate modules/ast.tp @ 252:004946743678

Added code for building a method symbol table
author Michael Pavone <pavone@retrodev.com>
date Sat, 10 May 2014 19:11:01 -0700
parents b76f683d076e
children be224817a14b
rev   line source
pavone@246 1 {
pavone@247 2 _binary <- 0
pavone@247 3 _string <- 1
pavone@247 4 _int <- 2
pavone@247 5 _symbol <- 3
pavone@247 6 _call <- 4
pavone@247 7 _object <- 5
pavone@247 8 _sequence <- 6
pavone@247 9 _assignment <- 7
pavone@247 10 _lambda <- 8
pavone@246 11
pavone@246 12 #{
pavone@246 13 binary <- { _binary }
pavone@246 14 stringlit <- { _string }
pavone@246 15 intlit <- { _int }
pavone@247 16 sym <- { _symbol }
pavone@247 17 call <- { _call }
pavone@247 18 obj <- { _object }
pavone@247 19 sequence <- { _sequence }
pavone@247 20 assignment <- { _assignment }
pavone@247 21 lambda <- { _lambda }
pavone@246 22
pavone@246 23 binaryOp:withArgs <- :opname :_left _right {
pavone@246 24 #{
pavone@246 25 nodeType <- { _binary }
pavone@246 26 left <- _left
pavone@246 27 op <- opname
pavone@246 28 right <- _right
pavone@246 29
pavone@246 30 leftAssociative? <- {
pavone@246 31 op != "|"
pavone@246 32 }
pavone@246 33 stringIndent <- :indent {
pavone@246 34 (left stringIndent: indent) . " " . op . (right stringIndent: indent)
pavone@246 35 }
pavone@246 36 string <- {
pavone@246 37 stringIndent: ""
pavone@246 38 }
pavone@252 39 fold:with <- :acc :fun {
pavone@252 40 acc <- fun: acc self
pavone@252 41 acc <- _left fold: acc with: fun
pavone@252 42 _right fold: acc with: fun
pavone@252 43 }
pavone@246 44 }
pavone@246 45 }
pavone@246 46
pavone@246 47 stringLit <- :_val {
pavone@246 48 #{
pavone@246 49 nodeType <- { _string }
pavone@246 50 val <- _val
pavone@246 51 stringIndent <- :indent {
pavone@246 52 "\"" . val . "\""
pavone@246 53 }
pavone@246 54 string <- {
pavone@246 55 stringIndent: ""
pavone@246 56 }
pavone@252 57 fold:with <- :acc :fun {
pavone@252 58 fun: acc self
pavone@252 59 }
pavone@246 60 }
pavone@246 61 }
pavone@246 62
pavone@246 63 intLit:withBits:andBase:signed? <- :_val :_bits :_base :_signed? {
pavone@246 64 #{
pavone@246 65 nodeType <- { _int }
pavone@246 66 val <- _val
pavone@246 67 base <- _base
pavone@246 68 bits <- _bits
pavone@246 69 signed? <- _signed?
pavone@246 70 stringIndent <- :indent {
pavone@246 71 suffix <- ""
pavone@246 72 if: bits != 32 || (not: signed?) {
pavone@246 73 suffix <- (if: signed? {"i"} else: {"u"}) . bits
pavone@246 74 }
pavone@246 75 if: base = 16 {
pavone@246 76 "0x" . (hex: val) . suffix
pavone@246 77 } else: {
pavone@246 78 if: base = 2 {
pavone@246 79 str <- "0b"
pavone@246 80 i <- bits - 1
pavone@246 81 printzero <- false
pavone@246 82 while: { i >= 0 } do: {
pavone@246 83 str <- str . (if: (lshift: 1 by: i) and val > 0 {
pavone@246 84 printzero <- true
pavone@246 85 "1"
pavone@246 86 } else: {
pavone@246 87 if: printzero {"0"} else: {""}
pavone@246 88 })
pavone@246 89 i <- i - 1
pavone@246 90 }
pavone@246 91 str . suffix
pavone@246 92 } else: {
pavone@246 93 (string: val) . suffix
pavone@246 94 }
pavone@246 95 }
pavone@246 96 }
pavone@246 97 string <- {
pavone@246 98 stringIndent: ""
pavone@246 99 }
pavone@252 100 fold:with <- :acc :fun {
pavone@252 101 fun: acc self
pavone@252 102 }
pavone@246 103 }
pavone@246 104 }
pavone@247 105
pavone@247 106 symbol <- :_name {
pavone@247 107 #{
pavone@247 108 nodeType <- { _symbol }
pavone@247 109 name <- _name
pavone@247 110 stringIndent <- :indent {
pavone@247 111 name
pavone@247 112 }
pavone@247 113 string <- {
pavone@247 114 stringIndent: ""
pavone@247 115 }
pavone@252 116 fold:with <- :acc :fun {
pavone@252 117 fun: acc self
pavone@252 118 }
pavone@247 119 }
pavone@247 120 }
pavone@247 121
pavone@247 122 funcall:withArgs:hasReceiver? <- :_tocall :_args :_receiver? {
pavone@247 123 #{
pavone@252 124 nodeType <- { _call }
pavone@247 125 tocall <- _tocall
pavone@247 126 args <- _args
pavone@247 127 hasReceiver? <- _receiver?
pavone@247 128 stringIndent <- :indent {
pavone@247 129 argparts <- []
pavone@247 130 if: (tocall nodeType) = _symbol {
pavone@247 131 argparts <- (tocall name) splitOn: ":"
pavone@247 132 } else: {
pavone@247 133 argparts <- [tocall stringIndent: indent]
pavone@247 134 }
pavone@247 135 curarg <- args
pavone@247 136 str <- ""
pavone@247 137 if: hasReceiver? {
pavone@247 138 str <- ((curarg value) stringIndent: indent) . " "
pavone@247 139 curarg <- curarg tail
pavone@247 140 }
pavone@247 141 foreach: argparts :idx part {
pavone@247 142 str <- str . part . ":"
pavone@247 143 if: (not: (curarg empty?)) {
pavone@247 144 str <- str . " " . ((curarg value) stringIndent: indent)
pavone@247 145 curarg <- curarg tail
pavone@247 146 }
pavone@247 147 }
pavone@247 148 while: { not: (curarg empty?) } do: {
pavone@247 149 str <- str . " " . ((curarg value) stringIndent: indent)
pavone@247 150 curarg <- curarg tail
pavone@247 151 }
pavone@247 152 str
pavone@247 153 }
pavone@247 154 string <- {
pavone@247 155 stringIndent: ""
pavone@247 156 }
pavone@252 157 fold:with <- :acc :fun {
pavone@252 158 acc <- fun: acc self
pavone@252 159 _args fold: acc with: :acc el {
pavone@252 160 fun: acc el
pavone@252 161 }
pavone@252 162 }
pavone@247 163 }
pavone@247 164 }
pavone@247 165
pavone@247 166 object <- :_messages {
pavone@247 167 #{
pavone@247 168 nodeType <- { _object }
pavone@247 169 messages <- _messages
pavone@247 170 stringIndent <- :indent {
pavone@247 171 nextindent <- "\t" . indent
pavone@247 172 (messages fold: "#{" with: :acc el {
pavone@247 173 acc . "\n" . nextindent . (el stringIndent: nextindent)
pavone@247 174 }) . "\n" . indent . "}"
pavone@247 175 }
pavone@247 176 string <- {
pavone@247 177 stringIndent: ""
pavone@247 178 }
pavone@252 179 fold:with <- :acc :fun {
pavone@252 180 acc <- fun: acc self
pavone@252 181 messages fold: acc with: :acc el {
pavone@252 182 fun: acc el
pavone@252 183 }
pavone@252 184 }
pavone@247 185 }
pavone@247 186 }
pavone@247 187
pavone@247 188 seqLit:array? <- :_els :_array? {
pavone@247 189 #{
pavone@247 190 nodeType <- { _sequence }
pavone@247 191 els <- _els
pavone@247 192 array? <- _array?
pavone@247 193 stringIndent <- :indent {
pavone@247 194 nextIndent <- "\t" . indent
pavone@247 195 (els fold: (if: array? {"#["} else: {"["}) with: :acc el {
pavone@247 196 acc . "\n" . nextIndent . (el stringIndent: nextIndent)
pavone@247 197 }) . "\n" . indent . "]"
pavone@247 198 }
pavone@247 199 string <- {
pavone@247 200 stringIndent: ""
pavone@247 201 }
pavone@252 202 fold:with <- :acc :fun {
pavone@252 203 acc <- fun: acc self
pavone@252 204 els fold: acc with: :acc el {
pavone@252 205 fun: acc el
pavone@252 206 }
pavone@252 207 }
pavone@247 208 }
pavone@247 209 }
pavone@247 210
pavone@247 211 assign:to <- :_expr :_sym {
pavone@247 212 #{
pavone@247 213 nodeType <- { _assignment }
pavone@247 214 assign <- _expr
pavone@247 215 to <- _sym
pavone@247 216 stringIndent <- :indent {
pavone@247 217 (to stringIndent: indent) . " <- " . (assign stringIndent: indent)
pavone@247 218 }
pavone@247 219 string <- {
pavone@247 220 stringIndent: ""
pavone@247 221 }
pavone@252 222 fold:with <- :acc :fun {
pavone@252 223 acc <- fun: acc self
pavone@252 224 acc <- fun: acc _sym
pavone@252 225 fun: acc _expr
pavone@252 226 }
pavone@247 227 }
pavone@247 228 }
pavone@247 229
pavone@247 230 lambda:withArgs <- :_exprs :_args {
pavone@247 231 #{
pavone@247 232 nodeType <- { _lambda }
pavone@247 233 args <- _args
pavone@247 234 expressions <- _exprs
pavone@247 235 stringIndent <- :indent {
pavone@247 236 argStr <- args join: " "
pavone@247 237 if: (argStr length) > 0 {
pavone@247 238 argStr <- argStr . " "
pavone@247 239 }
pavone@247 240 nextIndent <- "\t" . indent
pavone@247 241 (expressions fold: argStr . "{" with: :acc el {
pavone@247 242 acc . "\n" . nextIndent . (el stringIndent: nextIndent)
pavone@247 243 }) . "\n" . indent . "}"
pavone@247 244 }
pavone@247 245 string <- {
pavone@247 246 stringIndent: ""
pavone@247 247 }
pavone@252 248 fold:with <- :acc :fun {
pavone@252 249 acc <- fun: acc self
pavone@252 250 expressions fold: acc with: :acc el {
pavone@252 251 fun: acc el
pavone@252 252 }
pavone@252 253 }
pavone@247 254 }
pavone@247 255 }
pavone@246 256 }
pavone@246 257 }