added len and range

This commit is contained in:
pca006132 2020-12-23 10:42:57 +08:00 committed by pca006132
parent ee7c1713a5
commit b8719e5214

View File

@ -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())