gdjn  Diff

Differences From Artifact [21ecd655b6]:

To Artifact [a0ecf192d6]:


3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
..
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
...
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
...
862
863
864
865
866
867
868

869
870
871
872
873
874
875
876







877
878
879
880
881
882
883
884
885








886
887
888
889
890
891
892
#  🄯 AGPLv3
#  ? compiles a godot class definition to C source
#  > janet tool/class-compile.janet <class> (loader|header)

(def *src-file* (gensym))

(def parse-doc
	(do
		(def doc-parser (peg/compile '{
			:hs          (+ " " "\t")
			:-           "-"
			:open-line   (* (? " ") (? '(some (if-not "\n" 1))) "\n")
			:single-line (* (? " ") (? '(some (* (not :hs) 1))) (any :hs) -1)
			:mid-line    (+ (* (any :hs) :- (? " ")
			                   (? '(some (if-not "\n" 1))) "\n")
			                (* (? '(some (if-not "\n" 1))) "\n"))
................................................................................
			:close-line  (+ (* (any :hs) -1)
							(* (any :hs) :- (? " ")
							   (? '(some (if-not (* (any :hs) -1) 1)))
			                   (any :hs) -1))
			:main        (+ (* :open-line (any :mid-line) :close-line)
			                :single-line
							'(any 1)) # admit defeat
	   }))

		(fn parse-doc[str]
			(peg/match doc-parser str))))

(def syntaxes
	(do (def quot-syntax
			'(nth 1 (unref (* (<- (+ `"` `'`) :quo)
................................................................................
					(string "\t.has_return_value = "
							(if (= :void (f :ret)) "false" "true") ",")
					(string "\t.call_func = " invocant ",")
					(string "\t.ptrcall_func = " invocant-ptr ",")
				] [])
				;ret-info
				`};`
				(string `printf("binding method %s\n",`
						(string/format "%q" fn-path)
						`);`)
				(string `_t(classdb).`
						(case kind
							:method "registerExtensionClassMethod"
							:impl "registerExtensionClassVirtualMethod")
						`(gdjn_ctx -> gd.lib, &s_className, &info);`)))
	   (array/concat @[] "{" ;(with-names [:s_className (class :id)]
				 ;(map |(bind $ :method) (class :methods))
................................................................................
						   ;(if (= :native (c :base-mode))
							   (with-names ["superName" (c :base)]
								   "super = _t(classdb).constructObject(&superName);")
							   [(string/format "super = %s_create();"
											   id-base)])
						   "return super;"))


		(array/push (unit :funcs)
					(:dec <func-c> self-ref-t id-ctor []
					  (string "typeof("id")* me = _alloc("id", 1);")
					  ;(with-names ["className" (c :id)]
						   (string/format "auto gdobj = %s();"
										  id-create)
						   `printf("constructed super object %p\n", gdobj);`
						   "_t(object).setInstance(gdobj, &className, me);"







						   (string id-init "(me, gdobj);"))
					  "return me;"))
		(push-event :dtor id-dtor :void
					[[:void* :_data]
					 [:GDExtensionClassInstancePtr :_ptr_me]]
					|[(string "typeof("id")* me = _ptr_me;")
					  ;$
					  "_free(me);"])
		(def id-virt (class-prefix (c :cursor) (c :id) "virt"))









		(array/push (unit :funcs) (:dec- <func-c> :void* id-virt
			 [[:void* :data]
			  [:GDExtensionConstStringNamePtr :method]
			  [:uint32_t :hash]]
			 `bool res = false;`
			 ;(catseq [[name idx] :pairs (c :vtbl-map)] [







<
|







 







|







 







|

|







 







>






|

>
>
>
>
>
>
>









>
>
>
>
>
>
>
>







3
4
5
6
7
8
9

10
11
12
13
14
15
16
17
..
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
...
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
...
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
#  🄯 AGPLv3
#  ? compiles a godot class definition to C source
#  > janet tool/class-compile.janet <class> (loader|header)

(def *src-file* (gensym))

(def parse-doc

	(do (def doc-parser (peg/compile '{
			:hs          (+ " " "\t")
			:-           "-"
			:open-line   (* (? " ") (? '(some (if-not "\n" 1))) "\n")
			:single-line (* (? " ") (? '(some (* (not :hs) 1))) (any :hs) -1)
			:mid-line    (+ (* (any :hs) :- (? " ")
			                   (? '(some (if-not "\n" 1))) "\n")
			                (* (? '(some (if-not "\n" 1))) "\n"))
................................................................................
			:close-line  (+ (* (any :hs) -1)
							(* (any :hs) :- (? " ")
							   (? '(some (if-not (* (any :hs) -1) 1)))
			                   (any :hs) -1))
			:main        (+ (* :open-line (any :mid-line) :close-line)
			                :single-line
							'(any 1)) # admit defeat
		}))

		(fn parse-doc[str]
			(peg/match doc-parser str))))

(def syntaxes
	(do (def quot-syntax
			'(nth 1 (unref (* (<- (+ `"` `'`) :quo)
................................................................................
					(string "\t.has_return_value = "
							(if (= :void (f :ret)) "false" "true") ",")
					(string "\t.call_func = " invocant ",")
					(string "\t.ptrcall_func = " invocant-ptr ",")
				] [])
				;ret-info
				`};`
				(comment (string `printf("binding method %s\n",`
						(string/format "%q" fn-path)
						`);`))
				(string `_t(classdb).`
						(case kind
							:method "registerExtensionClassMethod"
							:impl "registerExtensionClassVirtualMethod")
						`(gdjn_ctx -> gd.lib, &s_className, &info);`)))
	   (array/concat @[] "{" ;(with-names [:s_className (class :id)]
				 ;(map |(bind $ :method) (class :methods))
................................................................................
						   ;(if (= :native (c :base-mode))
							   (with-names ["superName" (c :base)]
								   "super = _t(classdb).constructObject(&superName);")
							   [(string/format "super = %s_create();"
											   id-base)])
						   "return super;"))

		(def icb-null "(&(GDExtensionInstanceBindingCallbacks){})")
		(array/push (unit :funcs)
					(:dec <func-c> self-ref-t id-ctor []
					  (string "typeof("id")* me = _alloc("id", 1);")
					  ;(with-names ["className" (c :id)]
						   (string/format "auto gdobj = %s();"
										  id-create)
						   #`printf("constructed super object %p\n", gdobj);`
						   "_t(object).setInstance(gdobj, &className, me);"
						   # register the instance as a binding so
						   # that other classes can access it. this
						   # is so dumb
						   "_t(object).setInstanceBinding("
						   "	gdobj, gdjn_ctx -> gd.lib, me,"
								icb-null
						   ");"
						   (string id-init "(me, gdobj);"))
					  "return me;"))
		(push-event :dtor id-dtor :void
					[[:void* :_data]
					 [:GDExtensionClassInstancePtr :_ptr_me]]
					|[(string "typeof("id")* me = _ptr_me;")
					  ;$
					  "_free(me);"])
		(def id-virt (class-prefix (c :cursor) (c :id) "virt"))
		(array/push (unit :funcs)
					(:dec* <func-c> [:inline :static]
						   self-ref-t (string id "_data")
						  [[:GDExtensionObjectPtr :self]]
						  "return _t(object).getInstanceBinding("
						  "	self, gdjn_ctx -> gd.lib,"
							icb-null
						  ");"))

		(array/push (unit :funcs) (:dec- <func-c> :void* id-virt
			 [[:void* :data]
			  [:GDExtensionConstStringNamePtr :method]
			  [:uint32_t :hash]]
			 `bool res = false;`
			 ;(catseq [[name idx] :pairs (c :vtbl-map)] [