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
|
/* --------------------------------------------------------------------------
* Code generator
*
* The Hugs 98 system is Copyright (c) Mark P Jones, Alastair Reid, the
* Yale Haskell Group, and the Oregon Graduate Institute of Science and
* Technology, 1994-1999, All rights reserved. It is distributed as
* free software under the license in the file "License", which is
* included in the distribution.
*
* $RCSfile: codegen.c,v $
* $Revision: 1.16 $
* $Date: 2000/02/08 15:32:29 $
* ------------------------------------------------------------------------*/
#include "prelude.h"
#include "storage.h"
#include "backend.h"
#include "connect.h"
#include "errors.h"
#include "Assembler.h"
#include "link.h"
#include "Rts.h" /* IF_DEBUG */
#include "RtsFlags.h"
/* --------------------------------------------------------------------------
* Local function prototypes:
* ------------------------------------------------------------------------*/
#define getPos(v) intOf(stgVarInfo(v))
#define setPos(v,sp) stgVarInfo(v) = mkInt(sp)
#define getObj(v) ptrOf(stgVarInfo(v))
#define setObj(v,obj) stgVarInfo(v) = mkPtr(obj)
#define repOf(x) charOf(stgVarRep(x))
static void cgBind ( AsmBCO bco, StgVar v );
static Void pushVar ( AsmBCO bco, StgVar v );
static Void pushAtom ( AsmBCO bco, StgAtom atom );
static Void alloc ( AsmBCO bco, StgRhs rhs );
static Void build ( AsmBCO bco, StgRhs rhs );
static Void cgExpr ( AsmBCO bco, AsmSp root, StgExpr e );
static AsmBCO cgAlts ( AsmSp root, AsmSp sp, List alts );
static void testPrimPats ( AsmBCO bco, AsmSp root, List pats, StgExpr e );
//static void cgPrimAlt ( AsmBCO bco, AsmSp root, List vs, StgExpr e );
static AsmBCO cgLambda ( StgExpr e );
static AsmBCO cgRhs ( StgRhs rhs );
static void beginTop ( StgVar v );
static void endTop ( StgVar v );
static StgVar currentTop;
/* --------------------------------------------------------------------------
*
* ------------------------------------------------------------------------*/
static Cell cptrFromName ( Name n )
{
char buf[1000];
void* p;
Module m = name(n).mod;
Text mt = module(m).text;
sprintf(buf,"%s_%s_closure",
textToStr(mt),
textToStr( enZcodeThenFindText ( textToStr (name(n).text) ) ) );
p = lookupOTabName ( m, buf );
if (!p) {
ERRMSG(0) "Can't find object symbol %s", buf
EEND;
}
return mkCPtr(p);
}
static Bool varHasClosure( StgVar v )
{
return asmObjectHasClosure((AsmClosure*)ptrOf(stgVarInfo(v)));
}
/* should be AsmClosure* */
void* closureOfVar( StgVar v )
{
return asmClosureOfObject((AsmClosure*)ptrOf(stgVarInfo(v)));
}
char* lookupHugsName( void* closure )
{
extern Name nameHw;
Name nm;
for( nm=NAMEMIN; nm<nameHw; ++nm ) {
StgVar v = name(nm).stgVar;
if (isStgVar(v)
&& isPtr(stgVarInfo(v))
&& varHasClosure(v)
&& closureOfVar(v) == closure) {
return textToStr(name(nm).text);
}
}
return 0;
}
/* called at the start of GC */
void markHugsObjects( void )
{
extern Name nameHw;
Name nm;
for( nm=NAMEMIN; nm<nameHw; ++nm ) {
StgVar v = name(nm).stgVar;
if (isStgVar(v) && isPtr(stgVarInfo(v))) {
asmMarkObject((AsmClosure*)ptrOf(stgVarInfo(v)));
}
}
}
static void cgBindRep( AsmBCO bco, StgVar v, AsmRep rep )
{
setPos(v,asmBind(bco,rep));
}
static void cgBind( AsmBCO bco, StgVar v )
{
cgBindRep(bco,v,repOf(v));
}
static Void pushVar( AsmBCO bco, StgVar v )
{
Cell info;
#if 0
printf ( "pushVar: %d ", v ); fflush(stdout);
print(v,10);printf("\n");
#endif
assert(isStgVar(v) || isCPtr(v));
if (isCPtr(v)) {
asmGHCClosure(bco, cptrOf(v));
} else {
info = stgVarInfo(v);
if (isPtr(info)) {
asmClosure(bco,ptrOf(info));
} else if (isInt(info)) {
asmVar(bco,intOf(info),repOf(v));
} else {
internal("pushVar");
}
}
}
static Void pushAtom( AsmBCO bco, StgAtom e )
{
#if 0
printf ( "pushAtom: %d ", e ); fflush(stdout);
print(e,10);printf("\n");
#endif
switch (whatIs(e)) {
case STGVAR:
pushVar(bco,e);
break;
case NAME:
if (nonNull(name(e).stgVar)) {
pushVar(bco,name(e).stgVar);
} else {
Cell /*CPtr*/ addr = cptrFromName(e);
fprintf ( stderr, "nativeAtom: name %s\n",
nameFromOPtr(cptrOf(addr)) );
pushVar(bco,addr);
}
break;
case CHARCELL:
asmConstChar(bco,charOf(e));
break;
case INTCELL:
asmConstInt(bco,intOf(e));
break;
case BIGCELL:
asmConstInteger(bco,bignumToString(e));
break;
case FLOATCELL:
asmConstDouble(bco,floatOf(e));
break;
case STRCELL:
#if USE_ADDR_FOR_STRINGS
asmConstAddr(bco,textToStr(textOf(e)));
#else
asmClosure(bco,asmStringObj(textToStr(textOf(e))));
#endif
break;
case CPTRCELL:
asmGHCClosure(bco,cptrOf(e));
break;
case PTRCELL:
asmConstAddr(bco,ptrOf(e));
break;
default:
fprintf(stderr,"\nYoiks1: "); printExp(stderr,e);
internal("pushAtom");
}
}
static AsmBCO cgAlts( AsmSp root, AsmSp sp, List alts )
{
#ifdef CRUDE_PROFILING
AsmBCO bco = asmBeginContinuation(sp, currentTop + 1000000000);
#else
AsmBCO bco = asmBeginContinuation(sp, alts);
#endif
Bool omit_test
= length(alts) == 2 &&
isDefaultAlt(hd(tl(alts))) &&
!isDefaultAlt(hd(alts));
if (omit_test) {
/* refine the condition */
Name con;
Tycon t;
omit_test = FALSE;
con = stgCaseAltCon(hd(alts));
/* special case: dictionary constructors */
if (strncmp(":D",textToStr(name(con).text),2)==0) {
omit_test = TRUE;
goto xyzzy;
}
/* special case: Tuples */
if (isTuple(con) || (isName(con) && con==nameUnit)) {
omit_test = TRUE;
goto xyzzy;
}
t = name(con).parent;
if (tycon(t).what == DATATYPE) {
if (length(tycon(t).defn) == 1) omit_test = TRUE;
}
}
xyzzy:
for(; nonNull(alts); alts=tl(alts)) {
StgCaseAlt alt = hd(alts);
if (isDefaultAlt(alt)) {
cgBind(bco,stgDefaultVar(alt));
cgExpr(bco,root,stgDefaultBody(alt));
asmEndContinuation(bco);
return bco; /* ignore any further alternatives */
} else {
StgDiscr con = stgCaseAltCon(alt);
List vs = stgCaseAltVars(alt);
AsmSp begin = asmBeginAlt(bco);
AsmPc fix;
if (omit_test) fix=-1; else fix = asmTest(bco,stgDiscrTag(con));
asmBind(bco,PTR_REP); /* Adjust simulated sp to acct for return value */
if (isBoxingCon(con)) {
setPos(hd(vs),asmUnbox(bco,boxingConRep(con)));
} else {
asmBeginUnpack(bco);
map1Proc(cgBind,bco,reverse(vs));
asmEndUnpack(bco);
}
cgExpr(bco,root,stgCaseAltBody(alt));
asmEndAlt(bco,begin);
if (fix != -1) asmFixBranch(bco,fix);
}
}
/* if we got this far and didn't match, panic! */
asmPanic(bco);
asmEndContinuation(bco);
return bco;
}
static void testPrimPats( AsmBCO bco, AsmSp root, List pats, StgExpr e )
{
if (isNull(pats)) {
cgExpr(bco,root,e);
} else {
StgVar pat = hd(pats);
if (isInt(stgVarBody(pat))) {
/* asmTestInt leaves stack unchanged - so no need to adjust it */
AsmPc tst = asmTestInt(bco,getPos(pat),intOf(stgVarBody(pat)));
assert(repOf(pat) == INT_REP);
testPrimPats(bco,root,tl(pats),e);
asmFixBranch(bco,tst);
} else {
testPrimPats(bco,root,tl(pats),e);
}
}
}
#if 0 /* appears to be unused */
static void cgPrimAlt( AsmBCO bco, AsmSp root, List vs, StgExpr e )
{
assert(0); /* ToDo: test for patterns */
map1Proc(cgBind,bco,vs); /* ToDo: are these in right order? */
cgExpr(bco,root,e);
}
#endif
static AsmBCO cgLambda( StgExpr e )
{
AsmBCO bco = asmBeginBCO(e);
AsmSp root = asmBeginArgCheck(bco);
map1Proc(cgBind,bco,reverse(stgLambdaArgs(e)));
asmEndArgCheck(bco,root);
/* ppStgExpr(e); */
cgExpr(bco,root,stgLambdaBody(e));
asmEndBCO(bco);
return bco;
}
static AsmBCO cgRhs( StgRhs rhs )
{
AsmBCO bco = asmBeginBCO(rhs );
AsmSp root = asmBeginArgCheck(bco);
asmEndArgCheck(bco,root);
/* ppStgExpr(rhs); */
cgExpr(bco,root,rhs);
asmEndBCO(bco);
return bco;
}
static Void cgExpr( AsmBCO bco, AsmSp root, StgExpr e )
{
#if 0
printf("cgExpr:");ppStgExpr(e);printf("\n");
#endif
switch (whatIs(e)) {
case LETREC:
{
List binds = stgLetBinds(e);
map1Proc(alloc,bco,binds);
map1Proc(build,bco,binds);
cgExpr(bco,root,stgLetBody(e));
break;
}
case LAMBDA:
{
AsmSp begin = asmBeginEnter(bco);
asmClosure(bco,cgLambda(e));
asmEndEnter(bco,begin,root);
break;
}
case CASE:
{
List alts = stgCaseAlts(e);
AsmSp sp = asmBeginCase(bco);
AsmSp caseroot = asmContinuation(bco,cgAlts(root,sp,alts));
cgExpr(bco,caseroot,stgCaseScrut(e));
asmEndCase(bco);
break;
}
case PRIMCASE:
{
StgExpr scrut = stgPrimCaseScrut(e);
List alts = stgPrimCaseAlts(e);
if (whatIs(scrut) == STGPRIM) { /* this is an optimisation */
/* No need to use return address or to Slide */
AsmSp beginPrim = asmBeginPrim(bco);
map1Proc(pushAtom,bco,reverse(stgPrimArgs(scrut)));
asmEndPrim(bco,(AsmPrim*)name(stgPrimOp(scrut)).primop,beginPrim);
for(; nonNull(alts); alts=tl(alts)) {
StgPrimAlt alt = hd(alts);
List pats = stgPrimAltVars(alt);
StgExpr body = stgPrimAltBody(alt);
AsmSp altBegin = asmBeginAlt(bco);
map1Proc(cgBind,bco,reverse(pats));
testPrimPats(bco,root,pats,body);
asmEndAlt(bco,altBegin);
}
/* if we got this far and didn't match, panic! */
asmPanic(bco);
} else if (whatIs(scrut) == STGVAR) { /* another optimisation */
/* No need to use return address or to Slide */
/* only part different from primop code... todo */
AsmSp beginCase = asmBeginCase(bco);
pushVar(bco,scrut);
asmEndAlt(bco,beginCase); /* hack, hack - */
for(; nonNull(alts); alts=tl(alts)) {
StgPrimAlt alt = hd(alts);
List pats = stgPrimAltVars(alt);
StgExpr body = stgPrimAltBody(alt);
AsmSp altBegin = asmBeginAlt(bco);
map1Proc(cgBind,bco,pats);
testPrimPats(bco,root,pats,body);
asmEndAlt(bco,altBegin);
}
/* if we got this far and didn't match, panic! */
asmPanic(bco);
} else {
/* ToDo: implement this code... */
assert(0);
/* asmPushRet(bco,delayPrimAlt( stgPrimCaseVars(e),
stgPrimCaseBody(e))); */
/* cgExpr( bco,root,scrut ); */
}
break;
}
case STGAPP: /* Tail call */
{
AsmSp env = asmBeginEnter(bco);
map1Proc(pushAtom,bco,reverse(stgAppArgs(e)));
pushAtom(bco,stgAppFun(e));
asmEndEnter(bco,env,root);
break;
}
case NAME: /* Tail call (with no args) */
{
AsmSp env = asmBeginEnter(bco);
/* JRS 000112: next line used to be: pushVar(bco,name(e).stgVar); */
pushAtom(bco,e);
asmEndEnter(bco,env,root);
break;
}
case STGVAR: /* Tail call (with no args), plus unboxed return */
switch (repOf(e)) {
case PTR_REP:
case ALPHA_REP:
case BETA_REP:
{
AsmSp env = asmBeginEnter(bco);
pushVar(bco,e);
asmEndEnter(bco,env,root);
break;
}
case INT_REP:
assert(0);
/* cgTailCall(bco,singleton(e)); */
/* asmReturnInt(bco); */
break;
default:
internal("cgExpr StgVar");
}
break;
case STGPRIM: /* Tail call again */
{
AsmSp beginPrim = asmBeginPrim(bco);
map1Proc(pushAtom,bco,reverse(stgPrimArgs(e)));
asmEndPrim(bco,(AsmPrim*)name(e).primop,beginPrim);
/* map1Proc(cgBind,bco,rs_vars); */
assert(0); /* asmReturn_retty(); */
break;
}
default:
fprintf(stderr,"\nYoiks2: "); printExp(stderr,e);
internal("cgExpr");
}
}
#define M_ITBLNAMES 35000
void* itblNames[M_ITBLNAMES];
int nItblNames = 0;
/* allocate space for top level variable
* any change requires a corresponding change in 'build'.
*/
static Void alloc( AsmBCO bco, StgVar v )
{
StgRhs rhs = stgVarBody(v);
assert(isStgVar(v));
#if 0
printf("alloc: ");ppStgExpr(v);
#endif
switch (whatIs(rhs)) {
case STGCON:
{
StgDiscr con = stgConCon(rhs);
List args = stgConArgs(rhs);
if (isBoxingCon(con)) {
pushAtom(bco,hd(args));
setPos(v,asmBox(bco,boxingConRep(con)));
} else {
void* vv = stgConInfo(con);
if (!(nItblNames < (M_ITBLNAMES-2)))
internal("alloc -- M_ITBLNAMES too small");
if (isName(con)) {
itblNames[nItblNames++] = vv;
itblNames[nItblNames++] = textToStr(name(con).text);
} else
if (isTuple(con)) {
itblNames[nItblNames++] = vv;
itblNames[nItblNames++] = textToStr(ghcTupleText(con));
} else
assert ( /* cant identify constructor name */ 0 );
setPos(v,asmAllocCONSTR(bco, vv));
}
break;
}
case STGAPP: {
Int totSizeW = 0;
List bs = stgAppArgs(rhs);
for (; nonNull(bs); bs=tl(bs)) {
if (isName(hd(bs))) {
totSizeW += 1;
} else {
ASSERT(whatIs(hd(bs))==STGVAR);
totSizeW += asmRepSizeW( charOf(stgVarRep(hd(bs))) );
}
}
setPos(v,asmAllocAP(bco,totSizeW));
//ORIGINALLY:setPos(v,asmAllocAP(bco,length(stgAppArgs(rhs))));
break;
}
case LAMBDA: /* optimisation */
setObj(v,cgLambda(rhs));
break;
default:
setPos(v,asmAllocAP(bco,0));
break;
}
}
static Void build( AsmBCO bco, StgVar v )
{
StgRhs rhs = stgVarBody(v);
assert(isStgVar(v));
//ppStg(v);
switch (whatIs(rhs)) {
case STGCON:
{
StgDiscr con = stgConCon(rhs);
List args = stgConArgs(rhs);
if (isBoxingCon(con)) {
doNothing(); /* already done in alloc */
} else {
AsmSp start = asmBeginPack(bco);
map1Proc(pushAtom,bco,reverse(args));
asmEndPack(bco,getPos(v),start,stgConInfo(con));
}
return;
}
case STGAPP:
{
Bool itsaPAP;
StgVar fun = stgAppFun(rhs);
StgVar fun0 = fun;
List args = stgAppArgs(rhs);
if (isName(fun)) {
if (nonNull(name(fun).stgVar))
fun = name(fun).stgVar; else
fun = cptrFromName(fun);
}
if (isCPtr(fun)) {
assert(isName(fun0));
itsaPAP = name(fun0).arity > length(args);
fprintf ( stderr, "nativeCall: name %s, arity %d, args %d\n",
nameFromOPtr(cptrOf(fun)), name(fun0).arity, length(args) );
} else {
itsaPAP = FALSE;
if (nonNull(stgVarBody(fun))
&& whatIs(stgVarBody(fun)) == LAMBDA
&& length(stgLambdaArgs(stgVarBody(fun))) > length(args)
)
itsaPAP = TRUE;
}
if (itsaPAP) {
AsmSp start = asmBeginMkPAP(bco);
map1Proc(pushAtom,bco,reverse(args));
pushAtom(bco,fun);
asmEndMkPAP(bco,getPos(v),start); /* optimisation */
} else {
AsmSp start = asmBeginMkAP(bco);
map1Proc(pushAtom,bco,reverse(args));
pushAtom(bco,fun);
asmEndMkAP(bco,getPos(v),start);
}
return;
}
case LAMBDA: /* optimisation */
doNothing(); /* already pushed in alloc */
break;
/* These two cases look almost identical to the default but they're really
* special cases of STGAPP. The essential thing here is that we can't call
* cgRhs(rhs) because that expects the rhs to have no free variables when,
* in fact, the rhs is _always_ a free variable.
*
* ToDo: a simple optimiser would eliminate all examples
* of this except "let x = x in ..."
*/
case NAME:
if (nonNull(name(rhs).stgVar))
rhs = name(rhs).stgVar; else
rhs = cptrFromName(rhs);
/* fall thru */
case STGVAR:
{
AsmSp start = asmBeginMkAP(bco);
pushAtom(bco,rhs);
asmEndMkAP(bco,getPos(v),start);
}
return;
default:
{
AsmSp start = asmBeginMkAP(bco); /* make it updateable! */
asmClosure(bco,cgRhs(rhs));
asmEndMkAP(bco,getPos(v),start);
return;
}
}
}
/* --------------------------------------------------------------------------
* Top level variables
*
* ToDo: these should be handled by allocating a dynamic unentered CAF
* for each top level variable - this should be simpler!
* ------------------------------------------------------------------------*/
#if 0 /* appears to be unused */
static void cgAddVar( AsmObject obj, StgAtom v )
{
if (isName(v)) {
v = name(v).stgVar;
}
assert(isStgVar(v));
asmAddPtr(obj,getObj(v));
}
#endif
/* allocate AsmObject for top level variables
* any change requires a corresponding change in endTop
*/
static void beginTop( StgVar v )
{
StgRhs rhs;
assert(isStgVar(v));
currentTop = v;
rhs = stgVarBody(v);
switch (whatIs(rhs)) {
case STGCON:
{
//List as = stgConArgs(rhs);
setObj(v,asmBeginCon(stgConInfo(stgConCon(rhs))));
break;
}
case LAMBDA:
#ifdef CRUDE_PROFILING
setObj(v,asmBeginBCO(currentTop));
#else
setObj(v,asmBeginBCO(rhs));
#endif
break;
default:
setObj(v,asmBeginCAF());
break;
}
}
static void endTop( StgVar v )
{
StgRhs rhs = stgVarBody(v);
currentTop = v;
switch (whatIs(rhs)) {
case STGCON:
{
List as = stgConArgs(rhs);
AsmCon con = (AsmCon)getObj(v);
for( ; nonNull(as); as=tl(as)) {
StgAtom a = hd(as);
switch (whatIs(a)) {
case STGVAR:
/* should be a delayed combinator! */
asmAddPtr(con,(AsmObject)getObj(a));
break;
case NAME:
{
StgVar var = name(a).stgVar;
assert(var);
asmAddPtr(con,(AsmObject)getObj(a));
break;
}
#if !USE_ADDR_FOR_STRINGS
case STRCELL:
asmAddPtr(con,asmStringObj(textToStr(textOf(a))));
break;
#endif
default:
/* asmAddPtr(con,??); */
assert(0);
break;
}
}
asmEndCon(con);
break;
}
case LAMBDA: /* optimisation */
{
/* ToDo: merge this code with cgLambda */
AsmBCO bco = (AsmBCO)getObj(v);
AsmSp root = asmBeginArgCheck(bco);
map1Proc(cgBind,bco,reverse(stgLambdaArgs(rhs)));
asmEndArgCheck(bco,root);
cgExpr(bco,root,stgLambdaBody(rhs));
asmEndBCO(bco);
break;
}
default: /* updateable caf */
{
AsmCAF caf = (AsmCAF)getObj(v);
asmEndCAF(caf,cgRhs(rhs));
break;
}
}
}
static void zap( StgVar v )
{
// ToDo: reinstate
// stgVarBody(v) = NIL;
}
/* external entry point */
Void cgBinds( List binds )
{
List b;
int i;
#if 0
if (lastModule() != modulePrelude) {
printf("\n\ncgBinds: before ll\n\n" );
for (b=binds; nonNull(b); b=tl(b)) {
printStg ( stdout, hd(b) ); printf("\n\n");
}
}
#endif
binds = liftBinds(binds);
#if 0
if (lastModule() != modulePrelude) {
printf("\n\ncgBinds: after ll\n\n" );
for (b=binds; nonNull(b); b=tl(b)) {
printStg ( stdout, hd(b) ); printf("\n\n");
}
}
#endif
for (b=binds,i=0; nonNull(b); b=tl(b),i++) {
beginTop(hd(b));
}
for (b=binds,i=0; nonNull(b); b=tl(b),i++) {
//printStg( stdout, hd(b) ); printf( "\n\n");
endTop(hd(b));
}
//mapProc(zap,binds);
}
/* --------------------------------------------------------------------------
* Code Generator control:
* ------------------------------------------------------------------------*/
Void codegen(what)
Int what; {
switch (what) {
case PREPREL:
case RESET:
case MARK:
case POSTPREL:
break;
}
liftControl(what);
}
/*-------------------------------------------------------------------------*/
|