Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
iris
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Paolo G. Giarrusso
iris
Commits
f4db0245
Commit
f4db0245
authored
7 months ago
by
Robbert Krebbers
Browse files
Options
Downloads
Patches
Plain Diff
Better version of `ident_to_string`, also by
@lepigre
.
parent
9fdd6724
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
iris/proofmode/string_ident.v
+17
-17
17 additions, 17 deletions
iris/proofmode/string_ident.v
with
17 additions
and
17 deletions
iris/proofmode/string_ident.v
+
17
−
17
View file @
f4db0245
From
Ltac2
Require
Ltac2
.
From
Coq
Require
Import
Strings
.
String
.
From
Coq
Require
Import
Init
.
Byte
.
From
Coq
Require
Import
Init
.
Byte
Ascii
.
From
iris
.
prelude
Require
Import
options
.
Import
List
.
ListNotations
.
...
...
@@ -77,26 +77,26 @@ End StringToIdent.
Module
IdentToString
.
Import
Ltac2
.
Ltac2
char_to_coq_byte
(
c
:
char
)
:
constr
:=
let
(
ind
,
inst
)
:=
match
Constr
.
Unsafe
.
kind
constr
:(
byte
)
with
|
Constr
.
Unsafe
.
Ind
ind
inst
=>
(
ind
,
inst
)
|
_
=>
Control
.
zero
(
Invalid_argument
None
)
end
in
let
c
:=
Constr
.
Unsafe
.
constructor
ind
(
Char
.
to_int
c
)
in
Constr
.
Unsafe
.
make
(
Constr
.
Unsafe
.
Constructor
c
inst
)
.
Ltac2
get_bit
(
n
:
int
)
(
i
:
int
)
:
bool
:=
Int
.
equal
(
Int
.
land
(
Int
.
lsr
n
i
)
1
)
1
.
Ltac2
get_bit_coq_bool
(
n
:
int
)
(
i
:
int
)
:
constr
:=
if
get_bit
n
i
then
constr
:(
true
)
else
constr
:(
false
)
.
Ltac2
char_to_coq_ascii
(
c
:
char
)
:
constr
:=
let
i
:=
Char
.
to_int
c
in
let
bs
:=
Array
.
init
8
(
get_bit_coq_bool
i
)
in
Constr
.
Unsafe
.
make
(
Constr
.
Unsafe
.
App
constr
:(
Ascii
)
bs
)
.
Ltac2
string_to_coq_string
(
s
:
string
)
:
constr
:=
let
len
:=
String
.
length
s
in
let
rec
to_string
acc
i
:=
if
Int
.
equal
i
-1
then
acc
else
let
c
:=
String
.
get
s
i
in
let
byte
:=
char_to_coq_byte
c
in
let
a
:=
compute
constr
:(
Ascii
.
ascii_of_byte
$
byte
)
in
to_string
constr
:(
String
$
a
$
acc
)
(
Int
.
sub
i
1
)
let
rec
to_string
i
:=
if
Int
.
equal
i
len
then
constr
:(
EmptyString
)
else
let
tail
:=
to_string
(
Int
.
add
i
1
)
in
let
head
:=
char_to_coq_ascii
(
String
.
get
s
i
)
in
constr
:(
String
$
head
$
tail
)
in
to_string
constr
:(
EmptyString
)
(
Int
.
sub
len
1
)
.
to_string
0
.
Ltac2
ident_to_string
(
id
:
ident
)
:
constr
:=
string_to_coq_string
(
Ident
.
to_string
id
)
.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment