<commit_before>(ns mikron.buffer-macro
  "`mikron.runtime.buffer` macro namespace."
  (:require [macrowbar.core :as macrowbar]
            [mikron.util :as util]
            [mikron.buffer-spec :as buffer-spec]
            [mikron.compiler.schema :as compiler.schema])
  #?(:cljs (:require-macros [mikron.buffer-macro])))

(macrowbar/emit :debug
  (defmacro with-delta
    "Executes `body` and updates the position `pos` with the delta `delta`."
    [pos delta body]
    (macrowbar/with-syms {:gen [value]}
      `(let [~value ~body]
         (set! ~pos (unchecked-add ~pos ~delta))
         ~value)))

  (defmacro with-le
    "Executes the expressions with the endianness automatically set to `le`."
    [le [method & args]]
    `(if ~le
       (~(symbol (str method "LE")) ~@args)
       (~(symbol (str method "BE")) ~@args)))

  (defn without-tag
    "Removes the `tag` metadata from `value`."
    [value]
    (assert (util/can-have-meta? value))
    (vary-meta value dissoc :tag))

  (defn without-primitive-tag
    "Removes the primitive `tag` metadata from `value`."
    [value]
    (assert (util/can-have-meta? value))
    (vary-meta value (fn [{:keys [tag] :as meta}]
                       (cond-> meta
                         (#{'long 'double} tag) (dissoc :tag)))))

  (defn with-runtime-tag
    "Takes the `tag` metadata of `value` and returns a piece of code which reapplies it to what `value` evaluates to."
    [value]
    `(if-not (util/can-have-meta? ~value)
       ~value
       (vary-meta ~value assoc :tag '~(:tag (meta value)))))

  (defmacro definterface+
    "Expands to a `definterface` call in clj, `defprotocol` call in cljs."<commit_msg>Replace assert with explicit throws<commit_after>(ns mikron.buffer-macro
  "`mikron.runtime.buffer` macro namespace."
  (:require [macrowbar.core :as macrowbar]
            [mikron.util :as util]
            [mikron.buffer-spec :as buffer-spec]
            [mikron.compiler.schema :as compiler.schema])
  #?(:cljs (:require-macros [mikron.buffer-macro])))

(macrowbar/emit :debug
  (defmacro with-delta
    "Executes `body` and updates the position `pos` with the delta `delta`."
    [pos delta body]
    (macrowbar/with-syms {:gen [value]}
      `(let [~value ~body]
         (set! ~pos (unchecked-add ~pos ~delta))
         ~value)))

  (defmacro with-le
    "Executes the expressions with the endianness automatically set to `le`."
    [le [method & args]]
    `(if ~le
       (~(symbol (str method "LE")) ~@args)
       (~(symbol (str method "BE")) ~@args)))

  (defn without-tag
    "Removes the `tag` metadata from `value`."
    [value]
    (when-not (util/can-have-meta? value)
      (throw (ex-info "Cannot apply metadata to value" {:value value})))
    (vary-meta value dissoc :tag))

  (defn without-primitive-tag
    "Removes the primitive `tag` metadata from `value`."
    [value]
    (when-not (util/can-have-meta? value)
      (throw (ex-info "Cannot apply metadata to value" {:value value})))
    (vary-meta value (fn [{:keys [tag] :as meta}]
                       (cond-> meta
                         (#{'long 'double} tag) (dissoc :tag)))))

  (defn with-runtime-tag
    "Takes the `tag` metadata of `value` and returns a piece of code which reapplies it to what `value` evaluates to."
    [value]
    `(if-not (util/can-have-meta? ~value)
       ~value
       (vary-meta ~value assoc :tag '~(:tag (meta value)))))

  (defmacro definterface+
    "Expands to a `definterface` call in clj, `defprotocol` call in cljs."
{'fraction_non_alphanumeric': 0.15085714285714286, 'fraction_numerical': 0.0, 'mean_word_length': 2.752411575562701, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, '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': '5885676', 'n_tokens_mistral': 1199, 'n_tokens_neox': 1148, 'n_words': 359}