summaryrefslogtreecommitdiff
path: root/tnslc/compile/compile.tnsl
blob: b8c6cd3d3550e4fc95e428d70d5e7fc60c534c40 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
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
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
/##
	Copyright 2021-2022 Kyle Gunger

	This file is licensed under the CDDL 1.0 (the License)
	and may only be used in accordance with the License.
	You should have received a copy of the License with this
	software/source code. If you did not, a copy can be found
	at the following URL:

	https://opensource.org/licenses/CDDL-1.0

	THIS SOFTWARE/SOURCE CODE IS PROVIDED "AS IS" WITH NO
	WARRANTY, GUARANTEE, OR CLAIM OF FITNESS FOR ANY PURPOSE
	EXPRESS OR IMPLIED
#/


;{}{}uint8 COMMON_ASM = {
	"\tret\n"
}

# Represents a type
;struct VType {
	uint
		_size,
	int
		ptr,
	
	{}uint8 name,

	{}VType sub_types,
	{}{}uint8 sub_names
}

/; method VType
	/; get_sub_type({}uint8 name) [VType]
		/; loop (int i = 0; i < len (self.sub_types)) [i++]
			/; if (string_equate(~name, ~(self.sub_names{i})))
				;return self.sub_types{i}
			;/
		;/
		;return NT
	;/

	/; get_offset({}uint8 name) [int]
		;int out = 0
		/; loop (int i = 0; i < len (self.on_stack)) [i++]
			/; if (string_equate(~name, ~(self.sub_types{i*2 + 1})))
				;return out
			;; else if (self.on_stack{i})
				;VType tmp = vtype_by_name(self.sub_types{i*2})
				;out = out + tmp.size
			;/
		;/
		;return -1
	;/

	/; print
		;tnsl.io.print("Size: ")
		;tnsl.io.print(self._size)
		;tnsl.io.print(" | Ptr: ")
		;tnsl.io.print(self.ptr)
		;tnsl.io.print(" | Name: ")
		;tnsl.io.println(self.name)
	;/
;/

# Tracks defined variables in a block
;struct VTrack {
	{}{}uint8
		sym_names,
	
	{}bool
		on_stack,

	{}VType
		sym_types
}

/; method VTrack
	# returns true if the value is allocated to the stack
	/; add_track({}uint8 name, VType _type) [int]
		;bool to_stack = is_struct(_type)
		;int count = 0

		/; loop (int i = 0; i < len (self.on_stack) && !to_stack) [i++]
			/; if (!self.on_stack{i})
				;count++
			;/

			/; if (count > 7)
				;to_stack = true
			;/
		;/

		;self.sym_names.append(name)
		;self.sym_types.append(_type)
		;self.on_stack.append(to_stack)

		/; if (count > 7)
			;return -1
		;/

		;return count
	;/

	# Returns true if the variable is being tracked
	/; in_vtrack({}uint8 name) [bool]
		/; loop (int i = 0; i < len (self.on_stack)) [i++]
			/; if (string_equate(~name, ~(self.sym_names{i})))
				;return true
			;/
		;/
		;return false
	;/

	# Returns the total allocated memory on the stack for this tracker
	/; stack_total [int]
		;int out = 0
		/; loop (int i = 0; i < len (self.on_stack)) [i++]
			/; if (self.on_stack{i})
				;out = out + (self.sym_types{i}._size)
			;/
		;/
		;return out
	;/

	# returns the type of the named variable
	/; get_vtype ({}uint8 name) [VType]
		/; loop (int i = 0; i < len (self.on_stack)) [i++]
			/; if (string_equate(name, self.sym_names{i}))
				;return (self.sym_types{i})
			;/
		;/
	;/
;/

# Sizes of items
;{}VType type_table = {
	{1, 0, "int8", {}, {}},
	{2, 0, "int16", {}, {}},
	{4, 0, "int32", {}, {}},
	{8, 0, "int64", {}, {}},
	{8, 0, "int", {}, {}},
	{1, 0, "uint8", {}, {}},
	{2, 0, "uint16", {}, {}},
	{4, 0, "uint32", {}, {}},
	{8, 0, "uint64", {}, {}},
	{8, 0, "uint", {}, {}},
	{4, 0, "float32", {}, {}},
	{8, 0, "float64", {}, {}},
	{8, 0, "float", {}, {}},
	{1, 0, "bool", {}, {}},
	{8, 0, "void", {}, {}}
}

# Null type
;VType NT = {0, 0, "null", {}, {}}

# Returns an index in the vtrack for a given variable name
/; name_to_index ({}uint8 name, ~VTrack tab) [int]
	/; loop (int i = 0; i < len (tab`.sym_names)) [i++]
		/; if (string_equate(tab`.sym_names{i}, name))
			;return i
		;/
	;/
	
	;tnsl.io.print("Failed to find vairable ")
	;tnsl.io.println(name)

	;return -1
;/

# Given an index in the vtrack, returns a string representation of the
# register or memory where that variable is
/; index_to_loc (int index, ~VTrack tab) [{}uint8]
	;{}uint8 out = ""
	;int stack_bytes = 0
	;int reg = 0
	;int i = 0

	/; loop (i < index) [i++]
		/; if (tab`.sym_types{i}._size !> 8 && reg < 7)
			;reg++
		;; else
			;stack_bytes = stack_bytes + tab`.sym_types{i}._size
		;/
	;/

	/; if (is_struct(tab`.sym_types{index}))
		;out = "(todo: structs)"
	;; else
		;out = reg_by_num(reg)
	;/
	
	;return out
;/

# Is struct returns true if the type name given is a struct
/; is_struct (VType t) [bool]
	/; if (t.ptr > 0)
		;return false
	;/

	/; loop (int i = 0; i < 15) [i++]
		/; if (string_equate(type_table{i}.name, t.name))
			;return false
		;/
	;/

	;return true
;/

# Using the given offset (in bytes), return an asm value of form ".quad <offset>"
/; construct_value (int size, int offset) [{}uint8]
	;{}uint8 out = ".byte "
	/; if (size == 2)
		;out = ".word "
	;; if (size == 4)
		;out = ".long"
	;; if (size == 8)
		;out = ".quad "
	;/
	;{}uint8 tmp = string_from_int(offset)
	;add_strings(~out, ~tmp)
	;return out
;/

/; construct_text_value ({}uint8 t) [{}uint8]
	;{}uint8 tmp = "\n\t.ascii "
	;add_strings(~tmp, ~t)
	;return tmp
;/

/; construct_mov_literal({}uint8 value, reg) [{}uint8]
	;{}uint8 tmp = "$"
	;add_strings(~tmp, ~value)
	;return mov_asm(tmp, reg)
;/

# Parse a struct and add it to the table
/; def_struct (~int cur, ~{}Token data, ~{}uint8 dsec) [VType]
	;VType out = {0, 0, "", {}, {}}
	;cur`++

	;out.name = data`{cur`}.data`

	;cur`++
	;cur`++
	# Should be indexed at first type in the type list

	/; if (token_is(cur, data, "}"))
		;return NT
	;/

	;VType ctype = get_vtype(cur, data)
	;cur`++

	/; loop (cur` < len data`) [cur`++]
		/; if (token_is(cur, data, "}"))
			;break
		;; else if (token_is(cur, data, ","))
			;cur`++
		;/

		;cur`++
		/; if (token_is(cur, data, ",") || token_is(cur, data, "}"))
			# Use ctype
			;cur`--

			/; if (ctype.ptr > 0)
				;out._size = out._size + 8
			;; else
				;out._size = out._size + ctype._size
			;/
			;out.sub_types.append(ctype)
			;out.sub_names.append(data`{cur`}.data`)
			
		;; else
			# Get type
			;cur`--
			;ctype = get_vtype(cur, data)
		;/
	;/
	;out.print()
	;type_table.append(out)
	
	;return out
;/

# Checks if the current token's data member is equal to a given string
/; token_is(~int cur, ~{}Token data, {}uint8 str) [bool]
	;return string_equate(data`{cur`}.data`, str)
;/

# Skips in a definition or list until it finds a name
/; skip_to_name (~int cur, ~{}Token data)
	;int tmp = 0
	/; loop (cur` < len data`) [cur`++]
		;tmp = cur` + 1
		/; if (data`{cur`}.token_type == TOKEN_TYPE.DEFWORD && 
				( token_is(~tmp, data, ",") || token_is(~tmp, data, ")") || token_is(~tmp, data, "}") || token_is(~tmp, data, ";") ))
			;break
		;/
	;/
;/

# Searches the type table for a type
/; vtype_by_name ({}uint8 name) [VType]
	/; loop (int i = 0; i < len type_table) [i++]
		;VType tmp = tnslc.type_table{i}
		/; if (string_equate(name, tmp.name))
			;return tmp
		;/
	;/
	;return NT
;/

# Parses a type in a definition or list
/; get_vtype (~int cur, ~{}Token data) [VType]
	;uint ptr = 0
	;VType out = NT

	/; loop (cur` < len data`) [cur`++]
		;int i = data`{cur`}.token_type
		/; if (token_is(cur, data, "~") || token_is(cur, data, "{"))
			;ptr++
		;; else if (i == TOKEN_TYPE.DEFWORD || i == TOKEN_TYPE.KEYTYPE)
			;out = vtype_by_name(data`{cur`}.data`)
			;break
		;; else if (!token_is(cur, data, "}"))
			;break
		;/
	;/

	;out.ptr = ptr

	;return out
;/

# Assumes cur points to the beginning of the arguments list
# Sets up the VTrack struct that is pointed to.
/; setup_vtrack (~int cur, ~{}Token data, ~VTrack tab)
	;cur`++

	;VType last = NT

	/; loop (cur` < len data`) [cur`++]
		;int pre_skip = cur`
		/; if (token_is(cur, data, ")"))
			;break
		;; else if (!token_is(cur, data, ","))
			;skip_to_name(cur, data)
			/; if (pre_skip == cur`)
				;tab`.sym_types.append(last)
				;tab`.sym_names.append(data`{cur`}.data`)
			;; else
				;last = get_vtype(~pre_skip, data)
				;tab`.sym_types.append(last)
				;tab`.sym_names.append(data`{cur`}.data`)
			;/
		;/
	;/
;/

# Mostly deals with structs and enums
/; compile_global (~int cur, ~{}Token data, ~VTrack gsc, ~{}uint8 hsec, csec, dsec)
	;cur`++
	/; if (token_is(cur, data, "struct"))
		;def_struct(cur, data, dsec)
	;/
;/

# Evaluate a value and return it to the register pointed at by reg
/; eval_value (~int cur, ~{}Token data, ~VTrack tab, gsc, ~{}uint8 hsec, csec, dsec, int reg)
	/; if (token_is(cur, data, ";/"))
		;return
	;/

	;int val_layer = 0

	/; loop (cur` < len data`)
		/; if (data`{cur`}.token_type == TOKEN_TYPE.LITERAL)
			/; if (data`{cur`}.data`{0} == '"')
				# String literal
			
			;; else if (data`{cur`}.data`{0} == '\'')
				# Char literal
			;; else
				# int literal
				;{}uint8 tmp = construct_mov_literal(data`{cur`}.data`, get_reg(8, reg_by_num(val_layer)))
				;add_strings(csec, ~tmp)
				;val_layer++
				;cur`++
			;/
		;; else if (data`{cur`}.token_type == TOKEN_TYPE.DEFWORD)
		;; else if (token_is(cur, data, "~"))
		;; else if (data`{cur`}.token_type == TOKEN_TYPE.AUGMENT)
		;; else
			;break
		;/
	;/
;/

/; get_function_label(~int cur, ~{}Token data) [{}uint8]
	/; if (string_equate(data`{cur` + 1}.data`, "("))
		;return data`{cur`}.data`
	;/

	;{}{}uint8 func_path = {}

	/; loop (cur` < len data`) [cur`++]
		/; if (token_is(cur, data, "("))
			;break
		;; else if (!token_is(cur, data, "."))
			;func_path.append(data`{cur`}.data`)
		;/
	;/
	;{}uint8 out = "_."
	;{}uint8 jn_tmp = join(func_path, '.')
	;add_strings(~out, ~jn_tmp)
	;return out
;/

# Sets up a call and reports back where the return value is stored
/; eval_call (~int cur, ~{}Token data, ~VTrack tab, gsc, ~{}uint8 hsec, csec, dsec) [{}uint8]
	
		# Store the name of the function we are calling
	;{}uint8 to_call = get_function_label(cur, data)
	;tnsl.io.println(to_call)
		# Set read head to first parameter
	;cur`++
	;int reg = 0
	/; loop (!token_is(cur, data, ")"))
		/; if (token_is(cur, data, ","))
			;cur`++
		;; else
			/; if (reg < 7)
				;eval_value(cur, data, tab, gsc, hsec, csec, dsec, reg)
				;reg++
			;; else
				;eval_value(cur, data, tab, gsc, hsec, csec, dsec, reg)
				;push_asm(get_reg(8, "bp"))
			;/
		;/
	;/
	;cur`++

	;{}uint8 call_ist = call_asm(to_call)

	;add_strings(csec, ~call_ist)
	;return "ax"
;/

/; set_struct_value (~{}uint8 csec)

;/

/; copy_struct ({}uint8 from, to, VType t) [{}uint8]
	;{}uint8 out = ""
	;{}uint8 init = ""
;/

/; set_value ({}uint8 from, to, int size, ~{}uint8 csec)
	/; if (is_common_reg(from))
		;from = get_reg(size, from)
	;; if (is_common_reg(to))
		;to = get_reg(size, to)
	;/

	;{}uint8 tmp = "\tmov"
	/; if (size == 1)
		;mov.append('b')
	;; else if (size == 2)
		;mov.append('d')
	;; else if (size == 4)
		;mov.append('w')
	;; else if (size == 8)
		;mov.append('q')
	;/

	;tmp = construct_statement(tmp, {from, to})
	;add_strings(csec, ~tmp)
;/

/; is_call (~int cur, ~{}Token data) [bool]
	;bool look_def = true
	/; loop (int i = cur`; i < len data`) [i++]
		/; if (look_def && data`{i}.token_type == TOKEN_TYPE.DEFWORD)
			;look_def = false
		;; else if (!look_def && token_is(~i, data, "."))
			;look_def = true
		;; else if (!look_def && token_is(~i, data, "("))
			;return true
		;; else
			;break
		;/
	;/
	;return false
;/

# Compile a statement in a function
/; compile_statement (~int cur, ~{}Token data, ~VTrack tab, gsc, ~{}uint8 hsec, csec, dsec) [bool]
	;cur`++
	;bool r = false
	/; if (cur` < len data`)
		/; if (token_is(cur, data, "asm"))
			;cur`++
			;{}uint8 raw_asm = unquote_string(data`{cur`}.data`)
			;raw_asm.append('\n')
			;csec`.append('\t')
			;add_strings(csec, ~raw_asm)
			;cur`++
		;; else if (token_is(cur, data, "raw"))
			;cur`++
			;r = true
		;; else if (token_is(cur, data, "return"))
			;cur`++
			;eval_value(cur, data, tab, gsc, hsec, csec, dsec, 0)
			;tail_guard(csec)
			;add_strings(csec, ~(tnslc.COMMON_ASM{0}))
			;return true
		;; else if (is_call(cur, data))
			# Function call
			;eval_call(cur, data, tab, gsc, hsec, csec, dsec)
		;; else if (name_to_index(data`{cur`}.data`, tab) !< 0)
			# set value
			;int i = name_to_index(data`{cur`}.data`, tab)
			;{}uint8 tmp = index_to_loc(i)
			;eval_value(cur, data, tab, gsc, hsec, csec, dsec, 0)
			;tmp = mov_asm(get_reg(tab`.sym_types{i}._size, "ax"), tmp)
			;add_strings(csec, ~tmp)
		;; else
			#Definition
			;VType def_t = get_vtype(cur, data)
			;cur`++
			
			/; loop (data`{cur`}.token_type == TOKEN_TYPE.DEFWORD)
				;int stack = tab`.add_track()
				
				/; if (token_is(cur, data, ","))
					;cur`++
				;; else if (token_is(cur, data, "="))
					;{}uint8 loc = index_to_loc(len tab`.sym_names - 1, tab)
					;eval_value(cur, data, tab, gsc, hsec, csec, dsec, loc)
					/; if (token_is(cur, data, ","))
						;cur`++
					;/
				;/
			;/
			/; if (string_equate(data`{cur`+1}.data`, "="))

			;/
		;; if (token_is(cur, data, "return"))
			;add_strings(csec, ~(tnslc.COMMON_ASM{0}))
			;return true
		;/
	;/

	;return false
;/



/; compile_block (~int cur, ~{}Token data, ~VTrack gsc, ~{}uint8 hsec, csec, dsec, {}{}uint8 mod_path, Path rel)
	;VTrack tab = { {}, {}, {} }
	;VType out_type = tnslc.type_table{14}
	;{}uint8 name = ""
	;bool r = false

	/; loop (cur`++; cur` < len data`) [cur`++]
		/; if (token_is(cur, data, "module"))
			;mod_path.append(data`{cur` + 1}.data`)
			;cur` = cur` + 2
			;break
		;/
		/; if (data`{cur`}.token_type == TOKEN_TYPE.DEFWORD && len name == 0)
			;name = data`{cur`}.data`
			/; if (len mod_path > 0)
				;{}uint8 frs = "_."
				;{}uint8 jn = join(mod_path, '.')
				;add_strings(~frs, ~jn)
				;add_strings(csec, ~frs)
				;csec`.append('.')
			;/
			;add_strings(csec, ~name)
			;csec`.append(':')
			;csec`.append('\n')
		;; else if (token_is(cur, data, "("))
			;setup_vtrack(cur, data, ~tab)
		;; else if (token_is(cur, data, "["))
			;cur`++
			;out_type = get_vtype(cur, data)
			;cur`++
		;; else if (token_is(cur, data, "raw"))
			;r = true
		;; else
			;break
		;/
	;/

	;tnsl.io.println(out_type.name)

	/; if (!r)
		;header_guard(csec)
	;/

	;bool ret = false
	/; loop (cur` < len data` && !ret)
		/; if (token_is(cur, data, ";/"))
			/; if (!r)
				;tail_guard(csec)
			;/
			;add_strings(csec, ~(tnslc.COMMON_ASM{0}))
			;break
		;; else if (token_is(cur, data, "/;"))
			;bool ch = true
			/; loop (ch)
				;compile_block(cur, data, gsc, hsec, csec, dsec, mod_path)
				/; if (cur` !< len data`)
					;break
				;/
				;ch = token_is(cur, data, ";;")
			;/
		;; else if (string_equate(data`{cur`}.data`, ":"))
			;cur` = cur` + 2
			;Path inc = rel.rel_file(unquote_string(data`{cur`}.data`))
			;compile_include(inc, gsc, hsec, csec, dsec, mod_path)
			;cur`++
		;; else if (string_equate(data`{cur`}.data`, ";"))
			;ret = compile_statement(cur, data, ~tab, gsc, hsec, csec, dsec)
		;; else
			;tnsl.io.print("Failed to compile token [compile_block]: ")
			;data`{cur`}.print()
			;tnsl.io.println("")
			;break
		;/
	;/

	;csec`.append('\n')
;/

/; compile_include (Path file_path, ~VTrack global, ~{}uint8 hsec, csec, dsec, {}{}uint8 mod_path)
	# Autocomplete in the case of module syntax
	;bool d = file_path.extension_is("tnsl")
	/; if (!d)
		;file_path.dirs.append(file_path.file)
		;{}uint8 ftmp = file_path.file
		;{}uint8 tmp = ".tnsl"
		;add_strings(~ftmp, ~tmp)
		;file_path.file = ftmp
	;/

	;tnsl.io.print("[TNSLC:INCLUDE] ")
	;tnsl.io.println(file_path.full_path())

	;tnsl.io.File inc = file_path.open_r()
	;~{}Token data = parse.tokenize(inc)
	;inc.close()

	;tnsl.io.print(len data`)
	;tnsl.io.println(" tokens parsed.")
	
	;compile_file(file_path, data, global, hsec, csec, dsec, mod_path)
;/

/; compile_file (Path rel, ~{}Token data, ~VTrack global, ~{}uint8 hsec, csec, dsec, {}{}uint8 mod_path)
	
	;int j = len data`

	/; loop (int i = 0; i < j) [i++]
		/; if (string_equate(data`{i}.data`, "/;"))
			;compile_block(~i, data, global, hsec, csec, dsec, mod_path, rel)
		;; else if (string_equate(data`{i}.data`, ";"))
			;compile_global(~i, data, global, hsec, csec, dsec)
		;; else if (string_equate(data`{i}.data`, ":"))
			;i = i + 2
			;Path inc = rel.rel_file(unquote_string(data`{i}.data`))
			;compile_include(inc, global, hsec, csec, dsec, mod_path)
		;; else
			;break
		;/
	;/

;/

/; do_compile ({}uint8 file_out, Path rel)
	;{}uint8 hsec = ".global main\n"
	;{}uint8 csec = ".text\n"
	;{}uint8 dsec = ".data\n"
	
	;VTrack global_scope = {{}, {}}

	;tnslc.compile_include(rel, ~global_scope, ~hsec, ~csec, ~dsec, {})

	;tnsl.io.File out = tnsl.io.writeFile(file_out)
	
	/; loop (int i = 0; i < len hsec) [i++]
		;out.write(hsec{i})
	;/

	;out.write('\n')

	/; loop (int i = 0; i < len csec) [i++]
		;out.write(csec{i})
	;/

	;out.write('\n')

	/; loop (int i = 0; i < len dsec) [i++]
		;out.write(dsec{i})
	;/

	;out.write('\n')
	;out.close()
;/