diff --git a/CHANGELOG.md b/CHANGELOG.md index ff646ef..685ae07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,11 @@ ## Master -- Don't make things const by default as we don't get `const` info from the jextracts anyway -- Add `vc/comptime` -- Support nested components in VybeC +- VybeC + - Don't make things const by default as we don't get `const` info from the jextracts anyway + - Add `vc/comptime` + - Support nested components in VybeC + - Static calls with no arguments are now called in compile time automatically +- ## v0.7.469 diff --git a/src/vybe/c.clj b/src/vybe/c.clj index 85f7a83..b5431f7 100644 --- a/src/vybe/c.clj +++ b/src/vybe/c.clj @@ -818,6 +818,8 @@ signal(SIGSEGV, sighandler); (= (:type v) :vector) (format "{%s}" (->> (:val v) + (mapv #(emit (analyze % (-> (ana/empty-env) + (update :locals merge (:locals (:env v))))))) (str/join ", "))) (string? (:val v)) @@ -842,72 +844,78 @@ signal(SIGSEGV, sighandler); (str/join ", "))) :static-call - (let [{:keys [method args] klass :class} v] - (case (->sym klass) - clojure.lang.Util - (case (->sym method) - identical - (format "(%s == %s)" - (emit (first args)) - (emit (second args)))) - - clojure.lang.Numbers - (case (->sym method) - (add multiply divide minus gt gte lt lte) - (->> args - (mapv emit) - (str/join (format " %s " - ('{multiply * - divide / - add + - minus - - gt > gte >= lt < lte <=} - (->sym method)))) - parens) - - inc - (format "(%s + 1)" (emit (first args))) - - dec - (format "(%s - 1)" (emit (first args))) - - abs - (format "vybe_abs(%s)" (emit (first args))) - - ;; bit-and - and - (apply format "(%s & %s)" (mapv emit args)) - - or - (apply format "(%s | %s)" (mapv emit args))) - - clojure.lang.RT - (case (->sym method) - aset - (let [[s1 s2 s3] (mapv emit args)] - (-> (->> (format " %s[%s] = %s" - s1 s2 s3) - parens) - (str ";"))) - - (nth aget) - (let [[s1 s2] (mapv emit args)] - (->> (format " %s[%s] " - s1 s2) - parens)) - - get - (let [[s1 s2] (mapv emit args)] - (format "%s.%s" s1 s2)) - - intCast - (format "(int)%s" (emit (first args))) - - floatCast - (format "(float)%s" (emit (first args))) - - doubleCast - (format "(double)%s" (emit (first args)))))) + (let [{:keys [form method args] klass :class} v] + ;; If no args, then this is likely a constant. + (if (empty? args) + (emit (analyze (eval form))) + (case (->sym klass) + clojure.lang.Util + (case (->sym method) + identical + (format "(%s == %s)" + (emit (first args)) + (emit (second args)))) + + clojure.lang.Numbers + (case (->sym method) + (add multiply divide minus gt gte lt lte) + (->> args + (mapv emit) + (str/join (format " %s " + ('{multiply * + divide / + add + + minus - + gt > gte >= lt < lte <=} + (->sym method)))) + parens) + + inc + (format "(%s + 1)" (emit (first args))) + + dec + (format "(%s - 1)" (emit (first args))) + + abs + (format "vybe_abs(%s)" (emit (first args))) + + ;; bit-and + and + (apply format "(%s & %s)" (mapv emit args)) + + or + (apply format "(%s | %s)" (mapv emit args))) + + clojure.lang.RT + (case (->sym method) + aset + (let [[s1 s2 s3] (mapv emit args)] + (-> (->> (format " %s[%s] = %s" + s1 s2 s3) + parens) + (str ";"))) + + (nth aget) + (let [[s1 s2] (mapv emit args)] + (->> (format " %s[%s] " + s1 s2) + parens)) + + get + (let [[s1 s2] (mapv emit args)] + (format "%s.%s" s1 s2)) + + intCast + (format "(int)%s" (emit (first args))) + + longCast + (format "(long)%s" (emit (first args))) + + floatCast + (format "(float)%s" (emit (first args))) + + doubleCast + (format "(double)%s" (emit (first args))))))) :keyword-invoke (let [{:keys [keyword target]} v] @@ -1832,6 +1840,10 @@ long long int: \"long long int\", unsigned long long int: \"unsigned long long i [{:keys [args]}] (format "(*%s)" (emit (first args)))) +(defmethod c-macroexpand #'name + [{:keys [form]}] + (eval form)) + (defmethod c-invoke #'merge [{:keys [args]}] (let [[target] args] @@ -1867,11 +1879,14 @@ long long int: \"long long int\", unsigned long long int: \"unsigned long long i (defmethod c-invoke #'vp/as [{:keys [args]}] - (def args args) (format "(%s)%s" (-adapt-type (:val (second args))) (emit (first args)))) +(defmethod c-macroexpand #'vp/arr + [{:keys [args]}] + `(vp/as ~(first args) [:vec ~(second args)])) + (defmethod c-invoke #'vp/sizeof [{:keys [args]}] (if (= (count args) 2) @@ -1904,9 +1919,9 @@ _my_v; c-sym c-sym (emit (analyze `(merge ~'@_my_v - ~(:form (first args))) - (-> (:env (first args)) - (update :locals assoc '_my_v {}))))) + ~(:form (first args))) + (-> (:env (first args)) + (update :locals assoc '_my_v {}))))) (format "((%s*)malloc(sizeof (%s)))" c-sym c-sym)))) (declare ^:private ^:no-ns memset) diff --git a/test/vybe/flecs_test.clj b/test/vybe/flecs_test.clj index 84d08d1..6e1f367 100644 --- a/test/vybe/flecs_test.clj +++ b/test/vybe/flecs_test.clj @@ -90,18 +90,33 @@ ["alice" {:x 10.0, :y 20.0}]} (set @*acc)))))) +#_(vc/defn* vybe-transform :- :void + [it :- vf/iter_t]) + (vc/defn* ^:debug default-systems :- :void [^:mut w :- :*] (let [e (vf.c/ecs-entity-init w #vp/& (vf/entity_desc_t {:name "vybe_transform" - :add (-> [(vc/comptime - (vf.c/vybe-pair (flecs/EcsDependsOn) - (flecs/EcsOnUpdate)))] - (vp/as [:vec :long]))}))] + :add (-> [(vf.c/vybe-pair (flecs/EcsDependsOn) + (flecs/EcsOnUpdate))] + (vp/arr :long))}))] (vf.c/ecs-system-init w #vp/& (vf/system_desc_t {:entity e - :query {} + #_:callback + :query {:terms [{:first {:name (name vt/Translation)} :inout (flecs/EcsIn)} + {:first {:name (name vt/Rotation)} :inout (flecs/EcsIn)} + {:first {:name (name vt/Scale)} :inout (flecs/EcsIn)} + {:first {:name (name vt/Transform)} + :second {:name "global"} + :inout (flecs/EcsOut)} + {:first {:name (name vt/Transform)} + :inout (flecs/EcsOut)} + {:first {:name (name vt/Transform)} + :second {:name "global"} + :src {:id (bit-or (flecs/EcsCascade) (flecs/EcsUp))} + :inout (flecs/EcsOut) + :oper (flecs/EcsOptional)}]} #_ #_:callback (-system-callback (fn [it-p] (let [it (vp/jx-p->map it-p ecs_iter_t)