Commit 909e37a5 authored by Tom Niget's avatar Tom Niget

List interop

parent 9dc8cec5
......@@ -81,7 +81,7 @@ struct TyList__oo : classtype<_Base0, TyList__oo<>> {
}
} static constexpr oo__getitem__oo{};
template <typename T> struct Obj : instance<TyList__oo<>, Obj<T>> {
template <typename T> struct Obj : value<TyList__oo<>, Obj<T>> {
using value_type = T;
std::shared_ptr<std::vector<T>> _v;
......@@ -93,14 +93,20 @@ struct TyList__oo : classtype<_Base0, TyList__oo<>> {
: _v(std::make_shared<std::vector<T>>(std::move(v))) {}
Obj() : _v(std::make_shared<std::vector<T>>()) {}
void clear() { _v->clear(); }
void push_back(const T &value) { _v->push_back(value); }
size_t size() const { return _v->size(); }
auto begin() const { return _v->begin(); }
auto end() const { return _v->end(); }
};
template <typename T> auto operator()(std::initializer_list<T> &&v) const {
return rc(Obj(std::move(v)));
return (Obj(std::move(v)));
}
template <typename... Args> auto operator()(Args &&...args) const {
return rc(Obj(std::forward<Args>(args)...));
return (Obj(std::forward<Args>(args)...));
}
/*
......
# test numpy interop
#from numpy import square
from numpy import square
import math
if __name__ == "__main__":
x = [1, 2, 3, 4]
# y: list[int] = square(x)
# print(x, y)
y: list[int] = square(x)
print(x, y)
f: int = math.factorial(5)
print("5! =", f)
\ No newline at end of file
......@@ -71,6 +71,8 @@ class NodeVisitor(UniversalVisitor):
yield "typon::TyNone"
case types.TY_STR:
yield 'decltype(""_ps)'
case types.TY_LIST:
yield "typon::TyList__oo<>::Obj"
case types.TypeVariable(name, emit_as_is=em, decltype_str=dt):
if em:
yield name
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment