Commit 3cfe74c9 authored by Pietro Abate's avatar Pietro Abate
Browse files

[r2004-05-11 22:44:26 by afrisch] Fixed an extremely embarassing bug which...

[r2004-05-11 22:44:26 by afrisch] Fixed an extremely embarassing bug which made ("" @ "a") segfaults...

Original author: afrisch
Date: 2004-05-11 22:44:27+00:00
parent fb963851
......@@ -214,26 +214,48 @@ types/builtin.cmx: types/atoms.cmx types/builtin_defs.cmx types/chars.cmx \
runtime/value.cmx types/builtin.cmi
driver/librarian.cmo: types/builtin.cmi compile/compile.cmi \
misc/encodings.cmi runtime/eval.cmi types/ident.cmo compile/lambda.cmo \
parser/location.cmi parser/parser.cmi types/sequence.cmi \
misc/serialize.cmi typing/typer.cmi types/types.cmi runtime/value.cmi \
driver/librarian.cmi
parser/location.cmi parser/parser.cmi misc/serialize.cmi typing/typer.cmi \
types/types.cmi runtime/value.cmi driver/librarian.cmi
driver/librarian.cmx: types/builtin.cmx compile/compile.cmx \
misc/encodings.cmx runtime/eval.cmx types/ident.cmx compile/lambda.cmx \
parser/location.cmx parser/parser.cmx types/sequence.cmx \
misc/serialize.cmx typing/typer.cmx types/types.cmx runtime/value.cmx \
driver/librarian.cmi
parser/location.cmx parser/parser.cmx misc/serialize.cmx typing/typer.cmx \
types/types.cmx runtime/value.cmx driver/librarian.cmi
cdo2cmo/ml_types.cmo: types/types.cmi
cdo2cmo/ml_types.cmx: types/types.cmx
cdo2cmo/ml_cduce.cmo: types/atoms.cmi types/builtin_defs.cmi types/chars.cmi \
compile/compile.cmi misc/encodings.cmi types/ident.cmo \
types/intervals.cmi compile/lambda.cmo driver/librarian.cmi \
cdo2cmo/ml_types.cmo misc/ns.cmi types/sequence.cmi typing/typer.cmi \
types/types.cmi
cdo2cmo/ml_cduce.cmx: types/atoms.cmx types/builtin_defs.cmx types/chars.cmx \
compile/compile.cmx misc/encodings.cmx types/ident.cmx \
types/intervals.cmx compile/lambda.cmx driver/librarian.cmx \
cdo2cmo/ml_types.cmx misc/ns.cmx types/sequence.cmx typing/typer.cmx \
types/types.cmx
cdo2cmo/ml_ocaml.cmo: driver/librarian.cmi cdo2cmo/ml_types.cmo
cdo2cmo/ml_ocaml.cmx: driver/librarian.cmx cdo2cmo/ml_types.cmx
cdo2cmo/ml_checker.cmo: cdo2cmo/ml_cduce.cmo cdo2cmo/ml_ocaml.cmo \
cdo2cmo/ml_types.cmo
cdo2cmo/ml_checker.cmx: cdo2cmo/ml_cduce.cmx cdo2cmo/ml_ocaml.cmx \
cdo2cmo/ml_types.cmx
cdo2cmo/ml_generator.cmo: cdo2cmo/ml_cduce.cmo cdo2cmo/ml_ocaml.cmo \
cdo2cmo/ml_types.cmo
cdo2cmo/ml_generator.cmx: cdo2cmo/ml_cduce.cmx cdo2cmo/ml_ocaml.cmx \
cdo2cmo/ml_types.cmx
driver/cduce.cmo: parser/ast.cmo types/builtin.cmi compile/compile.cmi \
misc/encodings.cmi runtime/eval.cmi runtime/explain.cmi types/ident.cmo \
driver/librarian.cmi parser/location.cmi misc/ns.cmi parser/parser.cmi \
types/patterns.cmi types/sample.cmi schema/schema_common.cmi \
misc/state.cmi typing/typer.cmi types/types.cmi parser/ulexer.cmi \
runtime/value.cmi driver/cduce.cmi
driver/librarian.cmi parser/location.cmi cdo2cmo/ml_cduce.cmo \
cdo2cmo/ml_checker.cmo cdo2cmo/ml_generator.cmo cdo2cmo/ml_ocaml.cmo \
misc/ns.cmi parser/parser.cmi types/patterns.cmi types/sample.cmi \
schema/schema_common.cmi misc/state.cmi typing/typer.cmi types/types.cmi \
parser/ulexer.cmi runtime/value.cmi driver/cduce.cmi
driver/cduce.cmx: parser/ast.cmx types/builtin.cmx compile/compile.cmx \
misc/encodings.cmx runtime/eval.cmx runtime/explain.cmx types/ident.cmx \
driver/librarian.cmx parser/location.cmx misc/ns.cmx parser/parser.cmx \
types/patterns.cmx types/sample.cmx schema/schema_common.cmx \
misc/state.cmx typing/typer.cmx types/types.cmx parser/ulexer.cmx \
runtime/value.cmx driver/cduce.cmi
driver/librarian.cmx parser/location.cmx cdo2cmo/ml_cduce.cmx \
cdo2cmo/ml_checker.cmx cdo2cmo/ml_generator.cmx cdo2cmo/ml_ocaml.cmx \
misc/ns.cmx parser/parser.cmx types/patterns.cmx types/sample.cmx \
schema/schema_common.cmx misc/state.cmx typing/typer.cmx types/types.cmx \
parser/ulexer.cmx runtime/value.cmx driver/cduce.cmi
query/query.cmo: parser/ast.cmo types/atoms.cmi types/builtin_defs.cmi \
types/chars.cmi types/ident.cmo types/intervals.cmi parser/location.cmi \
parser/parser.cmi types/types.cmi query/query.cmi
......@@ -246,12 +268,12 @@ query/query_parse.cmo: parser/ast.cmo types/atoms.cmi types/ident.cmo \
query/query_parse.cmx: parser/ast.cmx types/atoms.cmx types/ident.cmx \
parser/location.cmx parser/parser.cmx query/query.cmx types/sequence.cmx \
types/types.cmx
driver/run.cmo: driver/cduce.cmi types/ident.cmo driver/librarian.cmi \
runtime/load_xml.cmi parser/location.cmi types/sequence.cmi \
driver/run.cmo: types/builtin.cmi driver/cduce.cmi types/ident.cmo \
driver/librarian.cmi runtime/load_xml.cmi parser/location.cmi \
misc/state.cmi misc/stats.cmi parser/ulexer.cmi parser/url.cmi \
runtime/value.cmi
driver/run.cmx: driver/cduce.cmx types/ident.cmx driver/librarian.cmx \
runtime/load_xml.cmx parser/location.cmx types/sequence.cmx \
driver/run.cmx: types/builtin.cmx driver/cduce.cmx types/ident.cmx \
driver/librarian.cmx runtime/load_xml.cmx parser/location.cmx \
misc/state.cmx misc/stats.cmx parser/ulexer.cmx parser/url.cmx \
runtime/value.cmx
driver/webiface.cmo: driver/cduce.cmi driver/examples.cmo parser/location.cmi \
......@@ -307,9 +329,8 @@ compile/compile.cmi: parser/ast.cmo types/ident.cmo compile/lambda.cmo \
runtime/value.cmi
compile/operators.cmi: misc/custom.cmo parser/location.cmi misc/serialize.cmi \
typing/typer.cmi types/types.cmi runtime/value.cmi
types/builtin.cmi: typing/typer.cmi
driver/librarian.cmi: types/types.cmi runtime/value.cmi
driver/cduce.cmi: types/ident.cmo types/types.cmi runtime/value.cmi
types/builtin.cmi: typing/typer.cmi runtime/value.cmi
driver/librarian.cmi: types/types.cmi
query/query.cmi: parser/ast.cmo
schema/schema_types.cmi: misc/encodings.cmi types/intervals.cmi misc/ns.cmi \
runtime/value.cmi
......@@ -100,7 +100,7 @@ let rec eval env = function
let v3 = eval env e3 in
Value.Xml (v1,v2,v3)
| Record r -> Value.Record (LabelMap.map (eval env) r)
| String (i,j,s,q) -> Value.String_utf8 (i,j,s,eval env q)
| String (i,j,s,q) -> Value.substring_utf8 i j s (eval env q)
| Match (e,brs) -> eval_branches env brs (eval env e)
| Map (arg,brs) -> eval_map env brs (eval env arg)
......
......@@ -18,12 +18,25 @@ type t =
| Delayed of t ref
(*
The only representation of the empty sequence is nil.
In particular, in String_latin1 and String_utf8, the string cannot be empty.
*)
let dump_forward = ref (fun _ _ -> assert false)
exception CDuceExn of t
let nil = Atom Sequence.nil_atom
let string_latin1 s = String_latin1 (0,String.length s, s, nil)
let string_utf8 s = String_utf8 (Utf8.start_index s,Utf8.end_index s, s, nil)
let string_latin1 s =
if String.length s = 0 then nil
else String_latin1 (0,String.length s, s, nil)
let string_utf8 s =
if String.length (Utf8.get_str s) = 0 then nil
else String_utf8 (Utf8.start_index s,Utf8.end_index s, s, nil)
let substring_utf8 i j s q =
if Utf8.equal_index i j then q
else String_utf8 (i,j,s,q)
let vtrue = Atom (Atoms.V.mk_ascii "true")
let vfalse = Atom (Atoms.V.mk_ascii "false")
let vbool x = if x then vtrue else vfalse
......@@ -513,3 +526,4 @@ let rec flatten = function
let failwith' s = raise (CDuceExn (string_latin1 s))
let raise' v = raise (CDuceExn v)
let () = dump_forward := dump_xml
......@@ -40,6 +40,7 @@ val const : Types.const -> t (* extract the const value from a const type *)
val inv_const : t -> Types.const (* build a const type from a const value *)
val string_latin1 : string -> t
val string_utf8 : U.t -> t
val substring_utf8: U.uindex -> U.uindex -> U.t -> t -> t
val nil : t
val vtrue : t
val vfalse : t
......
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
<page name="hacking">
<page name="hacking" new="">
<title>Hacking CDuce</title>
......
......@@ -21,6 +21,7 @@
<include file="documentation.xml"/>
<include file="examples.xml"/>
<include file="hacking.xml"/>
<include file="tips.xml"/>
<include file="mailing.xml"/>
<include file="team.xml"/>
<include file="sitemap.xml"/>
......
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
<page name="tips">
<title>Tips and Tricks with CDuce</title>
<box title="Poor-man ML-like polymorphism" link="pmpoly">
<p>
CDuce does not currently support ML-like parametric polymorphism.
For instance, a <code>fold_left</code> function can be defined
for arbitrary fixed types, but not in a polymorphic way.
Here is one possible definition:
</p>
<sample>
let fold_left (f : ((A,B) -> A), x : A, l : [B*]) : A =
let accu = ref A x in
(transform l with y -> accu := f (!accu,y));
!accu
</sample>
<p>
Of course, it is possible to set <code>A=B=Any</code>, but then
one looses all the type information.
</p>
<p>
A technique which was suggested by Serge Leblanc on the CDuce users
mailing list is to rely on the <code>include</code> feature.
Here is an example, which assumes that the above piece of code is in a
file <code>fold_left.cd</code>:
</p>
<sample>
type A = Int
type B = Int
include "fold_left.cd";;
let fold_int_int = fold_left
type A = Latin1
type B = Any
include "fold_left.cd";;
let fold_string_any = fold_left
let s1 = fold_int_int
((fun (x : Int, y : Int) : Int = x + y), 0, [ 1 2 3 ])
let s2 = fold_string_any
((fun (x : Latin1, y : Any) : Latin1 = x @ (string_of y)), "",[ 1 `x 'a' ])
</sample>
<p>
Of course, this is nothing but textual substitution, and this could
also be handled through a general-purpose preprocessor such as
cpp or m4.
</p>
</box>
</page>
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