PageRenderTime 21ms CodeModel.GetById 19ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/Z80-Assm-BAK/src/ll.Mod

https://github.com/fitzer8/Z80Asm
Unknown | 278 lines | 238 code | 40 blank | 0 comment | 0 complexity | 300ba68d25715382ae8c847c802b38b9 MD5 | raw file
  1MODULE ll;
  2(*###############################################################
  3# Title:	ll
  4# Func:		This is a test of the ArrayList lib in oo2c.
  5# Author:	Fitz.
  6# Ver:		0.0
  7# Todo:
  8#					Add something here.
  9#================================================================
 10# HISTORY
 11#================================================================
 12#   DATE   #    NAME    # COMMENT
 13#================================================================
 14# 20110428 # Fitz       # Original.
 15# 20110428 # Fitz       # Original 0.1 release.
 16# 20110428 # Fitz       # 0.2 Object code now output.
 17###############################################################*)
 18IMPORT
 19	libc,
 20	Out,
 21	Ascii,
 22	Strings,
 23	CharClass,
 24	Object,
 25
 26	LL		:= ADT:LinkedList,
 27
 28	Utils,
 29	This, Debug
 30	;
 31
 32CONST
 33	maxStringLen = 256;
 34	maxSymLen    = 256;
 35	maxOpcdLen   = 6;
 36	maxLineNoLen = 8;
 37
 38TYPE
 39	Integer	= INTEGER;
 40	Boolean	= BOOLEAN;
 41
 42	String*	= ARRAY maxStringLen OF CHAR;
 43	SymStr*	= ARRAY maxSymLen OF CHAR;
 44
 45	SymEntry*		= POINTER TO SymEntryDesc;
 46	SymEntryDesc	= RECORD (Object.ObjectDesc)
 47		name*		: SymStr;   (* Symbol name *)
 48		value*		: LONGINT;  (* Symbol value *)
 49		next		: SymEntry;	(* Pointer to next symtab entry *)
 50		defined*	: Boolean;  (* TRUE if defined *)
 51		multiDef*	: Boolean;  (* TRUE if multiply defined *)
 52		isSet*		: Boolean;  (* TRUE if defined with SET pseudo *)
 53		equ*		: Boolean;  (* TRUE if defined with EQU pseudo *)
 54	END;
 55
 56	symList*		= LL.LinkedList( SymEntry );
 57	symIter*		= LL.Iterator( SymEntry );
 58	
 59VAR
 60	DBG					: BOOLEAN;
 61
 62	symTab:				SymEntry;	(* Pointer to first entry in symtab *)
 63
 64	SymNtry				: SymEntry;
 65	SymList				: symList;
 66	SymIter				: symIter;
 67	Ntry				: SymEntry;
 68
 69	name				: SymStr;
 70
 71(*###############################################################
 72# Title:	FindSym
 73# Func:		Assign object and list files to their file handles.
 74# Author:	Fitz
 75# Ver:		0.0
 76#================================================================
 77# HISTORY
 78#================================================================
 79#   DATE   #    NAME    # COMMENT
 80#================================================================
 81# 201012203 # Fitz       # Original.
 82###############################################################*)
 83PROCEDURE FindSym( );
 84VAR
 85	DBG			: BOOLEAN;
 86
 87	Ntry		: SymEntry;
 88	found		: Boolean;
 89
 90BEGIN
 91	DBG := FALSE;
 92	DBG := TRUE;
 93	IF DBG THEN
 94		Debug.Entry( This.File(), This.Func() );
 95	END;
 96
 97	Ntry := SymList.Get( 0 );
 98	SymIter := SymList.GetIterator(NIL);
 99	WHILE SymIter.HasNext() DO
100		Ntry := SymIter.Next();
101		IF DBG THEN
102			Out.String( "Addr: 0x" );
103			Out.Hex( Ntry.value, 4 );
104			Out.String( "    name: " ); Out.String( Ntry.name );
105			Out.Ln; Out.Ln;
106		END;
107	END;
108
109	IF DBG THEN
110		Debug.Exit( This.File(), This.Func() );
111	END;
112END FindSym;
113	
114(*###############################################################
115# Title:	NextSym
116# Func:		Find the symbol that has a lexical value greater
117#			than SymStr.
118# Author:	Fitz
119# Ver:		0.0
120#================================================================
121# HISTORY
122#================================================================
123#   DATE   #    NAME    # COMMENT
124#================================================================
125# 20110502 # Fitz       # Original.
126###############################################################*)
127PROCEDURE NextSym( SymName: SymStr ) : LONGINT;
128VAR
129	DBG			: BOOLEAN;
130
131	Ntry		: SymEntry;
132	found		: Boolean;
133	idx			: LONGINT;
134
135BEGIN
136	DBG := FALSE;
137	DBG := TRUE;
138	IF DBG THEN
139		Debug.Entry( This.File(), This.Func() );
140	END;
141
142	IF DBG THEN
143		Debug.Debug;
144		Debug.Label( "SymName" );
145		Debug.QString( SymName );
146		Debug.Nl;
147	END;
148
149	found := FALSE;
150
151	NEW( Ntry );
152	Ntry := SymList.Get( 0 );
153	SymIter := SymList.GetIterator(NIL);
154	LOOP
155		IF SymIter.HasNext() THEN
156			Ntry := SymIter.Next();
157		ELSE
158			EXIT;
159		END;
160		IF DBG THEN
161			Out.String( "idx: " );
162			Out.LongInt( SymList.IndexOf( Ntry ), 3 );
163			Out.String( "    Addr: 0x" );
164			Out.Hex( Ntry.value, 4 );
165			Out.String( "    Ntry.name: " ); Out.String( Ntry.name );
166			Out.String( "    SymName: " ); Out.String( SymName );
167			Out.Ln; Out.Ln;
168		END;
169		IF Strings.Compare( Ntry.name, SymName ) = Strings.greater THEN
170			Out.String( "greater" ); Out.Ln;
171			found := TRUE;
172			EXIT;
173		END;
174	END;
175	idx := SymList.IndexOf( Ntry );
176
177	IF DBG THEN
178		Debug.Exit( This.File(), This.Func() );
179	END;
180	RETURN idx;
181END NextSym;
182	
183(*###############################################################
184# Title:	AddSym
185# Func:		Assign object and list files to their file handles.
186# Author:	Fitz
187# Ver:		0.0
188#================================================================
189# HISTORY
190#================================================================
191#   DATE   #    NAME    # COMMENT
192#================================================================
193# 201012203 # Fitz       # Original.
194###############################################################*)
195PROCEDURE AddSym( SymName: SymStr );
196VAR
197	DBG			: BOOLEAN;
198
199	Ntry		: SymEntry;
200	p			: SymEntry;
201	found		: Boolean;
202	idx			: LONGINT;
203
204BEGIN
205	DBG := FALSE;
206	DBG := TRUE;
207	IF DBG THEN
208		Debug.Entry( This.File(), This.Func() );
209	END;
210
211	IF DBG THEN
212		Debug.Debug;
213		Debug.Label( "SymName" );
214		Debug.QString( SymName );
215		Debug.Nl;
216	END;
217
218	found := FALSE;
219	NEW( p );
220	p.value		:= 0;
221	p.name		:= SymName;
222	p.defined	:= FALSE;
223	p.multiDef	:= FALSE;
224	p.isSet		:= FALSE;
225	p.equ		:= FALSE;
226			Out.String( "    p.name: " ); Out.String( p.name );
227			Out.Ln; Out.Ln;
228idx := NextSym( SymName );
229
230	Ntry := SymList.Get( idx );
231	SymList.Insert( idx, p );
232
233	IF DBG THEN
234		Debug.Exit( This.File(), This.Func() );
235	END;
236END AddSym;
237	
238BEGIN
239	(*################################################
240	# This symbol put in there to prevent conditional
241	# processing later to determine if we need an
242	# Insert or an Append.
243	################################################*)
244	SymList := NEW( symList );
245	NEW( SymNtry );
246	SymNtry.value := 0;
247	SymNtry.name := "ooo";
248	SymList.Append( SymNtry );
249(*
250	SymList.Insert( 0, SymNtry );
251*)
252
253	NEW( SymNtry );
254	SymNtry.value := 0100H;
255	SymNtry.name := "stack";
256	SymList.Append( SymNtry );
257
258	Out.LongInt( SymNtry.value, 5 );
259	Out.String( " :  Total Error(s)" );
260	Out.Ln;
261
262	name := "aaa";
263	AddSym( name );
264	
265	name := "rrr";
266	AddSym( name );
267	
268	name := "zzz";
269	AddSym( name );
270	
271	FindSym;
272
273END ll.
274
275(*###############################################################
276FFFFFFFFFFFFFFFFFFFFFFFFFF
277###############################################################*)
278