-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Re-implement PixMap writer in Elpi"
- Loading branch information
Showing
14 changed files
with
194 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Dump is a Coq plugin that exports rasters to graymap PGM files. | ||
Rasters are defined in module CoRN.raster.Raster, as matrices of booleans. | ||
|
||
Type make to build this plugin, then | ||
Require Import CoRN.dump.theories.Loader | ||
from a Coq file where you have rasters to export. | ||
The vernac command defined by the plugin is DumpGrayMap, which takes | ||
as argument the name of a global definition of a raster. It exports | ||
the raster in file plot.pgm, which it will place in the current directory. | ||
See module CoRN.examples.Circle. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
ifeq "$(COQBIN)" "" | ||
COQBIN=$(dir $(shell which coqtop))/ | ||
endif | ||
|
||
%: Makefile.coq | ||
|
||
Makefile.coq: _CoqProject | ||
$(COQBIN)coq_makefile -f _CoqProject -o Makefile.coq | ||
|
||
tests: all | ||
@$(MAKE) -C tests -s clean | ||
@$(MAKE) -C tests -s all | ||
|
||
-include Makefile.coq |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
-R theories CoRN.dump.theories | ||
-I src | ||
|
||
theories/Loader.v | ||
|
||
src/g_dump.mlg | ||
src/dump_plugin.mlpack |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
G_dump |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
(library | ||
(name dump_plugin) | ||
(public_name coq.plugins.tutorial.p0) | ||
(libraries coq.plugins.ltac)) | ||
|
||
(coq.pp (modules g_dump)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
DECLARE PLUGIN "dump_plugin" | ||
|
||
{ | ||
|
||
open Pp | ||
open Names | ||
open Printer | ||
open Globnames | ||
open Stdarg | ||
open Typeops | ||
open Constr | ||
|
||
exception Bad_list | ||
exception Bad_int | ||
|
||
let rec int_of_pos (p : Constr.t) : int = | ||
if isApp p then | ||
(let (constructorTag, args) = destApp p in | ||
let (r,_) = destRef constructorTag in | ||
match r with | ||
| GlobRef.ConstructRef (_,r) -> (* r is the number of the constructor, | ||
starting from 1. *) | ||
(if r = 1 then 2*int_of_pos args.(0)+1 else 2*int_of_pos args.(0)) | ||
| _ -> raise Bad_int) | ||
else 1 | ||
|
||
let int_of_z (z : Constr.t) : int = | ||
if isApp z then | ||
(let (constructorTag, args) = destApp z in | ||
let (r,_) = destRef constructorTag in | ||
match r with | ||
| GlobRef.ConstructRef (_,r) -> (* r is the number of the constructor, | ||
starting from 1. *) | ||
(if r = 2 then int_of_pos args.(0) else -int_of_pos args.(0)) | ||
| _ -> raise Bad_int) | ||
else 0 | ||
|
||
let pair_int_of_pair_z (zz : Constr.t) : int*int = | ||
if isApp zz then | ||
(let (constructorTag, args) = destApp zz in | ||
(int_of_z args.(2), int_of_z args.(3))) | ||
else raise Bad_int | ||
|
||
let rec process_constr_list (l : Constr.t) (f : Constr.t -> unit) : unit = | ||
if isApp l then | ||
(let (constructorTag, args) = destApp l in | ||
if Array.length args = 3 then | ||
(* args stores type, current element and tail *) | ||
(f args.(1) ; process_constr_list args.(2) f) | ||
else ()) (* empty list *) | ||
else raise Bad_list | ||
|
||
let dump_bool_list (l : Constr.t) (oc : out_channel) : unit = | ||
process_constr_list l | ||
(fun b -> | ||
(* b is either true of false, which are constructors of the type bool *) | ||
let (r,_) = destRef b in | ||
match r with | ||
| GlobRef.ConstructRef (_,r) -> (* r is the number of the constructor, | ||
starting from 1. *) | ||
output_string oc (if r = 1 then "1 " else "0 ") | ||
| _ -> raise Bad_list) ; | ||
output_string oc "\n" | ||
|
||
let dump_pgm (raster : Constr.t) (rastertype : Pp.t) = | ||
let bufType = Buffer.create 1000 in | ||
let fmtType = Format.formatter_of_buffer bufType in | ||
pp_with fmtType rastertype; | ||
Format.pp_print_flush fmtType (); | ||
let (strType : string) = Buffer.contents bufType in | ||
if Str.string_match (Str.regexp "(sparse_raster \\([0-9]+\\) \\([0-9]+\\))") | ||
strType 0 then | ||
(let line_count = int_of_string (Str.matched_group 2 strType) in | ||
let column_count = int_of_string (Str.matched_group 1 strType) in | ||
let oc = open_out "plot.pgm" in | ||
let pixels = Array.make_matrix line_count column_count false in | ||
let (constructorTag, args) = destApp raster in | ||
process_constr_list args.(2) | ||
(fun zz -> let (i,j) = pair_int_of_pair_z zz in | ||
pixels.(i).(j) <- true); | ||
(* P2 is the magic number for PGM ascii files. | ||
Then come the dimensions of the image and | ||
the number of levels of gray, ie 1. *) | ||
output_string oc "P2\n"; | ||
output_string oc (string_of_int column_count); | ||
output_string oc " "; | ||
output_string oc (string_of_int line_count); | ||
output_string oc "\n1\n"; | ||
(for i=0 to line_count-1 do | ||
for j=0 to column_count-1 do | ||
output_string oc (if pixels.(i).(j) then "1 " else "0 ") | ||
done; | ||
output_string oc "\n" | ||
done); | ||
close_out oc) | ||
else failwith "Bad raster" | ||
|
||
(* Write the global term t to an ascii PGM file (portable gray map), | ||
which is a format for grayscale matrices. | ||
t should be already reduced, for example by | ||
Definition t := Eval vm_compute in [some raster expression] *) | ||
let eval_and_dump_pgm (t : Libnames.qualid) = | ||
let env = Global.env () in | ||
prerr_endline "dumping to plot.pgm"; | ||
let (tg : GlobRef.t) = Constrintern.intern_reference t in | ||
let (tt : Constr.types) = fst (type_of_global_in_context env tg) in | ||
let (c : Constr.constr) = printable_constr_of_global tg in | ||
(* Delta-reduce c to unfold the name of the matrix of booleans | ||
and get its contents. *) | ||
let evalc = Reductionops.whd_delta env (Evd.from_env env) (EConstr.of_constr c) in | ||
let evalt = Reductionops.nf_all env (Evd.from_env env) (EConstr.of_constr tt) in | ||
dump_pgm (EConstr.to_constr (Evd.from_env env) evalc) | ||
(pr_econstr_env env (Evd.from_env env) evalt) | ||
|
||
} | ||
|
||
VERNAC COMMAND EXTEND DumpGrayMap CLASSIFIED AS QUERY | ||
| [ "DumpGrayMap" global(a) ] -> { eval_and_dump_pgm a } | ||
END | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Declare ML Module "dump_plugin". |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.