This repository has been archived by the owner on Jun 9, 2018. It is now read-only.
/
luaaux.pir
1263 lines (1017 loc) · 23 KB
/
luaaux.pir
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
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright (C) 2005-2009, Parrot Foundation.
# $Id$
=head1 Lua Auxiliary PIR Library
=head2 Description
=head3 Functions
=over 4
=cut
.HLL 'lua'
.loadlib 'lua_group'
.namespace []
=item C<lua_argerror (narg, extramsg, ...)>
Raises an error with the following message, where C<func> is retrieved from
the call stack:
bad argument #<narg> to <func> (<extramsg>)
This function never returns.
CAUTION: don't used it in an exception handler, but lua_x_argerror & rethrow.
=cut
.sub 'lua_argerror'
.param int narg
.param pmc extramsg :slurpy
$S0 = lua_x_argerror(narg, extramsg :flat)
die $S0
.end
.sub 'lua_x_argerror'
.param int narg
.param pmc extramsg :slurpy
$S1 = narg
$S0 = caller()
.tailcall lua_x_error("bad argument #", $S1, " to '", $S0, "' (", extramsg :flat, ")")
.end
.sub 'caller' :anon
$P0 = getinterp
$I0 = 0
L1:
inc $I0
push_eh _handler
$P1 = $P0['sub'; $I0]
pop_eh
$P2 = $P1.'getfenv'()
unless $P2 goto L1
$S0 = $P1.'get_name'()
.return ($S0)
_handler:
.return ("?")
.end
=item C<lua_checkany (narg, arg)>
Checks whether the function has an argument of any type (including B<nil>)
at position C<narg>.
=cut
.sub 'lua_checkany'
.param int narg
.param pmc arg
unless null arg goto L1
lua_argerror(narg, "value expected")
L1:
.end
=item C<lua_checknumber (narg, arg)>
Checks whether the function argument C<narg> is a number
and returns this number.
=cut
.sub 'lua_checknumber'
.param int narg
.param pmc arg
$S0 = "no value"
if null arg goto L1
$S1 = typeof arg
if $S1 == 'Undef' goto L1
$S0 = $S1
$I0 = isa arg, 'LuaNumber'
unless $I0 goto L2
.return (arg)
L2:
$I0 = isa arg, 'LuaString'
unless $I0 goto L1
$P0 = arg.'tonumber'()
$I0 = isa $P0, 'LuaNumber'
unless $I0 goto L1
.return ($P0)
L1:
lua_typerror(narg, $S0, "number")
.end
=item C<lua_checkoption (narg, val, options)>
=cut
.sub 'lua_checkoption'
.param int narg
.param string name
.param string options
.local int i
i = 0
$P1 = split ' ', options
L1:
unless $P1 goto L2
$S0 = shift $P1
unless $S0 == name goto L3
.return (i)
L3:
inc i
goto L1
L2:
lua_argerror(narg, "invalid option '", name, "'")
.end
=item C<lua_checkstring (narg, arg)>
Checks whether the function argument C<narg> is a string
and returns this string.
This function uses C<tostring> to get its result,
so all conversions and caveats of that function apply here.
=cut
.sub 'lua_checkstring'
.param int narg
.param pmc arg
.local pmc val
$S0 = "no value"
if null arg goto L1
$S1 = typeof arg
if $S1 == 'Undef' goto L1
$S0 = $S1
$I0 = isa arg, 'LuaString'
unless $I0 goto L2
val = arg
.return (val)
L2:
$I0 = isa arg, 'LuaNumber'
unless $I0 goto L1
val = arg.'tostring'()
.return (val)
L1:
lua_typerror(narg, $S0, "string")
.end
=item C<lua_checktype (narg, arg, t)>
Checks whether the function argument C<narg> has type C<t>.
=cut
.sub 'lua_checktype'
.param int narg
.param pmc arg
.param string type
$S0 = "no value"
if null arg goto L1
$S0 = typeof arg
if $S0 != type goto L1
.return ()
L1:
lua_typerror(narg, $S0, type)
.end
=item C<lua_checkudata (narg, arg, tname)>
Checks whether the function argument C<narg> is a userdata of the type C<tname>.
=cut
.sub 'lua_checkudata'
.param int narg
.param pmc arg
.param string type
$S0 = "no value"
if null arg goto L1
$S0 = typeof arg
$I0 = isa arg, 'LuaUserdata'
unless $I0 goto L1
.local pmc _lua__REGISTRY
.local pmc key
_lua__REGISTRY = get_hll_global '_REGISTRY'
new key, 'LuaString'
set key, type
$P0 = _lua__REGISTRY[key]
$P1 = arg.'get_metatable'()
unless $P0 == $P1 goto L1
.local pmc val
val = getattribute arg, 'data'
.return (val)
L1:
lua_typerror(narg, $S0, type)
.end
=item C<lua_error (message, ...)>
Raises an error.
This function never returns.
CAUTION: don't used it in an exception handler, but lua_x_error & rethrow.
=cut
.sub 'lua_error'
.param pmc message :slurpy
$S0 = lua_x_error(message :flat)
die $S0
.end
.sub 'lua_x_error'
.param pmc message :slurpy
$S0 = join '', message
.return ($S0)
.end
=item C<lua_findtable (t, fname)>
=cut
.sub 'lua_findtable'
.param pmc t
.param string fname
new $P1, 'LuaString'
L1:
$I1 = index fname, '.'
$I2 = $I1
unless $I1 < 0 goto L2
$I2 = length fname
L2:
$S1 = substr fname, 0, $I2
set $P1, $S1
$P0 = t[$P1]
$I0 = isa $P0, 'LuaNil'
unless $I0 goto L3
new $P0, 'LuaTable'
t[$P1] = $P0
goto L4
L3:
$I0 = isa $P0, 'LuaTable'
unless $I0 goto L4
null $P0
.return ($P0, fname)
L4:
if $I1 < 0 goto L5
inc $I1
fname = substr fname, $I1
t = $P0
goto L1
L5:
.return ($P0)
.end
=item C<lua_gc (what, data)>
Controls the garbage collector.
This function performs several tasks, according to the value of the parameter
C<what>:
=over 4
=item B<"stop">
stops the garbage collector.
=item B<"restart">
restarts the garbage collector.
=item B<"collect">
performs a full garbage-collection cycle.
=item B<"count">
returns the total memory in use by Lua (in Kbytes).
=item B<"step">
performs an incremental step of garbage collection The step C<"size">
is controlled by C<data> (larger values mean more steps) in a non-specified way.
If you want to control the step size you must tune experimentally the value
of C<data>. Returns B<true> if the step finished a garbage-collection cycle.
=item B<"steppause">
sets C<data>/100 as the new value for the I<pause> of the collector.
The function returns the previous value of the pause.
=item B<"setstepmul">
sets C<data>/100 as the new value for the I<step multiplier> of the collector.
The function returns the previous value of the step multiplier.
=back
STILL INCOMPLETE.
=cut
.include 'interpinfo.pasm'
.sub 'lua_gc'
.param string what
.param int data :optional
.local num res
res = 0
L_stop:
unless what == 'stop' goto L_restart
sweepoff
collectoff
goto L_end
L_restart:
unless what == 'restart' goto L_collect
sweepon
collecton
goto L_end
L_collect:
unless what == 'collect' goto L_count
sweep 1
collect
goto L_end
L_count:
unless what == 'count' goto L_step
interpinfo $I0, .INTERPINFO_TOTAL_MEM_ALLOC
# GC values are expressed in Kbytes
res = $I0 / 1024
goto L_end
L_step:
unless what == 'step' goto L_setpause
goto L_end
L_setpause:
unless what == 'setpause' goto L_setstepmul
# not_implemented()
goto L_end
L_setstepmul:
unless what == 'setstepmul' goto L_default
goto L_end
L_default:
res = -1
L_end:
.return (res)
.end
=item C<lua_getfenv (o)>
Returns the environment table of the argument C<o>.
=cut
.sub 'lua_getfenv'
.param pmc o
.local pmc res
if null o goto L1
$I0 = can o, 'getfenv'
unless $I0 goto L1
res = o.'getfenv'()
.return (res)
L1:
new res, 'LuaNil'
.return (res)
.end
=item C<lua_getmetatable (tname)>
Returns the metatable registered with the name C<tname>.
=cut
.sub 'lua_getmetatable'
.param string tname
.local pmc _lua__REGISTRY
_lua__REGISTRY = get_hll_global '_REGISTRY'
.local pmc key
new key, 'LuaString'
set key, tname
.local pmc res
res= _lua__REGISTRY[key]
.return (res)
.end
=item C<lua_gsub (src, pat, repl)>
Returns a copy of string C<src> by replacing any occurrence of the string C<pat>
with the string C<rep>.
=cut
.sub 'lua_gsub'
.param string src
.param string pat
.param string repl
$I2 = length pat
.local string b
b = ''
L1:
$I0 = index src, pat
if $I0 < 0 goto L2
$S0 = substr src, 0, $I0
b .= $S0
b .= repl
$I0 += $I2
src = substr src, $I0
goto L1
L2:
b .= src
.return (b)
.end
=item C<lua_isboolean (val)>
Returns 1 if the value has type boolean, and 0 otherwise.
=cut
.sub 'lua_isboolean'
.param pmc val
.local int res
res = 0
if null val goto L1
res = isa val, 'LuaBoolean'
L1:
new $P0, 'LuaBoolean'
set $P0, res
.return ($P0)
.end
=item C<lua_isfunction (val)>
Returns 1 if the value is a function, and 0 otherwise.
=cut
.sub 'lua_isfunction'
.param pmc val
.local int res
res = 0
if null val goto L1
res = isa val, 'LuaFunction'
L1:
new $P0, 'LuaBoolean'
set $P0, res
.return ($P0)
.end
=item C<lua_isnil (val)>
Returns 1 if the value is nil, and 0 otherwise.
=cut
.sub 'lua_isnil'
.param pmc val
.local int res
res = 0
if null val goto L1
res = isa val, 'LuaNil'
L1:
new $P0, 'LuaBoolean'
set $P0, res
.return ($P0)
.end
=item C<lua_isnumber (val)>
Returns 1 if the value is a number or a string convertible to a number,
and 0 otherwise.
=cut
.sub 'lua_isnumber'
.param pmc val
.local int res
res = 0
if null val goto L1
res = isa val, 'LuaNumber'
if res goto L1
$P0 = val.'tonumber'()
res = isa $P0, 'LuaNumber'
L1:
new $P0, 'LuaBoolean'
set $P0, res
.return ($P0)
.end
=item C<lua_isstring (val)>
Returns 1 if the value is a string or a number (which is always convertible
to a string), and 0 otherwise.
=cut
.sub 'lua_isstring'
.param pmc val
.local int res
res = 0
if null val goto L1
res = isa val, 'LuaString'
if res goto L1
res = isa val, 'LuaNumber'
L1:
new $P0, 'LuaBoolean'
set $P0, res
.return ($P0)
.end
=item C<lua_istable (val)>
Returns 1 if the value is a table, and 0 otherwise.
=cut
.sub 'lua_istable'
.param pmc val
.local int res
res = 0
if null val goto L1
res = isa val, 'LuaTable'
L1:
new $P0, 'LuaBoolean'
set $P0, res
.return ($P0)
.end
=item C<lua_isuserdata (val)>
Returns 1 if the value is a userdata, and 0 otherwise.
=cut
.sub 'lua_isuserdata'
.param pmc val
.local int res
res = 0
if null val goto L1
res = isa val, 'LuaUserdata'
L1:
new $P0, 'LuaBoolean'
set $P0, res
.return ($P0)
.end
=item C<lua_load (data, name)>
This function only loads a chunk; it does not run it.
C<lua_load> automatically detects whether the chunk is text or binary,
and loads it accordingly.
The C<chunkname> argument gives a name to the chunk, which is used for error
messages and in debug information.
=cut
.sub 'lua_load'
.param string data
.param string chunkname
unless chunkname == '' goto L1
chunkname = '?'
L1:
$S0 = substr data, 0, 4
unless $S0 == "\033Lua" goto L2
.tailcall undump(data, chunkname)
L2:
.tailcall parser(data, chunkname)
.end
.sub 'parser' :anon
.param string data
.param string chunkname
$P0 = box chunkname
.lex '$?FILES', $P0
.local pmc lua_comp
lua_comp = compreg 'lua'
push_eh _handler
$P0 = lua_comp.'compile'(data)
$P0 = $P0[2] # 0=&start, 1=&on_require, 2=&main
.local pmc env
env = get_hll_global '_G'
$P0.'setfenv'(env)
pop_eh
.return ($P0)
_handler:
.get_results ($P0)
$S0 = $P0
null $P0
.return ($P0, $S0)
.end
.sub 'undump' :anon
.param string buff
.param string chunkname
push_eh _handler
new $P0, 'LuaBytecode'
$P1 = $P0.'undump'(buff)
.local string pir
pir = $P1.'translate'()
.local pmc pir_comp
pir_comp = compreg 'PIR'
$P0 = pir_comp(pir)
$P0 = $P0[1]
.local pmc env
env = get_hll_global '_G'
$P0.'setfenv'(env)
pop_eh
.return ($P0)
_handler:
.get_results ($P0)
$S0 = $P0
null $P0
.return ($P0, $S0)
.end
=item C<lua_loadbuffer (buff, name)>
Loads a buffer as a Lua chunk.
C<name> is the chunk name, used for debug information and error messages.
=cut
.sub 'lua_loadbuffer'
.param string buff
.param string chunkname
.tailcall lua_load(buff, chunkname)
.end
=item C<lua_loadfile (filename)>
Loads a file as a Lua chunk.
If C<filename> is a empty string, then it loads from the standard input.
The first line in the file is ignored if it starts with a #.
This function only loads the chunk; it does not run it.
=cut
.include 'stat.pasm'
.sub 'lua_loadfile'
.param string filename
.param string modname :optional
.param int has_modname :opt_flag
.local string chunkname
.local pmc f
unless filename == '' goto L1
chunkname = '=stdin'
f = getstdin
goto L2
L1:
chunkname = filename
unless has_modname goto L3
.local string pbcname
$I0 = index filename, '.lua'
pbcname = substr filename, 0, $I0
pbcname .= '.pbc'
$I0 = stat pbcname, .STAT_EXISTS
unless $I0 goto L3
$P0 = loadlib 'os'
new $P0, 'OS'
$S0 = $P0.'cwd'()
$S0 .= '/'
pbcname = $S0 . pbcname
load_bytecode pbcname
.local string funcname
funcname = mkfuncname(modname)
($P0, $S0) = loadfunc(pbcname, funcname)
if null $P0 goto L5
.return ($P0)
L5:
$S0 = 'lua.library.' . modname
funcname = mkfuncname($S0)
($P0, $S0) = loadfunc(pbcname, funcname)
if null $P0 goto L3
.return ($P0)
L3:
f = new 'FileHandle'
push_eh _handler
f.'open'(filename, 'r')
pop_eh
L2:
$S0 = f.'readall'()
if filename == '' goto L4
f.'close'()
L4:
.tailcall lua_load($S0, chunkname)
_handler:
$S0 = 'cannot open '
$S0 .= filename
$S0 .= ': '
$S1 = err
$S0 .= $S1
null $P0
.return ($P0, $S0)
.end
=item C<lua_newmetatable (tname)>
Unless the registry already has the key C<tname>, creates a new table to be
used as a metatable for userdata, adds it to the registry with key C<tname>.
In both cases returns the final value associated with C<tname> in the registry.
=cut
.sub 'lua_newmetatable'
.param string tname
.local pmc _lua__REGISTRY
.local pmc res
_lua__REGISTRY = get_hll_global '_REGISTRY'
new $P1, 'LuaString'
set $P1, tname
res = _lua__REGISTRY[$P1]
$I0 = isa res, 'LuaNil'
unless $I0 goto L1
new res, 'LuaTable'
_lua__REGISTRY[$P1] = res
L1:
.return (res)
.end
=item C<lua_newuserdata (data, mt)>
=cut
.sub 'lua_newuserdata'
.param pmc data
.param pmc mt
.local pmc res
new res, 'LuaUserdata'
setattribute res, 'data', data
res.'set_metatable'(mt)
.return (res)
.end
=item C<lua_openlibs ()>
Opens all standard Lua libraries.
=cut
.sub 'lua_openlibs'
$P0 = get_hll_global ['basic'], 'luaopen_basic'
$P0()
$P0 = get_hll_global ['coroutine'], 'luaopen_coroutine'
$P0()
$P0 = get_hll_global ['package'], 'luaopen_package'
$P0()
$P0 = get_hll_global ['table'], 'luaopen_table'
$P0()
$P0 = get_hll_global ['io'], 'luaopen_io'
$P0()
$P0 = get_hll_global ['os'], 'luaopen_os'
$P0()
$P0 = get_hll_global ['string'], 'luaopen_string'
$P0()
$P0 = get_hll_global ['math'], 'luaopen_math'
$P0()
$P0 = get_hll_global ['debug'], 'luaopen_debug'
$P0()
sweepon
sweep 1
.end
=item C<lua_optint (narg, arg, def)>
If the function argument C<narg> is a number, returns this number cast to an C<int>.
If this argument is absent or is B<nil>, returns C<def>. Otherwise, raises an error.
=cut
.sub 'lua_optint'
.param int narg
.param pmc arg
.param int default
if null arg goto L1
unless arg goto L1
$I1 = lua_checknumber(narg, arg)
.return ($I1)
L1:
.return (default)
.end
=item C<lua_optnumber (narg, arg, def)>
If the function argument C<narg> is a number, returns this number.
If this argument is absent or is B<nil>, returns C<def>. Otherwise, raises an error.
=cut
.sub 'lua_optnumber'
.param int narg
.param pmc arg
.param num default
if null arg goto L1
unless arg goto L1
.tailcall lua_checknumber(narg, arg)
L1:
.return (default)
.end
=item C<lua_optstring (narg, arg, def)>
If the function argument C<narg> is a string, returns this string.
If this argument is absent or is B<nil>, returns C<def>. Otherwise, raises an error.
=cut
.sub 'lua_optstring'
.param int narg
.param pmc arg
.param string default :optional
if null arg goto L1
unless arg goto L1
$S0 = arg
.return ($S0)
L1:
.return (default)
.end
=item C<lua_register (libname, lib, names, env)>
=cut
.sub 'lua_register'
.param pmc libname
.param pmc lib
.param pmc names
.param pmc env :optional
if null libname goto L1
.local pmc _loaded
_loaded = box '_LOADED'
.local pmc _lua__REGISTRY
_lua__REGISTRY = get_hll_global '_REGISTRY'
$P0 = _lua__REGISTRY[_loaded]
$P0[libname] = lib
L1:
unless null env goto L2
env = get_hll_global '_G'
L2:
.local pmc interp, ns
interp = getinterp
ns = interp['namespace'; 1]
new $P1, 'LuaString'
L3:
unless names goto L4
$S0 = shift names
unless $S0 goto L3
$P0 = ns[$S0]
unless null $P0 goto L5
lua_error("missing method ", $S0)
L5:
$P0.'setfenv'(env)
set $P1, $S0
lib[$P1] = $P0
goto L3
L4:
.end
=item C<lua_setfenv (o, table)>
Sets the table C<table> as the new environment for the value C<o>.
If the value C<o> is neither a function nor a thread nor a userdata,
returns 0. Otherwise it returns 1.
=cut
.sub 'lua_setfenv'
.param pmc o
.param pmc table
if null o goto L1
$I0 = can o, 'setfenv'
unless $I0 goto L1
o.'setfenv'(table)
.return (1)
L1:
.return (0)
.end
=item C<lua_typerror (narg, got, expec)>
Generates an error with a message like the following:
bad argument narg to 'func' (tname expected, got rt)
This function never returns.
=cut
.sub 'lua_typerror'
.param int narg
.param string got
.param string expec
lua_argerror(narg, expec, " expected, got ", got)
.end
=back
=head3 Others functions
=over 4
=item C<argstolua (env, args)>
=cut
.sub 'argstolua'
.param pmc env
.param pmc args
.local pmc res
new res, 'FixedPMCArray'
if null args goto L1
$I1 = args
set res, $I1
$I0 = 0
L2:
unless $I0 < $I1 goto L1
$S0 = shift args
new $P0, 'LuaString'
set $P0, $S0
res[$I0] = $P0
inc $I0
goto L2
L1:
if null args goto L3
# not interactive mode
.local pmc it, i
it = iter res
new i, 'LuaNumber'
set i, 0
new $P0, 'LuaTable'
L4:
unless it goto L5
$P1 = shift it
$P0[i] = $P1
inc i
goto L4
L5:
.local pmc k_arg
k_arg = box 'arg'
env.'rawset'(k_arg, $P0)
L3:
.return (res)
.end
=item C<checkforloop (start, limit, step)>
=cut
.sub 'checkforloop'
.param pmc start
.param pmc limit