Commit 50e07446 authored by Pietro Abate's avatar Pietro Abate
Browse files

Merge branch 'master' of https://git.cduce.org/cduce

parents a4fe1ca9 7b965b3c
......@@ -6,17 +6,17 @@ EXTDIR ?= $(SRCDIR)/externals
LIBFLAGS = -libs nums,pcre,netstring -lflags -I,`ocamlfind query pcre`\
-lflags -I,`ocamlfind query netstring`
INEXTFILES = misc/custom.ml misc/encodings.ml types/ident.ml\
compile/lambda.mli compile/lambda.ml misc/ns.ml misc/ns.mli misc/upool.ml\
misc/upool.mli types/sortedList.ml types/sortedList.mli types/compunit.ml\
types/compunit.mli types/types.mli types/types.ml runtime/eval.mli\
runtime/eval.ml types/boolVar.ml types/var.ml types/atoms.ml misc/imap.ml\
types/intervals.ml types/chars.ml misc/bool.ml compile/auto_pat.ml\
runtime/value.ml types/sequence.ml schema/schema_validator.ml\
schema/schema_pcre.ml schema/schema_common.ml schema/schema_common.mli\
schema/schema_types.ml schema/schema_xml.ml schema/schema_xml.mli\
schema/schema_builtin.ml types/builtin_defs.ml runtime/run_dispatch.ml\
runtime/explain.ml misc/stats.mli misc/stats.ml types/normal.mli\
types/normal.ml misc/pretty.ml misc/pretty.mli
compile/lambda.ml misc/ns.ml misc/ns.mli misc/upool.ml misc/upool.mli\
types/sortedList.ml types/sortedList.mli types/compunit.ml types/compunit.mli\
types/types.mli types/types.ml runtime/eval.mli runtime/eval.ml\
types/boolVar.ml types/var.ml types/atoms.ml misc/imap.ml types/intervals.ml\
types/chars.ml misc/bool.ml compile/auto_pat.ml runtime/value.ml\
types/sequence.ml schema/schema_validator.ml schema/schema_pcre.ml\
schema/schema_common.ml schema/schema_common.mli schema/schema_types.ml\
schema/schema_xml.ml schema/schema_xml.mli schema/schema_builtin.ml\
types/builtin_defs.ml runtime/run_dispatch.ml runtime/explain.ml\
misc/stats.mli misc/stats.ml types/normal.mli types/normal.ml misc/pretty.ml\
misc/pretty.mli
EXTFILES = $(INEXTFILES:%=$(ROOTDIR)/%)
RM ?= rm -f
......
open Printf
open Parse
open Lambda
open Auto_pat
let rec parse_to_lambda expr = (* TODO: Replace dummy_branches *)
let dummy_state = { uid=0; arity=[||]; actions=AIgnore(0,[||],0);
fail_code=0; expected_type="" } in
let dummy_branches = { brs_accept_chars=true; brs_disp=dummy_state;
brs_rhs=[||]; brs_stack_pos=0 } in
match expr with
| Parse.Apply(e1, e2) -> Apply(parse_to_lambda e1, parse_to_lambda e2)
| Abstract(fname, interface, body) ->
let params, nbrparams =
let rec fill_params params res nbr = match params with
| el :: rest ->
let curr = [|Local(0)|] in (* TODO: Not supposed to be 0 *)
fill_params rest (Array.append res curr) (nbr + 1)
| [] -> res, nbr
in
fill_params interface [||] 0
in
Abstraction(params, [], dummy_branches, nbrparams, true, List([[]]))
| Var(vname) -> Var(Local(0)) (* TODO: Not supposed to be 0 *)
| Int(i) -> Const(Value.Integer(Intervals.V.from_int i))
| Pair(e1, e2) -> Pair(parse_to_lambda e1, parse_to_lambda e2)
| Match(e, branches) ->
Match(parse_to_lambda e, dummy_branches)
| Let(x, e1, e2) -> (* TODO: Define the "_" *)
Apply(parse_to_lambda (Abstract("_", [x], e2)), parse_to_lambda e1)
let load_file f =
let ic = open_in f in
......@@ -14,8 +42,7 @@ let str = if Array.length Sys.argv > 1 then load_file Sys.argv.(1)
| (a,_),(b,_) -> a,b (* This (* is (* a nested *) *) comment *)
| _ -> x . z (* That doesn't make any sense *)" in
let expr = ExprParser.of_string str in
printf "Original: %s\nExpr: " str;
(*printf "Original: %s\nExpr: " str;
print_expr expr;
printf "\nResult: %s\n" (expr_to_string expr);
Eval.expr (Lambda.Var(Lambda.Local (2))) 100
printf "\nResult: %s\n" (expr_to_string expr);*)
Eval.expr (parse_to_lambda expr) 100
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