Skip to content

Commit 5edcf14

Browse files
committed
AOT clojure.string
1 parent dc5dd2e commit 5edcf14

File tree

3 files changed

+1421
-24
lines changed

3 files changed

+1421
-24
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ generate:
5555

5656
.PHONY: aot
5757
aot: gocmd $(STDLIB_TARGETS)
58-
@echo "(map compile '[clojure.core clojure.core.async clojure.walk clojure.template clojure.uuid glojure.go.types glojure.go.io])" | \
58+
@echo "(map compile '[clojure.core clojure.core.async clojure.walk clojure.string clojure.template clojure.uuid glojure.go.types glojure.go.io])" | \
5959
GLOJURE_USE_AOT=false GLOJURE_STDLIB_PATH=./pkg/stdlib $(GO_CMD) run -tags glj_no_aot_stdlib ./cmd/glj
6060

6161
.PHONY: build

pkg/stdlib/clojure/string.glj

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@
99
(ns clojure.string
1010
(:refer-clojure :exclude (replace reverse))
1111
(:import (regexp *Regexp)
12-
(github.com:glojurelang:glojure:pkg:lang ToString NewIllegalArgumentError Char CharAt)))
12+
#_(github.com:glojurelang:glojure:pkg:lang ToString NewIllegalArgumentError Char CharAt)
13+
(github.com:glojurelang:glojure:pkg:lang)))
1314

1415
(set! *warn-on-reflection* true)
1516

1617
(defn- check-string
1718
[maybe-s]
1819
(if (nil? maybe-s)
19-
(throw (NewIllegalArgumentError "cannot call clojure.string function on nil"))
20+
(throw (github.com:glojurelang:glojure:pkg:lang.NewIllegalArgumentError "cannot call clojure.string function on nil"))
2021
maybe-s))
2122

2223
(defn ^go/string reverse
@@ -45,7 +46,7 @@
4546
(do (.appendReplacement m buffer (re-quote-replacement (f (re-groups m))))
4647
(recur (.find m)))
4748
(do (.appendTail m buffer)
48-
(ToString buffer)))))
49+
(github.com:glojurelang:glojure:pkg:lang.ToString buffer)))))
4950
s)))
5051

5152
(defn ^go/string replace
@@ -76,12 +77,12 @@
7677
[^go/string s match replacement]
7778
(let [s (check-string s)]
7879
(cond
79-
(instance? Char match) (strings.ReplaceAll s match replacement)
80+
(instance? github.com:glojurelang:glojure:pkg:lang.Char match) (strings.ReplaceAll s match replacement)
8081
(instance? go/string match) (strings.ReplaceAll s match replacement)
8182
(instance? *Regexp match) (if (instance? go/string replacement)
8283
(.replaceAllString ^*Regexp match s replacement)
8384
(replace-by s match replacement))
84-
:else (throw (NewIllegalArgumentError (str "Invalid match arg: " match))))))
85+
:else (throw (github.com:glojurelang:glojure:pkg:lang.NewIllegalArgumentError (str "Invalid match arg: " match))))))
8586

8687
(defn- replace-first-by
8788
[^go/string s ^*Regexp re f]
@@ -95,16 +96,16 @@
9596
s)))
9697

9798
(defn- replace-first-char
98-
[^go/string s ^Char match replace]
99-
(let [s (ToString s)
99+
[^go/string s ^github.com:glojurelang:glojure:pkg:lang.Char match replace]
100+
(let [s (github.com:glojurelang:glojure:pkg:lang.ToString s)
100101
i (strings.Index s (int match))]
101102
(if (= -1 i)
102103
s
103104
(str (subs s 0 i) replace (subs s (inc i))))))
104105

105106
(defn- replace-first-str
106107
[^go/string s ^go/string match ^go/string replace]
107-
(let [^go/string s (ToString s)
108+
(let [^go/string s (github.com:glojurelang:glojure:pkg:lang.ToString s)
108109
i (strings.Index s match)]
109110
(if (= -1 i)
110111
s
@@ -139,11 +140,11 @@
139140
[^go/string s match replacement]
140141
(let [s (check-string s)]
141142
(cond
142-
(instance? Char match)
143+
(instance? github.com:glojurelang:glojure:pkg:lang.Char match)
143144
(replace-first-char s match replacement)
144145
(instance? go/string match)
145-
(replace-first-str s (ToString ^go/string match)
146-
(ToString ^go/string replacement))
146+
(replace-first-str s (github.com:glojurelang:glojure:pkg:lang.ToString ^go/string match)
147+
(github.com:glojurelang:glojure:pkg:lang.ToString ^go/string replacement))
147148
(instance? *Regexp match)
148149
(if (instance? go/string replacement)
149150
(let [done (atom false)]
@@ -155,7 +156,7 @@
155156
(reset! done true)
156157
(.ReplaceAllString ^*Regexp match m replacement))))))
157158
(replace-first-by s match replacement))
158-
:else (throw (NewIllegalArgumentError (str "Invalid match arg: " match))))))
159+
:else (throw (github.com:glojurelang:glojure:pkg:lang.NewIllegalArgumentError (str "Invalid match arg: " match))))))
159160

160161

161162
(defn ^go/string join
@@ -195,16 +196,17 @@
195196
the maximum number of parts. Not lazy. Returns vector of the parts.
196197
Trailing empty strings are not returned - pass limit of -1 to return all."
197198
{:added "1.2"}
198-
([^go/string s ^*Regexp re]
199+
([^go/string s ^regexp.*Regexp re]
199200
(github.com:glojurelang:glojure:pkg:lang.CreateOwningLazilyPersistentVector (.split re s -1)))
200-
([ ^go/string s ^*Regexp re limit]
201+
([ ^go/string s ^regexp.*Regexp re limit]
201202
(github.com:glojurelang:glojure:pkg:lang.CreateOwningLazilyPersistentVector (.split re s limit))))
202203

203204
(defn split-lines
204205
"Splits s on \\n or \\r\\n. Trailing empty lines are not returned."
205206
{:added "1.2"}
206207
[^go/string s]
207-
(split s #"\r?\n"))
208+
#_(split s #"\r?\n")
209+
(split s (re-pattern "\\r?\\n")))
208210

209211
(defn ^go/string trim
210212
"Removes whitespace from both ends of string."
@@ -239,7 +241,7 @@
239241
(loop [index (int 0)]
240242
(if (= (count s) index)
241243
true
242-
(if (unicode.IsSpace (CharAt s index))
244+
(if (unicode.IsSpace (github.com:glojurelang:glojure:pkg:lang.CharAt s index))
243245
(recur (inc index))
244246
false)))
245247
true))
@@ -263,8 +265,8 @@
263265
([^go/string s value]
264266
(let [s (check-string s)
265267
result ^long
266-
(if (instance? Char value)
267-
(strings.IndexRune s ^go/rune (go/rune ^Char value))
268+
(if (instance? github.com:glojurelang:glojure:pkg:lang.Char value)
269+
(strings.IndexRune s ^go/rune (go/rune ^github.com:glojurelang:glojure:pkg:lang.Char value))
268270
(strings.Index s ^go/string value))]
269271
(if (= result -1)
270272
nil
@@ -273,8 +275,8 @@
273275
(let [from-index (min (count s) (max 0 (unchecked-int from-index)))
274276
s (subs (check-string s) from-index)
275277
result ^long
276-
(if (instance? Char value)
277-
(strings.IndexRune s ^go/rune (go/rune ^Char value))
278+
(if (instance? github.com:glojurelang:glojure:pkg:lang.Char value)
279+
(strings.IndexRune s ^go/rune (go/rune ^github.com:glojurelang:glojure:pkg:lang.Char value))
278280
(strings.Index s ^go/string value))]
279281
(if (= result -1)
280282
nil
@@ -302,16 +304,16 @@
302304
"True if s starts with substr."
303305
{:added "1.8"}
304306
[^go/string s ^go/string substr]
305-
(strings.HasPrefix (ToString s) substr))
307+
(strings.HasPrefix (github.com:glojurelang:glojure:pkg:lang.ToString s) substr))
306308

307309
(defn ends-with?
308310
"True if s ends with substr."
309311
{:added "1.8"}
310312
[^go/string s ^go/string substr]
311-
(strings.HasSuffix (ToString s) substr))
313+
(strings.HasSuffix (github.com:glojurelang:glojure:pkg:lang.ToString s) substr))
312314

313315
(defn includes?
314316
"True if s includes substr."
315317
{:added "1.8"}
316318
[^go/string s ^go/string substr]
317-
(strings.Contains (ToString s) substr))
319+
(strings.Contains (github.com:glojurelang:glojure:pkg:lang.ToString s) substr))

0 commit comments

Comments
 (0)