Differences From
Artifact [21ecd655b6]:
3 3 # 🄯 AGPLv3
4 4 # ? compiles a godot class definition to C source
5 5 # > janet tool/class-compile.janet <class> (loader|header)
6 6
7 7 (def *src-file* (gensym))
8 8
9 9 (def parse-doc
10 - (do
11 - (def doc-parser (peg/compile '{
10 + (do (def doc-parser (peg/compile '{
12 11 :hs (+ " " "\t")
13 12 :- "-"
14 13 :open-line (* (? " ") (? '(some (if-not "\n" 1))) "\n")
15 14 :single-line (* (? " ") (? '(some (* (not :hs) 1))) (any :hs) -1)
16 15 :mid-line (+ (* (any :hs) :- (? " ")
17 16 (? '(some (if-not "\n" 1))) "\n")
18 17 (* (? '(some (if-not "\n" 1))) "\n"))
................................................................................
19 18 :close-line (+ (* (any :hs) -1)
20 19 (* (any :hs) :- (? " ")
21 20 (? '(some (if-not (* (any :hs) -1) 1)))
22 21 (any :hs) -1))
23 22 :main (+ (* :open-line (any :mid-line) :close-line)
24 23 :single-line
25 24 '(any 1)) # admit defeat
26 - }))
25 + }))
27 26
28 27 (fn parse-doc[str]
29 28 (peg/match doc-parser str))))
30 29
31 30 (def syntaxes
32 31 (do (def quot-syntax
33 32 '(nth 1 (unref (* (<- (+ `"` `'`) :quo)
................................................................................
786 785 (string "\t.has_return_value = "
787 786 (if (= :void (f :ret)) "false" "true") ",")
788 787 (string "\t.call_func = " invocant ",")
789 788 (string "\t.ptrcall_func = " invocant-ptr ",")
790 789 ] [])
791 790 ;ret-info
792 791 `};`
793 - (string `printf("binding method %s\n",`
792 + (comment (string `printf("binding method %s\n",`
794 793 (string/format "%q" fn-path)
795 - `);`)
794 + `);`))
796 795 (string `_t(classdb).`
797 796 (case kind
798 797 :method "registerExtensionClassMethod"
799 798 :impl "registerExtensionClassVirtualMethod")
800 799 `(gdjn_ctx -> gd.lib, &s_className, &info);`)))
801 800 (array/concat @[] "{" ;(with-names [:s_className (class :id)]
802 801 ;(map |(bind $ :method) (class :methods))
................................................................................
862 861 ;(if (= :native (c :base-mode))
863 862 (with-names ["superName" (c :base)]
864 863 "super = _t(classdb).constructObject(&superName);")
865 864 [(string/format "super = %s_create();"
866 865 id-base)])
867 866 "return super;"))
868 867
868 + (def icb-null "(&(GDExtensionInstanceBindingCallbacks){})")
869 869 (array/push (unit :funcs)
870 870 (:dec <func-c> self-ref-t id-ctor []
871 871 (string "typeof("id")* me = _alloc("id", 1);")
872 872 ;(with-names ["className" (c :id)]
873 873 (string/format "auto gdobj = %s();"
874 874 id-create)
875 - `printf("constructed super object %p\n", gdobj);`
875 + #`printf("constructed super object %p\n", gdobj);`
876 876 "_t(object).setInstance(gdobj, &className, me);"
877 + # register the instance as a binding so
878 + # that other classes can access it. this
879 + # is so dumb
880 + "_t(object).setInstanceBinding("
881 + " gdobj, gdjn_ctx -> gd.lib, me,"
882 + icb-null
883 + ");"
877 884 (string id-init "(me, gdobj);"))
878 885 "return me;"))
879 886 (push-event :dtor id-dtor :void
880 887 [[:void* :_data]
881 888 [:GDExtensionClassInstancePtr :_ptr_me]]
882 889 |[(string "typeof("id")* me = _ptr_me;")
883 890 ;$
884 891 "_free(me);"])
885 892 (def id-virt (class-prefix (c :cursor) (c :id) "virt"))
893 + (array/push (unit :funcs)
894 + (:dec* <func-c> [:inline :static]
895 + self-ref-t (string id "_data")
896 + [[:GDExtensionObjectPtr :self]]
897 + "return _t(object).getInstanceBinding("
898 + " self, gdjn_ctx -> gd.lib,"
899 + icb-null
900 + ");"))
886 901
887 902 (array/push (unit :funcs) (:dec- <func-c> :void* id-virt
888 903 [[:void* :data]
889 904 [:GDExtensionConstStringNamePtr :method]
890 905 [:uint32_t :hash]]
891 906 `bool res = false;`
892 907 ;(catseq [[name idx] :pairs (c :vtbl-map)] [