Commit 6666ff9b authored by Thierry Geraud's avatar Thierry Geraud
Browse files

2007-02-05 Thierry GERAUD <theo@tegucigalpa.lrde.epita.fr>

	Add a README and a "SCOOP 1+" translation in doc/tiny.
	
	* doc/tiny/a_la_scoop_1_plus: New.
	* doc/tiny/README: New.
	* doc/tiny/local/scoop.hh (Concept): Rename as...
	(concept_): ...this.
	(stc_equip_namespace): Add "vtypes< stc::any<E> >" so
	that we can have SCOOP 1 with SCOOP 2 tools.
	(stc_deferred): New.
	* doc/tiny/a_la_scoop_2/main.cc: Update. 
	* doc/tiny/a_la_scoop_2/desugar.cc: Update.
	* doc/tiny/more_scoop_2/main.cc: Update.
	(reference): New.
	* doc/tiny/design/main.cc (is_valid): Fix sig.



git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@736 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent 95ef2220
2007-02-05 Thierry GERAUD <theo@tegucigalpa.lrde.epita.fr>
Add a README and a "SCOOP 1+" translation in doc/tiny.
* doc/tiny/a_la_scoop_1_plus: New.
* doc/tiny/README: New.
* doc/tiny/local/scoop.hh (Concept): Rename as...
(concept_): ...this.
(stc_equip_namespace): Add "vtypes< stc::any<E> >" so
that we can have SCOOP 1 with SCOOP 2 tools.
(stc_deferred): New.
* doc/tiny/a_la_scoop_2/main.cc: Update.
* doc/tiny/a_la_scoop_2/desugar.cc: Update.
* doc/tiny/more_scoop_2/main.cc: Update.
(reference): New.
* doc/tiny/design/main.cc (is_valid): Fix sig.
2007-02-02 Thierry GERAUD <theo@tegucigalpa.lrde.epita.fr>
Clean stc/doc/tiny.
......
-*- outline -*-
* Introduction.
FIXME: ...
* Contents.
** design/
Presents the sample program in a pseudo language.
It defines Iterator as a record type with value (type), next,
is_valid, set (three methods). The class array_iterator[T] is an
implementation of an Iterator.
** classical/
Classical object-oriented C++ with abstract class and inheritance.
The use of "void*" maps a generalization of all value types and allows
to manually implement a covariant behavior of the "set" method.
** cpp_with_virtual_types/
Rewriting of the "classical" example but in an extension of the C++
language with virtual types. This code does not compile! Yet it
expresses an syntactically elegant solution to the covariance issue.
** a_la_scoop_1/
SCOOP 1 aims at writing C++ class hierarchies in a static way
(with methods and typedefs dispatching at compile-time).
Same as "cpp_with_virtual_types" but conforming to the 2003 ISO/ANSI
C++. The "virtual" keyword has disappeared so polymorphic methods
now are fast at run-time and the use of covariance is statically
solved and checked.
To break recursion that appears in types definitions (*), an auxiliary
structure (vtypes) is introduced. This structure shall map the
inheritance tree of the targeted classes so that we also get
inheritance for virtual types.
For instance, if B derives from A, we should have vtypes<B> deriving
from vtypes<A>.
(*) Precisely the following code cannot compile:
struct Iterator { typedef typename iter::value_ value; };
struct iter : Iterator { typedef int value_; };
because "Iterator" needs to be compiled before "iter" so
the definition of "value_" is unaccessible.
** a_la_scoop_1_plus/
Almost like the previous example but with the material offered to
design with SCOOP 2.
The main difference is that the "vtypes" definitions do not need
anymore to replicate class inheritance. When B derives from A,
vtypes<B> is no more required to derive from vtypes<A>. Yet the
expected properties of virtual type inheritance and lookup are
verified.
Extra features are also provided:
- "stc::abstract" to declare a typedef and get an error at
compile-time when a concrete subclass misses to give its definition;
- "stc::final" to ensure that a typedef is not overridden in a
subclass;
- "delegatee_type" to offer delegation;
- furthermore typedef definitions based on deferred ones are now
possible (*).
For instance, we can have:
stc_Header;
typedef stc::abstract value;
typedef stc::final< stc_deferred(value) & > reference;
stc_End;
** a_la_scoop_2/
SCOOP 2 aims both at writing C++ class hierarchies in a static way
(just like SCOOP 1) and at decoupling concepts, models, and
some automatic implementation when delegation is involved.
In this sample code the "Iterator" concept (deriving from "concept_")
is defined apart from the "array_iterator" class (deriving from
"top"). An intermediate (non-client) meta-code looks up for the
category of the implementation class so that it is plugged to the
appropriate concept.
What we can expect from this kind of design is better illustrated in
the "more_scoop_2/" directory.
** more_scoop_2/
A more elaborate example than the previous one.
FIXME: Give some explanations.
** local/
Material to equip a namespace with SCOOP 2 facilities and to program
with the SCOOP 2 paradigm.
** generic_programming/
Dual code than the "classical" object-oriented C++ example. Iterator
only appears in documentation and there is no explicit dependency
between this concept and the "array_iterator" model.
** cpp_with_concepts/
The example is here rewritten in C++0x according to the proposal n2081
from the evolution working group of the C++ Standard committee (*).
"Iterator" is then translated into a concept.
(*) www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2081.pdf
* Recap.
Iterator array_iterator[T]
------------------------- ------------------------
design/ type implementation class
(pseudo-code)
classical/ abstract class derived class
cpp_with_virtual_types/ abstract class derived class
(this is not C++)
generic_programming/ documentation stand-alone class
a_la_scoop_1/ abstract class derived class
(static) super is Any<Exact>
a_la_scoop_2/ concept-like "stand-alone"-like class
(static) super is concept_<Exact> super is top<Exact>
cpp_with_concepts/ concept stand-alone class
(future C++)
g++ -Wall -ansi -pedantic -I../../../ -I../../../../metalic $1
// Copyright (C) 2007 EPITA Research and Development Laboratory.
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
// of the GNU General Public License version 2 as published by the
// Free Software Foundation.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this library; see the file COPYING. If not, write to
// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
// Boston, MA 02111-1307, USA.
//
// As a special exception, you may use this file as part of a free
// software library without restriction. Specifically, if other files
// instantiate templates or use macros or inline functions from this
// file, or you compile this file and link it with other files to
// produce an executable, this file does not by itself cause the
// resulting executable to be covered by the GNU General Public
// License. This exception does not however invalidate any other
// reasons why the executable file might be covered by the GNU General
// Public License.
/* \file doc/tiny/a_la_scoop_1_plus/main.cc
\brief Tiny sample use of FIXME: SCOOP 1. */
#include "../local/scoop.hh"
stc_equip_namespace(abc);
namespace abc
{
// List of associated types.
stc_decl_associated_type(value);
// Iterator
# define super stc::any<Exact>
// -----------------
// ^
// |
# define current Iterator<Exact>
// -----------------
# define templ template <typename Exact>
# define classname Iterator
stc_Header;
typedef stc::abstract value; // stc::abstract is a feature of SCOOP 2.
stc_End;
template <typename Exact>
struct Iterator : public stc::any<Exact>
{
stc_typename(value);
void next() { this->exact().impl_next(); }
bool is_valid() const { return this->exact().impl_is_valid(); }
void set(const value& v) { this->exact().impl_set(v); }
};
# include "../local/undefs.hh"
// array_iterator
# define current array_iterator<T>
// -------------------
# define templ template <typename T>
# define classname array_iterator
# define super Iterator< current >
stc_Header;
typedef stc::final<T> value; // stc::final is a feature of SCOOP 2.
stc_End;
template <typename T>
class array_iterator : public super
{
public:
stc_using(value);
void impl_next() { i_ = i_ + 1; }
bool impl_is_valid() const { return i_ >= 0 and i_ < n_; }
void impl_set(const value& v) { v_ = v; }
array_iterator(int n) : i_(0), n_(n) {}
protected:
int i_, n_;
value v_;
};
# include "../local/undefs.hh"
// algo
template <typename I>
void algo(Iterator<I>& iter, typename I::value val)
{
if (iter.is_valid())
{
iter.set(val);
iter.next();
}
}
} // abc
int main()
{
abc::array_iterator<int> i(7);
int val = 51;
abc::algo(i, val);
}
......@@ -48,7 +48,7 @@ namespace abc
// Iterator
template <typename Exact>
struct Iterator : public Concept<Exact>,
struct Iterator : public concept_<Exact>,
public automatic::impl<Iterator, Exact>
{
stc_typename(value);
......
......@@ -48,7 +48,7 @@ namespace abc
// Iterator
template <typename Exact>
struct Iterator : public Concept<Exact>,
struct Iterator : public concept_<Exact>,
public automatic::impl<Iterator, Exact>
{
stc_typename(value);
......
......@@ -38,7 +38,7 @@ namespace abc
{
value : type
next : () -> void
is_valid : const bool
is_valid : const () -> bool
set : (v : value const&) -> void
}
......
......@@ -903,13 +903,24 @@ namespace SCOOPED_NAMESPACE \
\
\
\
/* stc::any vtypes in equipped namespace; code required for SCOOP 1 */ \
\
template <typename E> \
struct vtypes< stc::any<E> > \
{ \
typedef mlc::none super_type; \
typedef stc::final<E> exact_type; \
}; \
\
\
\
/* concept class */ \
\
template <typename E> \
struct Concept : public virtual stc::any<E> \
struct concept_ : public virtual stc::any<E> \
{ \
protected: \
Concept() {} \
concept_() {} \
}; \
\
\
......@@ -1031,6 +1042,12 @@ struct e_n_d__w_i_t_h___s_e_m_i_c_o_l_o_n;
# define stc_using(Type) typedef typename super::Type Type
# define stc_deferred(Type) \
typename deferred_vtype< typename deferred_vtype< current, \
typedef_::exact_type >::ret, \
typedef_::Type >::ret
// For impl classes.
# define stc_lookup(Type) typedef typename vtype< stc_type(current, exact_type), typedef_::Type>::ret Type
......@@ -1050,6 +1067,8 @@ templ struct vtypes< current > /* vtypes */ \
{ \
typedef super super_type \
# define stc_End }
......
......@@ -43,6 +43,7 @@ namespace abc
// List of associated types.
stc_decl_associated_type(value);
stc_decl_associated_type(reference);
stc_decl_associated_type(forward);
stc_decl_associated_type(backward);
......@@ -54,7 +55,7 @@ namespace abc
// Iterator
template <typename Exact>
struct Iterator : public Concept<Exact>,
struct Iterator : public concept_<Exact>,
public automatic::impl<Iterator, Exact>
{
stc_typename(value);
......@@ -120,7 +121,7 @@ namespace abc
# define super top<E>
// -------
// --------
// ^
// |
# define current iterator_base<E>
......@@ -134,6 +135,7 @@ namespace abc
typedef stc::is<Iterator> category;
typedef stc::abstract value;
typedef stc::final< stc_deferred(value) & > reference;
stc_End;
......
Supports Markdown
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