annotate modules/ast.tp @ 263:98147071baf6

Add support for llMessage definitions in buildMethodTables
author Michael Pavone <pavone@retrodev.com>
date Mon, 14 Jul 2014 09:30:31 -0700
parents be224817a14b
children 2308336790d4
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@263 128 llMessage? <- {
pavone@263 129 (tocall nodeType) = _symbol && (tocall name) = "llMessage:withVars:andCode"
pavone@263 130 }
pavone@247 131 stringIndent <- :indent {
pavone@247 132 argparts <- []
pavone@247 133 if: (tocall nodeType) = _symbol {
pavone@247 134 argparts <- (tocall name) splitOn: ":"
pavone@247 135 } else: {
pavone@247 136 argparts <- [tocall stringIndent: indent]
pavone@247 137 }
pavone@247 138 curarg <- args
pavone@247 139 str <- ""
pavone@247 140 if: hasReceiver? {
pavone@247 141 str <- ((curarg value) stringIndent: indent) . " "
pavone@247 142 curarg <- curarg tail
pavone@247 143 }
pavone@247 144 foreach: argparts :idx part {
pavone@247 145 str <- str . part . ":"
pavone@247 146 if: (not: (curarg empty?)) {
pavone@247 147 str <- str . " " . ((curarg value) stringIndent: indent)
pavone@247 148 curarg <- curarg tail
pavone@247 149 }
pavone@247 150 }
pavone@247 151 while: { not: (curarg empty?) } do: {
pavone@247 152 str <- str . " " . ((curarg value) stringIndent: indent)
pavone@247 153 curarg <- curarg tail
pavone@247 154 }
pavone@247 155 str
pavone@247 156 }
pavone@247 157 string <- {
pavone@247 158 stringIndent: ""
pavone@247 159 }
pavone@252 160 fold:with <- :acc :fun {
pavone@252 161 acc <- fun: acc self
pavone@252 162 _args fold: acc with: :acc el {
pavone@257 163 el fold: acc with: fun
pavone@252 164 }
pavone@252 165 }
pavone@247 166 }
pavone@247 167 }
pavone@247 168
pavone@247 169 object <- :_messages {
pavone@247 170 #{
pavone@247 171 nodeType <- { _object }
pavone@247 172 messages <- _messages
pavone@247 173 stringIndent <- :indent {
pavone@247 174 nextindent <- "\t" . indent
pavone@247 175 (messages fold: "#{" with: :acc el {
pavone@247 176 acc . "\n" . nextindent . (el stringIndent: nextindent)
pavone@247 177 }) . "\n" . indent . "}"
pavone@247 178 }
pavone@247 179 string <- {
pavone@247 180 stringIndent: ""
pavone@247 181 }
pavone@252 182 fold:with <- :acc :fun {
pavone@252 183 acc <- fun: acc self
pavone@252 184 messages fold: acc with: :acc el {
pavone@257 185 el fold: acc with: fun
pavone@252 186 }
pavone@252 187 }
pavone@247 188 }
pavone@247 189 }
pavone@247 190
pavone@247 191 seqLit:array? <- :_els :_array? {
pavone@247 192 #{
pavone@247 193 nodeType <- { _sequence }
pavone@247 194 els <- _els
pavone@247 195 array? <- _array?
pavone@247 196 stringIndent <- :indent {
pavone@247 197 nextIndent <- "\t" . indent
pavone@247 198 (els fold: (if: array? {"#["} else: {"["}) with: :acc el {
pavone@247 199 acc . "\n" . nextIndent . (el stringIndent: nextIndent)
pavone@247 200 }) . "\n" . indent . "]"
pavone@247 201 }
pavone@247 202 string <- {
pavone@247 203 stringIndent: ""
pavone@247 204 }
pavone@252 205 fold:with <- :acc :fun {
pavone@252 206 acc <- fun: acc self
pavone@252 207 els fold: acc with: :acc el {
pavone@257 208 el fold: acc with: fun
pavone@252 209 }
pavone@252 210 }
pavone@247 211 }
pavone@247 212 }
pavone@247 213
pavone@247 214 assign:to <- :_expr :_sym {
pavone@247 215 #{
pavone@247 216 nodeType <- { _assignment }
pavone@247 217 assign <- _expr
pavone@247 218 to <- _sym
pavone@247 219 stringIndent <- :indent {
pavone@247 220 (to stringIndent: indent) . " <- " . (assign stringIndent: indent)
pavone@247 221 }
pavone@247 222 string <- {
pavone@247 223 stringIndent: ""
pavone@247 224 }
pavone@252 225 fold:with <- :acc :fun {
pavone@252 226 acc <- fun: acc self
pavone@257 227 acc <- _sym fold: acc with: fun
pavone@257 228 _expr fold: acc with: fun
pavone@252 229 }
pavone@247 230 }
pavone@247 231 }
pavone@247 232
pavone@247 233 lambda:withArgs <- :_exprs :_args {
pavone@247 234 #{
pavone@247 235 nodeType <- { _lambda }
pavone@247 236 args <- _args
pavone@247 237 expressions <- _exprs
pavone@247 238 stringIndent <- :indent {
pavone@247 239 argStr <- args join: " "
pavone@247 240 if: (argStr length) > 0 {
pavone@247 241 argStr <- argStr . " "
pavone@247 242 }
pavone@247 243 nextIndent <- "\t" . indent
pavone@247 244 (expressions fold: argStr . "{" with: :acc el {
pavone@247 245 acc . "\n" . nextIndent . (el stringIndent: nextIndent)
pavone@247 246 }) . "\n" . indent . "}"
pavone@247 247 }
pavone@247 248 string <- {
pavone@247 249 stringIndent: ""
pavone@247 250 }
pavone@252 251 fold:with <- :acc :fun {
pavone@252 252 acc <- fun: acc self
pavone@252 253 expressions fold: acc with: :acc el {
pavone@257 254 el fold: acc with: fun
pavone@252 255 }
pavone@252 256 }
pavone@247 257 }
pavone@247 258 }
pavone@246 259 }
pavone@246 260 }