diff --git a/common/goos/Object.h b/common/goos/Object.h index 13b0e2584d..aca66b059b 100644 --- a/common/goos/Object.h +++ b/common/goos/Object.h @@ -300,6 +300,14 @@ class Object { return float_obj.value; } + const FloatType& as_float() const { + if (type != ObjectType::FLOAT) { + throw std::runtime_error("as_float called on a " + object_type_to_string(type) + " " + + print()); + } + return float_obj.value; + } + char& as_char() { if (type != ObjectType::CHAR) { throw std::runtime_error("as_char called on a " + object_type_to_string(type) + " " + diff --git a/decompiler/config/all-types.gc b/decompiler/config/all-types.gc index 8be0462c20..3ec673dd38 100644 --- a/decompiler/config/all-types.gc +++ b/decompiler/config/all-types.gc @@ -12200,77 +12200,61 @@ ; ) ; ) -; ;; water-h -; (deftype water-vol (process-drawable) -; ((~Twater-height meters :offset-assert 176) -; (~Twade-height meters :offset-assert 180) -; (~Tswim-height meters :offset-assert 184) -; (~Tbottom-height meters :offset-assert 188) -; (~Tattack-event basic :offset-assert 192) -; (~Ttarget uint64 :offset-assert 200) -; (~Tflags uint32 :offset-assert 208) -; ) -; :method-count-assert 30 -; :size-assert #xd4 -; :flag-assert #x1e007000d4 -; ;; inherited inpspect of process-drawable -; (:methods -; (dummy-9 () none 9) -; (dummy-10 () none 10) -; (dummy-11 () none 11) -; (dummy-12 () none 12) -; (dummy-13 () none 13) -; (dummy-14 () none 14) -; (dummy-15 () none 15) -; (dummy-16 () none 16) -; (dummy-17 () none 17) -; (dummy-18 () none 18) -; (dummy-19 () none 19) -; (dummy-20 () none 20) -; (dummy-21 () none 21) -; (dummy-22 () none 22) -; (dummy-23 () none 23) -; (dummy-24 () none 24) -; (dummy-25 () none 25) -; (dummy-26 () none 26) -; (dummy-27 () none 27) -; (dummy-28 () none 28) -; (dummy-29 () none 29) -; ) -; ) +;; water-h +(deftype water-vol (process-drawable) + ((~Twater-height float :offset-assert 176) ;; meters + (~Twade-height float :offset-assert 180) ;; meters + (~Tswim-height float :offset-assert 184) ;; meters + (~Tbottom-height float :offset-assert 188) ;; meters + (~Tattack-event basic :offset-assert 192) + (~Ttarget uint64 :offset-assert 200) + (~Tflags uint32 :offset-assert 208) + ) + :heap-base #x70 + :method-count-assert 30 + :size-assert #xd4 + :flag-assert #x1e007000d4 + ;; inherited inpspect of process-drawable + (:methods + (dummy-20 () none 20) + (dummy-21 () none 21) + (dummy-22 () none 22) + (dummy-23 () none 23) + (dummy-24 () none 24) + (dummy-25 () none 25) + (dummy-26 () none 26) + (dummy-27 () none 27) + (dummy-28 () none 28) + (dummy-29 () none 29) + ) + ) -; ;; cam-master -; (deftype camera-master-bank (basic) -; ((onscreen-head-height meters :offset-assert 4) -; (onscreen-foot-height meters :offset-assert 8) -; (target-height meters :offset-assert 12) -; (up-move-to-pitch-ratio-in-air float :offset-assert 16) -; (down-move-to-pitch-ratio-in-air float :offset-assert 20) -; (up-move-to-pitch-on-ground float :offset-assert 24) -; (down-move-to-pitch-on-ground float :offset-assert 28) -; (pitch-off-blend float :offset-assert 32) -; ) -; :method-count-assert 9 -; :size-assert #x24 -; :flag-assert #x900000024 -; ) +;; cam-master +(deftype camera-master-bank (basic) + ((onscreen-head-height float :offset-assert 4) ;; meters + (onscreen-foot-height float :offset-assert 8) ;; meters + (target-height float :offset-assert 12) ;; meters + (up-move-to-pitch-ratio-in-air float :offset-assert 16) + (down-move-to-pitch-ratio-in-air float :offset-assert 20) + (up-move-to-pitch-on-ground float :offset-assert 24) + (down-move-to-pitch-on-ground float :offset-assert 28) + (pitch-off-blend float :offset-assert 32) + ) + :method-count-assert 9 + :size-assert #x24 + :flag-assert #x900000024 + ) -; ;; cam-master -; (deftype list-keeper (process) -; ((~Tdummy float :offset-assert 112) -; ) -; :method-count-assert 14 -; :size-assert #x74 -; :flag-assert #xe00100074 -; ;; inherited inpspect of process -; (:methods -; (dummy-9 () none 9) -; (dummy-10 () none 10) -; (dummy-11 () none 11) -; (dummy-12 () none 12) -; (dummy-13 () none 13) -; ) -; ) +;; cam-master +(deftype list-keeper (process) + ((~Tdummy float :offset-assert 112) + ) + :heap-base #x10 + :method-count-assert 14 + :size-assert #x74 + :flag-assert #xe00100074 + ;; inherited inpspect of process + ) ; ;; cam-states ; (deftype cam-eye-bank (UNKNOWN) @@ -12344,82 +12328,82 @@ ; ;; bad get label ; ) -; ;; cam-states-dbg -; (deftype cam-point-watch-bank (basic) -; ((speed float :offset-assert 4) -; (rot-speed deg :offset-assert 8) -; ) -; :method-count-assert 9 -; :size-assert #xc -; :flag-assert #x90000000c -; ) +;; cam-states-dbg +(deftype cam-point-watch-bank (basic) + ((speed float :offset-assert 4) + (rot-speed float :offset-assert 8) ;; deg + ) + :method-count-assert 9 + :size-assert #xc + :flag-assert #x90000000c + ) -; ;; cam-states-dbg -; (deftype cam-free-bank (basic) -; ((speed float :offset-assert 4) -; (rot-speed deg :offset-assert 8) -; ) -; :method-count-assert 9 -; :size-assert #xc -; :flag-assert #x90000000c -; ) +;; cam-states-dbg +(deftype cam-free-bank (basic) + ((speed float :offset-assert 4) + (rot-speed float :offset-assert 8) ;; deg + ) + :method-count-assert 9 + :size-assert #xc + :flag-assert #x90000000c + ) -; ;; cam-states-dbg -; (deftype camera-free-floating-move-info (structure) -; ((rv vector :inline :offset-assert 0) -; (tv vector :inline :offset-assert 16) -; (up vector :inline :offset-assert 32) -; (tm matrix :inline :offset-assert 48) -; ) -; :method-count-assert 9 -; :size-assert #x70 -; :flag-assert #x900000070 -; ) +;; cam-states-dbg +(deftype camera-free-floating-move-info (structure) + ((rv vector :inline :offset-assert 0) + (tv vector :inline :offset-assert 16) + (up vector :inline :offset-assert 32) + (tm matrix :inline :offset-assert 48) + ) + :method-count-assert 9 + :size-assert #x70 + :flag-assert #x900000070 + ) -; ;; cam-states-dbg -; (deftype camera-orbit-info (structure) -; ((radius float :offset-assert 0) -; (rot float :offset-assert 4) -; (target-off vector :inline :offset-assert 16) -; (orbit-off vector :inline :offset-assert 32) -; (radius-lerp float :offset-assert 48) -; ) -; :method-count-assert 9 -; :size-assert #x34 -; :flag-assert #x900000034 -; ) +;; cam-states-dbg +(deftype camera-orbit-info (structure) + ((radius float :offset-assert 0) + (rot float :offset-assert 4) + (target-off vector :inline :offset-assert 16) + (orbit-off vector :inline :offset-assert 32) + (radius-lerp float :offset-assert 48) + ) + :method-count-assert 9 + :size-assert #x34 + :flag-assert #x900000034 + ) -; ;; cam-states-dbg -; (deftype CAM_ORBIT-bank (basic) -; ((RADIUS_MAX float :offset-assert 4) -; (RADIUS_MIN float :offset-assert 8) -; (TARGET_OFF_ADJUST float :offset-assert 12) -; (ORBIT_OFF_ADJUST float :offset-assert 16) -; ) -; :method-count-assert 9 -; :size-assert #x14 -; :flag-assert #x900000014 -; ) +;; cam-states-dbg +(deftype CAM_ORBIT-bank (basic) + ((RADIUS_MAX float :offset-assert 4) + (RADIUS_MIN float :offset-assert 8) + (TARGET_OFF_ADJUST float :offset-assert 12) + (ORBIT_OFF_ADJUST float :offset-assert 16) + ) + :method-count-assert 9 + :size-assert #x14 + :flag-assert #x900000014 + ) -; ;; vol-h -; (deftype plane-volume (structure) -; ((volume-type basic :offset-assert 0) -; (point-count int16 :offset-assert 4) -; (normal-count int16 :offset-assert 6) -; (first-point vector :offset-assert 8) -; (first-normal vector :offset-assert 12) -; (num-planes int32 :offset-assert 16) -; (plane uint32 :offset-assert 20) -; ) -; :method-count-assert 12 -; :size-assert #x18 -; :flag-assert #xc00000018 -; (:methods -; (dummy-9 () none 9) -; (dummy-10 () none 10) -; (dummy-11 () none 11) -; ) -; ) +;; vol-h +(deftype plane-volume (structure) + ((volume-type basic :offset-assert 0) + (point-count int16 :offset-assert 4) + (normal-count int16 :offset-assert 6) + (first-point vector :offset-assert 8) + (first-normal vector :offset-assert 12) + (num-planes int32 :offset-assert 16) + (plane uint32 :offset-assert 20) + ) + :method-count-assert 12 + :size-assert #x18 + :flag-assert #xc00000018 + (:methods + (dummy-9 () none 9) + (dummy-10 () none 10) + (dummy-11 () none 11) + ) + ) ; ;; vol-h ; (deftype vol-control (basic) @@ -12576,28 +12560,28 @@ ; :flag-assert #x900000044 ; ) -; ;; cam-debug -; (deftype cam-collision-record (structure) -; ((pos vector :inline :offset-assert 0) -; (vel vector :inline :offset-assert 16) -; (desired-pos vector :inline :offset-assert 32) -; (cam-tpos-cur vector :inline :offset-assert 48) -; (cam-tpos-old vector :inline :offset-assert 64) -; (view-flat vector :inline :offset-assert 80) -; (string-min-val vector :inline :offset-assert 96) -; (string-max-val vector :inline :offset-assert 112) -; (view-off vector :inline :offset-assert 128) -; (min-z-override float :offset-assert 144) -; (string-push-z float :offset-assert 148) -; (view-off-param float :offset-assert 152) -; (frame int32 :offset-assert 156) -; (iteration int32 :offset-assert 160) -; (move-type basic :offset-assert 164) -; ) -; :method-count-assert 9 -; :size-assert #xa8 -; :flag-assert #x9000000a8 -; ) +;; cam-debug +(deftype cam-collision-record (structure) + ((pos vector :inline :offset-assert 0) + (vel vector :inline :offset-assert 16) + (desired-pos vector :inline :offset-assert 32) + (cam-tpos-cur vector :inline :offset-assert 48) + (cam-tpos-old vector :inline :offset-assert 64) + (view-flat vector :inline :offset-assert 80) + (string-min-val vector :inline :offset-assert 96) + (string-max-val vector :inline :offset-assert 112) + (view-off vector :inline :offset-assert 128) + (min-z-override float :offset-assert 144) + (string-push-z float :offset-assert 148) + (view-off-param float :offset-assert 152) + (frame int32 :offset-assert 156) + (iteration int32 :offset-assert 160) + (move-type basic :offset-assert 164) + ) + :method-count-assert 9 + :size-assert #xa8 + :flag-assert #x9000000a8 + ) ; ;; cam-debug ; (deftype cam-collision-record-array (inline-array-class) diff --git a/doc/changelog.md b/doc/changelog.md index 86149b81a5..aa7ea5a5dc 100644 --- a/doc/changelog.md +++ b/doc/changelog.md @@ -39,4 +39,8 @@ - The `&+` form now accepts more than two arguments. - The `&+` form now works on `inline-array` and `structure`. - In the case where the type system would use a result type of `lca(none, x)`, the result type is now `none` instead of compiler abort. -- The "none value" is now `(none)` instead of `none` \ No newline at end of file +- The "none value" is now `(none)` instead of `none` + +- Creating a field of 128-bit value type no longer causes a compiler crash +- 128-bit fields are inspected as `` +- Static fields can now contain floating point values \ No newline at end of file diff --git a/goal_src/engine/math/vector-h.gc b/goal_src/engine/math/vector-h.gc index c6c01ba0ee..5ca9f09394 100644 --- a/goal_src/engine/math/vector-h.gc +++ b/goal_src/engine/math/vector-h.gc @@ -5,3 +5,429 @@ ;; name in dgo: vector-h ;; dgos: GAME, ENGINE +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; bit array +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(deftype bit-array (basic) + ((length int32 :offset-assert 4) + (allocated-length int32 :offset-assert 8) + (_pad uint8) + ) + :method-count-assert 13 + :size-assert #xd + :flag-assert #xd0000000d + (:methods + (dummy-9 () none 9) + (dummy-10 () none 10) + (dummy-11 () none 11) + (dummy-12 () none 12) + ) + ) + +;; todo new +;; todo 4 +;; todo 5 +;; todo 9 +;; todo 10 +;; todo 11 +;; todo 12 +;; + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; vector types (integer) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +;; Vector of 4 unsigned bytes. +(deftype vector4ub (structure) + ((data uint8 4 :offset-assert 0) + (x uint8 :offset 0) + (y uint8 :offset 1) + (z uint8 :offset 2) + (w uint8 :offset 3) + (clr uint32 :offset 0) + ) + :pack-me + :method-count-assert 9 + :size-assert #x4 + :flag-assert #x900000004 + ) + +;; Vector of 4 signed bytes +(deftype vector4b (structure) + ((data int8 4 :offset-assert 0) + (x int8 :offset 0) + (y int8 :offset 1) + (z int8 :offset 2) + (w int8 :offset 3) + ) + :method-count-assert 9 + :size-assert #x4 + :flag-assert #x900000004 + ) + +;; Vector of 2 signed halfwords +(deftype vector2h (structure) + ((data int16 2 :offset-assert 0) + (x int16 :offset 0) + (y int16 :offset 2) + ) + :pack-me + :method-count-assert 9 + :size-assert #x4 + :flag-assert #x900000004 + ) + +;; Vector of 2 unsigned halfwords +(deftype vector2uh (structure) + ((data uint16 2 :offset-assert 0) + (x uint16 :offset 0) + (y uint16 :offset 2) + (val uint32 :offset 0) + ) + :pack-me + :method-count-assert 9 + :size-assert #x4 + :flag-assert #x900000004 + ) + +;; Vector of 3 halfwords +(deftype vector3h (structure) + ((data int16 2 :offset-assert 0) ;; probably a bug, should be 3. + (x int16 :offset 0) + (y int16 :offset 2) + (z int16 :offset-assert 4) + ) + :method-count-assert 9 + :size-assert #x6 + :flag-assert #x900000006 + ) + +;; Vector of 2 signed words +(deftype vector2w (structure) + ((data int32 2 :offset-assert 0) + (x int32 :offset 0) + (y int32 :offset 4) + ) + :pack-me + :method-count-assert 9 + :size-assert #x8 + :flag-assert #x900000008 + ) + +;; Vector of 3 signed words +(deftype vector3w (structure) + ((data int32 3 :offset-assert 0) + (x int32 :offset 0) + (y int32 :offset 4) + (z int32 :offset 8) + ) + :method-count-assert 9 + :size-assert #xc + :flag-assert #x90000000c + ) + +;; Vector of 4 signed words +(deftype vector4w (structure) + ((data int32 4 :offset-assert 0) + (x int32 :offset 0) + (y int32 :offset 4) + (z int32 :offset 8) + (w int32 :offset 12) + (dword uint64 2 :offset 0) + (quad uint128 :offset 0) + ) + :method-count-assert 9 + :size-assert #x10 + :flag-assert #x900000010 + ) + +(defmethod print vector4w ((this vector4w)) + (format #t "#" + (-> this data 0) + (-> this data 1) + (-> this data 2) + (-> this data 3) + this) + this + ) + +;; Two vector4w's +(deftype vector4w-2 (structure) + ((data int32 8 :offset-assert 0) + (quad uint128 2 :offset 0) + (vector vector4w 2 :offset 0) + ) + :method-count-assert 9 + :size-assert #x20 + :flag-assert #x900000020 + ) + +;; Three vector4w's +(deftype vector4w-3 (structure) + ((data int32 12 :offset-assert 0) + (quad uint128 3 :offset 0) + (vector vector4w 3 :offset 0) + ) + :method-count-assert 9 + :size-assert #x30 + :flag-assert #x900000030 + ) + +;; Four vector4w's +(deftype vector4w-4 (structure) + ((data int32 16 :offset-assert 0) + (quad uint128 4 :offset 0) + (vector vector4w 4 :offset 0) + ) + :method-count-assert 9 + :size-assert #x40 + :flag-assert #x900000040 + ) + +;; Vector of 4 halfwords +(deftype vector4h (structure) + ((data int16 4 :offset-assert 0) + (x int16 :offset 0) + (y int16 :offset 2) + (z int16 :offset 4) + (w int16 :offset 6) + (long uint64 :offset 0) + ) + :method-count-assert 9 + :size-assert #x8 + :flag-assert #x900000008 + ) + +;; Vector of 8 halfwords +(deftype vector8h (structure) + ((data int16 8 :offset-assert 0) + (quad uint128 :offset 0) + ) + :method-count-assert 9 + :size-assert #x10 + :flag-assert #x900000010 + ) + +;; Vector of 16 signed bytes +(deftype vector16b (structure) + ((data int8 8 :offset-assert 0) + (quad uint128 :offset 0) + ) + :method-count-assert 9 + :size-assert #x10 + :flag-assert #x900000010 + ) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; vector types (floating point) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +;; Vector of 4 floats. Shortened to "vector" because it is commonly used. +(deftype vector (structure) + ((data float 4 :offset-assert 0) + (x float :offset 0) + (y float :offset 4) + (z float :offset 8) + (w float :offset 12) + (quad uint128 :offset 0) + ) + :method-count-assert 9 + :size-assert #x10 + :flag-assert #x900000010 + ) + +(defmethod inspect vector ((this vector)) + (format #t "[~8x] vector~%" this) + (format #t "~T[~F] [~F] [~F] [~F]~%" + (-> this data 0) + (-> this data 1) + (-> this data 2) + (-> this data 3)) + this) + +(defmethod print vector ((this vector)) + (format #t "#" + (-> this data 0) + (-> this data 1) + (-> this data 2) + (-> this data 3) + this) + this) + + +(define *null-vector* (new 'static 'vector :x 0. :y 0. :z 0. :w 1.)) +(define *identity-vector* (new 'static 'vector :x 1. :y 1. :z 1. :w 1.)) +(define *x-vector* (new 'static 'vector :x 1. :y 0. :z 0. :w 1.)) +(define *y-vector* (new 'static 'vector :x 0. :y 1. :z 0. :w 1.)) +(define *z-vector* (new 'static 'vector :x 0. :y 0. :z 1. :w 1.)) +(define *up-vector* (new 'static 'vector :x 0. :y 1. :z 0. :w 1.)) + + +;; Three vector's +(deftype vector4s-3 (structure) + ((data float 12 :offset-assert 0) ;; guess + (quad uint128 3 :offset 0) + (vector vector4w 3 :offset 0) ;; guess + ) + :method-count-assert 9 + :size-assert #x30 + :flag-assert #x900000030 + ) + +(deftype vector-array (inline-array-class) + ( + ) + :method-count-assert 9 + :size-assert #x10 + :flag-assert #x900000010 + ) + +(set! (-> vector-array heap-base) 16) + +(deftype rgbaf (vector) + ((r float :offset 0) + (g float :offset 4) + (b float :offset 8) + (a float :offset 12) + ) + :method-count-assert 9 + :size-assert #x10 + :flag-assert #x900000010 + ) + +(deftype plane (vector) + ((a float :offset 0) + (b float :offset 4) + (c float :offset 8) + (d float :offset 12) + ) + :method-count-assert 9 + :size-assert #x10 + :flag-assert #x900000010 + ) + +(deftype sphere (vector) + ((r float :offset 12) + ) + :method-count-assert 9 + :size-assert #x10 + :flag-assert #x900000010 + ) + +; (deftype isphere (vec4s) +; () +; :method-count-assert 9 +; :size-assert #x10 +; :flag-assert #x900000010 +; ) + +(deftype box8s (structure) + ((data float 8 :offset-assert 0) + (quad uint128 2 :offset 0) + (vector vector 2 :offset 0) + (min vector :inline :offset 0) + (max vector :inline :offset 16) + ) + :method-count-assert 9 + :size-assert #x20 + :flag-assert #x900000020 + ) + +(deftype box8s-array (inline-array-class) + () + :method-count-assert 9 + :size-assert #x10 + :flag-assert #x900000010 + ) + +(set! (-> box8s-array heap-base) 32) + +(deftype cylinder (structure) + ((origin vector :inline :offset-assert 0) + (axis vector :inline :offset-assert 16) + (radius float :offset-assert 32) + (length float :offset-assert 36) + ) + :method-count-assert 11 + :size-assert #x28 + :flag-assert #xb00000028 + (:methods + (dummy-9 () none 9) + (dummy-10 () none 10) + ) + ) + +(deftype cylinder-flat (structure) + ((origin vector :inline :offset-assert 0) + (axis vector :inline :offset-assert 16) + (radius float :offset-assert 32) + (length float :offset-assert 36) + ) + :method-count-assert 11 + :size-assert #x28 + :flag-assert #xb00000028 + (:methods + (dummy-9 () none 9) + (dummy-10 () none 10) + ) + ) + +;; vector-h +(deftype vertical-planes (structure) + ((data uint128 4 :offset-assert 0) ;; probably wrong + ) + :method-count-assert 9 + :size-assert #x40 + :flag-assert #x900000040 + ) + +(deftype vertical-planes-array (basic) + ((length uint32 :offset-assert 4) + (data vertical-planes :dynamic :offset 16) ;; todo, why is this here? + ) + :method-count-assert 9 + :size-assert #x10 + :flag-assert #x900000010 + ) + +(deftype qword (structure) + ((data uint32 4 :offset-assert 0) + (byte uint8 16 :offset 0) + (hword uint16 8 :offset 0) + (word uint32 4 :offset 0) + (dword uint64 2 :offset 0) + (quad uint128 :offset 0) + (vector vector :inline :offset 0) + (vector4w vector4w :inline :offset 0) + ) + :method-count-assert 9 + :size-assert #x10 + :flag-assert #x900000010 + ) + +(deftype vector3s (structure) + ((data float 3 :offset-assert 0) + (x float :offset 0) + (y float :offset 4) + (z float :offset 8) + ) + :method-count-assert 9 + :size-assert #xc + :flag-assert #x90000000c + ) + +;; todo dot, dot-vu, 4-dot, 4-dot-vu, +!, -!, zero!, reset!, copy! + +; (defun vector-dot ((a vector) (b vector)) +; "Take the dot product of two vectors. +; Only does the x, y, z compoments" +; (let ((result 0.)) +; (+! result (* (-> a x) (-> b x))) +; (+! result (* (-> a y) (-> b y))) +; (+! result (* (-> a z) (-> b z))) +; ) +; result +; ) + +(define *zero-vector* (new 'static 'vector :x 0. :y 0. :z 0. :w 0.)) \ No newline at end of file diff --git a/goalc/compiler/Compiler.h b/goalc/compiler/Compiler.h index 34aa7cc813..049c2d99b1 100644 --- a/goalc/compiler/Compiler.h +++ b/goalc/compiler/Compiler.h @@ -94,6 +94,7 @@ class Compiler { const std::string& method_type_name = ""); bool try_getting_constant_integer(const goos::Object& in, int64_t* out, Env* env); + float try_getting_constant_float(const goos::Object& in, float* out, Env* env); TypeSystem m_ts; std::unique_ptr m_global_env = nullptr; @@ -189,6 +190,7 @@ class Compiler { // Math Val* compile_add(const goos::Object& form, const goos::Object& rest, Env* env); + Val* compile_sub(const goos::Object& form, const goos::Object& rest, Env* env); Val* compile_mul(const goos::Object& form, const goos::Object& rest, Env* env); Val* compile_div(const goos::Object& form, const goos::Object& rest, Env* env); diff --git a/goalc/compiler/Util.cpp b/goalc/compiler/Util.cpp index b3a805be69..40329ebdf7 100644 --- a/goalc/compiler/Util.cpp +++ b/goalc/compiler/Util.cpp @@ -215,6 +215,17 @@ bool Compiler::try_getting_constant_integer(const goos::Object& in, int64_t* out return true; } + // todo, try more things like constants before giving up. + return false; +} + +float Compiler::try_getting_constant_float(const goos::Object& in, float* out, Env* env) { + (void)env; + if (in.is_float()) { + *out = in.as_float(); + return true; + } + // todo, try more things like constants before giving up. return false; } \ No newline at end of file diff --git a/goalc/compiler/compilation/Static.cpp b/goalc/compiler/compilation/Static.cpp index e1eead7400..a8ea2dfbb4 100644 --- a/goalc/compiler/compilation/Static.cpp +++ b/goalc/compiler/compilation/Static.cpp @@ -119,6 +119,14 @@ Val* Compiler::compile_new_static_structure_or_basic(const goos::Object& form, throw_compile_error( form, "Setting a basic field to anything other than a symbol is currently unsupported"); } + } else if (is_float(field_info.type)) { + float value = 0.f; + if (!try_getting_constant_float(field_value, &value, env)) { + throw_compile_error(form, fmt::format("Field {} is a float, but the value given couldn't " + "be converted to a float at compile time.", + field_name_def)); + } + memcpy(obj->data.data() + field_offset, &value, sizeof(float)); } else { diff --git a/goalc/compiler/compilation/Type.cpp b/goalc/compiler/compilation/Type.cpp index ae2e07beba..478d07d411 100644 --- a/goalc/compiler/compilation/Type.cpp +++ b/goalc/compiler/compilation/Type.cpp @@ -111,24 +111,6 @@ void Compiler::generate_field_description(const goos::Object& form, if (m_ts.typecheck(m_ts.make_typespec("type"), f.type(), "", false, false)) { // type return; - } else if (m_ts.typecheck(m_ts.make_typespec("basic"), f.type(), "", false, false) || - m_ts.typecheck(m_ts.make_typespec("binteger"), f.type(), "", false, false) || - m_ts.typecheck(m_ts.make_typespec("pair"), f.type(), "", false, false)) { - // basic, binteger, pair - str_template += fmt::format("~T{}: ~A~%", f.name()); - format_args.push_back(get_field_of_structure(type, reg, f.name(), env)->to_gpr(env)); - } else if (m_ts.typecheck(m_ts.make_typespec("integer"), f.type(), "", false, false)) { - // Integer - str_template += fmt::format("~T{}: ~D~%", f.name()); - format_args.push_back(get_field_of_structure(type, reg, f.name(), env)->to_gpr(env)); - } else if (m_ts.typecheck(m_ts.make_typespec("float"), f.type(), "", false, false)) { - // Float - str_template += fmt::format("~T{}: ~f~%", f.name()); - format_args.push_back(get_field_of_structure(type, reg, f.name(), env)->to_gpr(env)); - } else if (m_ts.typecheck(m_ts.make_typespec("pointer"), f.type(), "", false, false)) { - // Pointers - str_template += fmt::format("~T{}: #x~X~%", f.name()); - format_args.push_back(get_field_of_structure(type, reg, f.name(), env)->to_gpr(env)); } else if (f.is_array() && !f.is_dynamic()) { // Arrays str_template += fmt::format("~T{}[{}] @ #x~X~%", f.name(), f.array_size()); @@ -141,6 +123,29 @@ void Compiler::generate_field_description(const goos::Object& form, // Structure str_template += fmt::format("~T{}: #<{} @ #x~X>~%", f.name(), f.type().print()); format_args.push_back(get_field_of_structure(type, reg, f.name(), env)->to_gpr(env)); + } else if (m_ts.typecheck(m_ts.make_typespec("basic"), f.type(), "", false, false) || + m_ts.typecheck(m_ts.make_typespec("binteger"), f.type(), "", false, false) || + m_ts.typecheck(m_ts.make_typespec("pair"), f.type(), "", false, false)) { + // basic, binteger, pair + str_template += fmt::format("~T{}: ~A~%", f.name()); + format_args.push_back(get_field_of_structure(type, reg, f.name(), env)->to_gpr(env)); + } else if (m_ts.typecheck(m_ts.make_typespec("integer"), f.type(), "", false, false)) { + // Integer + if (f.type().print() == "uint128") { + str_template += fmt::format("~T{}: ~%", f.name()); + } else { + str_template += fmt::format("~T{}: ~D~%", f.name()); + format_args.push_back(get_field_of_structure(type, reg, f.name(), env)->to_gpr(env)); + } + + } else if (m_ts.typecheck(m_ts.make_typespec("float"), f.type(), "", false, false)) { + // Float + str_template += fmt::format("~T{}: ~f~%", f.name()); + format_args.push_back(get_field_of_structure(type, reg, f.name(), env)->to_gpr(env)); + } else if (m_ts.typecheck(m_ts.make_typespec("pointer"), f.type(), "", false, false)) { + // Pointers + str_template += fmt::format("~T{}: #x~X~%", f.name()); + format_args.push_back(get_field_of_structure(type, reg, f.name(), env)->to_gpr(env)); } else { // Otherwise, we havn't implemented it! str_template += fmt::format("~T{}: Undefined!~%", f.name());