annotate modules/symbols.tp @ 338:1458c069c715

Added "value" method to option value and option none. It behaves similarly to value:none, except the none case just propagates the none value and the value case wraps the result in an option value
author Michael Pavone <pavone@retrodev.com>
date Sat, 04 Apr 2015 11:54:46 -0700
parents aea99b93cf2f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
252
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1 {
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2 _null <- #{
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
3 find:else <- :_ :else {
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
4 else:
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
5 }
302
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
6 ifDefined:else <- :name ifdef :else {
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
7 else:
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
8 }
252
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
9 }
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
10 _local <- 0
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
11 _closedover <- 1
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
12 _upvar <- 2
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
13 _method <- 3
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
14 _self <- 4
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
15 _parent <- 5
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
16
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
17 _nextMethodId <- 0
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
18 _method <- :_name {
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
19 _id <- _nextMethodId
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
20 _nextMethodId <- _id + 1
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
21 #{
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
22 name <- { _name }
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
23 id <- { _id }
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
24 string <- { "method " . _name . "(" . _id . ")" }
302
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
25 isMethod? <- { true }
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
26 isLocal? <- { false }
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
27 }
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
28 }
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
29 _local <- :_name _def {
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
30 #{
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
31 name <- { _name }
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
32 string <- { "local " . _name }
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
33 def <- { _def }
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
34 isMethod? <- { false }
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
35 closedOver? <- false
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
36 isLocal? <- { true }
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
37 }
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
38 }
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
39 _upvar <- :parent {
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
40 if: (parent isLocal?) {
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
41 parent closedOver?!: true
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
42 #{
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
43 name <- { parent name }
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
44 def <- { parent def }
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
45 closedOver? <- { parent closedOver? }
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
46 isMethod? <- { parent isMethod? }
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
47 string <- { "upvar " . name}
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
48 isLocal? <- { false }
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
49 depth <- 1
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
50 }
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
51 } else: {
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
52 parent depth!: (parent depth) + 1
252
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
53 }
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
54 }
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
55 #{
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
56 nullTable <- { _null }
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
57
302
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
58 tableWithParent <- :_parent {
252
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
59 _symbols <- dict hash
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
60 #{
302
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
61 ifDefined:else <- :name ifdef :else {
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
62 _symbols ifget: name :sym {
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
63 ifdef: sym
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
64 } else: {
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
65 _parent ifDefined: name :sym {
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
66 ifdef: (_upvar: sym)
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
67 } else: else
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
68 }
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
69 }
252
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
70 find:else <- :name :else {
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
71 _symbols get: name else: {
302
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
72 _parent ifDefined: name :sym {
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
73 if: (sym isMethod?) {
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
74 //TODO: methods on parent objects
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
75 sym
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
76 } else: {
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
77 _upvar: sym
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
78 }
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
79 } else: {
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
80 else:
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
81 }
252
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
82 }
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
83 }
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
84 defineMethod <- :name {
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
85 _symbols get: name else: {
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
86 _symbols set: name (_method: name)
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
87 }
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
88 self
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
89 }
302
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
90 define <- :name def {
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
91 s <- (_local: name def)
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
92 _symbols set: name s
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
93 s
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
94 }
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
95 find:elseDefine <- :name :def {
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
96 find: name else: {
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
97 define: name def
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
98 }
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
99 }
252
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
100 print <- {
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
101 foreach: _symbols :name info {
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
102 print: name . ": " . info . "\n"
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
103 }
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
104 }
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
105 }
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
106 }
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
107
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
108 table <- {
302
aea99b93cf2f More fleshed out implementation of symbol tables
Michael Pavone <pavone@retrodev.com>
parents: 263
diff changeset
109 tableWithParent: _null
252
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
110 }
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
111
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
112 buildMethodTable <- :tree {
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
113 _object <- ast obj
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
114 _assignment <- ast assignment
263
98147071baf6 Add support for llMessage definitions in buildMethodTables
Michael Pavone <pavone@retrodev.com>
parents: 252
diff changeset
115 _call <- ast call
98147071baf6 Add support for llMessage definitions in buildMethodTables
Michael Pavone <pavone@retrodev.com>
parents: 252
diff changeset
116
252
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
117 tree fold: table with: :acc el {
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
118 if: (el nodeType) = _object {
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
119 (el messages) fold: acc with: :acc msg {
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
120 if: (msg nodeType) = _assignment {
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
121 acc defineMethod: ((msg to) name)
263
98147071baf6 Add support for llMessage definitions in buildMethodTables
Michael Pavone <pavone@retrodev.com>
parents: 252
diff changeset
122 } else: {
98147071baf6 Add support for llMessage definitions in buildMethodTables
Michael Pavone <pavone@retrodev.com>
parents: 252
diff changeset
123 if: (msg nodeType) = _call && (msg llMessage?) {
98147071baf6 Add support for llMessage definitions in buildMethodTables
Michael Pavone <pavone@retrodev.com>
parents: 252
diff changeset
124 acc defineMethod: (((msg args) value) name)
98147071baf6 Add support for llMessage definitions in buildMethodTables
Michael Pavone <pavone@retrodev.com>
parents: 252
diff changeset
125 }
252
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
126 }
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
127 acc
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
128 }
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
129 } else: {
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
130 acc
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
131 }
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
132 }
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
133 }
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
134 }
004946743678 Added code for building a method symbol table
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
135 }