Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create FmcToCoq.js #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions FmcToCoq.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const fmc = require("./FormCore.js");

// Coq (simplified) Abstract Syntax
// ====

// Coq variables
const CoqVar = (name, indx) => ({ ctor: "Var", name, indx });
// Coq references to defined objects
const CoqRef = (name) => ({ ctor: "Ref", name });
// Coq "Type"
const CoqTyp = () => ({ ctor: "Typ" });
// Coq dependent products
const CoqAll = (name, bind, body) => ({ ctor: "All", name, bind, body });
// Coq lambdas
const CoqLam = (name, body) => ({ ctor: "Lam", name, body });
// Coq applications
const CoqApp = (func, argm) => ({ ctor: "App", func, argm });
// Coq let-bindings
const CoqLet = (name, expr, body) => ({ ctor: "Let", name, expr, body });
// Coq definitions
const CoqDef = (name, expr, body) => ({ ctor: "Def", name, expr, body });
// Coq Theorems
const CoqThm = (name, stmt, proof) => ({ ctor: "Thm", name, stmt, proof });

/**
* Compiler from Core to Coq.
*
* This compiler can't be complete for theoretical reasons:
* it tries to generate Coq code from Core but might
* fail or generate Coq code that is going to be rejected
* by the Coq compiler.
*
* @param {*} fmc_ast Core code
* @param {*} name name of the source
* @param {*} opts options
*/
let compile_defs = (fmc_ast, name, opts) => {
throw "Not implemented";
}

let compile = (fmc_code, name, opts) => {
compile_defs(fmc.parse_defs(fmc_code), name, opts)
}

module.exports = { compile, compile_defs };
1 change: 1 addition & 0 deletions libs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ module.exports = {
fmc: require("./FormCore.js"),
fmc_to_js: require("./FmcToJs"),
fmc_to_hs: require("./FmcToHs"),
fmc_to_coq: require("./FmcToCoq"),
};