Skip to content

Commit 6b09ff7

Browse files
authored
Merge pull request #446 from vlad-km/cls-reord
Some features and pathes
2 parents 22e2415 + fc724c7 commit 6b09ff7

File tree

11 files changed

+397
-80
lines changed

11 files changed

+397
-80
lines changed

src/boot.lisp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,4 +585,15 @@
585585
(defmacro print-unreadable-object ((object stream &key type identity) &body body)
586586
`(!print-unreadable-object (,object ,stream :type ,type :identity ,identity) ,@body))
587587

588+
589+
(defmacro %%assert (test &optional ignore datum &rest args)
590+
(let ((value (gensym "ASSERT-VALUE")))
591+
`(let ((,value ,test))
592+
(when (not ,value)
593+
(jscl::%%assert-error ',test ,datum ,@args)))))
594+
#+jscl
595+
(defmacro assert (test &optional ignore datum &rest args)
596+
`(%%assert ,test ,ignore ,datum ,@args))
597+
598+
588599
;;; EOF

src/clos/std-object.lisp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@
376376
;; accessor writer fn
377377
;; make (setf name) symbolic name
378378
(push-on-end `(setf ,(cadr olist)) writers))
379+
(:documentation)
379380
(otherwise
380381
(push-on-end `',(car olist) other-options)
381382
(push-on-end `',(cadr olist) other-options))))
@@ -398,6 +399,7 @@
398399
(eval-always
399400
(defun canonicalize-defclass-option (option)
400401
(case (car option)
402+
(:documentation)
401403
(:metaclass (list ':metaclass `(!find-class ',(cadr option))))
402404
(:default-initargs
403405
(list ':direct-default-initargs
@@ -492,6 +494,7 @@
492494

493495
;;; N.B. Quietly retain all unknown slot options (rather than signaling an
494496
;;; error), so that it's easy to add new ones.
497+
;;; BUG: this lambda form is not working - &allow-other-keys parsed incorrectly
495498
(defun make-direct-slot-definition
496499
(&rest properties
497500
&key name (initargs ()) (initform nil) (initfunction nil) (readers ()) (writers ()) (allocation :instance)
@@ -506,6 +509,7 @@
506509
(setf (getf* slot ':allocation) allocation)
507510
slot))
508511

512+
;;; BUG: this lambda form is not working - &allow-other-keys parsed incorrectly
509513
(defun make-effective-slot-definition
510514
(&rest properties
511515
&key name (initargs ()) (initform nil) (initfunction nil) (allocation :instance)

src/conditions.lisp

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,9 @@
127127
(check-type condition warning)
128128
(%%signal condition)
129129
(format stream "WARNING: ")
130-
(format stream (simple-condition-format-control condition)
131-
(simple-condition-format-arguments condition))
132-
(write-char #\newline)
130+
(apply 'format stream (simple-condition-format-control condition)
131+
(simple-condition-format-arguments condition))
132+
(write-char #\newline stream)
133133
nil))
134134

135135
(defun %%error (datum &rest args)
@@ -231,16 +231,7 @@
231231
:format-control "Assert failed: ~s."
232232
:format-arguments (list form)))))
233233

234-
(defmacro %%assert (test &optional ignore datum &rest args)
235-
(let ((value (gensym "ASSERT-VALUE"))
236-
(name (gensym "ASSERT-BLOCK")))
237-
`(block
238-
,name
239-
(let ((,value ,test))
240-
(when (not ,value)
241-
(%%assert-error ',test ,datum ,@args))))))
242-
243-
234+
;;; @vlad-km macro %%assert moved to boot.lisp
244235

245236
#+jscl
246237
(progn
@@ -257,9 +248,6 @@
257248
(defmacro ignore-errors (&rest forms)
258249
`(%%ignore-errors ,@forms))
259250

260-
(defmacro assert (test &optional ignore datum &rest args)
261-
`(%%assert ,test ,ignore ,datum ,@args))
262-
263251
(fset 'make-condition #'%%make-condition)
264252
(fset 'signal #'%%signal)
265253
(fset 'warn #'%%warn)

src/load.lisp

Lines changed: 57 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
;;; -*- mode:lisp; coding:utf-8 -*-
22

3-
43
;;;
54
;;; LOAD - load & compile Common Lisp file.
65
;;; Simple implementation of the common Lisp function 'load'
@@ -48,7 +47,13 @@
4847
(format t " ~a~%" x))
4948
t)
5049
(error (msg)
51-
(format t "Error: ~a~%" (!condition-args msg))
50+
(typecase condition
51+
(simple-error
52+
(apply #'format t
53+
(simple-condition-format-control condition)
54+
(simple-condition-format-arguments condition)))
55+
(t (let* ((*print-escape* nil))
56+
(print-object condition))))
5257
nil))
5358
nil)
5459

@@ -112,12 +117,14 @@
112117
;;;
113118
;;; hook - #() store place for js-code
114119
;;;
115-
;;; (setq bin #())
120+
;;; IMPORTANT!! don't use literal #() (see Issue #345)
121+
;;; (setq bin (make-array 0 :fillpointer 0))
116122
;;; (load "file1.lisp" :hook bin)
117123
;;; (load "file2.lisp" :hook bin)
118124
;;; (load "file3.lisp" :hook bin :output "lib.js")
119125
;;; => will be bundle js-code file1, file2, file3 from bin to "lib.js"
120126
;;;
127+
;;;
121128
;;; you will be use (require "./lib") or use html tag:
122129
;;; <script src="lib.js" type="text/javascript" charset="utf-8"></script>
123130
;;; without compilation.
@@ -129,6 +136,21 @@
129136
(defun node-environment-p ()
130137
(if (find :node *features*) t))
131138

139+
;;;
140+
;;; how to bypass cors restrictions
141+
;;; 1. on the command line issue the command:
142+
;;; chrome.exe --user-data-dir="????????" --disable-web-security
143+
;;; will launch chrome in disbale-websecurity mode. (By path "????????" will be you Chrome account)
144+
;;; 2. enter devtool/source
145+
;;; 3. click add workspace
146+
;;; 4. add your folder with jscl.js, jscl-web.js, jscl.html
147+
;;; 5. allow devtool to work with the filesystem
148+
;;; all files from your directory will be loaded
149+
;;; 6. select the file JSCL.HTML and open it in a new tab
150+
;;; now, you can load:
151+
;;; source lisp files with the LOAD function
152+
;;; js files - with function JS-LOAD
153+
;;; css files - with function CSS-LOAD
132154

133155
(defun load (name &key verbose (sync (node-environment-p)) output place hook)
134156
(terpri)
@@ -142,12 +164,12 @@
142164
(loader-sync-mode name verbose output place hook)
143165
(loader-async-mode name verbose output place hook)))
144166
;; browser platform
145-
(t
146-
(when sync
147-
(warn "sync mode only for node/electron platform~%will be used async mode"))
148-
(when (or output hook)
149-
(warn "output/hook options only for node/electron platform"))
150-
(loader-browser-mode name verbose)))
167+
(t (when sync
168+
(warn "sync mode only for node/electron platform~%will be used async mode"))
169+
(when (or output hook)
170+
(warn "output/hook options only for node/electron platform"))
171+
(warn "In browser mode, the LOAD function is executed ONLY if `web-security` is DISABLED (CORS restriction)")
172+
(loader-browser-mode name verbose)))
151173
(values))
152174

153175

@@ -157,17 +179,17 @@
157179
(lambda (input)
158180
(_load_form_eval_ (_ldr_ctrl-r_replace_ input) verbose))
159181
(lambda (url status)
160-
(format t "~%Load: Can't load ~a~% Status ~%" url status))))
182+
(format t "~%Load: Can't load ~a~% Status: ~a~%" url status))))
161183

162184
;;; alowe make bundle from source received from local fs (by FILE:)
163-
;;; or from remote resource (by HTTP:)
185+
;;; or from remote resourse (by HTTP:)
164186
(defun loader-async-mode (name verbose bundle-name place hook)
165187
(_xhr_receiver_
166188
name
167189
(lambda (input)
168190
(_load_eval_bundle_ (_ldr_ctrl-r_replace_ input) verbose bundle-name place hook))
169191
(lambda (url status)
170-
(format t "~%Load: Can't load ~a~% Status ~%" url status))))
192+
(format t "~%Load: Can't load ~a~% Status: ~a~%" url status))))
171193

172194
;;; sync mode
173195
(defun loader-sync-mode (name verbose bundle-name place hook)
@@ -188,7 +210,8 @@
188210
(when bundle-name
189211
(if hook
190212
(setq code-stor hook)
191-
(setq code-stor #()))
213+
;; see Issue #345, #350, #397
214+
(setq code-stor (make-array 0 :fill-pointer 0)))
192215
(setq fbundle t))
193216
(setq stream (make-string-input-stream input))
194217
(tagbody sync-loader-rdr
@@ -202,13 +225,14 @@
202225
(setq code (compile-toplevel expr t t))
203226
(setq rc (js-eval code))
204227
(when verbose (format t " ~a~%" rc))
205-
;; so, expr already verified
228+
;; so, expr already verifyed
206229
;; store expression after compilation/evaluated
207230
(cond (fbundle ((oget code-stor "push") code))
208231
(hook ((oget code-stor "push") code))
209232
(t t)) ))
210233
(error (msg)
211-
(format t "Error: ~a~%" (!condition-args msg))
234+
(format t " Error: ")
235+
(load_cond_err_handl_ msg)
212236
;; break read-eval loop
213237
;; no bundle
214238
(setq fbundle nil)
@@ -222,6 +246,24 @@
222246
(setq code-stor nil))
223247
(values)))
224248

249+
;;; error message handle path
250+
(defun _load_cond_err_handl_(condition)
251+
(typecase condition
252+
(simple-error
253+
(apply #'format t
254+
(simple-condition-format-control condition)
255+
(simple-condition-format-arguments condition)))
256+
(type-error
257+
;; note:
258+
;; there can be custom event handling here.
259+
;; while it remains as it was done.
260+
;; sometime later
261+
(let* ((*print-escape* nil))
262+
(print-object condition)))
263+
(t (let* ((*print-escape* nil))
264+
(print-object condition))))
265+
(write-char #\newline))
266+
225267

226268
;;; Check what output directory exists
227269
(defun _loader_check_output_directory_ (path)

src/misc.lisp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,25 @@
6868
(defvar *traced-functions* nil)
6969
(defvar *trace-level* 0)
7070

71+
;;; @vlad-km 04-09-2022
72+
;;; Prevent RangeError: Maximum call stack size exceeded
73+
;;; on trace call
74+
(defvar *prevent-trace-stop-list*
75+
'(trace
76+
princ prin1 prin1-to-string princ-to-string
77+
print
78+
format !format
79+
write write-char write-string write-integer write-symbol write-line write-to-string
80+
terpri fresh-line))
81+
82+
(defun %prevent-infinite-trace (name)
83+
(typecase name
84+
(symbol
85+
(if (jscl::memq name *prevent-trace-stop-list*)
86+
(error "Trace - `~S` this function is not traceable." name)))
87+
(otherwise (error "Trace - the traceable function name `~S` must be a symbol." name))))
88+
89+
7190
(defun trace-report-call (name args)
7291
(dotimes (i *trace-level*) (write-string " "))
7392
(format t "~a: ~S~%" *trace-level* (cons name args)))
@@ -82,13 +101,14 @@
82101
(if (null names)
83102
(mapcar #'car *traced-functions*)
84103
(dolist (name names names)
104+
(%prevent-infinite-trace name)
85105
(if (find name *traced-functions* :key #'car)
86106
(format t "`~S' is already traced.~%" name)
87107
(let ((func (fdefinition name)))
88108
(fset name (lambda (&rest args)
89109
(let (values)
90110
(trace-report-call name args)
91-
(let ((*trace-level* (+ *trace-level* 1)))
111+
(let ((*trace-level* (1+ *trace-level*)))
92112
(setq values (multiple-value-list (apply func args))))
93113
(trace-report-return name values)
94114
(values-list values))))

0 commit comments

Comments
 (0)