<commit_before>#lang typed/racket/base

(require racket/format
         racket/match
         "config.rkt"
         "util.rkt")

(provide name-in-module
         BASE-ENV)

(define-type-alias RenameMap (HashTable Symbol Symbol))

(: name-in-module (-> Symbol Symbol Symbol))
(define (name-in-module mod name)
  (match mod
    ['core (string->symbol (~a (jsruntime-core-module) "." name))]
    ['kernel (string->symbol (~a (jsruntime-kernel-module) "." name))]
    [_ (error "Invalid module name")]))

(: add-import (-> RenameMap String Symbol RenameMap))
(define (add-import env prefix id)
  (hash-set env id (string->symbol (~a prefix "." (normalize-symbol id)))))

(: add-imports* (-> RenameMap String (Listof Symbol) RenameMap))
(define (add-imports* env prefix ids*)
  (foldl (λ ([id : Symbol] [env* : RenameMap])
           (add-import env* prefix id))
         env
         ids*))

(: add-kernel-imports* (-> RenameMap (Listof Symbol) RenameMap))
(define (add-kernel-imports* env ids*)
  (add-imports* env (jsruntime-kernel-module) ids*))

(: add-core-imports* (-> RenameMap (Listof Symbol) RenameMap))
(define (add-core-imports* env ids*)
  (add-imports* env (jsruntime-core-module) ids*))

(: CORE-IMPORTS RenameMap)
(define CORE-IMPORTS
  ;; TODO: Many of these could be represented using JS operators
  (let ([build-core-env (λ ([pairs* : (Listof (Pairof Symbol Symbol))])
                          (map (λ (p*)
                                 (match-define (cons k v) p*)
                                 (cons k (string->symbol (~a (jsruntime-core-module) "." v))))
                               pairs*))])
    ((inst make-immutable-hash Symbol Symbol)
     (build-core-env
      '((* . Number.mul)
        (+ . Number.add)
        (- . Number.sub)
        (/ . Number.div)
        (< . Number.lt)
        (> . Number.gt)
        (<= . Number.lte)
        (>= . Number.gte)
        (= . Number.equal))))))
  
(: BASE-ENV (HashTable Symbol Symbol))
(define BASE-ENV (hash))
#;(define BASE-ENV
  (add-kernel-imports*
   CORE-IMPORTS
   '(zero?
     car
     cdr
     list
     first
     rest
     sub1
     add1
     displayln
     equal?
     values
     call-with-values
     not
     empty?
     print-values
     cons
     null?
     empty?
     list?

     ~a
     string-append
     display
     )))<commit_msg>Cleanup base environment setup as its no longer needed<commit_after>#lang typed/racket/base

(require racket/format
         racket/match
         "config.rkt"
         "util.rkt")

(provide name-in-module
         BASE-ENV)

(: name-in-module (-> Symbol Symbol Symbol))
(define (name-in-module mod name)
  (match mod
    ['core (string->symbol (~a (jsruntime-core-module) "." name))]
    ['kernel (string->symbol (~a (jsruntime-kernel-module) "." name))]
    [_ (error "Invalid module name")]))

(: BASE-ENV (HashTable Symbol Symbol))
(define BASE-ENV (hash))
{'fraction_non_alphanumeric': 0.156401384083045, 'fraction_numerical': 0.0006920415224913495, 'mean_word_length': 2.2852272727272727, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7349298', 'n_tokens_mistral': 969, 'n_tokens_neox': 951, 'n_words': 239}