<commit_before>;;;; Cyclone Scheme
;;;; https://github.com/justinethier/cyclone
;;;;
;;;; Copyright (c) 2014-2016, <NAME>
;;;; All rights reserved.
;;;;
;;;; This module implements r7rs libraries. In our compiler, these are used to
;;;; encapsulate C modules.
;;;;
;;;; Initially, this a quicky-and-dirty (for now) implementation of r7rs libraries.
;;;;
;;;; TODO: go through functions and ensure consistent naming conventions.
;;;;   probably should also clean up some of the function names, this is
;;;;   not a very clean or nice API at the moment.
;;;;
(define-library (scheme cyclone libraries)
  (import (scheme base)
          (scheme read)
          (scheme cyclone util)
  )
  (export
    library?
    lib:list->import-set
    lib:name
    lib:name->string
    lib:name->symbol
    lib:result
    lib:exports
    lib:rename-exports
    lib:imports
    lib:body
    lib:includes
    lib:include-c-headers
    lib:import->filename
    lib:import->metalist
    lib:import->path
    lib:read-imports
    lib:import->export-list
    lib:resolve-imports
    lib:resolve-meta
    lib:get-all
    lib:get-all-import-deps
    lib:get-dep-list
    lib:imports->idb
    lib:idb:ids
    lib:idb:id->import
  )
  (begin
  ;  (define read cyc-read)

(define (library? ast)
  (tagged-list? 'define-library ast))

;; Convert a raw list to an import set. For example, a list might be
;; (srfi 18) containing the number 18. An import set contains only symbols.
(define (lib:list->import-set lis)
  (map
    (lambda (atom)
      (cond
        ((number? atom)
         (string->symbol (number->string atom)))
        (else atom)))
    lis))

(define (lib:name ast) 
  (lib:list->import-set (cadr ast)))

;; Convert name (as list of symbols) to a mangled string
(define (lib:name->string name)
  (apply string-append (map mangle name)))

;; Convert library name to a unique symbol
(define (lib:name->symbol name)
  (string->symbol 
    (string-append
      "lib-init:" ;; Maybe make this an optional param? Trying to ensure uniqueness
      (lib:name->string name))))

;; Helper function that returns an empty list as a default value
(define (lib:result result)
  (if result result '()))

;; TODO: most of these below assume 0 or 1 instances of the directive.
;; may need to replace some of these later with filter operations to
;; support more than 1 instance.

;; Get all instances of given tagged list from a library definition,
;; and collect the contents of them into a single list.
(define (lib:get-all ast tag)
  (foldr append '()
    (map cdr 
      (filter (lambda (l) (tagged-list? 'import l)) (cddr ast)))))

(define (lib:raw-exports ast)
  (lib:result 
    (let ((code (assoc 'export (cddr ast))))
      (if code (cdr code) #f))))
(define (lib:rename-exports ast)
  (filter
    (lambda (ex)
      (tagged-list? 'rename ex))
    (lib:raw-exports ast)))
(define (lib:exports ast)
  (map<commit_msg>Remove hardcoded tag<commit_after>;;;; Cyclone Scheme
;;;; https://github.com/justinethier/cyclone
;;;;
;;;; Copyright (c) 2014-2016, <NAME>
;;;; All rights reserved.
;;;;
;;;; This module implements r7rs libraries. In our compiler, these are used to
;;;; encapsulate C modules.
;;;;
;;;; Initially, this a quicky-and-dirty (for now) implementation of r7rs libraries.
;;;;
;;;; TODO: go through functions and ensure consistent naming conventions.
;;;;   probably should also clean up some of the function names, this is
;;;;   not a very clean or nice API at the moment.
;;;;
(define-library (scheme cyclone libraries)
  (import (scheme base)
          (scheme read)
          (scheme cyclone util)
  )
  (export
    library?
    lib:list->import-set
    lib:name
    lib:name->string
    lib:name->symbol
    lib:result
    lib:exports
    lib:rename-exports
    lib:imports
    lib:body
    lib:includes
    lib:include-c-headers
    lib:import->filename
    lib:import->metalist
    lib:import->path
    lib:read-imports
    lib:import->export-list
    lib:resolve-imports
    lib:resolve-meta
    lib:get-all
    lib:get-all-import-deps
    lib:get-dep-list
    lib:imports->idb
    lib:idb:ids
    lib:idb:id->import
  )
  (begin
  ;  (define read cyc-read)

(define (library? ast)
  (tagged-list? 'define-library ast))

;; Convert a raw list to an import set. For example, a list might be
;; (srfi 18) containing the number 18. An import set contains only symbols.
(define (lib:list->import-set lis)
  (map
    (lambda (atom)
      (cond
        ((number? atom)
         (string->symbol (number->string atom)))
        (else atom)))
    lis))

(define (lib:name ast) 
  (lib:list->import-set (cadr ast)))

;; Convert name (as list of symbols) to a mangled string
(define (lib:name->string name)
  (apply string-append (map mangle name)))

;; Convert library name to a unique symbol
(define (lib:name->symbol name)
  (string->symbol 
    (string-append
      "lib-init:" ;; Maybe make this an optional param? Trying to ensure uniqueness
      (lib:name->string name))))

;; Helper function that returns an empty list as a default value
(define (lib:result result)
  (if result result '()))

;; TODO: most of these below assume 0 or 1 instances of the directive.
;; may need to replace some of these later with filter operations to
;; support more than 1 instance.

;; Get all instances of given tagged list from a library definition,
;; and collect the contents of them into a single list.
(define (lib:get-all ast tag)
  (foldr append '()
    (map cdr 
      (filter (lambda (l) (tagged-list? tag l)) (cddr ast)))))

(define (lib:raw-exports ast)
  (lib:result 
    (let ((code (assoc 'export (cddr ast))))
      (if code (cdr code) #f))))
(define (lib:rename-exports ast)
  (filter
    (lambda (ex)
      (tagged-list? 'rename ex))
    (lib:raw-exports ast)))
(define (lib:exports ast)
  (map
{'fraction_non_alphanumeric': 0.13097497842968076, 'fraction_numerical': 0.005867126833477136, 'mean_word_length': 3.296515937731653, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 39, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1755298', 'n_tokens_mistral': 1878, 'n_tokens_neox': 1784, 'n_words': 639}