@@ -58,6 +58,34 @@ The builtin.python namespace is mapped to the top-level namespace.
5858For example, builtin.python.f will appear as f.
5959-/
6060
61+ nki builtin.python.isinstance (t : Term) (ty : Term) := do
62+ match t, ty with
63+ | .object cls .., .source { name }
64+ | .ref _ (.object cls), .source { name } => return .bool (cls == name)
65+ | .none, .builtin `builtin.python.NoneType ..
66+ | .bool .., .builtin `builtin.python.bool ..
67+ | .int .., .builtin `builtin.python.int ..
68+ | .float .., .builtin `builtin.python.float ..
69+ | .string .., .builtin `builtin.python.str ..
70+ | .tuple .., .builtin `builtin.python.tuple ..
71+ | .list .., .builtin `builtin.python.list ..
72+ | .ref _ .list, .builtin `builtin.python.list ..
73+ | .dict .., .builtin `builtin.python.dict ..
74+ | .ref _ .dict, .builtin `builtin.python.dict ..
75+ | .scalar .., .builtin `builtin.typing.scalar ..
76+ | .ellipsis, .builtin `builtin.python.ellipsis ..
77+ | .slice .., .builtin `builtin.python.slice .. => return .bool true
78+ | _, _ => return .bool false
79+
80+ nki builtin.python.NoneType := do
81+ return .none
82+
83+ nki builtin.python.EllipsisType := do
84+ return .ellipsis
85+
86+ nki builtin.python.ellipsis := do
87+ return .ellipsis
88+
6189nki builtin.python.slice (args : List Term) := do
6290 match args with
6391 | [e] => return .slice (some 0 ) (<- fromNKI? e) (some 1 )
@@ -91,6 +119,9 @@ nki builtin.python.abs (t : Term) := do
91119 | .float f => return .float f.abs
92120 | _ => throw "abs expects an integer or float number"
93121
122+ nki builtin.python.tuple (l : List Term := []) := do
123+ return .tuple l
124+
94125nki builtin.python.str (t : Term) := do
95126 return .string (<- t.toStr)
96127
0 commit comments