Fil-C on Nix

Filnix wiki

the formal campaign

rocq/backend/Nfb.v

NFB (docs/nfb.md) for the modules of Syntax.v: encode writes a module's words and decode reads them back, in place of the term the Prolog compiler prints and Transport.v's decode_module reads.

A module of Syntax.v is written as the term ir.pl would print for it (enc_module, from IrTerm.v's encoders of instructions), and that term as words by NfbTerm.v. A function outside the core subset is already its term (IOutside), so it is written the same way. Reading is the converse: NfbTerm.v's reader gives the module term, decode_module the module, and the words are taken only if they are what encode writes for that module.

From Stdlib Require Import String ZArith List Bool
From Nanofil Require Import Term Syntax Validate Transport Cfg
From Backend Require Import IrTerm NfbTerm
Import ListNotations
Open Scope string_scope
Open Scope list_scope
Open Scope Z_scope

A module as its term

As ir.pl writes a data object's Linkage.

24Definition enc_linkagelk : linkage : term ≔
match lk with
⇒
TAtom"export"
⇒
TAtom"local"
⇒
TAtom"weak"
⇒
TApp"ro" l
⇒
TApp"tls" l
⇒
TApp"init" w; p
⇒
TApp"extern" TAtom"weak"
⇒
t

As ir.pl writes a data item; a string's bytes as the term reader makes their characters.

38Definition enc_data_itemit : data_item : term ≔
match it with
Itemw n
⇒
TApp"item" enc_widthw; TApp"const" TIntn
Strcodes
⇒
TApp"item" TAtom"b"; TApp"str" TListmapcode_char codes
Syms off
⇒
TApp"item" TAtom"p"; TApp"sym" s; TIntoff
⇒
TApp"zero" TIntn

As ir.pl writes a function's Ret.

48Definition enc_retr : ret_type : term ≔
match r with
⇒
TAtom"void"
⇒
TApp"tuple" TListmapeclass ks

As ir.pl writes a block.

56Definition enc_blockb : block : term ≔

As ir.pl writes a function.

61Definition enc_funcf : func : term ≔
TApp"func" fn_namef; fn_linkagef; enc_retfn_retf; TListmapλp ⇒ TApp"param" eclassfstp; TApp"tmp" sndp fn_paramsf; TListmapenc_block fn_blocksf

As ir.pl writes an item; a function outside the core subset is its term.

68Definition enc_itemit : item : term ≔
match it with
⇒
t
IDatan lk al its
⇒
TApp"data" n; enc_linkagelk; TIntal; TListmapenc_data_item its
IAliasn lk tg
⇒
TApp"alias" n; lk; tg

The module as the term module(Items).

77Definition enc_modulem : module : term ≔
TApp"module" TListmapenc_item m

Words

The NFB of the module m, with its NAMES section when names is true; none for a module that has no encoding, such as one whose symbol is not an atom.

84Definition encode_withnames : bool m : module : optionlistZ ≔

The NFB of the module m, NAMES included.

88Definition encodem : module : optionlistZ ≔

The module the NFB ws encode: the words must be what encode_with writes for it, NAMES if ws have it, CONTEXT and tools' sections aside.

93Definition decodews : listZ : optionmodule ≔
let* p ≔ read_termws in
let* m ≔ decode_modulefstp in
let* ws1 ≔ encode_withsndp m in
let* ws2 ≔ module_wordsws in
words_eqbws1 ws2
→
Somem
else
None