Subversion Repositories Kolibri OS

Rev

Rev 1053 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
31 halyavin 1
 
2
; Copyright (c) 1999-2009, Tomasz Grysztar.
1039 heavyiron 3
; All rights reserved.
31 halyavin 4
5
 
6
	mov	edi,characters
157 heavyiron 7
	xor	al,al
8
      make_characters_table:
31 halyavin 9
	stosb
157 heavyiron 10
	inc	al
11
	jnz	make_characters_table
253 heavyiron 12
	mov	esi,characters+'a'
157 heavyiron 13
	mov	edi,characters+'A'
14
	mov	ecx,26
15
	rep	movsb
16
	mov	edi,characters
17
	mov	esi,symbol_characters+1
18
	movzx	ecx,byte [esi-1]
19
	xor	eax,eax
20
      mark_symbol_characters:
31 halyavin 21
	lodsb
157 heavyiron 22
	mov	byte [edi+eax],0
23
	loop	mark_symbol_characters
24
	mov	edi,locals_counter
25
	mov	ax,1 + '0' shl 8
692 heavyiron 26
	stos	word [edi]
27
	mov	edi,[memory_start]
157 heavyiron 28
	mov	[include_paths],edi
29
	mov	esi,include_variable
30
	call	get_environment_variable
31
	xor	al,al
32
	stos	byte [edi]
1053 heavyiron 33
	mov	[memory_start],edi
157 heavyiron 34
	mov	eax,[additional_memory]
35
	mov	[free_additional_memory],eax
36
	mov	eax,[additional_memory_end]
37
	mov	[labels_list],eax
38
	xor	eax,eax
39
	mov	[source_start],eax
1189 heavyiron 40
	mov	[display_buffer],eax
157 heavyiron 41
	mov	[hash_tree],eax
42
	mov	[macro_status],al
43
	mov	esi,[input_file]
44
	mov	edx,esi
45
	call	open
46
	jc	main_file_not_found
47
	mov	edi,[memory_start]
48
	call	preprocess_file
49
	mov	eax,[error_line]
50
	mov	[current_line],eax
51
	cmp	[macro_status],0
52
	jne	incomplete_macro
53
	mov	[source_start],edi
54
	ret
55
31 halyavin 56
 
57
	push	[memory_end]
157 heavyiron 58
	push	esi
59
	mov	al,2
60
	xor	edx,edx
61
	call	lseek
62
	push	eax
63
	xor	al,al
64
	xor	edx,edx
65
	call	lseek
66
	pop	ecx
67
	mov	edx,[memory_end]
68
	dec	edx
69
	mov	byte [edx],1Ah
70
	sub	edx,ecx
71
	jc	out_of_memory
72
	mov	esi,edx
73
	cmp	edx,edi
74
	jbe	out_of_memory
75
	mov	[memory_end],edx
76
	call	read
77
	call	close
78
	pop	edx
79
	xor	ecx,ecx
80
	mov	ebx,esi
81
      preprocess_source:
31 halyavin 82
	inc	ecx
157 heavyiron 83
	mov	[current_line],edi
84
	mov	eax,edx
85
	stos	dword [edi]
86
	mov	eax,ecx
87
	stos	dword [edi]
88
	mov	eax,esi
89
	sub	eax,ebx
90
	stos	dword [edi]
91
	xor	eax,eax
92
	stos	dword [edi]
93
	push	ebx edx
94
	call	convert_line
95
	call	preprocess_line
96
	pop	edx ebx
97
      next_line:
31 halyavin 98
	cmp	byte [esi-1],1Ah
157 heavyiron 99
	jne	preprocess_source
100
      file_end:
31 halyavin 101
	pop	[memory_end]
157 heavyiron 102
	clc
103
	ret
104
31 halyavin 105
 
106
	push	ecx
157 heavyiron 107
	test	[macro_status],0Fh
108
	jz	convert_line_data
109
	mov	ax,3Bh
110
	stos	word [edi]
111
      convert_line_data:
31 halyavin 112
	cmp	edi,[memory_end]
157 heavyiron 113
	jae	out_of_memory
114
	lods	byte [esi]
115
	cmp	al,20h
116
	je	convert_line_data
117
	cmp	al,9
118
	je	convert_line_data
119
	mov	ah,al
120
	mov	ebx,characters
121
	xlat	byte [ebx]
122
	or	al,al
123
	jz	convert_separator
124
	cmp	ah,27h
125
	je	convert_string
126
	cmp	ah,22h
127
	je	convert_string
128
	mov	byte [edi],1Ah
129
	scas	word [edi]
130
	xchg	al,ah
131
	stos	byte [edi]
132
	mov	ebx,characters
133
	xor	ecx,ecx
134
      convert_symbol:
31 halyavin 135
	lods	byte [esi]
157 heavyiron 136
	stos	byte [edi]
137
	xlat	byte [ebx]
138
	or	al,al
139
	loopnzd convert_symbol
140
	neg	ecx
141
	cmp	ecx,255
142
	ja	name_too_long
143
	mov	ebx,edi
144
	sub	ebx,ecx
145
	mov	byte [ebx-2],cl
146
      found_separator:
31 halyavin 147
	dec	edi
157 heavyiron 148
	mov	ah,[esi-1]
149
      convert_separator:
31 halyavin 150
	xchg	al,ah
157 heavyiron 151
	cmp	al,20h
152
	jb	control_character
153
	je	convert_line_data
154
      symbol_character:
31 halyavin 155
	cmp	al,3Bh
157 heavyiron 156
	je	ignore_comment
157
	cmp	al,5Ch
158
	je	backslash_character
159
	stos	byte [edi]
160
	jmp	convert_line_data
161
      control_character:
31 halyavin 162
	cmp	al,1Ah
157 heavyiron 163
	je	line_end
164
	cmp	al,0Dh
165
	je	cr_character
166
	cmp	al,0Ah
167
	je	lf_character
168
	cmp	al,9
169
	je	convert_line_data
170
	or	al,al
171
	jnz	symbol_character
172
	jmp	line_end
173
      lf_character:
31 halyavin 174
	lods	byte [esi]
157 heavyiron 175
	cmp	al,0Dh
176
	je	line_end
177
	dec	esi
178
	jmp	line_end
179
      cr_character:
31 halyavin 180
	lods	byte [esi]
157 heavyiron 181
	cmp	al,0Ah
182
	je	line_end
183
	dec	esi
184
	jmp	line_end
185
      convert_string:
31 halyavin 186
	mov	al,22h
157 heavyiron 187
	stos	byte [edi]
188
	scas	dword [edi]
189
	mov	ebx,edi
190
      copy_string:
31 halyavin 191
	lods	byte [esi]
157 heavyiron 192
	stos	byte [edi]
193
	cmp	al,0Ah
194
	je	missing_end_quote
195
	cmp	al,0Dh
196
	je	missing_end_quote
197
	or	al,al
198
	jz	missing_end_quote
199
	cmp	al,1Ah
200
	je	missing_end_quote
201
	cmp	al,ah
202
	jne	copy_string
203
	lods	byte [esi]
204
	cmp	al,ah
205
	je	copy_string
206
	dec	esi
207
	dec	edi
208
	mov	eax,edi
209
	sub	eax,ebx
210
	mov	[ebx-4],eax
211
	jmp	convert_line_data
212
      backslash_character:
31 halyavin 213
	mov	byte [edi],0
157 heavyiron 214
	lods	byte [esi]
215
	cmp	al,20h
216
	je	concatenate_lines
217
	cmp	al,9
218
	je	concatenate_lines
219
	cmp	al,1Ah
220
	je	unexpected_end_of_file
221
	cmp	al,0Ah
222
	je	concatenate_lf
223
	cmp	al,0Dh
224
	je	concatenate_cr
225
	cmp	al,3Bh
226
	je	find_concatenated_line
227
	mov	al,1Ah
228
	stos	byte [edi]
229
	mov	ecx,edi
230
	mov	ax,5C01h
231
	stos	word [edi]
232
	dec	esi
233
      group_backslashes:
31 halyavin 234
	lods	byte [esi]
157 heavyiron 235
	cmp	al,5Ch
236
	jne	backslashed_symbol
237
	stos	byte [edi]
238
	inc	byte [ecx]
239
	jmp	group_backslashes
240
      backslashed_symbol:
31 halyavin 241
	cmp	al,1Ah
157 heavyiron 242
	je	unexpected_end_of_file
243
	cmp	al,0Ah
244
	je	extra_characters_on_line
245
	cmp	al,0Dh
246
	je	extra_characters_on_line
247
	cmp	al,20h
248
	je	extra_characters_on_line
249
	cmp	al,9
250
	je	extra_characters_on_line
251
	cmp	al,22h
252
	je	extra_characters_on_line
253
	cmp	al,27h
254
	je	extra_characters_on_line
255
	cmp	al,3Bh
256
	je	extra_characters_on_line
257
	mov	ah,al
258
	mov	ebx,characters
259
	xlat	byte [ebx]
260
	or	al,al
261
	jz	backslashed_symbol_character
262
	mov	al,ah
263
      convert_backslashed_symbol:
31 halyavin 264
	stos	byte [edi]
157 heavyiron 265
	xlat	byte [ebx]
266
	or	al,al
267
	jz	found_separator
268
	inc	byte [ecx]
269
	jz	name_too_long
270
	lods	byte [esi]
271
	jmp	convert_backslashed_symbol
272
      backslashed_symbol_character:
31 halyavin 273
	mov	al,ah
157 heavyiron 274
	stos	byte [edi]
275
	inc	byte [ecx]
276
	jmp	convert_line_data
277
      concatenate_lines:
31 halyavin 278
	lods	byte [esi]
157 heavyiron 279
	cmp	al,20h
280
	je	concatenate_lines
281
	cmp	al,9
282
	je	concatenate_lines
283
	cmp	al,1Ah
284
	je	unexpected_end_of_file
285
	cmp	al,0Ah
286
	je	concatenate_lf
287
	cmp	al,0Dh
288
	je	concatenate_cr
289
	cmp	al,3Bh
290
	jne	extra_characters_on_line
291
      find_concatenated_line:
31 halyavin 292
	lods	byte [esi]
157 heavyiron 293
	cmp	al,0Ah
294
	je	concatenate_lf
295
	cmp	al,0Dh
296
	je	concatenate_cr
297
	or	al,al
298
	jz	concatenate_ok
299
	cmp	al,1Ah
300
	jne	find_concatenated_line
301
	jmp	unexpected_end_of_file
302
      concatenate_lf:
31 halyavin 303
	lods	byte [esi]
157 heavyiron 304
	cmp	al,0Dh
305
	je	concatenate_ok
306
	dec	esi
307
	jmp	concatenate_ok
308
      concatenate_cr:
31 halyavin 309
	lods	byte [esi]
157 heavyiron 310
	cmp	al,0Ah
311
	je	concatenate_ok
312
	dec	esi
313
      concatenate_ok:
31 halyavin 314
	inc	dword [esp]
157 heavyiron 315
	jmp	convert_line_data
316
      ignore_comment:
31 halyavin 317
	lods	byte [esi]
157 heavyiron 318
	cmp	al,0Ah
319
	je	lf_character
320
	cmp	al,0Dh
321
	je	cr_character
322
	or	al,al
323
	jz	line_end
324
	cmp	al,1Ah
325
	jne	ignore_comment
326
      line_end:
31 halyavin 327
	xor	al,al
157 heavyiron 328
	stos	byte [edi]
329
	pop	ecx
330
	ret
331
31 halyavin 332
 
109 heavyiron 333
	mov	edi,converted
157 heavyiron 334
	mov	ebx,characters
335
      convert_case:
109 heavyiron 336
	lods	byte [esi]
157 heavyiron 337
	xlat	byte [ebx]
338
	stos	byte [edi]
339
	loop	convert_case
340
      case_ok:
109 heavyiron 341
	ret
157 heavyiron 342
109 heavyiron 343
 
344
	push	edi
157 heavyiron 345
	mov	edx,esi
346
	mov	ebp,ecx
347
	call	lower_case
348
	pop	edi
349
      scan_directives:
109 heavyiron 350
	mov	esi,converted
157 heavyiron 351
	movzx	eax,byte [edi]
352
	or	al,al
353
	jz	no_directive
354
	mov	ecx,ebp
355
	inc	edi
356
	mov	ebx,edi
357
	add	ebx,eax
358
	mov	ah,[esi]
359
	cmp	ah,[edi]
360
	jb	no_directive
361
	ja	next_directive
362
	cmp	cl,al
363
	jne	next_directive
364
	repe	cmps byte [esi],[edi]
365
	jb	no_directive
366
	je	directive_ok
367
      next_directive:
109 heavyiron 368
	mov	edi,ebx
157 heavyiron 369
	add	edi,2
370
	jmp	scan_directives
371
      no_directive:
109 heavyiron 372
	mov	esi,edx
157 heavyiron 373
	mov	ecx,ebp
374
	stc
375
	ret
376
      directive_ok:
109 heavyiron 377
	lea	esi,[edx+ebp]
157 heavyiron 378
	call	directive_handler
1189 heavyiron 379
      directive_handler:
380
	pop	ecx
381
	movzx	eax,word [ebx]
157 heavyiron 382
	add	eax,ecx
1189 heavyiron 383
	clc
157 heavyiron 384
	ret
385
109 heavyiron 386
 
31 halyavin 387
	mov	eax,esp
157 heavyiron 388
	sub	eax,100h
389
	jc	stack_overflow
390
	cmp	eax,[stack_limit]
391
	jb	stack_overflow
392
	push	ecx esi
393
      preprocess_current_line:
31 halyavin 394
	mov	esi,[current_line]
157 heavyiron 395
	add	esi,16
396
	cmp	word [esi],3Bh
397
	jne	line_start_ok
398
	add	esi,2
399
      line_start_ok:
31 halyavin 400
	test	[macro_status],0F0h
157 heavyiron 401
	jnz	macro_preprocessing
402
	cmp	byte [esi],1Ah
403
	jne	not_fix_constant
404
	movzx	edx,byte [esi+1]
405
	lea	edx,[esi+2+edx]
406
	cmp	word [edx],031Ah
407
	jne	not_fix_constant
408
	mov	ebx,characters
409
	movzx	eax,byte [edx+2]
410
	xlat	byte [ebx]
411
	ror	eax,8
412
	mov	al,[edx+3]
413
	xlat	byte [ebx]
414
	ror	eax,8
415
	mov	al,[edx+4]
416
	xlat	byte [ebx]
417
	ror	eax,16
418
	cmp	eax,'fix'
419
	je	define_fix_constant
420
      not_fix_constant:
31 halyavin 421
	call	process_fix_constants
157 heavyiron 422
	jmp	initial_preprocessing_ok
423
      macro_preprocessing:
31 halyavin 424
	call	process_macro_operators
157 heavyiron 425
      initial_preprocessing_ok:
31 halyavin 426
	mov	esi,[current_line]
157 heavyiron 427
	add	esi,16
428
	mov	al,[macro_status]
429
	test	al,2
430
	jnz	skip_macro_block
431
	test	al,1
432
	jnz	find_macro_block
433
      preprocess_instruction:
31 halyavin 434
	mov	[current_offset],esi
157 heavyiron 435
	lods	byte [esi]
436
	movzx	ecx,byte [esi]
437
	inc	esi
438
	cmp	al,1Ah
439
	jne	not_preprocessor_symbol
440
	cmp	cl,3
441
	jb	not_preprocessor_directive
442
	push	edi
443
	mov	edi,preprocessor_directives
444
	call	get_directive
445
	pop	edi
446
	jc	not_preprocessor_directive
447
	mov	byte [edx-2],3Bh
448
	jmp	near eax
449
      not_preprocessor_directive:
31 halyavin 450
	xor	ch,ch
157 heavyiron 451
	call	get_preprocessor_symbol
452
	jc	not_macro
453
	mov	byte [ebx-2],3Bh
454
	mov	[struc_name],0
455
	jmp	use_macro
456
      not_macro:
31 halyavin 457
	mov	[struc_name],esi
157 heavyiron 458
	add	esi,ecx
459
	lods	byte [esi]
460
	cmp	al,':'
461
	je	preprocess_label
462
	cmp	al,1Ah
463
	jne	not_preprocessor_symbol
464
	lods	byte [esi]
465
	cmp	al,3
466
	jne	not_symbolic_constant
467
	mov	ebx,characters
468
	movzx	eax,byte [esi]
469
	xlat	byte [ebx]
470
	ror	eax,8
471
	mov	al,[esi+1]
472
	xlat	byte [ebx]
473
	ror	eax,8
474
	mov	al,[esi+2]
475
	xlat	byte [ebx]
476
	ror	eax,16
477
	cmp	eax,'equ'
478
	je	define_equ_constant
479
	mov	al,3
480
      not_symbolic_constant:
31 halyavin 481
	mov	ch,1
157 heavyiron 482
	mov	cl,al
483
	call	get_preprocessor_symbol
484
	jc	not_preprocessor_symbol
485
	push	edx esi
486
	mov	esi,[struc_name]
487
	mov	[struc_label],esi
488
	sub	[struc_label],2
489
	mov	cl,[esi-1]
490
	mov	ch,10b
491
	call	get_preprocessor_symbol
492
	jc	struc_name_ok
493
	mov	ecx,[edx+12]
494
	add	ecx,3
495
	lea	ebx,[edi+ecx]
496
	mov	ecx,edi
497
	sub	ecx,[struc_label]
498
	lea	esi,[edi-1]
499
	lea	edi,[ebx-1]
500
	std
501
	rep	movs byte [edi],[esi]
502
	cld
503
	mov	edi,[struc_label]
504
	mov	esi,[edx+8]
505
	mov	ecx,[edx+12]
506
	add	[struc_name],ecx
507
	add	[struc_name],3
508
	call	move_data
509
	mov	al,3Ah
510
	stos	byte [edi]
511
	mov	ax,3Bh
512
	stos	word [edi]
513
	mov	edi,ebx
514
	pop	esi
515
	add	esi,[edx+12]
516
	add	esi,3
517
	pop	edx
518
	jmp	use_macro
519
      struc_name_ok:
31 halyavin 520
	mov	edx,[struc_name]
157 heavyiron 521
	movzx	eax,byte [edx-1]
522
	add	edx,eax
523
	push	edi
992 heavyiron 524
	lea	esi,[edi-1]
525
	mov	ecx,edi
526
	sub	ecx,edx
527
	std
528
	rep	movs byte [edi],[esi]
529
	cld
530
	pop	edi
531
	inc	edi
532
	mov	al,3Ah
157 heavyiron 533
	mov	[edx],al
534
	inc	al
535
	mov	[edx+1],al
992 heavyiron 536
	pop	esi edx
157 heavyiron 537
	inc	esi
992 heavyiron 538
	jmp	use_macro
157 heavyiron 539
      preprocess_label:
31 halyavin 540
	dec	esi
157 heavyiron 541
	sub	esi,ecx
542
	lea	ebp,[esi-2]
543
	mov	ch,10b
544
	call	get_preprocessor_symbol
545
	jnc	symbolic_constant_in_label
546
	lea	esi,[esi+ecx+1]
547
	jmp	preprocess_instruction
548
      symbolic_constant_in_label:
31 halyavin 549
	mov	ebx,[edx+8]
157 heavyiron 550
	mov	ecx,[edx+12]
551
	add	ecx,ebx
552
      check_for_broken_label:
31 halyavin 553
	cmp	ebx,ecx
157 heavyiron 554
	je	label_broken
555
	cmp	byte [ebx],1Ah
556
	jne	label_broken
557
	movzx	eax,byte [ebx+1]
558
	lea	ebx,[ebx+2+eax]
559
	cmp	ebx,ecx
560
	je	label_constant_ok
561
	cmp	byte [ebx],':'
562
	jne	label_broken
563
	inc	ebx
564
	jmp	check_for_broken_label
565
      label_broken:
31 halyavin 566
	push	line_preprocessed
157 heavyiron 567
	jmp	replace_symbolic_constant
568
      label_constant_ok:
31 halyavin 569
	mov	ecx,edi
157 heavyiron 570
	sub	ecx,esi
571
	mov	edi,[edx+12]
572
	add	edi,ebp
573
	push	edi
574
	lea	eax,[edi+ecx]
575
	push	eax
576
	cmp	esi,edi
577
	je	replace_label
578
	jb	move_rest_of_line_up
579
	rep	movs byte [edi],[esi]
580
	jmp	replace_label
581
      move_rest_of_line_up:
31 halyavin 582
	lea	esi,[esi+ecx-1]
157 heavyiron 583
	lea	edi,[edi+ecx-1]
584
	std
585
	rep	movs byte [edi],[esi]
586
	cld
587
      replace_label:
31 halyavin 588
	mov	ecx,[edx+12]
157 heavyiron 589
	mov	edi,[esp+4]
590
	sub	edi,ecx
591
	mov	esi,[edx+8]
592
	rep	movs byte [edi],[esi]
593
	pop	edi esi
594
	inc	esi
595
	jmp	preprocess_instruction
596
      not_preprocessor_symbol:
31 halyavin 597
	mov	esi,[current_offset]
157 heavyiron 598
	call	process_equ_constants
599
      line_preprocessed:
31 halyavin 600
	pop	esi ecx
157 heavyiron 601
	ret
602
31 halyavin 603
 
604
	push	ebp edi esi
157 heavyiron 605
	mov	ebp,ecx
606
	shl	ebp,22
607
	movzx	ecx,cl
608
	mov	ebx,hash_tree
609
	mov	edi,10
610
      follow_hashes_roots:
31 halyavin 611
	mov	edx,[ebx]
157 heavyiron 612
	or	edx,edx
613
	jz	preprocessor_symbol_not_found
614
	xor	eax,eax
615
	shl	ebp,1
616
	adc	eax,0
617
	lea	ebx,[edx+eax*4]
618
	dec	edi
619
	jnz	follow_hashes_roots
620
	mov	edi,ebx
621
	call	calculate_hash
622
	mov	ebp,eax
623
	and	ebp,3FFh
624
	shl	ebp,10
625
	xor	ebp,eax
626
	mov	ebx,edi
627
	mov	edi,22
628
      follow_hashes_tree:
31 halyavin 629
	mov	edx,[ebx]
157 heavyiron 630
	or	edx,edx
631
	jz	preprocessor_symbol_not_found
632
	xor	eax,eax
633
	shl	ebp,1
634
	adc	eax,0
635
	lea	ebx,[edx+eax*4]
636
	dec	edi
637
	jnz	follow_hashes_tree
638
	mov	al,cl
639
	mov	edx,[ebx]
640
	or	edx,edx
641
	jz	preprocessor_symbol_not_found
642
      compare_with_preprocessor_symbol:
31 halyavin 643
	mov	edi,[edx+4]
157 heavyiron 644
	cmp	edi,1
645
	jbe	next_equal_hash
646
	repe	cmps byte [esi],[edi]
647
	je	preprocessor_symbol_found
648
	mov	cl,al
649
	mov	esi,[esp]
650
      next_equal_hash:
31 halyavin 651
	mov	edx,[edx]
157 heavyiron 652
	or	edx,edx
653
	jnz	compare_with_preprocessor_symbol
654
      preprocessor_symbol_not_found:
31 halyavin 655
	pop	esi edi ebp
157 heavyiron 656
	stc
657
	ret
658
      preprocessor_symbol_found:
31 halyavin 659
	pop	ebx edi ebp
157 heavyiron 660
	clc
661
	ret
662
      calculate_hash:
31 halyavin 663
	xor	ebx,ebx
157 heavyiron 664
	mov	eax,2166136261
665
	mov	ebp,16777619
666
      fnv1a_hash:
31 halyavin 667
	xor	al,[esi+ebx]
157 heavyiron 668
	mul	ebp
669
	inc	bl
670
	cmp	bl,cl
671
	jb	fnv1a_hash
672
	ret
673
add_preprocessor_symbol:
31 halyavin 674
	push	edi esi
157 heavyiron 675
	cmp	ch,11b
992 heavyiron 676
	je	preprocessor_symbol_name_ok
677
	push	ecx
678
	movzx	ecx,cl
679
	mov	edi,preprocessor_directives
872 heavyiron 680
	call	get_directive
681
	jnc	reserved_word_used_as_symbol
682
	pop	ecx
992 heavyiron 683
      preprocessor_symbol_name_ok:
684
	call	calculate_hash
157 heavyiron 685
	mov	ebp,eax
686
	and	ebp,3FFh
687
	shr	eax,10
688
	xor	ebp,eax
689
	shl	ecx,22
690
	or	ebp,ecx
691
	mov	ebx,hash_tree
692
	mov	ecx,32
693
      find_leave_for_symbol:
31 halyavin 694
	mov	edx,[ebx]
157 heavyiron 695
	or	edx,edx
696
	jz	extend_hashes_tree
697
	xor	eax,eax
698
	rol	ebp,1
699
	adc	eax,0
700
	lea	ebx,[edx+eax*4]
701
	dec	ecx
702
	jnz	find_leave_for_symbol
703
	mov	edx,[ebx]
704
	or	edx,edx
705
	jz	add_symbol_entry
706
	shr	ebp,30
707
	cmp	ebp,11b
708
	je	reuse_symbol_entry
709
	cmp	dword [edx+4],0
710
	jne	add_symbol_entry
711
      find_entry_to_reuse:
31 halyavin 712
	mov	edi,[edx]
157 heavyiron 713
	or	edi,edi
714
	jz	reuse_symbol_entry
715
	cmp	dword [edi+4],0
716
	jne	reuse_symbol_entry
717
	mov	edx,edi
718
	jmp	find_entry_to_reuse
719
      add_symbol_entry:
31 halyavin 720
	mov	eax,edx
157 heavyiron 721
	mov	edx,[labels_list]
722
	sub	edx,16
723
	cmp	edx,[free_additional_memory]
724
	jb	out_of_memory
725
	mov	[labels_list],edx
726
	mov	[edx],eax
727
	mov	[ebx],edx
728
      reuse_symbol_entry:
31 halyavin 729
	pop	esi edi
157 heavyiron 730
	mov	[edx+4],esi
731
	ret
732
      extend_hashes_tree:
31 halyavin 733
	mov	edx,[labels_list]
157 heavyiron 734
	sub	edx,8
735
	cmp	edx,[free_additional_memory]
736
	jb	out_of_memory
737
	mov	[labels_list],edx
738
	xor	eax,eax
739
	mov	[edx],eax
740
	mov	[edx+4],eax
741
	shl	ebp,1
742
	adc	eax,0
743
	mov	[ebx],edx
744
	lea	ebx,[edx+eax*4]
745
	dec	ecx
746
	jnz	extend_hashes_tree
747
	mov	edx,[labels_list]
748
	sub	edx,16
749
	cmp	edx,[free_additional_memory]
750
	jb	out_of_memory
751
	mov	[labels_list],edx
752
	mov	dword [edx],0
753
	mov	[ebx],edx
754
	pop	esi edi
755
	mov	[edx+4],esi
756
	ret
757
31 halyavin 758
 
759
	add	edx,5
157 heavyiron 760
	add	esi,2
761
	push	edx
1189 heavyiron 762
	mov	ch,11b
157 heavyiron 763
	jmp	define_preprocessor_constant
764
define_equ_constant:
31 halyavin 765
	add	esi,3
157 heavyiron 766
	push	esi
767
	call	process_equ_constants
768
	mov	esi,[struc_name]
769
	mov	ch,10b
770
      define_preprocessor_constant:
109 heavyiron 771
	mov	byte [esi-2],3Bh
157 heavyiron 772
	mov	cl,[esi-1]
773
	call	add_preprocessor_symbol
774
	pop	ebx
1189 heavyiron 775
	mov	ecx,edi
157 heavyiron 776
	dec	ecx
777
	sub	ecx,ebx
778
	mov	[edx+8],ebx
779
	mov	[edx+12],ecx
780
	jmp	line_preprocessed
781
define_symbolic_constant:
109 heavyiron 782
	lods	byte [esi]
157 heavyiron 783
	cmp	al,1Ah
784
	jne	invalid_name
785
	lods	byte [esi]
786
	mov	cl,al
787
	mov	ch,10b
788
	call	add_preprocessor_symbol
789
	movzx	eax,byte [esi-1]
790
	add	esi,eax
791
	lea	ecx,[edi-1]
1189 heavyiron 792
	sub	ecx,esi
793
	mov	[edx+8],esi
794
	mov	[edx+12],ecx
157 heavyiron 795
	jmp	line_preprocessed
796
109 heavyiron 797
 
31 halyavin 798
	mov	ch,1
157 heavyiron 799
	jmp	make_macro
800
define_macro:
31 halyavin 801
	xor	ch,ch
157 heavyiron 802
      make_macro:
31 halyavin 803
	lods	byte [esi]
157 heavyiron 804
	cmp	al,1Ah
805
	jne	invalid_name
806
	lods	byte [esi]
807
	mov	cl,al
808
	call	add_preprocessor_symbol
809
	mov	eax,[current_line]
810
	mov	[edx+12],eax
811
	movzx	eax,byte [esi-1]
812
	add	esi,eax
813
	mov	[edx+8],esi
814
	mov	al,[macro_status]
815
	and	al,0F0h
816
	or	al,1
817
	mov	[macro_status],al
818
	mov	eax,[current_line]
819
	mov	[error_line],eax
820
	xor	bl,bl
821
	lods	byte [esi]
822
	or	al,al
823
	jz	line_preprocessed
824
	cmp	al,'{'
825
	je	found_macro_block
826
	dec	esi
827
      skip_macro_arguments:
31 halyavin 828
	lods	byte [esi]
157 heavyiron 829
	cmp	al,1Ah
830
	je	skip_macro_argument
831
	cmp	al,'['
832
	jne	invalid_macro_arguments
833
	xor	bl,-1
834
	jz	invalid_macro_arguments
835
	lods	byte [esi]
836
	cmp	al,1Ah
837
	jne	invalid_macro_arguments
838
      skip_macro_argument:
31 halyavin 839
	movzx	eax,byte [esi]
157 heavyiron 840
	inc	esi
841
	add	esi,eax
842
	lods	byte [esi]
843
	cmp	al,'*'
844
	jne	macro_argument_end
845
	lods	byte [esi]
846
      macro_argument_end:
31 halyavin 847
	cmp	al,','
157 heavyiron 848
	je	skip_macro_arguments
849
	cmp	al,']'
850
	jne	end_macro_arguments
851
	lods	byte [esi]
852
	not	bl
853
      end_macro_arguments:
31 halyavin 854
	or	bl,bl
157 heavyiron 855
	jnz	invalid_macro_arguments
856
	or	al,al
857
	jz	line_preprocessed
858
	cmp	al,'{'
859
	je	found_macro_block
860
	jmp	invalid_macro_arguments
861
      find_macro_block:
31 halyavin 862
	add	esi,2
157 heavyiron 863
	lods	byte [esi]
864
	or	al,al
865
	jz	line_preprocessed
866
	cmp	al,'{'
867
	jne	unexpected_characters
868
      found_macro_block:
31 halyavin 869
	or	[macro_status],2
157 heavyiron 870
      skip_macro_block:
31 halyavin 871
	lods	byte [esi]
157 heavyiron 872
	cmp	al,1Ah
873
	je	skip_macro_symbol
874
	cmp	al,3Bh
875
	je	skip_macro_symbol
876
	cmp	al,22h
877
	je	skip_macro_string
878
	or	al,al
879
	jz	line_preprocessed
880
	cmp	al,'}'
881
	jne	skip_macro_block
882
	mov	al,[macro_status]
883
	and	[macro_status],0F0h
884
	test	al,8
885
	jnz	use_instant_macro
886
	cmp	byte [esi],0
887
	je	line_preprocessed
888
	mov	ecx,edi
889
	sub	ecx,esi
890
	mov	edx,esi
891
	lea	esi,[esi+ecx-1]
892
	lea	edi,[edi+1+16]
893
	mov	ebx,edi
894
	dec	edi
895
	std
896
	rep	movs byte [edi],[esi]
897
	cld
898
	mov	edi,edx
899
	xor	al,al
900
	stos	byte [edi]
901
	mov	esi,[current_line]
902
	mov	[current_line],edi
903
	mov	ecx,4
904
	rep	movs dword [edi],[esi]
905
	mov	edi,ebx
906
	jmp	initial_preprocessing_ok
907
      skip_macro_symbol:
31 halyavin 908
	movzx	eax,byte [esi]
157 heavyiron 909
	inc	esi
910
	add	esi,eax
911
	jmp	skip_macro_block
912
      skip_macro_string:
31 halyavin 913
	lods	dword [esi]
157 heavyiron 914
	add	esi,eax
915
	jmp	skip_macro_block
916
rept_directive:
31 halyavin 917
	mov	[base_code],0
157 heavyiron 918
	jmp	define_instant_macro
919
irp_directive:
31 halyavin 920
	mov	[base_code],1
157 heavyiron 921
	jmp	define_instant_macro
922
irps_directive:
31 halyavin 923
	mov	[base_code],2
157 heavyiron 924
	jmp	define_instant_macro
925
match_directive:
31 halyavin 926
	mov	[base_code],10h
157 heavyiron 927
define_instant_macro:
31 halyavin 928
	mov	al,[macro_status]
157 heavyiron 929
	and	al,0F0h
930
	or	al,8+1
931
	mov	[macro_status],al
932
	mov	eax,[current_line]
933
	mov	[error_line],eax
934
	mov	[instant_macro_start],esi
935
	cmp	[base_code],10h
936
	je	prepare_match
937
      skip_parameters:
1189 heavyiron 938
	lods	byte [esi]
939
	or	al,al
940
	jz	parameters_skipped
941
	cmp	al,'{'
942
	je	parameters_skipped
943
	cmp	al,22h
944
	je	skip_quoted_parameter
945
	cmp	al,1Ah
946
	jne	skip_parameters
947
	lods	byte [esi]
948
	movzx	eax,al
949
	add	esi,eax
950
	jmp	skip_parameters
951
      skip_quoted_parameter:
952
	lods	dword [esi]
953
	add	esi,eax
954
	jmp	skip_parameters
955
      parameters_skipped:
956
	dec	esi
157 heavyiron 957
	mov	[parameters_end],esi
958
	lods	byte [esi]
959
	cmp	al,'{'
960
	je	found_macro_block
961
	or	al,al
962
	jnz	invalid_macro_arguments
963
	jmp	line_preprocessed
964
prepare_match:
31 halyavin 965
	call	skip_pattern
157 heavyiron 966
	mov	[value_type],80h+10b
967
	call	process_symbolic_constants
968
	jmp	parameters_skipped
1189 heavyiron 969
      skip_pattern:
31 halyavin 970
	lods	byte [esi]
157 heavyiron 971
	or	al,al
972
	jz	invalid_macro_arguments
973
	cmp	al,','
974
	je	pattern_skipped
975
	cmp	al,22h
976
	je	skip_quoted_string_in_pattern
977
	cmp	al,1Ah
978
	je	skip_symbol_in_pattern
979
	cmp	al,'='
980
	jne	skip_pattern
981
	mov	al,[esi]
982
	cmp	al,1Ah
983
	je	skip_pattern
984
	cmp	al,22h
985
	je	skip_pattern
986
	inc	esi
987
	jmp	skip_pattern
988
      skip_symbol_in_pattern:
31 halyavin 989
	lods	byte [esi]
157 heavyiron 990
	movzx	eax,al
991
	add	esi,eax
992
	jmp	skip_pattern
993
      skip_quoted_string_in_pattern:
31 halyavin 994
	lods	dword [esi]
157 heavyiron 995
	add	esi,eax
996
	jmp	skip_pattern
997
      pattern_skipped:
31 halyavin 998
	ret
157 heavyiron 999
31 halyavin 1000
 
1001
	xor	ch,ch
157 heavyiron 1002
	jmp	restore_preprocessor_symbol
1003
purge_struc:
31 halyavin 1004
	mov	ch,1
157 heavyiron 1005
	jmp	restore_preprocessor_symbol
1006
restore_equ_constant:
31 halyavin 1007
	mov	ch,10b
157 heavyiron 1008
      restore_preprocessor_symbol:
31 halyavin 1009
	push	ecx
157 heavyiron 1010
	lods	byte [esi]
1011
	cmp	al,1Ah
1012
	jne	invalid_name
1013
	lods	byte [esi]
1014
	mov	cl,al
1015
	call	get_preprocessor_symbol
1016
	jc	no_symbol_to_restore
1017
	mov	dword [edx+4],0
1018
	jmp	symbol_restored
1019
      no_symbol_to_restore:
31 halyavin 1020
	add	esi,ecx
157 heavyiron 1021
      symbol_restored:
31 halyavin 1022
	pop	ecx
157 heavyiron 1023
	lods	byte [esi]
1024
	cmp	al,','
1025
	je	restore_preprocessor_symbol
1026
	or	al,al
1027
	jnz	extra_characters_on_line
1028
	jmp	line_preprocessed
1029
31 halyavin 1030
 
1031
	mov	[value_type],11b
157 heavyiron 1032
	jmp	process_symbolic_constants
1033
process_equ_constants:
31 halyavin 1034
	mov	[value_type],10b
157 heavyiron 1035
      process_symbolic_constants:
31 halyavin 1036
	mov	ebp,esi
157 heavyiron 1037
	lods	byte [esi]
1038
	cmp	al,1Ah
1039
	je	check_symbol
1040
	cmp	al,22h
1041
	je	ignore_string
1042
	cmp	al,'{'
1043
	je	check_brace
1044
	or	al,al
1045
	jnz	process_symbolic_constants
1046
	ret
1047
      ignore_string:
31 halyavin 1048
	lods	dword [esi]
157 heavyiron 1049
	add	esi,eax
1050
	jmp	process_symbolic_constants
1051
      check_brace:
31 halyavin 1052
	test	[value_type],80h
157 heavyiron 1053
	jz	process_symbolic_constants
1054
	ret
1055
      no_replacing:
31 halyavin 1056
	movzx	ecx,byte [esi-1]
157 heavyiron 1057
	add	esi,ecx
1058
	jmp	process_symbolic_constants
1059
      check_symbol:
31 halyavin 1060
	mov	cl,[esi]
157 heavyiron 1061
	inc	esi
1062
	mov	ch,[value_type]
1063
	call	get_preprocessor_symbol
1064
	jc	no_replacing
1065
	mov	[current_section],edi
1066
      replace_symbolic_constant:
31 halyavin 1067
	mov	ecx,[edx+12]
157 heavyiron 1068
	mov	edx,[edx+8]
1069
	xchg	esi,edx
1070
	call	move_data
1071
	mov	esi,edx
1072
      process_after_replaced:
31 halyavin 1073
	lods	byte [esi]
157 heavyiron 1074
	cmp	al,1Ah
1075
	je	symbol_after_replaced
1076
	stos	byte [edi]
1077
	cmp	al,22h
1078
	je	string_after_replaced
1079
	cmp	al,'{'
1080
	je	brace_after_replaced
1081
	or	al,al
1082
	jnz	process_after_replaced
1083
	mov	ecx,edi
1084
	sub	ecx,esi
1085
	mov	edi,ebp
1086
	call	move_data
1087
	mov	esi,edi
1088
	ret
1089
      move_data:
31 halyavin 1090
	lea	eax,[edi+ecx]
157 heavyiron 1091
	cmp	eax,[memory_end]
1092
	jae	out_of_memory
1093
	shr	ecx,1
1094
	jnc	movsb_ok
1095
	movs	byte [edi],[esi]
1096
      movsb_ok:
31 halyavin 1097
	shr	ecx,1
157 heavyiron 1098
	jnc	movsw_ok
1099
	movs	word [edi],[esi]
1100
      movsw_ok:
31 halyavin 1101
	rep	movs dword [edi],[esi]
157 heavyiron 1102
	ret
1103
      string_after_replaced:
31 halyavin 1104
	lods	dword [esi]
157 heavyiron 1105
	stos	dword [edi]
1106
	mov	ecx,eax
1107
	call	move_data
1108
	jmp	process_after_replaced
1109
      brace_after_replaced:
31 halyavin 1110
	test	[value_type],80h
157 heavyiron 1111
	jz	process_after_replaced
1112
	mov	edx,edi
1113
	mov	ecx,[current_section]
1114
	sub	edx,ecx
1115
	sub	ecx,esi
1116
	rep	movs byte [edi],[esi]
1117
	mov	ecx,edi
1118
	sub	ecx,esi
1119
	mov	edi,ebp
1120
	call	move_data
1121
	lea	esi,[ebp+edx]
1122
	ret
1123
      symbol_after_replaced:
31 halyavin 1124
	mov	cl,[esi]
157 heavyiron 1125
	inc	esi
1126
	mov	ch,[value_type]
1127
	call	get_preprocessor_symbol
1128
	jnc	replace_symbolic_constant
1129
	movzx	ecx,byte [esi-1]
1130
	mov	al,1Ah
1131
	mov	ah,cl
1132
	stos	word [edi]
1133
	call	move_data
1134
	jmp	process_after_replaced
1135
process_macro_operators:
31 halyavin 1136
	xor	dl,dl
157 heavyiron 1137
	mov	ebp,edi
1138
      before_macro_operators:
31 halyavin 1139
	mov	edi,esi
157 heavyiron 1140
	lods	byte [esi]
1141
	cmp	al,'`'
1142
	je	symbol_conversion
1143
	cmp	al,'#'
1144
	je	concatenation
1145
	cmp	al,1Ah
1146
	je	symbol_before_macro_operators
1147
	cmp	al,3Bh
1148
	je	no_more_macro_operators
1149
	cmp	al,22h
1150
	je	string_before_macro_operators
1151
	xor	dl,dl
1152
	or	al,al
1153
	jnz	before_macro_operators
1154
	mov	edi,esi
1155
	ret
1156
      no_more_macro_operators:
31 halyavin 1157
	mov	edi,ebp
157 heavyiron 1158
	ret
1159
      symbol_before_macro_operators:
31 halyavin 1160
	mov	dl,1Ah
157 heavyiron 1161
	mov	ebx,esi
1162
	lods	byte [esi]
1163
	movzx	ecx,al
1164
	jecxz	symbol_before_macro_operators_ok
1165
	mov	edi,esi
1166
	cmp	byte [esi],'\'
1167
	je	escaped_symbol
1168
      symbol_before_macro_operators_ok:
31 halyavin 1169
	add	esi,ecx
157 heavyiron 1170
	jmp	before_macro_operators
1171
      string_before_macro_operators:
31 halyavin 1172
	mov	dl,22h
157 heavyiron 1173
	mov	ebx,esi
1174
	lods	dword [esi]
1175
	add	esi,eax
1176
	jmp	before_macro_operators
1177
      escaped_symbol:
31 halyavin 1178
	dec	byte [edi-1]
157 heavyiron 1179
	dec	ecx
1180
	inc	esi
1181
	cmp	ecx,1
1182
	rep	movs byte [edi],[esi]
1183
	jne	after_macro_operators
1184
	mov	al,[esi-1]
1185
	mov	ecx,ebx
1186
	mov	ebx,characters
1187
	xlat	byte [ebx]
1188
	mov	ebx,ecx
1189
	or	al,al
1190
	jnz	after_macro_operators
1191
	sub	edi,3
1192
	mov	al,[esi-1]
1193
	stos	byte [edi]
1194
	xor	dl,dl
1195
	jmp	after_macro_operators
1196
      reduce_symbol_conversion:
109 heavyiron 1197
	inc	esi
157 heavyiron 1198
      symbol_conversion:
31 halyavin 1199
	mov	edx,esi
157 heavyiron 1200
	mov	al,[esi]
1201
	cmp	al,1Ah
1202
	jne	symbol_character_conversion
1203
	lods	word [esi]
1204
	movzx	ecx,ah
1205
	lea	ebx,[edi+3]
1206
	jecxz	convert_to_quoted_string
242 heavyiron 1207
	cmp	byte [esi],'\'
1208
	jne	convert_to_quoted_string
1209
	inc	esi
1210
	dec	ecx
1211
	dec	ebx
1212
	jmp	convert_to_quoted_string
157 heavyiron 1213
      symbol_character_conversion:
109 heavyiron 1214
	cmp	al,22h
157 heavyiron 1215
	je	after_macro_operators
1216
	cmp	al,'`'
1217
	je	reduce_symbol_conversion
1218
	lea	ebx,[edi+5]
1219
	xor	ecx,ecx
1220
	or	al,al
1221
	jz	convert_to_quoted_string
1222
	cmp	al,'#'
1223
	je	convert_to_quoted_string
1224
	inc	ecx
1225
      convert_to_quoted_string:
109 heavyiron 1226
	sub	ebx,edx
157 heavyiron 1227
	ja	shift_line_data
1228
	mov	al,22h
1229
	mov	dl,al
1230
	stos	byte [edi]
1231
	mov	ebx,edi
1232
	mov	eax,ecx
1233
	stos	dword [edi]
1234
	rep	movs byte [edi],[esi]
1235
	cmp	edi,esi
1236
	je	before_macro_operators
1237
	jmp	after_macro_operators
1238
      shift_line_data:
31 halyavin 1239
	push	ecx
157 heavyiron 1240
	mov	edx,esi
1241
	lea	esi,[ebp-1]
1242
	add	ebp,ebx
1243
	lea	edi,[ebp-1]
1244
	lea	ecx,[esi+1]
1245
	sub	ecx,edx
1246
	std
1247
	rep	movs byte [edi],[esi]
1248
	cld
1249
	pop	eax
1250
	sub	edi,3
1251
	mov	dl,22h
1252
	mov	[edi-1],dl
1253
	mov	ebx,edi
1254
	mov	[edi],eax
1255
	lea	esi,[edi+4+eax]
1256
	jmp	before_macro_operators
1257
      concatenation:
31 halyavin 1258
	cmp	dl,1Ah
157 heavyiron 1259
	je	symbol_concatenation
1260
	cmp	dl,22h
1261
	je	string_concatenation
1262
      no_concatenation:
31 halyavin 1263
	cmp	esi,edi
157 heavyiron 1264
	je	before_macro_operators
1265
	jmp	after_macro_operators
1266
      symbol_concatenation:
31 halyavin 1267
	cmp	byte [esi],1Ah
157 heavyiron 1268
	jne	no_concatenation
1269
	inc	esi
1270
	lods	byte [esi]
1271
	movzx	ecx,al
1272
	jecxz	do_symbol_concatenation
1273
	cmp	byte [esi],'\'
1274
	je	concatenate_escaped_symbol
242 heavyiron 1275
      do_symbol_concatenation:
31 halyavin 1276
	add	[ebx],cl
242 heavyiron 1277
	jc	name_too_long
157 heavyiron 1278
	rep	movs byte [edi],[esi]
1279
	jmp	after_macro_operators
1280
      concatenate_escaped_symbol:
242 heavyiron 1281
	inc	esi
1282
	dec	ecx
1283
	jz	do_symbol_concatenation
1284
	movzx	eax,byte [esi]
1285
	cmp	byte [characters+eax],0
1286
	jne	do_symbol_concatenation
1287
	sub	esi,3
1288
	jmp	no_concatenation
1289
      string_concatenation:
31 halyavin 1290
	cmp	byte [esi],22h
157 heavyiron 1291
	je	do_string_concatenation
1292
	cmp	byte [esi],'`'
1293
	jne	no_concatenation
1294
      concatenate_converted_symbol:
109 heavyiron 1295
	inc	esi
157 heavyiron 1296
	mov	al,[esi]
1297
	cmp	al,'`'
1298
	je	concatenate_converted_symbol
1299
	cmp	al,22h
1300
	je	do_string_concatenation
1301
	cmp	al,1Ah
1302
	jne	concatenate_converted_symbol_character
1303
	inc	esi
1304
	lods	byte [esi]
1305
	movzx	ecx,al
1306
	jecxz	finish_concatenating_converted_symbol
242 heavyiron 1307
	cmp	byte [esi],'\'
1308
	jne	finish_concatenating_converted_symbol
1309
	inc	esi
1310
	dec	ecx
1311
      finish_concatenating_converted_symbol:
1312
	add	[ebx],ecx
157 heavyiron 1313
	rep	movs byte [edi],[esi]
1314
	jmp	after_macro_operators
1315
      concatenate_converted_symbol_character:
109 heavyiron 1316
	or	al,al
157 heavyiron 1317
	jz	after_macro_operators
1318
	cmp	al,'#'
1319
	je	after_macro_operators
1320
	inc	dword [ebx]
1321
	movs	byte [edi],[esi]
1322
	jmp	after_macro_operators
1323
      do_string_concatenation:
31 halyavin 1324
	inc	esi
157 heavyiron 1325
	lods	dword [esi]
1326
	mov	ecx,eax
1327
	add	[ebx],eax
1328
	rep	movs byte [edi],[esi]
1329
      after_macro_operators:
31 halyavin 1330
	lods	byte [esi]
157 heavyiron 1331
	cmp	al,'`'
1332
	je	symbol_conversion
1333
	cmp	al,'#'
1334
	je	concatenation
1335
	stos	byte [edi]
1336
	cmp	al,1Ah
1337
	je	symbol_after_macro_operators
1338
	cmp	al,3Bh
1339
	je	no_more_macro_operators
1340
	cmp	al,22h
1341
	je	string_after_macro_operators
1342
	xor	dl,dl
1343
	or	al,al
1344
	jnz	after_macro_operators
1345
	ret
1346
      symbol_after_macro_operators:
31 halyavin 1347
	mov	dl,1Ah
157 heavyiron 1348
	mov	ebx,edi
1349
	lods	byte [esi]
1350
	stos	byte [edi]
1351
	movzx	ecx,al
1352
	jecxz	symbol_after_macro_operatorss_ok
1353
	cmp	byte [esi],'\'
1354
	je	escaped_symbol
1355
      symbol_after_macro_operatorss_ok:
31 halyavin 1356
	rep	movs byte [edi],[esi]
157 heavyiron 1357
	jmp	after_macro_operators
1358
      string_after_macro_operators:
31 halyavin 1359
	mov	dl,22h
157 heavyiron 1360
	mov	ebx,edi
1361
	lods	dword [esi]
1362
	stos	dword [edi]
1363
	mov	ecx,eax
1364
	rep	movs byte [edi],[esi]
1365
	jmp	after_macro_operators
1366
31 halyavin 1367
 
1368
	push	[free_additional_memory]
157 heavyiron 1369
	push	[macro_symbols]
1370
	mov	[macro_symbols],0
1371
	push	[counter_limit]
1372
	push	dword [edx+4]
1373
	mov	dword [edx+4],1
1374
	push	edx
1375
	mov	ebx,esi
1376
	mov	esi,[edx+8]
1377
	mov	eax,[edx+12]
1378
	mov	[macro_line],eax
1379
	mov	[counter_limit],0
1380
      process_macro_arguments:
31 halyavin 1381
	mov	al,[esi]
157 heavyiron 1382
	or	al,al
1383
	jz	arguments_end
1384
	cmp	al,'{'
1385
	je	arguments_end
1386
	inc	esi
1387
	cmp	al,'['
1388
	jne	get_macro_arguments
1389
	mov	ebp,esi
1390
	inc	esi
1391
	inc	[counter_limit]
1392
      get_macro_arguments:
31 halyavin 1393
	call	get_macro_argument
157 heavyiron 1394
	lods	byte [esi]
1395
	cmp	al,','
1396
	je	next_argument
1397
	cmp	al,']'
1398
	je	next_arguments_group
1399
	dec	esi
1400
	jmp	arguments_end
1401
      next_argument:
31 halyavin 1402
	cmp	byte [ebx],','
157 heavyiron 1403
	jne	process_macro_arguments
1404
	inc	ebx
1405
	jmp	process_macro_arguments
1406
      next_arguments_group:
31 halyavin 1407
	cmp	byte [ebx],','
157 heavyiron 1408
	jne	arguments_end
1409
	inc	ebx
1410
	inc	[counter_limit]
1411
	mov	esi,ebp
1412
	jmp	process_macro_arguments
1413
      get_macro_argument:
31 halyavin 1414
	lods	byte [esi]
157 heavyiron 1415
	movzx	ecx,al
1416
	mov	eax,[counter_limit]
1417
	call	add_macro_symbol
1418
	add	esi,ecx
1419
	xchg	esi,ebx
1420
	mov	[edx+12],esi
1421
	cmp	byte [esi],'<'
1422
	jne	simple_argument
1423
	inc	esi
1424
	mov	[edx+12],esi
1425
	mov	ecx,1
1426
      enclosed_argument:
31 halyavin 1427
	lods	byte [esi]
157 heavyiron 1428
	or	al,al
1429
	jz	invalid_macro_arguments
1430
	cmp	al,1Ah
1431
	je	enclosed_symbol
1432
	cmp	al,22h
1433
	je	enclosed_string
1434
	cmp	al,'>'
1435
	je	enclosed_argument_end
1436
	cmp	al,'<'
1437
	jne	enclosed_argument
1438
	inc	ecx
1439
	jmp	enclosed_argument
1440
      enclosed_symbol:
31 halyavin 1441
	movzx	eax,byte [esi]
157 heavyiron 1442
	inc	esi
1443
	add	esi,eax
1444
	jmp	enclosed_argument
1445
      enclosed_string:
31 halyavin 1446
	lods	dword [esi]
157 heavyiron 1447
	add	esi,eax
1448
	jmp	enclosed_argument
1449
      enclosed_argument_end:
31 halyavin 1450
	loop	enclosed_argument
157 heavyiron 1451
	mov	al,[esi]
1452
	or	al,al
1453
	jz	enclosed_argument_ok
1454
	cmp	al,','
1455
	jne	invalid_macro_arguments
1456
      enclosed_argument_ok:
31 halyavin 1457
	mov	eax,esi
157 heavyiron 1458
	sub	eax,[edx+12]
1459
	dec	eax
1460
	or	eax,80000000h
1461
	mov	[edx+8],eax
1462
	jmp	argument_value_ok
1463
      simple_argument:
31 halyavin 1464
	lods	byte [esi]
157 heavyiron 1465
	or	al,al
1466
	jz	argument_value_end
1467
	cmp	al,','
1468
	je	argument_value_end
1469
	cmp	al,22h
1470
	je	argument_string
1471
	cmp	al,1Ah
1472
	jne	simple_argument
1473
	movzx	eax,byte [esi]
1474
	inc	esi
1475
	add	esi,eax
1476
	jmp	simple_argument
1477
      argument_string:
31 halyavin 1478
	lods	dword [esi]
157 heavyiron 1479
	add	esi,eax
1480
	jmp	simple_argument
1481
      argument_value_end:
31 halyavin 1482
	dec	esi
157 heavyiron 1483
	mov	eax,esi
1484
	sub	eax,[edx+12]
1485
	mov	[edx+8],eax
1486
      argument_value_ok:
31 halyavin 1487
	xchg	esi,ebx
157 heavyiron 1488
	cmp	byte [esi],'*'
1489
	jne	macro_argument_ok
1490
	cmp	dword [edx+8],0
1491
	je	invalid_macro_arguments
1492
	inc	esi
1493
      macro_argument_ok:
31 halyavin 1494
	ret
157 heavyiron 1495
      arguments_end:
31 halyavin 1496
	cmp	byte [ebx],0
157 heavyiron 1497
	jne	invalid_macro_arguments
1498
	mov	eax,[esp+4]
1499
	dec	eax
1500
	call	process_macro
1501
	pop	edx
1502
	pop	dword [edx+4]
1503
	pop	[counter_limit]
1504
	pop	[macro_symbols]
1505
	pop	[free_additional_memory]
1506
	jmp	line_preprocessed
1507
use_instant_macro:
31 halyavin 1508
	push	edi [current_line] esi
157 heavyiron 1509
	mov	eax,[error_line]
1510
	mov	[current_line],eax
1511
	mov	[macro_line],eax
1512
	mov	esi,[instant_macro_start]
1513
	cmp	[base_code],10h
1514
	jae	do_match
1515
	cmp	[base_code],0
1516
	jne	do_irp
1517
	call	precalculate_value
1189 heavyiron 1518
	cmp	eax,0
1519
	jl	value_out_of_range
1520
	push	[free_additional_memory]
157 heavyiron 1521
	push	[macro_symbols]
1522
	mov	[macro_symbols],0
1523
	push	[counter_limit]
1524
	mov	[struc_name],0
1525
	mov	[counter_limit],eax
1526
	lods	byte [esi]
1527
	or	al,al
1528
	jz	rept_counters_ok
1529
	cmp	al,'{'
1530
	je	rept_counters_ok
1531
	cmp	al,1Ah
1532
	jne	invalid_macro_arguments
1533
      add_rept_counter:
31 halyavin 1534
	lods	byte [esi]
157 heavyiron 1535
	movzx	ecx,al
1536
	xor	eax,eax
1537
	call	add_macro_symbol
1538
	add	esi,ecx
1539
	xor	eax,eax
1540
	mov	dword [edx+12],eax
1541
	inc	eax
1542
	mov	dword [edx+8],eax
1543
	lods	byte [esi]
1544
	cmp	al,':'
1545
	jne	rept_counter_added
1546
	push	edx
1547
	call	precalculate_value
1189 heavyiron 1548
	mov	edx,eax
157 heavyiron 1549
	add	edx,[counter_limit]
1550
	jo	value_out_of_range
1189 heavyiron 1551
	pop	edx
157 heavyiron 1552
	mov	dword [edx+8],eax
1553
	lods	byte [esi]
1554
      rept_counter_added:
31 halyavin 1555
	cmp	al,','
157 heavyiron 1556
	jne	rept_counters_ok
1557
	lods	byte [esi]
1558
	cmp	al,1Ah
1559
	jne	invalid_macro_arguments
1560
	jmp	add_rept_counter
1561
      rept_counters_ok:
31 halyavin 1562
	dec	esi
157 heavyiron 1563
	cmp	[counter_limit],0
872 heavyiron 1564
	je	instant_macro_finish
1565
      instant_macro_parameters_ok:
31 halyavin 1566
	xor	eax,eax
157 heavyiron 1567
	call	process_macro
1568
      instant_macro_finish:
872 heavyiron 1569
	pop	[counter_limit]
157 heavyiron 1570
	pop	[macro_symbols]
1571
	pop	[free_additional_memory]
1572
      instant_macro_done:
31 halyavin 1573
	pop	ebx esi edx
157 heavyiron 1574
	cmp	byte [ebx],0
1575
	je	line_preprocessed
1576
	mov	[current_line],edi
1577
	mov	ecx,4
1578
	rep	movs dword [edi],[esi]
1579
	test	[macro_status],0Fh
1580
	jz	instant_macro_attached_line
1581
	mov	ax,3Bh
1582
	stos	word [edi]
1583
      instant_macro_attached_line:
31 halyavin 1584
	mov	esi,ebx
157 heavyiron 1585
	sub	edx,ebx
1586
	mov	ecx,edx
1587
	call	move_data
1588
	jmp	initial_preprocessing_ok
1589
      precalculate_value:
1189 heavyiron 1590
	push	edi
1591
	call	convert_expression
1592
	mov	al,')'
1593
	stosb
1594
	push	esi
1595
	mov	esi,[esp+4]
1596
	call	calculate_expression
1597
	mov	eax,[edi]
1598
	mov	ecx,[edi+4]
1599
	pop	esi edi
1600
	cdq
1601
	cmp	edx,ecx
1602
	jne	value_out_of_range
1603
	ret
1604
do_irp:
31 halyavin 1605
	cmp	byte [esi],1Ah
157 heavyiron 1606
	jne	invalid_macro_arguments
1607
	movzx	eax,byte [esi+1]
1608
	lea	esi,[esi+2+eax]
1609
	lods	byte [esi]
1610
	cmp	[base_code],1
1611
	ja	irps_name_ok
1612
	cmp	al,'*'
1613
	jne	irp_name_ok
1614
	lods	byte [esi]
1615
      irp_name_ok:
31 halyavin 1616
	cmp	al,','
157 heavyiron 1617
	jne	invalid_macro_arguments
1618
	jmp	irp_parameters_start
1619
      irps_name_ok:
31 halyavin 1620
	cmp	al,','
157 heavyiron 1621
	jne	invalid_macro_arguments
1622
	mov	al,[esi]
1623
	or	al,al
1624
	jz	instant_macro_done
1625
	cmp	al,'{'
1626
	je	instant_macro_done
1627
      irp_parameters_start:
31 halyavin 1628
	xor	eax,eax
157 heavyiron 1629
	push	[free_additional_memory]
1630
	push	[macro_symbols]
1631
	mov	[macro_symbols],eax
1632
	push	[counter_limit]
1633
	mov	[counter_limit],eax
1634
	mov	[struc_name],eax
1635
	mov	ebx,esi
1636
	cmp	[base_code],1
1637
	ja	get_irps_parameter
1638
	mov	edx,[parameters_end]
1639
	mov	al,[edx]
1640
	push	eax
1641
	mov	byte [edx],0
1642
      get_irp_parameter:
31 halyavin 1643
	inc	[counter_limit]
157 heavyiron 1644
	mov	esi,[instant_macro_start]
1645
	inc	esi
1646
	call	get_macro_argument
1647
	cmp	byte [ebx],','
1648
	jne	irp_parameters_end
1649
	inc	ebx
1650
	jmp	get_irp_parameter
1651
      irp_parameters_end:
31 halyavin 1652
	mov	esi,ebx
157 heavyiron 1653
	pop	eax
1654
	mov	[esi],al
1655
	jmp	instant_macro_parameters_ok
1656
      get_irps_parameter:
31 halyavin 1657
	mov	esi,[instant_macro_start]
157 heavyiron 1658
	inc	esi
1659
	lods	byte [esi]
1660
	movzx	ecx,al
1661
	inc	[counter_limit]
1662
	mov	eax,[counter_limit]
1663
	call	add_macro_symbol
1664
	mov	[edx+12],ebx
1665
	cmp	byte [ebx],1Ah
1666
	je	irps_symbol
1667
	cmp	byte [ebx],22h
1668
	je	irps_quoted_string
1669
	mov	eax,1
1670
	jmp	irps_parameter_ok
1671
      irps_quoted_string:
31 halyavin 1672
	mov	eax,[ebx+1]
157 heavyiron 1673
	add	eax,1+4
1674
	jmp	irps_parameter_ok
1675
      irps_symbol:
31 halyavin 1676
	movzx	eax,byte [ebx+1]
157 heavyiron 1677
	add	eax,1+1
1678
      irps_parameter_ok:
31 halyavin 1679
	mov	[edx+8],eax
157 heavyiron 1680
	add	ebx,eax
1681
	cmp	byte [ebx],0
1682
	je	irps_parameters_end
1683
	cmp	byte [ebx],'{'
1684
	jne	get_irps_parameter
1685
      irps_parameters_end:
31 halyavin 1686
	mov	esi,ebx
157 heavyiron 1687
	jmp	instant_macro_parameters_ok
1688
do_match:
31 halyavin 1689
	mov	ebx,esi
157 heavyiron 1690
	call	skip_pattern
1691
	call	exact_match
1692
	mov	edx,edi
1693
	mov	al,[ebx]
1694
	cmp	al,1Ah
1695
	je	free_match
1696
	cmp	al,','
1697
	jne	instant_macro_done
1698
	cmp	esi,[parameters_end]
1699
	je	matched_pattern
1700
	jmp	instant_macro_done
1701
      free_match:
31 halyavin 1702
	add	edx,12
157 heavyiron 1703
	cmp	edx,[memory_end]
1704
	ja	out_of_memory
1705
	mov	[edx-12],ebx
1706
	mov	[edx-8],esi
1707
	call	skip_match_element
1708
	jc	try_different_matching
1709
	mov	[edx-4],esi
1710
	movzx	eax,byte [ebx+1]
1711
	lea	ebx,[ebx+2+eax]
1712
	cmp	byte [ebx],1Ah
1713
	je	free_match
1714
      find_exact_match:
31 halyavin 1715
	call	exact_match
157 heavyiron 1716
	cmp	esi,[parameters_end]
1717
	je	end_matching
1718
	cmp	byte [ebx],1Ah
1719
	je	free_match
1720
	mov	ebx,[edx-12]
1721
	movzx	eax,byte [ebx+1]
1722
	lea	ebx,[ebx+2+eax]
1723
	mov	esi,[edx-4]
1724
	jmp	match_more_elements
1725
      try_different_matching:
31 halyavin 1726
	sub	edx,12
157 heavyiron 1727
	cmp	edx,edi
1728
	je	instant_macro_done
1729
	mov	ebx,[edx-12]
1730
	movzx	eax,byte [ebx+1]
1731
	lea	ebx,[ebx+2+eax]
1732
	cmp	byte [ebx],1Ah
1733
	je	try_different_matching
1734
	mov	esi,[edx-4]
1735
      match_more_elements:
31 halyavin 1736
	call	skip_match_element
157 heavyiron 1737
	jc	try_different_matching
1738
	mov	[edx-4],esi
1739
	jmp	find_exact_match
1740
      skip_match_element:
31 halyavin 1741
	cmp	esi,[parameters_end]
157 heavyiron 1742
	je	cannot_match
1743
	mov	al,[esi]
1744
	cmp	al,1Ah
1745
	je	skip_match_symbol
1746
	cmp	al,22h
1747
	je	skip_match_quoted_string
1748
	add	esi,1
1749
	ret
1750
      skip_match_quoted_string:
31 halyavin 1751
	mov	eax,[esi+1]
157 heavyiron 1752
	add	esi,5
1753
	jmp	skip_match_ok
1754
      skip_match_symbol:
31 halyavin 1755
	movzx	eax,byte [esi+1]
157 heavyiron 1756
	add	esi,2
1757
      skip_match_ok:
31 halyavin 1758
	add	esi,eax
157 heavyiron 1759
	ret
1760
      cannot_match:
31 halyavin 1761
	stc
157 heavyiron 1762
	ret
1763
      exact_match:
31 halyavin 1764
	cmp	esi,[parameters_end]
157 heavyiron 1765
	je	exact_match_complete
1766
	mov	ah,[esi]
1767
	mov	al,[ebx]
1768
	cmp	al,','
1769
	je	exact_match_complete
1770
	cmp	al,1Ah
1771
	je	exact_match_complete
1772
	cmp	al,'='
1773
	je	match_verbatim
1774
	call	match_elements
1775
	je	exact_match
1776
      exact_match_complete:
31 halyavin 1777
	ret
157 heavyiron 1778
      match_verbatim:
31 halyavin 1779
	inc	ebx
157 heavyiron 1780
	call	match_elements
1781
	je	exact_match
1782
	dec	ebx
1783
	ret
1784
      match_elements:
31 halyavin 1785
	mov	al,[ebx]
157 heavyiron 1786
	cmp	al,1Ah
1787
	je	match_symbols
1788
	cmp	al,22h
1789
	je	match_quoted_strings
1790
	cmp	al,ah
1791
	je	symbol_characters_matched
1792
	ret
1793
      symbol_characters_matched:
31 halyavin 1794
	lea	ebx,[ebx+1]
157 heavyiron 1795
	lea	esi,[esi+1]
1796
	ret
1797
      match_quoted_strings:
31 halyavin 1798
	mov	ecx,[ebx+1]
157 heavyiron 1799
	add	ecx,5
1800
	jmp	compare_elements
1801
      match_symbols:
31 halyavin 1802
	movzx	ecx,byte [ebx+1]
157 heavyiron 1803
	add	ecx,2
1804
      compare_elements:
31 halyavin 1805
	mov	eax,esi
157 heavyiron 1806
	mov	ebp,edi
1807
	mov	edi,ebx
1808
	repe	cmps byte [esi],[edi]
1809
	jne	elements_mismatch
1810
	mov	ebx,edi
1811
	mov	edi,ebp
1812
	ret
1813
      elements_mismatch:
31 halyavin 1814
	mov	esi,eax
157 heavyiron 1815
	mov	edi,ebp
1816
	ret
1817
      end_matching:
31 halyavin 1818
	cmp	byte [ebx],','
157 heavyiron 1819
	jne	instant_macro_done
1820
      matched_pattern:
31 halyavin 1821
	xor	eax,eax
157 heavyiron 1822
	push	[free_additional_memory]
1823
	push	[macro_symbols]
1824
	mov	[macro_symbols],eax
1825
	push	[counter_limit]
1826
	mov	[counter_limit],eax
1827
	mov	[struc_name],eax
1828
	push	esi edi edx
1829
      add_matched_symbol:
31 halyavin 1830
	cmp	edi,[esp]
157 heavyiron 1831
	je	matched_symbols_ok
1832
	mov	esi,[edi]
1833
	inc	esi
1834
	lods	byte [esi]
1835
	movzx	ecx,al
1836
	xor	eax,eax
1837
	call	add_macro_symbol
1838
	mov	eax,[edi+4]
1839
	mov	dword [edx+12],eax
1840
	mov	ecx,[edi+8]
1841
	sub	ecx,eax
1842
	mov	dword [edx+8],ecx
1843
	add	edi,12
1844
	jmp	add_matched_symbol
1845
      matched_symbols_ok:
31 halyavin 1846
	pop	edx edi esi
157 heavyiron 1847
	jmp	instant_macro_parameters_ok
1848
31 halyavin 1849
 
1850
	push	dword [macro_status]
157 heavyiron 1851
	or	[macro_status],10h
1852
	push	[counter]
1853
	push	[macro_block]
1854
	push	[macro_block_line]
1855
	push	[macro_block_line_number]
1856
	push	[struc_label]
1857
	push	[struc_name]
1858
	push	eax
1859
	push	[current_line]
1860
	lods	byte [esi]
1861
	cmp	al,'{'
1862
	je	macro_instructions_start
1863
	or	al,al
1864
	jnz	unexpected_characters
1865
      find_macro_instructions:
31 halyavin 1866
	mov	[macro_line],esi
157 heavyiron 1867
	add	esi,16+2
1868
	lods	byte [esi]
1869
	or	al,al
1870
	jz	find_macro_instructions
1871
	cmp	al,'{'
1872
	je	macro_instructions_start
1873
	cmp	al,3Bh
1874
	jne	unexpected_characters
1875
	call	skip_foreign_symbol
1876
	jmp	find_macro_instructions
1877
      macro_instructions_start:
31 halyavin 1878
	mov	ecx,80000000h
157 heavyiron 1879
	mov	[macro_block],esi
1880
	mov	eax,[macro_line]
1881
	mov	[macro_block_line],eax
1882
	mov	[macro_block_line_number],ecx
1883
	xor	eax,eax
1884
	mov	[counter],eax
1885
	cmp	[counter_limit],eax
1886
	je	process_macro_line
1887
	inc	[counter]
1888
      process_macro_line:
31 halyavin 1889
	mov	[current_line],edi
157 heavyiron 1890
	lea	eax,[edi+10h]
1891
	cmp	eax,[memory_end]
1892
	jae	out_of_memory
1893
	mov	eax,[esp+4]
1894
	or	eax,eax
1895
	jz	instant_macro_line_header
1896
	stos	dword [edi]
1897
	mov	eax,ecx
1898
	stos	dword [edi]
1899
	mov	eax,[esp]
1900
	stos	dword [edi]
1901
	mov	eax,[macro_line]
1902
	stos	dword [edi]
1903
	jmp	macro_line_header_ok
1904
      instant_macro_line_header:
31 halyavin 1905
	mov	eax,[macro_line]
992 heavyiron 1906
	add	eax,16+1
1907
	stos	dword [edi]
157 heavyiron 1908
	mov	eax,ecx
992 heavyiron 1909
	stos	dword [edi]
157 heavyiron 1910
	mov	eax,[macro_line]
992 heavyiron 1911
	stos	dword [edi]
157 heavyiron 1912
	stos	dword [edi]
1913
      macro_line_header_ok:
31 halyavin 1914
	or	[macro_status],20h
157 heavyiron 1915
	push	ebx ecx
1916
	test	[macro_status],0Fh
1917
	jz	process_macro_line_element
1918
	mov	ax,3Bh
1919
	stos	word [edi]
1920
      process_macro_line_element:
31 halyavin 1921
	lea	eax,[edi+100h]
157 heavyiron 1922
	cmp	eax,[memory_end]
1923
	jae	out_of_memory
1924
	lods	byte [esi]
1925
	cmp	al,'}'
1926
	je	macro_line_processed
1927
	or	al,al
1928
	jz	macro_line_processed
1929
	cmp	al,1Ah
1930
	je	process_macro_symbol
1931
	cmp	al,3Bh
1932
	je	macro_foreign_line
1933
	and	[macro_status],not 20h
1934
	stos	byte [edi]
1935
	cmp	al,22h
1936
	jne	process_macro_line_element
1937
      copy_macro_string:
31 halyavin 1938
	mov	ecx,[esi]
157 heavyiron 1939
	add	ecx,4
1940
	call	move_data
1941
	jmp	process_macro_line_element
1942
      process_macro_symbol:
31 halyavin 1943
	push	esi edi
157 heavyiron 1944
	test	[macro_status],20h
1945
	jz	not_macro_directive
1946
	movzx	ecx,byte [esi]
1947
	inc	esi
1948
	mov	edi,macro_directives
1949
	call	get_directive
1950
	jnc	process_macro_directive
1951
	dec	esi
1952
	jmp	not_macro_directive
1953
      process_macro_directive:
31 halyavin 1954
	mov	edx,eax
157 heavyiron 1955
	pop	edi eax
1956
	mov	byte [edi],0
1957
	inc	edi
1958
	pop	ecx ebx
1959
	jmp	near edx
1960
      not_macro_directive:
31 halyavin 1961
	and	[macro_status],not 20h
157 heavyiron 1962
	movzx	ecx,byte [esi]
1963
	inc	esi
1964
	mov	eax,[counter]
1965
	call	get_macro_symbol
1966
	jnc	group_macro_symbol
1967
	xor	eax,eax
1968
	cmp	[counter],eax
1969
	je	multiple_macro_symbol_values
1970
	call	get_macro_symbol
1971
	jc	not_macro_symbol
1972
      replace_macro_symbol:
31 halyavin 1973
	pop	edi eax
157 heavyiron 1974
	mov	ecx,[edx+8]
1975
	mov	edx,[edx+12]
1976
	or	edx,edx
1977
	jz	replace_macro_counter
1978
	and	ecx,not 80000000h
1189 heavyiron 1979
	xchg	esi,edx
157 heavyiron 1980
	call	move_data
1981
	mov	esi,edx
1982
	jmp	process_macro_line_element
1983
      group_macro_symbol:
31 halyavin 1984
	xor	eax,eax
157 heavyiron 1985
	cmp	[counter],eax
1986
	je	replace_macro_symbol
1987
	push	esi edx
1988
	sub	esi,ecx
1989
	call	get_macro_symbol
1990
	mov	ebx,edx
1991
	pop	edx esi
1992
	jc	replace_macro_symbol
1993
	cmp	edx,ebx
1994
	ja	replace_macro_symbol
1995
	mov	edx,ebx
1996
	jmp	replace_macro_symbol
1997
      multiple_macro_symbol_values:
31 halyavin 1998
	inc	eax
157 heavyiron 1999
	push	eax
2000
	call	get_macro_symbol
2001
	pop	eax
2002
	jc	not_macro_symbol
2003
	pop	edi
2004
	push	ecx
2005
	mov	ecx,[edx+8]
2006
	mov	edx,[edx+12]
2007
	xchg	esi,edx
2008
	btr	ecx,31
2009
	jc	enclose_macro_symbol_value
2010
	rep	movs byte [edi],[esi]
2011
	jmp	macro_symbol_value_ok
2012
      enclose_macro_symbol_value:
31 halyavin 2013
	mov	byte [edi],'<'
157 heavyiron 2014
	inc	edi
2015
	rep	movs byte [edi],[esi]
2016
	mov	byte [edi],'>'
2017
	inc	edi
2018
      macro_symbol_value_ok:
31 halyavin 2019
	cmp	eax,[counter_limit]
157 heavyiron 2020
	je	multiple_macro_symbol_values_ok
2021
	mov	byte [edi],','
2022
	inc	edi
2023
	mov	esi,edx
2024
	pop	ecx
2025
	push	edi
2026
	sub	esi,ecx
2027
	jmp	multiple_macro_symbol_values
2028
      multiple_macro_symbol_values_ok:
31 halyavin 2029
	pop	ecx eax
157 heavyiron 2030
	mov	esi,edx
2031
	jmp	process_macro_line_element
2032
      replace_macro_counter:
31 halyavin 2033
	mov	eax,[counter]
157 heavyiron 2034
	and	eax,not 80000000h
2035
	jz	group_macro_counter
2036
	add	ecx,eax
2037
	dec	ecx
2038
	call	store_number_symbol
2039
	jmp	process_macro_line_element
2040
      group_macro_counter:
31 halyavin 2041
	mov	edx,ecx
157 heavyiron 2042
	xor	ecx,ecx
2043
      multiple_macro_counter_values:
31 halyavin 2044
	push	ecx edx
157 heavyiron 2045
	add	ecx,edx
2046
	call	store_number_symbol
2047
	pop	edx ecx
2048
	inc	ecx
2049
	cmp	ecx,[counter_limit]
2050
	je	process_macro_line_element
2051
	mov	byte [edi],','
2052
	inc	edi
2053
	jmp	multiple_macro_counter_values
2054
      store_number_symbol:
31 halyavin 2055
	cmp	ecx,0
1189 heavyiron 2056
	jge	numer_symbol_sign_ok
2057
	neg	ecx
2058
	mov	al,'-'
2059
	stos	byte [edi]
2060
      numer_symbol_sign_ok:
2061
	mov	ax,1Ah
157 heavyiron 2062
	stos	word [edi]
2063
	push	edi
2064
	mov	eax,ecx
2065
	mov	ecx,1000000000
2066
	xor	edx,edx
2067
	xor	bl,bl
2068
      store_number_digits:
31 halyavin 2069
	div	ecx
157 heavyiron 2070
	push	edx
2071
	or	bl,bl
2072
	jnz	store_number_digit
2073
	cmp	ecx,1
2074
	je	store_number_digit
2075
	or	al,al
2076
	jz	number_digit_ok
2077
	not	bl
2078
      store_number_digit:
31 halyavin 2079
	add	al,30h
157 heavyiron 2080
	stos	byte [edi]
2081
      number_digit_ok:
31 halyavin 2082
	mov	eax,ecx
157 heavyiron 2083
	xor	edx,edx
2084
	mov	ecx,10
2085
	div	ecx
2086
	mov	ecx,eax
2087
	pop	eax
2088
	or	ecx,ecx
2089
	jnz	store_number_digits
2090
	pop	ebx
2091
	mov	eax,edi
2092
	sub	eax,ebx
2093
	mov	[ebx-1],al
2094
	ret
2095
      not_macro_symbol:
31 halyavin 2096
	pop	edi esi
157 heavyiron 2097
	mov	al,1Ah
2098
	stos	byte [edi]
2099
	mov	al,[esi]
2100
	inc	esi
2101
	stos	byte [edi]
2102
	cmp	byte [esi],'.'
2103
	jne	copy_raw_symbol
2104
	mov	ebx,[esp+8+8]
2105
	or	ebx,ebx
2106
	jz	copy_raw_symbol
2107
	cmp	al,1
2108
	je	copy_struc_name
2109
	xchg	esi,ebx
2110
	movzx	ecx,byte [esi-1]
2111
	add	[edi-1],cl
2112
	jc	name_too_long
2113
	rep	movs byte [edi],[esi]
2114
	xchg	esi,ebx
2115
      copy_raw_symbol:
31 halyavin 2116
	movzx	ecx,al
157 heavyiron 2117
	rep	movs byte [edi],[esi]
2118
	jmp	process_macro_line_element
2119
      copy_struc_name:
31 halyavin 2120
	inc	esi
157 heavyiron 2121
	xchg	esi,ebx
2122
	movzx	ecx,byte [esi-1]
2123
	mov	[edi-1],cl
2124
	rep	movs byte [edi],[esi]
2125
	xchg	esi,ebx
2126
	mov	eax,[esp+8+12]
2127
	cmp	byte [eax],3Bh
2128
	je	process_macro_line_element
2129
	cmp	byte [eax],1Ah
2130
	jne	disable_replaced_struc_name
2131
	mov	byte [eax],3Bh
2132
	jmp	process_macro_line_element
2133
      disable_replaced_struc_name:
31 halyavin 2134
	mov	ebx,[esp+8+8]
157 heavyiron 2135
	push	esi edi
2136
	lea	edi,[ebx-3]
2137
	lea	esi,[edi-2]
2138
	lea	ecx,[esi+1]
2139
	sub	ecx,eax
2140
	std
2141
	rep	movs byte [edi],[esi]
2142
	cld
2143
	mov	word [eax],3Bh
2144
	pop	edi esi
2145
	jmp	process_macro_line_element
2146
      skip_foreign_symbol:
31 halyavin 2147
	lods	byte [esi]
157 heavyiron 2148
	movzx	eax,al
2149
	add	esi,eax
2150
      skip_foreign_line:
31 halyavin 2151
	lods	byte [esi]
157 heavyiron 2152
	cmp	al,1Ah
2153
	je	skip_foreign_symbol
2154
	cmp	al,3Bh
2155
	je	skip_foreign_symbol
2156
	cmp	al,22h
2157
	je	skip_foreign_string
2158
	or	al,al
2159
	jnz	skip_foreign_line
2160
	ret
2161
      skip_foreign_string:
31 halyavin 2162
	lods	dword [esi]
157 heavyiron 2163
	add	esi,eax
2164
	jmp	skip_foreign_line
2165
      macro_foreign_line:
31 halyavin 2166
	call	skip_foreign_symbol
157 heavyiron 2167
      macro_line_processed:
31 halyavin 2168
	mov	byte [edi],0
157 heavyiron 2169
	inc	edi
2170
	push	eax
2171
	call	preprocess_line
2172
	pop	eax
2173
	pop	ecx ebx
2174
	cmp	al,'}'
2175
	je	macro_block_processed
2176
      process_next_line:
31 halyavin 2177
	inc	ecx
157 heavyiron 2178
	mov	[macro_line],esi
2179
	add	esi,16+2
2180
	jmp	process_macro_line
2181
      macro_block_processed:
31 halyavin 2182
	call	close_macro_block
157 heavyiron 2183
	jc	process_macro_line
2184
	pop	[current_line]
2185
	add	esp,12
2186
	pop	[macro_block_line_number]
2187
	pop	[macro_block_line]
2188
	pop	[macro_block]
2189
	pop	[counter]
2190
	pop	eax
2191
	and	al,0F0h
2192
	and	[macro_status],0Fh
2193
	or	[macro_status],al
2194
	ret
2195
31 halyavin 2196
 
2197
	lods	byte [esi]
157 heavyiron 2198
	cmp	al,1Ah
2199
	jne	invalid_argument
2200
	mov	byte [edi-1],3Bh
2201
	xor	al,al
2202
	stos	byte [edi]
2203
      make_local_symbol:
31 halyavin 2204
	push	ecx
157 heavyiron 2205
	lods	byte [esi]
2206
	movzx	ecx,al
2207
	mov	eax,[counter]
2208
	call	add_macro_symbol
2209
	mov	[edx+12],edi
2210
	movzx	eax,[locals_counter]
2211
	add	eax,ecx
2212
	inc	eax
2213
	cmp	eax,100h
2214
	jae	name_too_long
2215
	lea	ebp,[edi+2+eax]
2216
	cmp	ebp,[memory_end]
2217
	jae	out_of_memory
2218
	mov	ah,al
2219
	mov	al,1Ah
2220
	stos	word [edi]
2221
	rep	movs byte [edi],[esi]
2222
	mov	al,'?'
2223
	stos	byte [edi]
2224
	push	esi
2225
	mov	esi,locals_counter+1
2226
	movzx	ecx,[locals_counter]
2227
	rep	movs byte [edi],[esi]
2228
	pop	esi
2229
	mov	eax,edi
2230
	sub	eax,[edx+12]
2231
	mov	[edx+8],eax
2232
	xor	al,al
2233
	stos	byte [edi]
2234
	mov	eax,locals_counter
2235
	movzx	ecx,byte [eax]
2236
      counter_loop:
31 halyavin 2237
	inc	byte [eax+ecx]
157 heavyiron 2238
	cmp	byte [eax+ecx],'9'+1
692 heavyiron 2239
	jb	counter_ok
157 heavyiron 2240
	jne	letter_digit
2241
	mov	byte [eax+ecx],'A'
2242
	jmp	counter_ok
2243
      letter_digit:
31 halyavin 2244
	cmp	byte [eax+ecx],'Z'+1
692 heavyiron 2245
	jb	counter_ok
2246
	jne	small_letter_digit
2247
	mov	byte [eax+ecx],'a'
2248
	jmp	counter_ok
2249
      small_letter_digit:
2250
	cmp	byte [eax+ecx],'z'+1
2251
	jb	counter_ok
2252
	mov	byte [eax+ecx],'0'
157 heavyiron 2253
	loop	counter_loop
2254
	inc	byte [eax]
692 heavyiron 2255
	movzx	ecx,byte [eax]
2256
	mov	byte [eax+ecx],'0'
2257
      counter_ok:
31 halyavin 2258
	pop	ecx
157 heavyiron 2259
	lods	byte [esi]
2260
	cmp	al,'}'
2261
	je	macro_block_processed
2262
	or	al,al
2263
	jz	process_next_line
2264
	cmp	al,','
2265
	jne	extra_characters_on_line
2266
	dec	edi
2267
	lods	byte [esi]
2268
	cmp	al,1Ah
2269
	je	make_local_symbol
2270
	jmp	invalid_argument
2271
common_block:
31 halyavin 2272
	call	close_macro_block
157 heavyiron 2273
	jc	process_macro_line
2274
	mov	[counter],0
2275
	jmp	new_macro_block
2276
forward_block:
31 halyavin 2277
	cmp	[counter_limit],0
157 heavyiron 2278
	je	common_block
2279
	call	close_macro_block
2280
	jc	process_macro_line
2281
	mov	[counter],1
2282
	jmp	new_macro_block
2283
reverse_block:
31 halyavin 2284
	cmp	[counter_limit],0
157 heavyiron 2285
	je	common_block
2286
	call	close_macro_block
2287
	jc	process_macro_line
2288
	mov	eax,[counter_limit]
2289
	or	eax,80000000h
2290
	mov	[counter],eax
2291
      new_macro_block:
31 halyavin 2292
	mov	[macro_block],esi
157 heavyiron 2293
	mov	eax,[macro_line]
2294
	mov	[macro_block_line],eax
2295
	mov	[macro_block_line_number],ecx
2296
	jmp	process_macro_line
2297
close_macro_block:
31 halyavin 2298
	cmp	[counter],0
157 heavyiron 2299
	je	block_closed
2300
	jl	reverse_counter
2301
	mov	eax,[counter]
2302
	cmp	eax,[counter_limit]
2303
	je	block_closed
2304
	inc	[counter]
2305
	jmp	continue_block
2306
      reverse_counter:
31 halyavin 2307
	mov	eax,[counter]
157 heavyiron 2308
	dec	eax
2309
	cmp	eax,80000000h
2310
	je	block_closed
2311
	mov	[counter],eax
2312
      continue_block:
31 halyavin 2313
	mov	esi,[macro_block]
157 heavyiron 2314
	mov	eax,[macro_block_line]
2315
	mov	[macro_line],eax
2316
	mov	ecx,[macro_block_line_number]
2317
	stc
2318
	ret
2319
      block_closed:
31 halyavin 2320
	clc
157 heavyiron 2321
	ret
2322
get_macro_symbol:
31 halyavin 2323
	push	ecx
157 heavyiron 2324
	call	find_macro_symbol_leaf
2325
	jc	macro_symbol_not_found
2326
	mov	edx,[ebx]
2327
	mov	ebx,esi
2328
      try_macro_symbol:
31 halyavin 2329
	or	edx,edx
157 heavyiron 2330
	jz	macro_symbol_not_found
2331
	mov	ecx,[esp]
2332
	mov	edi,[edx+4]
2333
	repe	cmps byte [esi],[edi]
2334
	je	macro_symbol_found
2335
	mov	esi,ebx
2336
	mov	edx,[edx]
2337
	jmp	try_macro_symbol
2338
      macro_symbol_found:
31 halyavin 2339
	pop	ecx
157 heavyiron 2340
	clc
2341
	ret
2342
      macro_symbol_not_found:
31 halyavin 2343
	pop	ecx
157 heavyiron 2344
	stc
2345
	ret
2346
      find_macro_symbol_leaf:
31 halyavin 2347
	shl	eax,8
157 heavyiron 2348
	mov	al,cl
2349
	mov	ebp,eax
2350
	mov	ebx,macro_symbols
2351
      follow_macro_symbols_tree:
31 halyavin 2352
	mov	edx,[ebx]
157 heavyiron 2353
	or	edx,edx
2354
	jz	no_such_macro_symbol
2355
	xor	eax,eax
2356
	shr	ebp,1
2357
	adc	eax,0
2358
	lea	ebx,[edx+eax*4]
2359
	or	ebp,ebp
2360
	jnz	follow_macro_symbols_tree
2361
	add	ebx,8
2362
	clc
2363
	ret
2364
      no_such_macro_symbol:
31 halyavin 2365
	stc
157 heavyiron 2366
	ret
2367
add_macro_symbol:
31 halyavin 2368
	push	ebx ebp
157 heavyiron 2369
	call	find_macro_symbol_leaf
2370
	jc	extend_macro_symbol_tree
2371
	mov	eax,[ebx]
2372
      make_macro_symbol:
31 halyavin 2373
	mov	edx,[free_additional_memory]
157 heavyiron 2374
	add	edx,16
2375
	cmp	edx,[labels_list]
2376
	ja	out_of_memory
2377
	xchg	edx,[free_additional_memory]
2378
	mov	[ebx],edx
2379
	mov	[edx],eax
2380
	mov	[edx+4],esi
2381
	pop	ebp ebx
2382
	ret
2383
      extend_macro_symbol_tree:
31 halyavin 2384
	mov	edx,[free_additional_memory]
157 heavyiron 2385
	add	edx,16
2386
	cmp	edx,[labels_list]
2387
	ja	out_of_memory
2388
	xchg	edx,[free_additional_memory]
2389
	xor	eax,eax
2390
	mov	[edx],eax
2391
	mov	[edx+4],eax
2392
	mov	[edx+8],eax
2393
	mov	[edx+12],eax
2394
	shr	ebp,1
2395
	adc	eax,0
2396
	mov	[ebx],edx
2397
	lea	ebx,[edx+eax*4]
2398
	or	ebp,ebp
2399
	jnz	extend_macro_symbol_tree
2400
	add	ebx,8
2401
	xor	eax,eax
2402
	jmp	make_macro_symbol
2403
31 halyavin 2404
 
2405
	lods	byte [esi]
157 heavyiron 2406
	cmp	al,22h
2407
	jne	invalid_argument
2408
	lods	dword [esi]
2409
	cmp	byte [esi+eax],0
2410
	jne	extra_characters_on_line
2411
	push	esi
2412
	push	edi
2413
	mov	ebx,[current_line]
2414
      find_current_file_path:
31 halyavin 2415
	mov	esi,[ebx]
157 heavyiron 2416
	test	byte [ebx+7],80h
2417
	jz	copy_current_file_path
2418
	mov	ebx,[ebx+8]
2419
	jmp	find_current_file_path
2420
      copy_current_file_path:
31 halyavin 2421
	lods	byte [esi]
157 heavyiron 2422
	stos	byte [edi]
2423
	or	al,al
2424
	jnz	copy_current_file_path
2425
      cut_current_file_name:
31 halyavin 2426
	cmp	edi,[esp]
157 heavyiron 2427
	je	current_file_path_ok
2428
	cmp	byte [edi-1],'\'
2429
	je	current_file_path_ok
2430
	cmp	byte [edi-1],'/'
2431
	je	current_file_path_ok
2432
	dec	edi
2433
	jmp	cut_current_file_name
2434
      current_file_path_ok:
31 halyavin 2435
	mov	esi,[esp+4]
157 heavyiron 2436
	call	preprocess_path
2437
	pop	edx
2438
	mov	esi,edx
2439
	call	open
2440
	jnc	include_path_ok
2441
	mov	ebp,[include_paths]
2442
      try_include_directories:
31 halyavin 2443
	mov	edi,esi
157 heavyiron 2444
	mov	esi,ebp
2445
	cmp	byte [esi],0
2446
	je	try_in_current_directory
2447
	push	ebp
2448
	push	edi
2449
      copy_include_directory:
31 halyavin 2450
	lods	byte [esi]
157 heavyiron 2451
	cmp	al,';'
2452
	je	include_directory_ok
2453
	stos	byte [edi]
2454
	or	al,al
2455
	jnz	copy_include_directory
2456
	dec	esi
2457
	dec	edi
2458
      include_directory_ok:
31 halyavin 2459
	cmp	byte [edi-1],'/'
157 heavyiron 2460
	je	path_separator_ok
2461
	cmp	byte [edi-1],'\'
2462
	je	path_separator_ok
2463
	mov	al,'/'
2464
	stos	byte [edi]
2465
      path_separator_ok:
31 halyavin 2466
	mov	[esp+4],esi
157 heavyiron 2467
	mov	esi,[esp+8]
2468
	call	preprocess_path
2469
	pop	edx
2470
	mov	esi,edx
2471
	call	open
2472
	pop	ebp
2473
	jnc	include_path_ok
2474
	jmp	try_include_directories
2475
	mov	edi,esi
2476
      try_in_current_directory:
31 halyavin 2477
	mov	esi,[esp]
157 heavyiron 2478
	push	edi
2479
	call	preprocess_path
2480
	pop	edx
2481
	mov	esi,edx
2482
	call	open
2483
	jc	file_not_found
2484
      include_path_ok:
31 halyavin 2485
	mov	edi,[esp]
157 heavyiron 2486
      copy_preprocessed_path:
31 halyavin 2487
	lods	byte [esi]
157 heavyiron 2488
	stos	byte [edi]
2489
	or	al,al
2490
	jnz	copy_preprocessed_path
2491
	pop	esi
2492
	lea	ecx,[edi-1]
2493
	sub	ecx,esi
2494
	mov	[esi-4],ecx
2495
	push	dword [macro_status]
2496
	and	[macro_status],0Fh
2497
	call	preprocess_file
2498
	pop	eax
2499
	mov	[macro_status],al
2500
	jmp	line_preprocessed
2501
      preprocess_path:
31 halyavin 2502
	lods	byte [esi]
157 heavyiron 2503
	cmp	al,'%'
2504
	je	environment_variable
2505
	stos	byte [edi]
2506
	or	al,al
2507
	jnz	preprocess_path
2508
	cmp	edi,[memory_end]
2509
	ja	out_of_memory
2510
	ret
2511
      environment_variable:
31 halyavin 2512
	mov	ebx,esi
157 heavyiron 2513
      find_variable_end:
31 halyavin 2514
	lods	byte [esi]
157 heavyiron 2515
	or	al,al
2516
	jz	not_environment_variable
2517
	cmp	al,'%'
2518
	jne	find_variable_end
2519
	mov	byte [esi-1],0
2520
	push	esi
2521
	mov	esi,ebx
2522
	call	get_environment_variable
2523
	pop	esi
2524
	mov	byte [esi-1],'%'
2525
	jmp	preprocess_path
2526
      not_environment_variable:
31 halyavin 2527
	mov	al,'%'
157 heavyiron 2528
	stos	byte [edi]
2529
	mov	esi,ebx
2530
	jmp	preprocess_path
2531
>