diff options
Diffstat (limited to 'rego-proofs/compiler/passes/extract-identifiers.scm')
| -rw-r--r-- | rego-proofs/compiler/passes/extract-identifiers.scm | 82 |
1 files changed, 0 insertions, 82 deletions
diff --git a/rego-proofs/compiler/passes/extract-identifiers.scm b/rego-proofs/compiler/passes/extract-identifiers.scm deleted file mode 100644 index af8694b..0000000 --- a/rego-proofs/compiler/passes/extract-identifiers.scm +++ /dev/null @@ -1,82 +0,0 @@ -;;; Copyright © 2023 Jakob L. Kreuze <zerodaysfordays@sdf.org> -;;; -;;; This program is free software; you can redistribute it and/or -;;; modify it under the terms of the GNU General Public License as -;;; published by the Free Software Foundation; either version 3 of the -;;; License, or (at your option) any later version. -;;; -;;; This program is distributed in the hope that it will be useful, -;;; but WITHOUT ANY WARRANTY; without even the implied warranty of -;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -;;; General Public License for more details. -;;; -;;; You should have received a copy of the GNU General Public License -;;; along with this program. If not, see -;;; <http://www.gnu.org/licenses/>. - -(define-module (compiler passes extract-identifiers) - #:use-module ((rnrs base) #:select (assert)) - #:use-module (compiler types) - #:use-module (compiler utilities) - #:use-module (compiler lean) - #:use-module (ice-9 match) - #:use-module (ice-9 regex) - #:use-module (lens) - #:use-module (oop goops) - #:use-module (srfi srfi-1) - #:use-module (srfi srfi-26) - #:use-module (srfi srfi-69) - #:export (add-rules-to-scope)) - -(define (identify-variables policy) - ;; TODO: Document me! - (define new-scope (make <scope> #:identifiers (make-hash-table))) - ;; Identify identifiers at terminals by observing rule heads. - (for-each - (lambda (rule-group) - (for-each - (lambda (rule i) - (let* ((breadcrumb `(,(name (head rule)) ,i)) - (lhs (left (head rule))) - (rhs (right (head rule)))) - (match `(,lhs ,rhs) - ((($ <reference> (($ <variable-ref> identifier-left))) - ($ <reference> (($ <variable-ref> identifier)))) - (add-to-scope new-scope breadcrumb (variable-ref->local (first (inner rhs)))) - (let ((local (make <local> - #:identifier (first (inner lhs)) - #:lean-name (first (inner lhs)) - #:constraints - `((== ,(canonicalize identifier-left breadcrumb) - ,(canonicalize identifier breadcrumb)))))) - (add-to-scope new-scope breadcrumb local))) - ;; Deprecated form? - ((($ <reference> (($ <variable-ref> identifier-left))) - ($ <variable-ref> identifier)) - (add-to-scope new-scope breadcrumb (variable-ref->local rhs)) - (let ((local (make <local> - #:identifier (first (inner lhs)) - #:lean-name (first (inner lhs)) - #:constraints - `((== ,(canonicalize identifier-left breadcrumb) - ,(canonicalize identifier breadcrumb)))))) - (add-to-scope new-scope breadcrumb local))) - ((($ <reference> (($ <variable-ref> identifier))) - ($ <constant> value)) - (let ((local (make <local> - #:identifier (first (inner lhs)) - #:lean-name (first (inner lhs)) - #:constraints - `((== ,(canonicalize identifier breadcrumb) - ,(scheme-value->type value)))))) - (add-to-scope new-scope breadcrumb local))) - (_ #f ;; TODO: Type inference should work on object keys as well. - )))) - (cdr rule-group) - (iota (length (cdr rule-group))))) - (rules policy)) - new-scope) - -(define (add-rules-to-scope policy) - ;; TODO: Document me! - (over (ι-policy-scope) (lambda (_) (identify-variables policy)) policy)) |