From 4336983087e5f96c1e0ba4b35e0338561270b7bf Mon Sep 17 00:00:00 2001 From: Stefan O'Rear Date: Tue, 10 Jan 2012 02:14:09 -0800 Subject: [PATCH] Treat subsets in MMD as base type + where --- lib/CodeGen.cs | 6 ++++++ src/niecza | 8 +++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/CodeGen.cs b/lib/CodeGen.cs index 727eb401..9b7431f0 100644 --- a/lib/CodeGen.cs +++ b/lib/CodeGen.cs @@ -4314,6 +4314,12 @@ public class DowncallReceiver : CallReceiver { subset.initVar = basety.initVar; return null; } + public static object type_get_basetype(object[] args) { + return Handle.Wrap(((STable)Handle.Unbox(args[1])).mo.superclasses[0]); + } + public static object type_get_type_var(object[] args) { + return Handle.Wrap(((STable)Handle.Unbox(args[1])).typeVar); + } public static object type_set_where(object[] args) { STable subset = (STable)Handle.Unbox(args[1]); SubInfo where = (SubInfo)Handle.Unbox(args[2]); diff --git a/src/niecza b/src/niecza index 24436812..c9392ec1 100644 --- a/src/niecza +++ b/src/niecza @@ -286,7 +286,13 @@ method parameter($/) { ::Op::GeneralConst.new(value => $tc.ast)); } else { $/.CURSOR.sorry("Parameter coercion NYI") if $tc.ast; - $/.ast.tclass = $tc.ast; + my $type = $tc.ast; + if $type.kind eq 'subset' { + push ($/.ast.where //= []), self.thunk_sub( + ::Op::GeneralConst.new(value => $type.get_type_var)); + $type = $type.get_basetype while $type.kind eq 'subset'; + } + $/.ast.tclass = $type; $/.ast.flags +|= $tc.ast; } }