summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLlewellyn Pritchard <xacc.ide@gmail.com>2024-02-02 19:22:48 +0200
committerLlewellyn Pritchard <xacc.ide@gmail.com>2024-02-02 19:22:48 +0200
commit7efb2f6aeeea12e5053e8d22e197e033564d9d05 (patch)
treee2f9e422ee10ed8122d3368cff9bbd709b0221e7
parent311b8dfd893b38d9234651cf71893e4b0fafdfe2 (diff)
parenta45354abd4741242705278642c062812dc011f71 (diff)
Merge remote-tracking branch 'origin/master'1.0.331
-rw-r--r--IronScheme/IronScheme.Console/build/base.sls8
-rw-r--r--IronScheme/IronScheme.Console/lib/ironscheme/async.sls68
-rw-r--r--IronScheme/IronScheme.Console/lib/ironscheme/regex.sls4
-rw-r--r--README.md2
4 files changed, 73 insertions, 9 deletions
diff --git a/IronScheme/IronScheme.Console/build/base.sls b/IronScheme/IronScheme.Console/build/base.sls
index b4cdfbfb..4ea3602c 100644
--- a/IronScheme/IronScheme.Console/build/base.sls
+++ b/IronScheme/IronScheme.Console/build/base.sls
@@ -330,22 +330,20 @@ See docs/license.txt. |#
(unless (and (fixnum? k) ($fx>=? k 0))
(assertion-violation 'string-set! "not a non-negative integer" k))
(unless (char? val)
- (assertion-violation 'string-fill! "not a character" val))
+ (assertion-violation 'string-set! "not a character" val))
(if (clr-is Char val)
(clr-prop-set! StringBuilder Chars str k val)
(begin
(clr-call StringBuilder Remove str k 1)
(clr-call StringBuilder (Insert Int32 String) str k (clr-call Object ToString val)))))
- (define (string-fill! str k fill)
+ (define (string-fill! str fill)
(unless (stringbuilder? str)
(assertion-violation 'string-fill! "not a mutable string" str))
- (unless (and (fixnum? k) ($fx>=? k 0))
- (assertion-violation 'string-fill! "not a non-negative integer" k))
(unless (char? fill)
(assertion-violation 'string-fill! "not a character" fill))
(let: (((str : StringBuilder) str)
- ((k : Int32) k)
+ ((k : Int32) (string-length str))
((fill : Char) fill))
(let f ((i 0))
(unless ($fx=? i k)
diff --git a/IronScheme/IronScheme.Console/lib/ironscheme/async.sls b/IronScheme/IronScheme.Console/lib/ironscheme/async.sls
new file mode 100644
index 00000000..783b20a1
--- /dev/null
+++ b/IronScheme/IronScheme.Console/lib/ironscheme/async.sls
@@ -0,0 +1,68 @@
+#| License
+Copyright (c) 2022 Robby Zambito
+All rights reserved.
+This source code is subject to terms and conditions of the BSD License.
+See docs/license.txt. |#
+
+(library (ironscheme async)
+ (export async-lambda
+ await
+ define-async
+ start
+ started?
+ status
+ task?)
+ (import (ironscheme)
+ (ironscheme clr)
+ (ironscheme clr dynamic))
+
+ (clr-using System.Threading.Tasks)
+ (clr-using System.Runtime.CompilerServices)
+
+ (define-syntax define-async
+ (syntax-rules (->)
+ ((_ (name params ...) -> ret-type body1 body2 ...)
+ (define name
+ (async-lambda (params ...) -> ret-type
+ body1
+ body2 ...)))
+ ((_ (name params ...) body1 body2 ...)
+ (define name
+ (async-lambda (params ...)
+ body1
+ body2 ...)))))
+
+ (define (started? task)
+ ;; Created is the only status where it has not yet been started.
+ (not (equal? (status task) 'Created)))
+
+ (define (status task)
+ (clr-prop-get Task Status task))
+
+ ;; Construct a Task
+ (define-syntax async-lambda
+ (syntax-rules (->)
+ ((_ (params ...) -> ret-type body1 body2 ...)
+ (lambda (params ...)
+ (clr-new (System.Threading.Tasks.Task ret-type)
+ (lambda ()
+ body1
+ body2 ...))))
+ ((_ (params ...) body1 body2 ...)
+ (async-lambda (params ...) -> Object body1 body2 ...))))
+
+ ;; Await the task and return the result.
+ (define (await task)
+ (start task)
+ (let ((awaiter (clr-dynamic task GetAwaiter)))
+ (clr-dynamic awaiter GetResult)))
+
+ ;; Can be called any number of times without error, unlike Task.Start()
+ ;; Returns the started task.
+ (define (start task)
+ (unless (started? task)
+ (clr-call Task Start task))
+ task)
+
+ (define (task? obj)
+ (clr-is Task obj)))
diff --git a/IronScheme/IronScheme.Console/lib/ironscheme/regex.sls b/IronScheme/IronScheme.Console/lib/ironscheme/regex.sls
index c7777f9d..81489781 100644
--- a/IronScheme/IronScheme.Console/lib/ironscheme/regex.sls
+++ b/IronScheme/IronScheme.Console/lib/ironscheme/regex.sls
@@ -10,6 +10,7 @@ See docs/license.txt. |#
make-regex
group-value
match-group
+ (rename (group-value match-value))
group-success?
regex-match
regex-matches
@@ -81,8 +82,6 @@ See docs/license.txt. |#
(clr-indexer-get GroupCollection
(clr-prop-get Match Groups match)
(clr-cast String group-name)))
-
-
(define/contract (regex-split input:string pattern/re)
(if (regex? pattern/re)
@@ -103,4 +102,3 @@ See docs/license.txt. |#
(define/contract (regex-unescape input:string)
(clr-static-call Regex Unescape input)))
- \ No newline at end of file
diff --git a/README.md b/README.md
index 33fe15ab..5b8945c2 100644
--- a/README.md
+++ b/README.md
@@ -49,7 +49,7 @@ IronScheme.ConsoleCore.exe --roll-forward LatestMajor <args...>
```
Running on Linux/MacOS
-======================
+=======================
The preferred way to run on non-Windows OS is to use .NET Core. You can also run IronScheme on Mono, but your mileage may vary.