Qcert.Compiler.Driver.CompLang


Section CompLang.







  Definition vdbindings := vdbindings.

  Context {ft:foreign_type}.
  Context {bm:brand_model}.

  Context {fr:foreign_runtime}.
  Context {fredop:foreign_reduce_op}.

  Definition rule := rule.
  Definition camp := pat.
  Definition oql := oql.
  Definition sql := sql.
  Definition lambda_nra := lnra.
  Definition nra := nra.
  Definition nraenv_core := cnraenv.
  Definition nraenv := nraenv.
  Definition nnrc_core := nnrc_core.
  Definition nnrc := nnrc.
  Definition nnrcmr := nnrcmr.
  Definition cldmr := cld_mrl.
  Definition dnnrc_dataset := dnnrc _ unit dataset.
  Definition dnnrc_typed_dataset {bm:brand_model} := dnnrc _ (type_annotation unit) dataset.
  Definition javascript := string.
  Definition java := string.
  Definition spark_rdd := string.
  Definition spark_dataset := string.
  Definition cloudant := (list (string × string) × (string × list string))%type.

  Inductive language : Set :=
    | L_rule : language
    | L_camp : language
    | L_oql : language
    | L_sql : language
    | L_lambda_nra : language
    | L_nra : language
    | L_nraenv_core : language
    | L_nraenv : language
    | L_nnrc_core : language
    | L_nnrc : language
    | L_nnrcmr : language
    | L_cldmr : language
    | L_dnnrc_dataset : language
    | L_dnnrc_typed_dataset : language
    | L_javascript : language
    | L_java : language
    | L_spark_rdd : language
    | L_spark_dataset : language
    | L_cloudant : language
    | L_error : string language.

  Lemma language_eq_dec : EqDec language eq.

  Global Instance language_eqdec : EqDec language eq := language_eq_dec.

  Inductive query : Set :=
    | Q_rule : rule query
    | Q_camp : camp query
    | Q_oql : oql query
    | Q_sql : sql query
    | Q_lambda_nra : lambda_nra query
    | Q_nra : nra query
    | Q_nraenv_core : nraenv_core query
    | Q_nraenv : nraenv query
    | Q_nnrc_core : nnrc_core query
    | Q_nnrc : nnrc query
    | Q_nnrcmr : nnrcmr query
    | Q_cldmr : cldmr query
    | Q_dnnrc_dataset : dnnrc_dataset query
    | Q_dnnrc_typed_dataset : dnnrc_typed_dataset query
    | Q_javascript : javascript query
    | Q_java : java query
    | Q_spark_rdd : spark_rdd query
    | Q_spark_dataset : spark_dataset query
    | Q_cloudant : cloudant query
    | Q_error : string query.

  Tactic Notation "query_cases" tactic(first) ident(c) :=
    first;
    [ Case_aux c "Q_rule"%string
    | Case_aux c "Q_camp"%string
    | Case_aux c "Q_oql"%string
    | Case_aux c "Q_sql"%string
    | Case_aux c "Q_lambda_nra"%string
    | Case_aux c "Q_nra"%string
    | Case_aux c "Q_nraenv_core"%string
    | Case_aux c "Q_nraenv"%string
    | Case_aux c "Q_nnrc_core"%string
    | Case_aux c "Q_nnrc"%string
    | Case_aux c "Q_nnrcmr"%string
    | Case_aux c "Q_cldmr"%string
    | Case_aux c "Q_dnnrc_dataset"%string
    | Case_aux c "Q_dnnrc_typed_dataset"%string
    | Case_aux c "Q_javascript"%string
    | Case_aux c "Q_java"%string
    | Case_aux c "Q_spark_rdd"%string
    | Case_aux c "Q_spark_dataset"%string
    | Case_aux c "Q_cloudant"%string
    | Case_aux c "Q_error"%string].

  Section CompLangUtil.

    Definition language_of_name_case_sensitive name : language:=
      match name with
      | "rule"%stringL_rule
      | "camp"%stringL_camp
      | "oql"%stringL_oql
      | "sql"%stringL_sql
      | "lambda_nra"%stringL_lambda_nra
      | "nra"%stringL_nra
      | "nraenv_core"%stringL_nraenv_core
      | "nraenv"%stringL_nraenv
      | "nnrc_core"%stringL_nnrc_core
      | "nnrc"%stringL_nnrc
      | "nnrcmr"%stringL_nnrcmr
      | "cldmr"%stringL_cldmr
      | "dnnrc"%stringL_dnnrc_dataset
      | "dnnrc_typed"%stringL_dnnrc_typed_dataset
      | "js"%string | "rhino"%string | "javascript"%stringL_javascript
      | "java"%stringL_java
      | "spark_rdd"%stringL_spark_rdd
      | "spark_dataset"%stringL_spark_dataset
      | "cloudant"%stringL_cloudant
      | "error"%stringL_error ""
      | _L_error ("'"++name++"' is not a language name")
      end.

    Definition name_of_language lang :=
      match lang with
      | L_rule ⇒ "rule"%string
      | L_camp ⇒ "camp"%string
      | L_oql ⇒ "oql"%string
      | L_sql ⇒ "sql"%string
      | L_lambda_nra ⇒ "lambda_nra"%string
      | L_nra ⇒ "nra"%string
      | L_nraenv_core ⇒ "nraenv_core"%string
      | L_nraenv ⇒ "nraenv"%string
      | L_nnrc_core ⇒ "nnrc_core"%string
      | L_nnrc ⇒ "nnrc"%string
      | L_nnrcmr ⇒ "nnrcmr"%string
      | L_cldmr ⇒ "cldmr"%string
      | L_dnnrc_dataset ⇒ "dnnrc"%string
      | L_dnnrc_typed_dataset ⇒ "dnnrc_typed"%string
      | L_javascript ⇒ "js"%string
      | L_java ⇒ "java"%string
      | L_spark_rdd ⇒ "spark_rdd"%string
      | L_spark_dataset ⇒ "spark_dataset"%string
      | L_cloudant ⇒ "cloudant"%string
      | L_error _ ⇒ "error"%string
      end.

    Definition language_of_query q :=
      match q with
      | Q_rule _L_rule
      | Q_camp _L_camp
      | Q_oql _L_oql
      | Q_sql _L_sql
      | Q_lambda_nra _L_lambda_nra
      | Q_nra _L_nra
      | Q_nraenv_core _L_nraenv_core
      | Q_nraenv _L_nraenv
      | Q_nnrc_core _L_nnrc_core
      | Q_nnrc _L_nnrc
      | Q_nnrcmr _L_nnrcmr
      | Q_cldmr _L_cldmr
      | Q_dnnrc_dataset _L_dnnrc_dataset
      | Q_dnnrc_typed_dataset _L_dnnrc_typed_dataset
      | Q_javascript _L_javascript
      | Q_java _L_java
      | Q_spark_rdd _L_spark_rdd
      | Q_spark_dataset _L_spark_dataset
      | Q_cloudant _L_cloudant
      | Q_error err
        L_error ("No language corresponding to error query '"++err++"'")
      end.

    Definition name_of_query q :=
      name_of_language (language_of_query q).

    Definition lang_desc : Set := (language × string).

    Inductive language_kind : Set :=
    | FrontEnd : language_kind
    | MiddleEnd : language_kind
    | BackEnd : language_kind.

    Lemma language_kind_eq_dec : EqDec language_kind eq.

    Global Instance language_kind_eqdec : EqDec language_kind eq := language_kind_eq_dec.

    Definition language_descriptions :=
      (L_rule,FrontEnd,"Rule","Rules for CAMP")
      :: (L_camp,MiddleEnd,"CAMP","Calculus of Aggregating Matching Patterns")
      :: (L_oql,FrontEnd,"OQL", "Object Query Language")
      :: (L_sql,FrontEnd,"SQL", "Structured Query Language")
      :: (L_lambda_nra,FrontEnd,"λNRA", "Lambda Nested Relational Algebra")
      :: (L_nra,MiddleEnd,"NRA","Nested Relational Algebra")
      :: (L_nraenv_core,MiddleEnd,"cNRAᵉ","Core Nested Relational Algebra with Environments")
      :: (L_nraenv,MiddleEnd,"NRAᵉ","Nested Relational Algebra with Environments")
      :: (L_nnrc_core,MiddleEnd,"cNNRC", "Core Named Nested Relational Calculus")
      :: (L_nnrc,MiddleEnd,"NNRC", "Named Nested Relational Calculus")
      :: (L_nnrcmr,MiddleEnd,"NNRCMR", "Named Nested Relational Calculus with Map/Reduce")
      :: (L_cldmr,MiddleEnd,"CldMR", "Nested Relational Calculus with Cloudant Map/Reduce")
      :: (L_dnnrc_dataset,MiddleEnd,"DNNRC","Distributed Named Nested Relational Calculus")
      :: (L_dnnrc_typed_dataset,MiddleEnd,"tDNNRC","Typed Distributed Named Nested Relational Calculus")
      :: (L_javascript,BackEnd,"JS","JavaScript")
      :: (L_java,BackEnd,"Java","Java")
      :: (L_spark_rdd,BackEnd,"Spark","Spark (RDDs)")
      :: (L_spark_dataset,BackEnd,"Spark2", "Spark (Datasets)")
      :: (L_cloudant,BackEnd,"Cloudant","Cloudant Map/Reduce Views")

      :: nil.

    Definition add_id_to_language_description (ld:language × language_kind × string × string) :=
      match ld with
      | (lang,kind,label,desc)
        (lang,name_of_language lang,kind,label,desc)
      end.

    Definition language_descriptions_with_ids :=
      map add_id_to_language_description language_descriptions.


    Definition check_kind (the_kind:language_kind)
               (ld:language × string × language_kind × string × string)
      :=
      match ld with
      | (lang,id,kind,label,desc)
        if (language_kind_eq_dec kind the_kind) then true else false
      end.

    Record export_desc :=
      mkExportDesc
      { frontend : list(language × string × language_kind × string × string);
        middleend : list(language × string × language_kind × string × string);
        backend : list(language × string × language_kind × string × string) }.

    Definition select_description_per_kind
               (ldl: list(language × string × language_kind × string × string)) :=
      mkExportDesc
        (filter (check_kind FrontEnd) ldl)
        (filter (check_kind MiddleEnd) ldl)
        (filter (check_kind BackEnd) ldl).


    Definition export_language_descriptions : export_desc :=
      select_description_per_kind language_descriptions_with_ids.

    Definition type_of_language (l:language) : Set :=
      match l with
      | L_rulerule
      | L_campcamp
      | L_oqloql
      | L_sqlsql
      | L_lambda_nralnra
      | L_nranra
      | L_nraenv_corenraenv_core
      | L_nraenvnraenv
      | L_nnrc_corennrc_core
      | L_nnrcnnrc
      | L_nnrcmrnnrcmr
      | L_cldmrcldmr
      | L_dnnrc_datasetdnnrc_dataset
      | L_dnnrc_typed_datasetdnnrc_typed_dataset
      | L_javascriptjavascript
      | L_javajava
      | L_spark_rddspark_rdd
      | L_spark_datasetspark_dataset
      | L_cloudantcloudant
      | L_error _string
      end.
  End CompLangUtil.

End CompLang.

Tactic Notation "language_cases" tactic(first) ident(c) :=
  first;
  [ Case_aux c "L_rule"%string
  | Case_aux c "L_camp"%string
  | Case_aux c "L_oql"%string
  | Case_aux c "L_sql"%string
  | Case_aux c "L_lambda_nra"%string
  | Case_aux c "L_nra"%string
  | Case_aux c "L_nraenv_core"%string
  | Case_aux c "L_nraenv"%string
  | Case_aux c "L_nnrc_core"%string
  | Case_aux c "L_nnrc"%string
  | Case_aux c "L_nnrcmr"%string
  | Case_aux c "L_cldmr"%string
  | Case_aux c "L_dnnrc_dataset"%string
  | Case_aux c "L_dnnrc_typed_dataset"%string
  | Case_aux c "L_javascript"%string
  | Case_aux c "L_java"%string
  | Case_aux c "L_spark_rdd"%string
  | Case_aux c "L_spark_dataset"%string
  | Case_aux c "L_cloudant"%string
  | Case_aux c "L_error"%string].