Kestrel-3

Check-in [c0b13ae1bb]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Support .word
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256:c0b13ae1bb56ae1716414707005edb887c3963e46941a19184a4b03224241059
User & Date: kc5tja 2019-09-03 04:23:25
Context
2019-09-03
04:31
.half and .byte supported check-in: 4f12102c36 user: kc5tja tags: trunk
04:23
Support .word check-in: c0b13ae1bb user: kc5tja tags: trunk
02:12
Remove debugging code check-in: 233d4785af user: kc5tja tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to dev/src/bcpl/assemrv/manifest.h.

101
102
103
104
105
106
107

108
109
    scs_integer;
    scs_string;
    scs_endstreamch = endstreamch;

    // Intermediate Representation order codes
    IR_LIT = 1000;
    IR_DWORD;

}








>


101
102
103
104
105
106
107
108
109
110
    scs_integer;
    scs_string;
    scs_endstreamch = endstreamch;

    // Intermediate Representation order codes
    IR_LIT = 1000;
    IR_DWORD;
    IR_WORD;
}

Changes to dev/src/bcpl/assemrv/parser.b.

1
2
3
4
5
6
7

8
9
10
11
12
13
14
..
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
LET parse(s, d, errp) BE {
	LET sym = scanner_sym(s)

	// Don't even try unless a chain of errors can be constructed.
	UNLESS errp DO RETURN

	IF sym = scs_dword DO scanner_next(s) <> dword(s, d, errp) <> RETURN


	error(errp, s, err_syntax_error)
}

AND error(errp, scanner, errcode) BE {
	LET errdesc = getvec(ed_sizeof)
	IF errdesc DO {
................................................................................
		errdesc!ed_code := errcode

		errdesc!ed_next := !errp
		!errp := errdesc
	}
}

AND dword(s, d, errp) BE {
	LET expr = VEC expr_sizeof

	zerovec(expr, expr_sizeof)

	dword_part(s, d, errp, expr)
	IF !errp DO RETURN
	WHILE scanner_sym(s) = ',' DO {
		scanner_next(s)
		dword_part(s, d, errp, expr)
		IF !errp DO RETURN
	}
}

AND dword_part(s, d, errp, expr) BE {
	expression(s, d, errp, expr)
	IF !errp DO RETURN

	IF expr!expr_type = et_integer DO {
		dynvec_put_at(d, IR_LIT, d!dv_length)
		dynvec_put_at(d, expr!expr_value, d!dv_length)
		dynvec_put_at(d, IR_DWORD, d!dv_length)
		RETURN
	}

	IF expr!expr_type = et_string DO {
		LET s = @expr!expr_string

		FOR i = 1 TO s%0 DO {
			dynvec_put_at(d, IR_LIT, d!dv_length)
			dynvec_put_at(d, s%i, d!dv_length)
			dynvec_put_at(d, IR_DWORD, d!dv_length)
		}
		RETURN
	}

	error(errp, s, err_int_str_expr_expected) <> RETURN
}







|
>







 







|




|



|




|






|









|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
..
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
LET parse(s, d, errp) BE {
	LET sym = scanner_sym(s)

	// Don't even try unless a chain of errors can be constructed.
	UNLESS errp DO RETURN

	IF sym = scs_dword DO scanner_next(s) <> const(s, d, errp, IR_DWORD) <> RETURN
	IF sym = scs_word DO scanner_next(s) <> const(s, d, errp, IR_WORD) <> RETURN

	error(errp, s, err_syntax_error)
}

AND error(errp, scanner, errcode) BE {
	LET errdesc = getvec(ed_sizeof)
	IF errdesc DO {
................................................................................
		errdesc!ed_code := errcode

		errdesc!ed_next := !errp
		!errp := errdesc
	}
}

AND const(s, d, errp, order) BE {
	LET expr = VEC expr_sizeof

	zerovec(expr, expr_sizeof)

	const_part(s, d, errp, expr, order)
	IF !errp DO RETURN
	WHILE scanner_sym(s) = ',' DO {
		scanner_next(s)
		const_part(s, d, errp, expr, order)
		IF !errp DO RETURN
	}
}

AND const_part(s, d, errp, expr, order) BE {
	expression(s, d, errp, expr)
	IF !errp DO RETURN

	IF expr!expr_type = et_integer DO {
		dynvec_put_at(d, IR_LIT, d!dv_length)
		dynvec_put_at(d, expr!expr_value, d!dv_length)
		dynvec_put_at(d, order, d!dv_length)
		RETURN
	}

	IF expr!expr_type = et_string DO {
		LET s = @expr!expr_string

		FOR i = 1 TO s%0 DO {
			dynvec_put_at(d, IR_LIT, d!dv_length)
			dynvec_put_at(d, s%i, d!dv_length)
			dynvec_put_at(d, order, d!dv_length)
		}
		RETURN
	}

	error(errp, s, err_int_str_expr_expected) <> RETURN
}

Changes to dev/src/bcpl/assemrv/test_parser.b.

60
61
62
63
64
65
66
67
68
69
70
71
72



73
74
75
76
77
78
79
80
81
82
83
84
...
198
199
200
201
202
203
204
















































































































































205
206
207
208
209
210
211
GET "globals_dynvec"
GET "globals_scanner"
GET "globals_utils"
GET "globals_parser"


LET testlist() = VALOF {
	MANIFEST { ntests = 3 }
	LET tl = getvec(ntests)
	tl!0 := ntests
	tl!1 := test_single_dword
	tl!2 := test_single_dword_chain
	tl!3 := test_single_dword_string



	RESULTIS tl
}


// Parser Tests: Simple listings

AND test_single_dword(r) = VALOF {
	LET err = failat
	LET scb, s, d = 0, 0, 0
	LET errlist = 0

	IF r DO RESULTIS r
................................................................................
	{
		LET outs = output()
		selectoutput(scb)
		writef(".dword 6, *"Abacab*"*n")
		selectoutput(outs)
		rewindstream(scb)
	}

















































































































































	s := make_scanner()
	UNLESS NEQ(s, 0, 1) DO GOTO unwind
	UNLESS EQ(scanner_get_stream(s, scb, "RAM:"), TRUE, 3) DO GOTO unwind
	scanner_nextchar(s)
	scanner_next(s)








|





>
>
>




|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
...
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
GET "globals_dynvec"
GET "globals_scanner"
GET "globals_utils"
GET "globals_parser"


LET testlist() = VALOF {
	MANIFEST { ntests = 6 }
	LET tl = getvec(ntests)
	tl!0 := ntests
	tl!1 := test_single_dword
	tl!2 := test_single_dword_chain
	tl!3 := test_single_dword_string
	tl!4 := test_single_word
	tl!5 := test_single_word_chain
	tl!6 := test_single_word_string
	RESULTIS tl
}


// Parser Tests: Simple listings: 64-bit words

AND test_single_dword(r) = VALOF {
	LET err = failat
	LET scb, s, d = 0, 0, 0
	LET errlist = 0

	IF r DO RESULTIS r
................................................................................
	{
		LET outs = output()
		selectoutput(scb)
		writef(".dword 6, *"Abacab*"*n")
		selectoutput(outs)
		rewindstream(scb)
	}

	s := make_scanner()
	UNLESS NEQ(s, 0, 1) DO GOTO unwind
	UNLESS EQ(scanner_get_stream(s, scb, "RAM:"), TRUE, 3) DO GOTO unwind
	scanner_nextchar(s)
	scanner_next(s)

	d := make_dynvec()
	UNLESS NEQ(d, 0, 4) DO GOTO unwind

	parse(s, d, @errlist)
	UNLESS EQ(errlist, 0, 5) DO GOTO unwind

	UNLESS EQ(d!dv_length, 21, 100) DO GOTO unwind
	FOR i = 0 TO 20 DO UNLESS EQ(dynvec_at(d, i), expected!i, 200+i) DO GOTO unwind

	err := 0

unwind:
	IF errlist DO free_errors(errlist)
	IF d DO dynvec_free(d)
	IF s DO scanner_free(s)
	IF scb DO endstream(scb)
	RESULTIS err
}

// Parser Tests: Simple listings: 32-bit words

AND test_single_word(r) = VALOF {
	LET err = failat
	LET scb, s, d = 0, 0, 0
	LET errlist = 0

	IF r DO RESULTIS r
	testid := "test_single_word"

	scb := findinoutput("RAM:")
	UNLESS NEQ(scb, 0, 0) DO GOTO unwind
	{
		LET outs = output()
		selectoutput(scb)
		writef(".word 1*n")
		selectoutput(outs)
		rewindstream(scb)
	}

	s := make_scanner()
	UNLESS NEQ(s, 0, 1) DO GOTO unwind
	UNLESS EQ(scanner_get_stream(s, scb, "RAM:"), TRUE, 3) DO GOTO unwind
	scanner_nextchar(s)
	scanner_next(s)

	d := make_dynvec()
	UNLESS NEQ(d, 0, 4) DO GOTO unwind

	parse(s, d, @errlist)
	UNLESS EQ(errlist, 0, 5) DO GOTO unwind

	UNLESS EQ(d!dv_length, 3, 100) DO GOTO unwind
	UNLESS EQ(dynvec_at(d, 0), IR_LIT, 101) DO GOTO unwind
	UNLESS EQ(dynvec_at(d, 1), 1, 102) DO GOTO unwind
	UNLESS EQ(dynvec_at(d, 2), IR_WORD, 103) DO GOTO unwind

	err := 0

unwind:
	IF errlist DO free_errors(errlist)
	IF d DO dynvec_free(d)
	IF s DO scanner_free(s)
	IF scb DO endstream(scb)
	RESULTIS err
}

AND test_single_word_chain(r) = VALOF {
	LET err = failat
	LET scb, s, d = 0, 0, 0
	LET expected = TABLE IR_LIT, 1, IR_WORD,
	                     IR_LIT, 2, IR_WORD,
	                     IR_LIT, 3, IR_WORD,
	                     IR_LIT, 4, IR_WORD
	LET errlist = 0

	IF r DO RESULTIS r
	testid := "test_single_word_chain"

	scb := findinoutput("RAM:")
	UNLESS NEQ(scb, 0, 0) DO GOTO unwind
	{
		LET outs = output()
		selectoutput(scb)
		writef(".word 1, 2, 3, 4*n")
		selectoutput(outs)
		rewindstream(scb)
	}

	s := make_scanner()
	UNLESS NEQ(s, 0, 1) DO GOTO unwind
	UNLESS EQ(scanner_get_stream(s, scb, "RAM:"), TRUE, 3) DO GOTO unwind
	scanner_nextchar(s)
	scanner_next(s)

	d := make_dynvec()
	UNLESS NEQ(d, 0, 4) DO GOTO unwind

	parse(s, d, @errlist)
	UNLESS EQ(errlist, 0, 5) DO GOTO unwind

	UNLESS EQ(d!dv_length, 12, 100) DO GOTO unwind
	FOR i = 0 TO 11 DO UNLESS EQ(dynvec_at(d, i), expected!i, 200+i) DO GOTO unwind

	err := 0

unwind:
	IF errlist DO free_errors(errlist)
	IF d DO dynvec_free(d)
	IF s DO scanner_free(s)
	IF scb DO endstream(scb)
	RESULTIS err
}

AND test_single_word_string(r) = VALOF {
	LET err = failat
	LET scb, s, d = 0, 0, 0
	LET expected = TABLE IR_LIT, 6, IR_WORD,
	                     IR_LIT, 'A', IR_WORD,
	                     IR_LIT, 'b', IR_WORD,
	                     IR_LIT, 'a', IR_WORD,
	                     IR_LIT, 'c', IR_WORD,
	                     IR_LIT, 'a', IR_WORD,
	                     IR_LIT, 'b', IR_WORD
	LET errlist = 0

	IF r DO RESULTIS r
	testid := "test_single_word_string"

	scb := findinoutput("RAM:")
	UNLESS NEQ(scb, 0, 0) DO GOTO unwind
	{
		LET outs = output()
		selectoutput(scb)
		writef(".word 6, *"Abacab*"*n")
		selectoutput(outs)
		rewindstream(scb)
	}

	s := make_scanner()
	UNLESS NEQ(s, 0, 1) DO GOTO unwind
	UNLESS EQ(scanner_get_stream(s, scb, "RAM:"), TRUE, 3) DO GOTO unwind
	scanner_nextchar(s)
	scanner_next(s)