Commit 36e1ed41 authored by POTTIER Francois's avatar POTTIER Francois

Implement [size] using [iter] instead of [reduce].

parent e53dc269
......@@ -199,21 +199,32 @@
(* -------------------------------------------------------------------------- *)
(* [size] could be defined in terms of [reduce]. We prefer to define it in
terms of [iter] because we wish to eliminate our dependency on [reduce]
visitors. *)
(* We use a mutable field [accu], but could also let the environment be a
reference. *)
#define SIZE_CLASS __size
#define SIZE_FUN(term) CONCAT(size_, term)
#define __SIZE \
class ['self] SIZE_CLASS = object (_ : 'self) \
inherit [_] reduce as super \
inherit [_] KitTrivial.reduce \
inherit [_] VisitorsRuntime.addition_monoid \
inherit [_] iter as super \
inherit [_] KitTrivial.iter \
val mutable accu = 0 \
method accu = accu \
method! VISIT(term) env t = \
1 + super # VISIT(term) env t \
accu <- accu + 1; \
super # VISIT(term) env t \
end \
#define SIZE(term) \
let SIZE_FUN(term) t = \
new SIZE_CLASS # VISIT(term) () t \
let o = new SIZE_CLASS in \
o # VISIT(term) () t; \
o # accu \
(* -------------------------------------------------------------------------- *)
......
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