Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion TeXmacs/plugins/goldfish/goldfish/liii/hash-table.scm
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
hash-table-size hash-table-keys hash-table-values hash-table-entries
hash-table-find hash-table-count hash-table-fold
hash-table-for-each hash-table-map->list
hash-table->alist
hash-table->alist hash-table-copy
)
(begin
) ; end of begin
Expand Down
7 changes: 6 additions & 1 deletion TeXmacs/plugins/goldfish/goldfish/liii/hashlib.scm
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@
; under the License.
;
(define-library (liii hashlib)
(export md5 sha1 sha256)
(export md5 sha1 sha256
md5-by-file sha1-by-file sha256-by-file)
(begin

(define (md5 str) (g_md5 str))
(define (sha1 str) (g_sha1 str))
(define (sha256 str) (g_sha256 str))

(define (md5-by-file path) (g_md5-by-file path))
(define (sha1-by-file path) (g_sha1-by-file path))
(define (sha256-by-file path) (g_sha256-by-file path))

) ; end of begin
) ; end of define-library
40 changes: 39 additions & 1 deletion TeXmacs/plugins/goldfish/goldfish/liii/http.scm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
(import (liii hash-table)
(liii alist))
(export http-head http-get http-post http-ok?
http-stream-get http-stream-post)
http-stream-get http-stream-post
http-async-get http-async-post http-async-head http-poll http-wait-all)
(begin

(define (http-ok? r)
Expand Down Expand Up @@ -65,6 +66,43 @@
(g_http-stream-post url params data '(("Content-Type" . "text/plain")) proxy userdata callback))
(else (g_http-stream-post url params data headers proxy userdata callback))))

;; Async HTTP API wrapper functions

(define* (http-async-get url callback (params '()) (headers '()) (proxy '()))
(when (not (alist? params))
(type-error params "is not a association list"))
(when (not (alist? proxy))
(type-error proxy "is not a association list"))
(when (not (procedure? callback))
(type-error callback "is not a procedure"))
(g_http-async-get url params headers proxy callback))

(define* (http-async-post url callback (params '()) (data "") (headers '()) (proxy '()))
(when (not (alist? params))
(type-error params "is not a association list"))
(when (not (alist? proxy))
(type-error proxy "is not a association list"))
(when (not (procedure? callback))
(type-error callback "is not a procedure"))
(cond ((and (string? data) (> (string-length data) 0) (null? headers))
(g_http-async-post url params data '(("Content-Type" . "text/plain")) proxy callback))
(else (g_http-async-post url params data headers proxy callback))))

(define* (http-async-head url callback (params '()) (headers '()) (proxy '()))
(when (not (alist? params))
(type-error params "is not a association list"))
(when (not (alist? proxy))
(type-error proxy "is not a association list"))
(when (not (procedure? callback))
(type-error callback "is not a procedure"))
(g_http-async-head url params headers proxy callback))

(define (http-poll)
(g_http-poll))

(define* (http-wait-all (timeout -1))
(g_http-wait-all timeout))

) ; end of begin
) ; end of define-library

17 changes: 14 additions & 3 deletions TeXmacs/plugins/goldfish/goldfish/scheme/time.scm
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,26 @@
;

(define-library (scheme time)
(export current-second current-jiffy jiffies-per-second)
(import (only (scheme base) let-values s7-round))
(export current-second current-jiffy jiffies-per-second
get-time-of-day monotonic-nanosecond
system-clock-resolution steady-clock-resolution)
(begin

(define (jiffies-per-second) 1000000)

(define (current-second) (g_current-second))
(define get-time-of-day g_get-time-of-day)
(define monotonic-nanosecond g_monotonic-nanosecond)
(define system-clock-resolution g_system-clock-resolution)
(define steady-clock-resolution g_steady-clock-resolution)

(define (current-second)
(let-values (((sec usec) (get-time-of-day)))
(+ sec (exact->inexact (/ usec 1000000)))))

(define (current-jiffy)
(round (* (current-second) (jiffies-per-second))))
;; NOTE: use the s7-round to ensure that a natural number is returned.
(s7-round (* (current-second) (jiffies-per-second))))

) ; end of begin
) ; end of define-library
14 changes: 12 additions & 2 deletions TeXmacs/plugins/goldfish/goldfish/srfi/srfi-125.scm
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
hash-table-update! hash-table-update!/default hash-table-pop! hash-table-clear!
hash-table-size hash-table-keys hash-table-values hash-table-entries hash-table-find
hash-table-count hash-table-fold hash-table-for-each hash-table-map->list
hash-table->alist)
hash-table->alist hash-table-copy)
(begin

(define (assert-hash-table-type ht f)
Expand Down Expand Up @@ -148,4 +148,14 @@

(define hash-table->alist
(typed-lambda ((ht hash-table?))
(append-map (lambda (x) (list (car x) (cdr x))) (map values ht))))))
(append-map (lambda (x) (list (car x) (cdr x))) (map values ht))))

(define hash-table-copy
(typed-lambda ((ht hash-table?) . rest)
(let ((new-ht (make-hash-table))
(mutable? (if (null? rest) #t (car rest))))
(hash-table-for-each
(lambda (k v)
(hash-table-set! new-ht k v))
ht)
new-ht)))))
Loading