From b8719e5214d514a23fd64a54947ee9d6876189c2 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Wed, 23 Dec 2020 10:42:57 +0800 Subject: [PATCH] added len and range --- toy-impl/primitives.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/toy-impl/primitives.py b/toy-impl/primitives.py index 635c5de..5b3edd6 100644 --- a/toy-impl/primitives.py +++ b/toy-impl/primitives.py @@ -12,6 +12,7 @@ i64 = types['int64'] f32 = types['float'] b = types['bool'] I = TypeVariable('I', [i32, i64, f32]) +A = TypeVariable('A', []) def impl_math(ty): ty.methods['__add__'] = ([SelfType(), ty], ty, set()) @@ -66,4 +67,6 @@ i64.methods['__init__'] = ([SelfType(), I], None, {'I'}) f32.methods['__init__'] = ([SelfType(), I], None, {'I'}) simplest_ctx = Context({}, types) +simplest_ctx.functions['len'] = ([ListType(A)], i32, {'A'}) +simplest_ctx.functions['range'] = ([i32], ListType(i32), set())