annotate modules/ast.tp @ 377:93c28eee141e default tip

Merge
author Michael Pavone <pavone@retrodev.com>
date Sat, 15 Aug 2015 22:45:33 -0700
parents 27477c8c2823
children
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 {
247
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
2 _binary <- 0
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
3 _string <- 1
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
4 _int <- 2
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
5 _symbol <- 3
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
6 _call <- 4
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
7 _object <- 5
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
8 _sequence <- 6
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
9 _assignment <- 7
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
10 _lambda <- 8
246
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 #{
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
13 binary <- { _binary }
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
14 stringlit <- { _string }
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
15 intlit <- { _int }
247
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
16 sym <- { _symbol }
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
17 call <- { _call }
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
18 obj <- { _object }
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
19 sequence <- { _sequence }
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
20 assignment <- { _assignment }
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
21 lambda <- { _lambda }
246
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
22
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
23 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
24 #{
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
25 nodeType <- { _binary }
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
26 left <- _left
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
27 op <- opname
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
28 right <- _right
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 leftAssociative? <- {
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
31 op != "|"
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 stringIndent <- :indent {
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
34 (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
35 }
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
36 string <- {
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
37 stringIndent: ""
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
38 }
252
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents: 247
diff changeset
39 fold:with <- :acc :fun {
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents: 247
diff changeset
40 acc <- fun: acc self
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents: 247
diff changeset
41 acc <- _left fold: acc with: fun
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents: 247
diff changeset
42 _right fold: acc with: fun
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents: 247
diff changeset
43 }
246
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
44 }
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
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
47 stringLit <- :_val {
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
48 #{
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
49 nodeType <- { _string }
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
50 val <- _val
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 "\"" . val . "\""
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
53 }
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
54 string <- {
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
55 stringIndent: ""
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
56 }
252
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents: 247
diff changeset
57 fold:with <- :acc :fun {
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents: 247
diff changeset
58 fun: acc self
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents: 247
diff changeset
59 }
246
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
60 }
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
61 }
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
62
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
63 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
64 #{
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
65 nodeType <- { _int }
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
66 val <- _val
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
67 base <- _base
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
68 bits <- _bits
310
2308336790d4 WIP compiler module for low-level dialect
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
69 size <- { _bits / 8 }
246
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
70 signed? <- _signed?
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
71 stringIndent <- :indent {
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
72 suffix <- ""
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
73 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
74 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
75 }
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
76 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
77 "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
78 } else: {
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
79 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
80 str <- "0b"
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
81 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
82 printzero <- false
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
83 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
84 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
85 printzero <- true
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
86 "1"
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
87 } else: {
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
88 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
89 })
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
90 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
91 }
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
92 str . suffix
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
93 } else: {
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
94 (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
95 }
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
96 }
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
97 }
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
98 string <- {
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
99 stringIndent: ""
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
100 }
252
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents: 247
diff changeset
101 fold:with <- :acc :fun {
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents: 247
diff changeset
102 fun: acc self
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents: 247
diff changeset
103 }
246
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
104 }
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
105 }
358
27477c8c2823 Add support for simple type annotations in parser and update llhello sample with a possible new low-level dialect syntax leveraging those annotations
Michael Pavone <pavone@retrodev.com>
parents: 310
diff changeset
106
27477c8c2823 Add support for simple type annotations in parser and update llhello sample with a possible new low-level dialect syntax leveraging those annotations
Michael Pavone <pavone@retrodev.com>
parents: 310
diff changeset
107 symbol:withType <- :_name :_type {
247
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
108 #{
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
109 nodeType <- { _symbol }
358
27477c8c2823 Add support for simple type annotations in parser and update llhello sample with a possible new low-level dialect syntax leveraging those annotations
Michael Pavone <pavone@retrodev.com>
parents: 310
diff changeset
110 type <- _type
247
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
111 name <- _name
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
112 stringIndent <- :indent {
358
27477c8c2823 Add support for simple type annotations in parser and update llhello sample with a possible new low-level dialect syntax leveraging those annotations
Michael Pavone <pavone@retrodev.com>
parents: 310
diff changeset
113 _type value: :type {
27477c8c2823 Add support for simple type annotations in parser and update llhello sample with a possible new low-level dialect syntax leveraging those annotations
Michael Pavone <pavone@retrodev.com>
parents: 310
diff changeset
114 name . " (" . type . ")"
27477c8c2823 Add support for simple type annotations in parser and update llhello sample with a possible new low-level dialect syntax leveraging those annotations
Michael Pavone <pavone@retrodev.com>
parents: 310
diff changeset
115 } none: {
27477c8c2823 Add support for simple type annotations in parser and update llhello sample with a possible new low-level dialect syntax leveraging those annotations
Michael Pavone <pavone@retrodev.com>
parents: 310
diff changeset
116 name
27477c8c2823 Add support for simple type annotations in parser and update llhello sample with a possible new low-level dialect syntax leveraging those annotations
Michael Pavone <pavone@retrodev.com>
parents: 310
diff changeset
117 }
247
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
118 }
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
119 string <- {
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
120 stringIndent: ""
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
121 }
252
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents: 247
diff changeset
122 fold:with <- :acc :fun {
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents: 247
diff changeset
123 fun: acc self
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents: 247
diff changeset
124 }
247
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
125 }
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
126 }
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
127
358
27477c8c2823 Add support for simple type annotations in parser and update llhello sample with a possible new low-level dialect syntax leveraging those annotations
Michael Pavone <pavone@retrodev.com>
parents: 310
diff changeset
128 symbol <- :_name {
27477c8c2823 Add support for simple type annotations in parser and update llhello sample with a possible new low-level dialect syntax leveraging those annotations
Michael Pavone <pavone@retrodev.com>
parents: 310
diff changeset
129 symbol: _name withType: (option none)
27477c8c2823 Add support for simple type annotations in parser and update llhello sample with a possible new low-level dialect syntax leveraging those annotations
Michael Pavone <pavone@retrodev.com>
parents: 310
diff changeset
130 }
27477c8c2823 Add support for simple type annotations in parser and update llhello sample with a possible new low-level dialect syntax leveraging those annotations
Michael Pavone <pavone@retrodev.com>
parents: 310
diff changeset
131
247
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
132 funcall:withArgs:hasReceiver? <- :_tocall :_args :_receiver? {
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
133 #{
252
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents: 247
diff changeset
134 nodeType <- { _call }
247
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
135 tocall <- _tocall
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
136 args <- _args
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
137 hasReceiver? <- _receiver?
263
98147071baf6 Add support for llMessage definitions in buildMethodTables
Michael Pavone <pavone@retrodev.com>
parents: 257
diff changeset
138 llMessage? <- {
98147071baf6 Add support for llMessage definitions in buildMethodTables
Michael Pavone <pavone@retrodev.com>
parents: 257
diff changeset
139 (tocall nodeType) = _symbol && (tocall name) = "llMessage:withVars:andCode"
98147071baf6 Add support for llMessage definitions in buildMethodTables
Michael Pavone <pavone@retrodev.com>
parents: 257
diff changeset
140 }
247
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
141 stringIndent <- :indent {
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
142 argparts <- []
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
143 if: (tocall nodeType) = _symbol {
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
144 argparts <- (tocall name) splitOn: ":"
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
145 } else: {
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
146 argparts <- [tocall stringIndent: indent]
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
147 }
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
148 curarg <- args
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
149 str <- ""
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
150 if: hasReceiver? {
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
151 str <- ((curarg value) stringIndent: indent) . " "
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
152 curarg <- curarg tail
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
153 }
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
154 foreach: argparts :idx part {
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
155 str <- str . part . ":"
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
156 if: (not: (curarg empty?)) {
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
157 str <- str . " " . ((curarg value) stringIndent: indent)
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
158 curarg <- curarg tail
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
159 }
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
160 }
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
161 while: { not: (curarg empty?) } do: {
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
162 str <- str . " " . ((curarg value) stringIndent: indent)
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
163 curarg <- curarg tail
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
164 }
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
165 str
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
166 }
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
167 string <- {
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
168 stringIndent: ""
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
169 }
252
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents: 247
diff changeset
170 fold:with <- :acc :fun {
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents: 247
diff changeset
171 acc <- fun: acc self
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents: 247
diff changeset
172 _args fold: acc with: :acc el {
257
be224817a14b Fix fold on ast nodes so that all nodes get visited
Michael Pavone <pavone@retrodev.com>
parents: 252
diff changeset
173 el fold: acc with: fun
252
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents: 247
diff changeset
174 }
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents: 247
diff changeset
175 }
247
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
176 }
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
177 }
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
178
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
179 object <- :_messages {
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
180 #{
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
181 nodeType <- { _object }
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
182 messages <- _messages
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
183 stringIndent <- :indent {
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
184 nextindent <- "\t" . indent
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
185 (messages fold: "#{" with: :acc el {
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
186 acc . "\n" . nextindent . (el stringIndent: nextindent)
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
187 }) . "\n" . indent . "}"
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
188 }
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
189 string <- {
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
190 stringIndent: ""
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
191 }
252
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents: 247
diff changeset
192 fold:with <- :acc :fun {
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents: 247
diff changeset
193 acc <- fun: acc self
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents: 247
diff changeset
194 messages fold: acc with: :acc el {
257
be224817a14b Fix fold on ast nodes so that all nodes get visited
Michael Pavone <pavone@retrodev.com>
parents: 252
diff changeset
195 el fold: acc with: fun
252
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents: 247
diff changeset
196 }
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents: 247
diff changeset
197 }
247
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
198 }
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
199 }
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
200
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
201 seqLit:array? <- :_els :_array? {
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
202 #{
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
203 nodeType <- { _sequence }
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
204 els <- _els
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
205 array? <- _array?
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
206 stringIndent <- :indent {
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
207 nextIndent <- "\t" . indent
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
208 (els fold: (if: array? {"#["} else: {"["}) with: :acc el {
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
209 acc . "\n" . nextIndent . (el stringIndent: nextIndent)
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
210 }) . "\n" . indent . "]"
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
211 }
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
212 string <- {
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
213 stringIndent: ""
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
214 }
252
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents: 247
diff changeset
215 fold:with <- :acc :fun {
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents: 247
diff changeset
216 acc <- fun: acc self
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents: 247
diff changeset
217 els fold: acc with: :acc el {
257
be224817a14b Fix fold on ast nodes so that all nodes get visited
Michael Pavone <pavone@retrodev.com>
parents: 252
diff changeset
218 el fold: acc with: fun
252
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents: 247
diff changeset
219 }
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents: 247
diff changeset
220 }
247
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
221 }
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
222 }
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
223
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
224 assign:to <- :_expr :_sym {
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
225 #{
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
226 nodeType <- { _assignment }
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
227 assign <- _expr
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
228 to <- _sym
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
229 stringIndent <- :indent {
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
230 (to stringIndent: indent) . " <- " . (assign stringIndent: indent)
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
231 }
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
232 string <- {
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
233 stringIndent: ""
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
234 }
252
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents: 247
diff changeset
235 fold:with <- :acc :fun {
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents: 247
diff changeset
236 acc <- fun: acc self
257
be224817a14b Fix fold on ast nodes so that all nodes get visited
Michael Pavone <pavone@retrodev.com>
parents: 252
diff changeset
237 acc <- _sym fold: acc with: fun
be224817a14b Fix fold on ast nodes so that all nodes get visited
Michael Pavone <pavone@retrodev.com>
parents: 252
diff changeset
238 _expr fold: acc with: fun
252
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents: 247
diff changeset
239 }
247
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
240 }
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
241 }
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
242
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
243 lambda:withArgs <- :_exprs :_args {
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
244 #{
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
245 nodeType <- { _lambda }
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
246 args <- _args
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
247 expressions <- _exprs
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
248 stringIndent <- :indent {
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
249 argStr <- args join: " "
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
250 if: (argStr length) > 0 {
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
251 argStr <- argStr . " "
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
252 }
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
253 nextIndent <- "\t" . indent
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
254 (expressions fold: argStr . "{" with: :acc el {
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
255 acc . "\n" . nextIndent . (el stringIndent: nextIndent)
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
256 }) . "\n" . indent . "}"
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
257 }
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
258 string <- {
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
259 stringIndent: ""
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
260 }
252
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents: 247
diff changeset
261 fold:with <- :acc :fun {
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents: 247
diff changeset
262 acc <- fun: acc self
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents: 247
diff changeset
263 expressions fold: acc with: :acc el {
257
be224817a14b Fix fold on ast nodes so that all nodes get visited
Michael Pavone <pavone@retrodev.com>
parents: 252
diff changeset
264 el fold: acc with: fun
252
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents: 247
diff changeset
265 }
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents: 247
diff changeset
266 }
247
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
267 }
b76f683d076e Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents: 246
diff changeset
268 }
246
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
269 }
8c81afd6d2d3 Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
270 }