diff --git a/pdfs/llvm2midden.pdf b/pdfs/llvm2midden.pdf new file mode 100644 index 000000000..b5b26c577 Binary files /dev/null and b/pdfs/llvm2midden.pdf differ diff --git a/ring.cxx b/ring.cxx index d4bdb62ba..24dc6b311 100644 --- a/ring.cxx +++ b/ring.cxx @@ -129,6 +129,7 @@ class N { // iterators constexpr N succ () const { return rep + 1; } constexpr N pred () const { return rep + n - 1; } + consteval static N zero() { return 0; } // oputput friend constexpr ::std::ostream & @@ -137,20 +138,20 @@ class N { ::std::string repr() const { return type_name() + "{" + ::std::to_string (get()) + "}"; } }; -template +template struct ring_iterator { - N v; + T v; bool ended; - ring_iterator() : v{0}, ended(false) {} - ring_iterator(int) : v{0}, ended(true) {} + ring_iterator() : v{T::zero()}, ended(false) {} + ring_iterator(int) : v{T::zero()}, ended(true) {} // dummy parameter - N operator*(){ return v; } - void operator++() { v = v.succ(); ended = v==N{0}; } - friend int operator <=>(ring_iterator,ring_iterator)=default; + T operator*(){ return v; } + void operator++() { v = v.succ(); ended = v==T::zero(); } + friend int operator <=>(ring_iterator,ring_iterator)=default; static ring_iterator begin() { return ring_iterator(); } - static ring_iterator end() { return ring_iterator(N::size()); } + static ring_iterator end() { return ring_iterator(0); } struct all { @@ -158,8 +159,8 @@ struct ring_iterator { ring_iterator begin() { return ring_iterator::begin(); } ring_iterator end() { return ring_iterator::end(); } }; - }; + //--------------------------------------- // products template @@ -367,6 +368,16 @@ namespace helper { return out::put (o,x); } }; + + template + struct ainit { + consteval static Nat init(Base head, Base tail...) { + return head.get() * sizeof(tail) * Base::size() + init(tail); + } + consteval static Nat init() { return 0; } + }; + + } // Cartesian Product @@ -398,6 +409,7 @@ struct Product<> { Product succ() const { return Product(); } Product pred() const { return Product(); } + Product zero() const { return Product(); } friend ::std::ostream& operator << (::std::ostream& o, Product x) { return o << "{}"; @@ -430,6 +442,7 @@ class Product { Product succ() const { return Product((rep + 1) % size()); } Product pred() const { return Product((rep + size() - 1) % size()); } + consteval static Product zero() { return 0; } // comparisons constexpr bool eq(Product x) const { return x.rep == rep; } @@ -480,6 +493,7 @@ class Sum { Sum succ() const { Nat x = size(); return Sum((rep + 1) % x); } Sum pred() const { return Sum((rep + size() - 1) % size()); } + consteval static Sum zero() { return 0; } // comparisons constexpr bool eq(Sum x) const { return x.rep == rep; } @@ -535,6 +549,43 @@ struct injection> { static auto inj (InjT x) -> S { return helper::pack_inj::inj(x.get()); } }; + +// standard array +template // index must be compact linear type +class Array { + Base data[Index::size()]; +public: + Base get(Index i) const { return data[i.get()]; } + void set (Index i, Base v) { data[i.get()] = v; } + consteval static Nat size() { return Index::size(); } +}; + +template +struct array_projection { + using A = Array; + static auto aprj (A a, Index i) -> A { return a.get(i); } +}; + +// Compact array +template // index must be compact linear type +class CompactArray { + Nat rep; +public: + CompactArray (Base v...) { + static_assert (sizeof(v) == Index::size()); + rep = helper::ainit::init(v); + } + Base get(Index i) const { return rep / (Base::size() * i.get()) % Base::size(); } + consteval static Nat size() { return Index::size() * Base::size(); } +}; + +// Standard Array Projection +template +struct compact_array_projection { + using A = CompactArray; + static auto aprj (A a, Index i) -> A { return a.get(i); } +}; + // ========================================================================= // ATOMIC @@ -750,11 +801,11 @@ int main() { ::std::cout << nullary << ::std::endl; ::std::cout << nullary.add(nullary) << ::std::endl; - for (auto i = ring_iterator<5>::begin(); i != ring_iterator<5>::end(); ++i) + for (auto i = ring_iterator>::begin(); i != ring_iterator>::end(); ++i) ::std::cout << *i << ::std::endl ; - for (auto i : ring_iterator<5>::all()) + for (auto i : ring_iterator>::all()) ::std::cout << i << ::std::endl ; @@ -775,4 +826,26 @@ int main() { ::std::cout << "c111 repr = " << c111.repr() << ::std::endl; ::std::cout << "c011 repr = " << c011.repr() << ::std::endl; + Array> a; + a.set(N<3>{0},0); + a.set(N<3>{1},1); + a.set(N<3>{2},2); + for (auto i : ring_iterator>::all()) + ::std::cout << a.get(i) << " "; + ::std::cout << ::std::endl; + + Array p; + auto v = 0; + + for (auto i : ring_iterator>::all()) + for (auto j : ring_iterator>::all()) + { + p.set(Product{i,j}, v); + ++v; + } + for (auto i : ring_iterator::all()) + ::std::cout << p.get(i); + ::std::cout << ::std::endl; + + auto ca = CompactArray,N<3>>{N<2>{1},N<2>{1},N<2>{0}}; } diff --git a/src/tex/llvm2midden.tex b/src/tex/llvm2midden.tex new file mode 100644 index 000000000..f469f2081 --- /dev/null +++ b/src/tex/llvm2midden.tex @@ -0,0 +1,35 @@ + +\documentclass{article} +\usepackage{xcolor} +\definecolor{bg}{rgb}{0.95,0.95,0.95} +\definecolor{emphcolor}{rgb}{0.5,0.0,0.0} +\newcommand{\empha}{\bf\color{emphcolor}} +\usepackage{parskip} +\usepackage{minted} +\usepackage{caption} +\usepackage{amsmath} +\usepackage{amssymb} +\usepackage{amscd} +\usepackage{makeidx} +\makeindex +\usemintedstyle{friendly} +\setminted{bgcolor=bg,xleftmargin=20pt} +\usepackage{hyperref} +\hypersetup{pdftex,colorlinks=true,allcolors=blue} +\usepackage{hypcap} +\newcommand*{\fullref}[1]{\hyperref[{#1}]{\autoref*{#1} \nameref*{#1}}} +\DeclareMathOperator{\quot}{div} +\DeclareMathOperator{\rmd}{rmd} +\newtheorem{theorem}{Theorem} +\newtheorem{lemma}{Lemma} +\newtheorem{definition}{Definition} +\newtheorem{notation}{Notation} +\def\restrict#1{\raise-.5ex\hbox{\ensuremath|}_{#1}} + + +\title{LLVMN to Midden\\Proof of Princple Prject} +\author{John Skaller} +\begin{document} +\maketitle + +\end{document}