smalltalk: Behavior>>compile: + addSelector:/removeSelector: + 9 tests
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled

This commit is contained in:
2026-04-25 09:30:18 +00:00
parent 1c4ac47450
commit 3e83624317
3 changed files with 75 additions and 2 deletions

View File

@@ -872,6 +872,29 @@
(= selector "category:")
(= selector "comment:"))
cref)
;; Behavior>>compile: parses the source string as a method and
;; installs it. Returns the selector as a symbol.
;; Sister forms: compile:classified: and compile:notifying:
;; ignore the extra arg, mirroring Pharo's tolerant behaviour.
((or (= selector "compile:")
(= selector "compile:classified:")
(= selector "compile:notifying:"))
(let ((src (nth args 0)))
(let ((method-ast (st-parse-method (str src))))
(st-class-add-method!
name (get method-ast :selector) method-ast)
(make-symbol (get method-ast :selector)))))
((or (= selector "addSelector:withMethod:")
(= selector "addSelector:method:"))
(let
((sel (str (nth args 0)))
(method-ast (nth args 1)))
(begin
(st-class-add-method! name sel method-ast)
(make-symbol sel))))
((= selector "removeSelector:")
(let ((sel (str (nth args 0))))
(st-class-remove-method! name sel)))
((= selector "printString") name)
((= selector "class") (st-class-ref "Metaclass"))
((= selector "==") (and (st-class-ref? (nth args 0))