Skip to content

Commit 76d7430

Browse files
ty_findの抜けを修正
1 parent 2ed0ebd commit 76d7430

3 files changed

Lines changed: 13 additions & 6 deletions

File tree

lib/closure.ml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ module KNorm = struct
135135
| (u, f) :: t -> destruct_uandf t (u::ru) (fun x -> rf (f x))
136136
| [] -> ru, rf
137137
in let us, f = destruct_uandf (List.rev uandf) [] (fun x -> x) in
138-
f (Cls.AppTy (x, List.length @@ Environment.find x args, List.length tvs, us))
138+
let (zs, outer_tvs_len) = Environment.find x args in
139+
f (Cls.AppTy (x, List.length zs, outer_tvs_len, us))
139140
| CastExp (x, u1, u2, (r, p)) ->
140141
let u1, udeclfun1 = ty_tv tvs u1 in
141142
let u2, udeclfun2 = ty_tv tvs u2 in
@@ -180,7 +181,7 @@ module KNorm = struct
180181
(* let zts = List.map (fun z -> (z, Environment.find z tyenv')) zs in *)
181182
let fundef = Cls.FundefD { name = Cls.to_label x; tvs = (new_tvs, List.length tvs'); arg = (y, z); formal_fv = zs; body = f1' } in
182183
if not @@ List.mem fundef !toplevel then toplevel := fundef :: !toplevel;
183-
let f2' = toCls_exp known' tvs (Environment.add x zs args) f2 in
184+
let f2' = toCls_exp known' tvs (Environment.add x (zs, List.length tvs) args) f2 in
184185
if V.mem x (Cls.fv_exp f2') then
185186
Cls.MakeCls (x, { Cls.entry = Cls.to_label x; Cls.actual_fv = zs }, { ftvs = tyvar_to_tyarg tvs; offset = List.length tvs' }, f2')
186187
else f2'
@@ -211,7 +212,7 @@ module KNorm = struct
211212
(* let zts = List.map (fun z -> (z, Environment.find z tyenv')) zs in *)
212213
let fundef = Cls.FundefM { name = Cls.to_label x; tvs = (new_tvs, List.length tvs'); arg = y; formal_fv = zs; body = f1' } in
213214
if not @@ List.mem fundef !toplevel then toplevel := fundef :: !toplevel;
214-
let f2' = toCls_exp known' tvs (Environment.add x zs args) f2 in
215+
let f2' = toCls_exp known' tvs (Environment.add x (zs, List.length tvs) args) f2 in
215216
if V.mem x (Cls.fv_exp f2') then
216217
Cls.MakeCls (x, { Cls.entry = Cls.to_label x; Cls.actual_fv = zs }, { ftvs = tyvar_to_tyarg tvs; offset = List.length tvs' }, f2')
217218
else f2'

lib/toC.ml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,12 +289,13 @@ let rec toC_exp ppf f = match f with
289289
y
290290
z
291291
| AppTy (y, k, n, tas) ->
292-
fprintf ppf "%s = (value)GC_MALLOC(sizeof(fun) + sizeof(void*) * %d);\n*((fun*)%s) = *((fun*)%s);\n%a" (* TODO *)
292+
let total_env_size = k + n + List.length tas in
293+
fprintf ppf "%s = (value)GC_MALLOC(sizeof(fun) + sizeof(void*) * %d);\n*((fun*)%s) = *((fun*)%s);\n%a"
293294
x
294-
(k + n + List.length tas)
295+
total_env_size
295296
x
296297
y
297-
toC_tas (y, k, n, x, tas)
298+
toC_tas (y, k, total_env_size, x, tas)
298299
| Cast (y, u1, u2, (r, p)) ->
299300
(*
300301
Insert(x, y:u1=>^(r, p)u2)

libC/capp.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "fun.h"
99
#include "lst.h"
1010
#include "app.h"
11+
#include "ty.h"
1112

1213
#include "capp.h"
1314

@@ -441,6 +442,7 @@ value coerce(value v, crc *s) {
441442
#endif
442443
}
443444
case TV_INJ: {
445+
s->crcdat.seq_tv.ptr.tv = ty_find(s->crcdat.seq_tv.ptr.tv);
444446
s = normalize_tv_inj(s);
445447
if (s == &crc_inj_INT) return tag_value(v, G_INT);
446448
if (s == &crc_inj_BOOL) return tag_value(v, G_BOOL);
@@ -513,6 +515,7 @@ value coerce(value v, crc *s) {
513515
}
514516

515517
case TV_PROJ: { // v<X?p> = u<<d>><X?p>
518+
s->crcdat.seq_tv.ptr.tv = ty_find(s->crcdat.seq_tv.ptr.tv);
516519
s = normalize_tv_proj(s);
517520
if (s->crckind != TV_PROJ) goto CASE_SEQ_PROJ;
518521
dti(tag_of(v), s->crcdat.seq_tv.ptr.tv);
@@ -521,6 +524,7 @@ value coerce(value v, crc *s) {
521524
}
522525

523526
case TV_PROJ_INJ: { // v<?pX!> = u<<d>><?pX!>
527+
s->crcdat.seq_tv.ptr.tv = ty_find(s->crcdat.seq_tv.ptr.tv);
524528
s = normalize_tv_proj_inj(s);
525529
if (s->crckind != TV_PROJ_INJ) goto CASE_SEQ_PROJ_INJ;
526530
dti(tag_of(v), s->crcdat.seq_tv.ptr.tv);
@@ -529,6 +533,7 @@ value coerce(value v, crc *s) {
529533
}
530534

531535
case TV_PROJ_OCCUR: {
536+
s->crcdat.seq_tv.ptr.tv = ty_find(s->crcdat.seq_tv.ptr.tv);
532537
s = normalize_tv_proj_occur(s);
533538
if (s->crckind != TV_PROJ_OCCUR) goto CASE_SEQ_PROJ_BOT;
534539
dti(tag_of(v), s->crcdat.seq_tv.ptr.tv);

0 commit comments

Comments
 (0)