Module: dfmc-reader Synopsis: A name lookup table that respects hygiene. Author: Keith Playford Copyright: Original Code is Copyright (c) 1995-2004 Functional Objects, Inc. All rights reserved. License: Functional Objects Library Public License Version 1.0 Dual-license: GNU Lesser General Public License Warranty: Distributed WITHOUT WARRANTY OF ANY KIND define class () constant slot entries :: = make(); end class; define method size (table :: ) => (size :: ) table.entries.size end method; define method element (table :: , name :: , #key default = unsupplied()) => (element-or-default) let entries = entries(table); let sz = size(entries); iterate walk (index :: = 0) if (index >= sz) if (supplied?(default)) default else error("No name matching %= found in variable name table %= and " "no default supplied.", name, table); end; else let test-name = entries[index]; if (same-name-when-local?(name, test-name)) entries[index + 1]; else walk(index + 2); end; end; end; end method; define method element-setter (value, table :: , name :: ) => (value) let entries = entries(table); let sz = size(entries); iterate walk (index :: = 0) if (index >= sz) add!(entries, name); add!(entries, value); value else let test-name = entries[index]; if (same-name-when-local?(name, test-name)) entries[index + 1] := value; else walk(index + 2); end; end; end; end method; define inline function table-next-state (collection :: , state :: ) => (state :: ) state + 2 end function; define inline function table-finished-state? (collection :: , state :: , limit :: ) => (result :: ) state = limit end function; define inline function table-current-key (collection :: , state :: ) => (result :: ) collection[state] end function; define inline function table-current-element (collection :: , state :: ) => (result) collection[state + 1] end function; define inline function table-current-element-setter (new-value, collection :: , state :: ) => (result) collection[state + 1] := new-value; end function; define inline function table-copy-state (collection :: , state :: ) => (state :: ) state end function; define sealed inline method forward-iteration-protocol (collection :: ) => (initial-state :: , limit :: , next-state :: , finished-state? :: , current-key :: , current-element :: , current-element-setter :: , copy-state :: ); values(0, size(collection.entries), table-next-state, table-finished-state?, table-current-key, table-current-element, table-current-element-setter, table-copy-state) end method forward-iteration-protocol; // eof