view modules/symbols.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
children 98147071baf6
line wrap: on
line source
{
	_null <- #{
		find:else <- :_ :else {
			else:
		}
	}
	_local <- 0
	_closedover <- 1
	_upvar <- 2
	_method <- 3
	_self <- 4
	_parent <- 5

	_nextMethodId <- 0
	_method <- :_name {
		_id <- _nextMethodId
		_nextMethodId <- _id + 1
		#{
			name <- { _name }
			id <- { _id }
			string <- { "method " . _name . "(" . _id . ")" }
		}
	}
	#{
		nullTable <- { _null }

		tablewithParent <- :_parent {
			_symbols <- dict hash
			#{
				find:else <- :name :else {
					_symbols get: name else: {
						_parent find: name else: else
					}
				}
				defineMethod <- :name {
					_symbols get: name else: {
						_symbols set: name (_method: name)
					}
					self
				}
				print <- {
					foreach: _symbols :name info {
						print: name . ": " . info . "\n"
					}
				}
			}
		}

		table <- {
			tablewithParent: _null
		}

		buildMethodTable <- :tree {
			_object <- ast obj
			_assignment <- ast assignment
			tree fold: table with: :acc el {
				if: (el nodeType) = _object {
					(el messages) fold: acc with: :acc msg {
						if: (msg nodeType) = _assignment {
							acc defineMethod: ((msg to) name)
						}
						acc
					}
				} else: {
					acc
				}
			}
		}
	}
}