diff --git a/decompiler/IR2/Form.cpp b/decompiler/IR2/Form.cpp index 101a6ddd5e..98b6a95d7f 100644 --- a/decompiler/IR2/Form.cpp +++ b/decompiler/IR2/Form.cpp @@ -2230,7 +2230,8 @@ StackVarDefElement::StackVarDefElement(const StackVarEntry& entry) : m_entry(ent goos::Object StackVarDefElement::to_form_internal(const Env&) const { switch (m_entry.hint.container_type) { case StackVariableHint::ContainerType::NONE: - return pretty_print::build_list(fmt::format("new 'stack '{}", m_entry.ref_type.print())); + return pretty_print::build_list( + fmt::format("new 'stack-no-clear '{}", m_entry.ref_type.print())); default: assert(false); } diff --git a/doc/changelog.md b/doc/changelog.md index 22b5a7946e..a9932e0fb4 100644 --- a/doc/changelog.md +++ b/doc/changelog.md @@ -131,4 +131,7 @@ - Fixed a bug where 128-bit variable spills could be misaligned, causing a segfault at `vmovaps`. - Added `.ppach` and `.pceqw` - Fixed a bug where setting 128-bit / 64-bit variables from each other only did a 32-bit set -- Added support for creating a static bitfield where fields may not be known at compile time. \ No newline at end of file +- Added support for creating a static bitfield where fields may not be known at compile time. +- Added support for `(size-of )` +- Fixed a bug where creating a stack array of 0 sized caused a compiler assertion. It is now a normal compiler error. +- Fixed a bug where the repl history was not loaded on compiler start \ No newline at end of file diff --git a/doc/goal_doc.md b/doc/goal_doc.md index 7dfe414bd3..9717558fdd 100644 --- a/doc/goal_doc.md +++ b/doc/goal_doc.md @@ -1259,6 +1259,22 @@ Example: None of the edge cases of `the` apply to `the-as`. +## `size-of` +Get the size of a type, in bytes. +```lisp +(size-of ) +``` +Get the size of a type, by name. The type must be a plain name, like `pointer` or `dma-bucket`. Compound types are not supported. It works on value and structure types and returns the size in memory. For dynamic types, it returns the size if there if the dynamic part has 0 size. For weird types like `none` it throws an error. + +This value can be used in most places where the compiler is expecting a constant integer as well, such as the size of a stack array, which must be known at compile time. + +Example: +```lisp +(size-of dma-bucket) +``` +Returns the size of the `dma-bucket` type which is 16 bytes. + + ## Pointer Math Not implemented well yet. diff --git a/goal_src/engine/math/euler.gc b/goal_src/engine/math/euler.gc index b095528142..3f3e7b383d 100644 --- a/goal_src/engine/math/euler.gc +++ b/goal_src/engine/math/euler.gc @@ -20,7 +20,7 @@ (defun eul->matrix ((arg0 matrix) (arg1 euler-angles)) "Convert euler angles to rotation matrix." (matrix-identity! arg0) - (let ((s5-0 (new 'stack 'vector))) + (let ((s5-0 (new 'stack-no-clear 'vector))) ;; copy to temp storage. (set! (-> s5-0 quad) (-> arg1 quad)) (if (= (logand (the int (-> s5-0 data 3)) 1) 1) @@ -238,7 +238,7 @@ (defun eul->quat ((arg0 quaternion) (arg1 euler-angles)) "Convert euler angles to quaternion" - (let ((s5-0 (new 'stack 'matrix))) + (let ((s5-0 (new 'stack-no-clear 'matrix))) (eul->matrix s5-0 arg1) (matrix->quaternion arg0 s5-0) ) @@ -247,7 +247,7 @@ (defun quat->eul ((arg0 euler-angles) (arg1 quaternion) (arg2 int)) "Convert quaternion to euler angles. The last argument is euler flags" - (let ((s5-0 (new 'stack 'matrix))) + (let ((s5-0 (new 'stack-no-clear 'matrix))) (quaternion->matrix s5-0 arg1) (matrix->eul arg0 s5-0 arg2) ) diff --git a/goal_src/engine/math/matrix.gc b/goal_src/engine/math/matrix.gc index 3cfb737a9c..ecf184327b 100644 --- a/goal_src/engine/math/matrix.gc +++ b/goal_src/engine/math/matrix.gc @@ -177,7 +177,7 @@ "Set dst = src1 * src2. NOTE: this function is a wrapper around matrix*! that adds no additional functionality. It seems to be a leftover from a time when matrix*! wasn't safe to use in place. This is unused." - (let ((temp-mat (new 'stack 'matrix))) + (let ((temp-mat (new 'stack-no-clear 'matrix))) (set! (-> temp-mat vector 0 quad) (the-as uint128 0)) (set! (-> temp-mat vector 1 quad) (the-as uint128 0)) (set! (-> temp-mat vector 2 quad) (the-as uint128 0)) @@ -251,7 +251,7 @@ (defun vector3s-matrix*! ((dst vector3s) (vec vector3s) (mat matrix)) "Set dst to be ([src 1.0] * mat).xyz. Doesn't touch the w of dst. dst and vec can be the same memory" - (let ((temp-vec3 (new 'stack 'vector))) + (let ((temp-vec3 (new 'stack-no-clear 'vector))) ;; create a temporary vec with [x, y, z, 1.0] (set! (-> temp-vec3 quad) (the-as uint128 0)) (let ((v1-0 temp-vec3)) @@ -272,7 +272,7 @@ (defun vector3s-rotate*! ((dst vector3s) (vec vector3s) (mat matrix)) "Set dst to vec rotated by the rotation in the homogeneous transform mat. mat should not have a scale/shear (the upper 3x3 should be a pure rotation)." - (let ((temp-vec3 (new 'stack 'vector))) + (let ((temp-vec3 (new 'stack-no-clear 'vector))) (set! (-> temp-vec3 quad) (the-as uint128 0)) (let ((v1-0 temp-vec3)) (set! (-> v1-0 data 0) (-> vec data 0)) @@ -717,12 +717,12 @@ (defun matrix-rotate-zyx! ((dst matrix) (rot-xyz-deg vector)) "Rotate in z,y,x order." - (let ((temp-mat (new 'stack 'matrix))) + (let ((temp-mat (new 'stack-no-clear 'matrix))) (set! (-> temp-mat vector 0 quad) (the-as uint128 0)) (set! (-> temp-mat vector 1 quad) (the-as uint128 0)) (set! (-> temp-mat vector 2 quad) (the-as uint128 0)) (set! (-> temp-mat vector 3 quad) (the-as uint128 0)) - (let ((rot-mat (new 'stack 'matrix))) + (let ((rot-mat (new 'stack-no-clear 'matrix))) (set! (-> rot-mat vector 0 quad) (the-as uint128 0)) (set! (-> rot-mat vector 1 quad) (the-as uint128 0)) (set! (-> rot-mat vector 2 quad) (the-as uint128 0)) @@ -743,12 +743,12 @@ (defun matrix-rotate-xyz! ((dst matrix) (rot-xyz-deg vector)) "Rotate in x,y,z order" - (let ((temp-mat (new 'stack 'matrix))) + (let ((temp-mat (new 'stack-no-clear 'matrix))) (set! (-> temp-mat vector 0 quad) (the-as uint128 0)) (set! (-> temp-mat vector 1 quad) (the-as uint128 0)) (set! (-> temp-mat vector 2 quad) (the-as uint128 0)) (set! (-> temp-mat vector 3 quad) (the-as uint128 0)) - (let ((rot-mat (new 'stack 'matrix))) + (let ((rot-mat (new 'stack-no-clear 'matrix))) (set! (-> rot-mat vector 0 quad) (the-as uint128 0)) (set! (-> rot-mat vector 1 quad) (the-as uint128 0)) (set! (-> rot-mat vector 2 quad) (the-as uint128 0)) @@ -765,12 +765,12 @@ (defun matrix-rotate-zxy! ((dst matrix) (rot-xyz-deg vector)) "Rotate in z,x,y order" - (let ((temp-mat (new 'stack 'matrix))) + (let ((temp-mat (new 'stack-no-clear 'matrix))) (set! (-> temp-mat vector 0 quad) (the-as uint128 0)) (set! (-> temp-mat vector 1 quad) (the-as uint128 0)) (set! (-> temp-mat vector 2 quad) (the-as uint128 0)) (set! (-> temp-mat vector 3 quad) (the-as uint128 0)) - (let ((rot-mat (new 'stack 'matrix))) + (let ((rot-mat (new 'stack-no-clear 'matrix))) (set! (-> rot-mat vector 0 quad) (the-as uint128 0)) (set! (-> rot-mat vector 1 quad) (the-as uint128 0)) (set! (-> rot-mat vector 2 quad) (the-as uint128 0)) @@ -787,12 +787,12 @@ (defun matrix-rotate-yxz! ((dst matrix) (rot-xyz-deg vector)) "Rotate in y,x,z order." - (let ((temp-mat (new 'stack 'matrix))) + (let ((temp-mat (new 'stack-no-clear 'matrix))) (set! (-> temp-mat vector 0 quad) (the-as uint128 0)) (set! (-> temp-mat vector 1 quad) (the-as uint128 0)) (set! (-> temp-mat vector 2 quad) (the-as uint128 0)) (set! (-> temp-mat vector 3 quad) (the-as uint128 0)) - (let ((rot-mat (new 'stack 'matrix))) + (let ((rot-mat (new 'stack-no-clear 'matrix))) (set! (-> rot-mat vector 0 quad) (the-as uint128 0)) (set! (-> rot-mat vector 1 quad) (the-as uint128 0)) (set! (-> rot-mat vector 2 quad) (the-as uint128 0)) @@ -809,12 +809,12 @@ (defun matrix-rotate-yzx! ((dst matrix) (rot-xyz-deg vector)) "Rotate in y,z,x order" - (let ((temp-mat (new 'stack 'matrix))) + (let ((temp-mat (new 'stack-no-clear 'matrix))) (set! (-> temp-mat vector 0 quad) (the-as uint128 0)) (set! (-> temp-mat vector 1 quad) (the-as uint128 0)) (set! (-> temp-mat vector 2 quad) (the-as uint128 0)) (set! (-> temp-mat vector 3 quad) (the-as uint128 0)) - (let ((rot-mat (new 'stack 'matrix))) + (let ((rot-mat (new 'stack-no-clear 'matrix))) (set! (-> rot-mat vector 0 quad) (the-as uint128 0)) (set! (-> rot-mat vector 1 quad) (the-as uint128 0)) (set! (-> rot-mat vector 2 quad) (the-as uint128 0)) @@ -832,9 +832,9 @@ (defun matrix-rotate-yxy! ((dst matrix) (rots-deg vector)) "Rotate. I believe in yxy order? Compared to the other rotations, this one is quite a bit more optimized and avoid repeated trig operations." - (let ((sincos-input (new 'stack 'vector)) - (sin-vec (new 'stack 'vector)) - (cos-vec (new 'stack 'vector)) + (let ((sincos-input (new 'stack-no-clear 'vector)) + (sin-vec (new 'stack-no-clear 'vector)) + (cos-vec (new 'stack-no-clear 'vector)) ) ;; the vector-sincos! lets us take the sine and cosine of 4 floats at a time. @@ -881,7 +881,7 @@ ;; this is weird. probably there is an inlined ctor in a new 'stack expression, used directly ;; in an argument. like (matrix-rotate-x! (new 'stack-with-ctor 'matrix) ...) (let ((t9-1 matrix-rotate-x!) - (a0-2 (new 'stack 'matrix)) + (a0-2 (new 'stack-no-clear 'matrix)) ) (set! (-> a0-2 vector 0 quad) (the-as uint128 0)) (set! (-> a0-2 vector 1 quad) (the-as uint128 0)) diff --git a/goal_src/engine/math/quaternion.gc b/goal_src/engine/math/quaternion.gc index 448734c489..78659173c0 100644 --- a/goal_src/engine/math/quaternion.gc +++ b/goal_src/engine/math/quaternion.gc @@ -603,7 +603,7 @@ (vf6 :class vf) (vf7 :class vf) ) - (let ((v1-0 (new 'stack 'matrix))) + (let ((v1-0 (new 'stack-no-clear 'matrix))) (set! (-> v1-0 vector 0 quad) (the-as uint128 0)) (set! (-> v1-0 vector 1 quad) (the-as uint128 0)) (set! (-> v1-0 vector 2 quad) (the-as uint128 0)) @@ -696,7 +696,7 @@ (set! (-> arg0 w) 1.0) ) (else - (let ((s5-0 (new 'stack 'vector))) + (let ((s5-0 (new 'stack-no-clear 'vector))) (sincos-rad! (the-as (pointer float) s5-0) f30-0) (let ((f0-6 (/ (-> s5-0 data 0) f30-0))) (set! (-> arg0 x) (* (-> arg1 x) f0-6)) @@ -753,7 +753,7 @@ (f28-0 (/ 1.0 f1-6)) ) (let ((f0-7 (atan-series-rad f0-6)) - (s2-0 (new 'stack 'vector)) + (s2-0 (new 'stack-no-clear 'vector)) ) (set! (-> s2-0 data 0) (* (- 1.0 arg3) f0-7)) (set! (-> s2-0 data 1) (* (* arg3 f0-7) f30-0)) @@ -827,9 +827,9 @@ (vf7 :class vf) ) (.lvf vf0 (new 'static 'vector :x 0.0 :y 0.0 :z 0.0 :w 1.0)) - (let ((s4-0 (new 'stack 'vector)) - (gp-0 (new 'stack 'vector)) - (s5-0 (new 'stack 'vector)) + (let ((s4-0 (new 'stack-no-clear 'vector)) + (gp-0 (new 'stack-no-clear 'vector)) + (s5-0 (new 'stack-no-clear 'vector)) ) (vector-rad<-vector-deg/2! s4-0 arg1) (vector-sincos-rad! gp-0 s5-0 s4-0) @@ -854,7 +854,7 @@ (defun vector-x-quaternion! ((arg0 vector) (arg1 quaternion)) "Get the first row of the rotation matrix for this quaternion" - (let ((s5-0 (new 'stack 'matrix))) + (let ((s5-0 (new 'stack-no-clear 'matrix))) (set! (-> s5-0 vector 0 quad) (the-as uint128 0)) (set! (-> s5-0 vector 1 quad) (the-as uint128 0)) (set! (-> s5-0 vector 2 quad) (the-as uint128 0)) @@ -867,7 +867,7 @@ (defun vector-y-quaternion! ((arg0 vector) (arg1 quaternion)) "Get the second row of the rotation matrix for this quaternion" - (let ((s5-0 (new 'stack 'matrix))) + (let ((s5-0 (new 'stack-no-clear 'matrix))) (set! (-> s5-0 vector 0 quad) (the-as uint128 0)) (set! (-> s5-0 vector 1 quad) (the-as uint128 0)) (set! (-> s5-0 vector 2 quad) (the-as uint128 0)) @@ -880,7 +880,7 @@ (defun vector-z-quaternion! ((arg0 vector) (arg1 quaternion)) "Get the third row of the rotation matrix for this quaternion" - (let ((s5-0 (new 'stack 'matrix))) + (let ((s5-0 (new 'stack-no-clear 'matrix))) (set! (-> s5-0 vector 0 quad) (the-as uint128 0)) (set! (-> s5-0 vector 1 quad) (the-as uint128 0)) (set! (-> s5-0 vector 2 quad) (the-as uint128 0)) @@ -893,7 +893,7 @@ (defun quaternion-y-angle ((arg0 quaternion)) "Not 100% sure, but get the y rotation angle?" - (let ((v1-1 (vector-z-quaternion! (new 'stack 'vector) arg0))) + (let ((v1-1 (vector-z-quaternion! (new 'stack-no-clear 'vector) arg0))) (atan (-> v1-1 data 0) (-> v1-1 data 2)) ) ) @@ -910,7 +910,7 @@ (defun quaternion-rotate-local-x! ((arg0 quaternion) (arg1 quaternion) (arg2 float)) "Rotate existing quaternion along x axis." (let ((t9-0 quaternion-vector-angle!) - (a0-1 (new 'stack 'quaternion)) + (a0-1 (new 'stack-no-clear 'quaternion)) ) (set! (-> a0-1 vec quad) (the-as uint128 0)) (let ((a2-1 (t9-0 a0-1 (new 'static 'vector :x 1.0 :w 1.0) arg2))) @@ -922,7 +922,7 @@ (defun quaternion-rotate-local-y! ((arg0 quaternion) (arg1 quaternion) (arg2 float)) "Rotate existing quaternion along y axis" (let ((t9-0 quaternion-vector-angle!) - (a0-1 (new 'stack 'quaternion)) + (a0-1 (new 'stack-no-clear 'quaternion)) ) (set! (-> a0-1 vec quad) (the-as uint128 0)) (let ((a2-1 (t9-0 a0-1 (new 'static 'vector :y 1.0 :w 1.0) arg2))) @@ -934,7 +934,7 @@ (defun quaternion-rotate-local-z! ((arg0 quaternion) (arg1 quaternion) (arg2 float)) "Rotate existing quaternion along z axis." (let ((t9-0 quaternion-vector-angle!) - (a0-1 (new 'stack 'quaternion)) + (a0-1 (new 'stack-no-clear 'quaternion)) ) (set! (-> a0-1 vec quad) (the-as uint128 0)) (let ((a2-1 (t9-0 a0-1 (new 'static 'vector :z 1.0 :w 1.0) arg2))) @@ -946,7 +946,7 @@ (defun quaternion-rotate-y! ((arg0 quaternion) (arg1 quaternion) (arg2 float)) "Rotate existing quaternion along y axis (right multiply)" (let ((t9-0 quaternion-vector-angle!) - (a0-1 (new 'stack 'quaternion)) + (a0-1 (new 'stack-no-clear 'quaternion)) ) (set! (-> a0-1 vec quad) (the-as uint128 0)) (let ((a1-2 (t9-0 a0-1 (new 'static 'vector :y 1.0 :w 1.0) arg2))) @@ -959,11 +959,11 @@ "Rotate existing quaternion along x axis. This has a different implementation from the others for some reason." (let ((s4-0 quaternion-vector-angle!) - (s3-0 (new 'stack 'quaternion)) + (s3-0 (new 'stack-no-clear 'quaternion)) ) (set! (-> s3-0 vec quad) (the-as uint128 0)) (let ((t9-0 vector-x-quaternion!) - (a0-1 (new 'stack 'vector)) + (a0-1 (new 'stack-no-clear 'vector)) ) (set! (-> a0-1 quad) (the-as uint128 0)) (let ((a1-3 (s4-0 s3-0 (t9-0 a0-1 arg1) arg2))) @@ -976,11 +976,11 @@ (defun quaternion-rotate-z! ((arg0 quaternion) (arg1 quaternion) (arg2 float)) "Rotate existing quaternion along z axis. Has the weird implementation too." (let ((s4-0 quaternion-vector-angle!) - (s3-0 (new 'stack 'quaternion)) + (s3-0 (new 'stack-no-clear 'quaternion)) ) (set! (-> s3-0 vec quad) (the-as uint128 0)) (let ((t9-0 vector-z-quaternion!) - (a0-1 (new 'stack 'vector)) + (a0-1 (new 'stack-no-clear 'vector)) ) (set! (-> a0-1 quad) (the-as uint128 0)) (let ((a1-3 (s4-0 s3-0 (t9-0 a0-1 arg1) arg2))) @@ -991,8 +991,8 @@ ) (defun quaternion-delta-y ((arg0 quaternion) (arg1 quaternion)) - (acos (vector-dot (vector-z-quaternion! (new 'stack 'vector) arg0) - (vector-z-quaternion! (new 'stack 'vector) arg1) + (acos (vector-dot (vector-z-quaternion! (new 'stack-no-clear 'vector) arg0) + (vector-z-quaternion! (new 'stack-no-clear 'vector) arg1) ) ) ) @@ -1017,9 +1017,9 @@ (defun quaternion-rotate-y-to-vector! ((arg0 quaternion) (arg1 quaternion) (arg2 quaternion) (arg3 float)) - (let ((s5-0 (new 'stack 'quaternion))) + (let ((s5-0 (new 'stack-no-clear 'quaternion))) (let ((t9-0 vector-xz-normalize!) - (a0-1 (new 'stack 'vector)) + (a0-1 (new 'stack-no-clear 'vector)) ) (set! (-> a0-1 data 0) (-> arg2 x)) (set! (-> a0-1 data 1) 0.0) @@ -1028,7 +1028,7 @@ (let ((s0-0 (t9-0 a0-1 1.0))) (quaternion-from-two-vectors-max-angle! s5-0 - (vector-z-quaternion! (the-as vector (new 'stack 'quaternion)) arg1) + (vector-z-quaternion! (the-as vector (new 'stack-no-clear 'quaternion)) arg1) s0-0 arg3 ) @@ -1041,12 +1041,12 @@ (defun vector-rotate-y! ((arg0 vector) (arg1 vector) (arg2 float)) (let ((a1-2 (quaternion-vector-angle! - (new 'stack 'quaternion) + (new 'stack-no-clear 'quaternion) (new 'static 'vector :y 1.0 :w 1.0) arg2 ) ) - (s4-0 (new 'stack 'matrix)) + (s4-0 (new 'stack-no-clear 'matrix)) ) (quaternion->matrix s4-0 a1-2) (vector-matrix*! arg0 arg1 s4-0) @@ -1070,8 +1070,8 @@ ) (defun quaternion-xz-angle ((arg0 quaternion)) - (let ((gp-0 (new 'stack 'matrix)) - (s5-0 (new 'stack 'vector)) + (let ((gp-0 (new 'stack-no-clear 'matrix)) + (s5-0 (new 'stack-no-clear 'vector)) ) (quaternion->matrix gp-0 arg0) (let ((v1-1 s5-0)) diff --git a/goal_src/engine/math/transform.gc b/goal_src/engine/math/transform.gc index 97ccfafd34..9713386961 100644 --- a/goal_src/engine/math/transform.gc +++ b/goal_src/engine/math/transform.gc @@ -40,12 +40,12 @@ (defun transform-matrix-calc! ((tf transform) (dst-mat matrix)) "Convert a transform to a matrix. This is not particularly efficient." - (let ((s4-0 (new 'stack 'matrix))) + (let ((s4-0 (new 'stack-no-clear 'matrix))) (set! (-> s4-0 vector 0 quad) (the-as uint128 0)) (set! (-> s4-0 vector 1 quad) (the-as uint128 0)) (set! (-> s4-0 vector 2 quad) (the-as uint128 0)) (set! (-> s4-0 vector 3 quad) (the-as uint128 0)) - (let ((s3-0 (new 'stack 'matrix))) + (let ((s3-0 (new 'stack-no-clear 'matrix))) (set! (-> s3-0 vector 0 quad) (the-as uint128 0)) (set! (-> s3-0 vector 1 quad) (the-as uint128 0)) (set! (-> s3-0 vector 2 quad) (the-as uint128 0)) @@ -72,12 +72,12 @@ (defun transform-matrix-parent-calc! ((tf transform) (dst-mat matrix) (inv-scale vector)) "Convert a transform to a matrix, applying an inverse scaling." - (let ((s4-0 (new 'stack 'matrix))) + (let ((s4-0 (new 'stack-no-clear 'matrix))) (set! (-> s4-0 vector 0 quad) (the-as uint128 0)) (set! (-> s4-0 vector 1 quad) (the-as uint128 0)) (set! (-> s4-0 vector 2 quad) (the-as uint128 0)) (set! (-> s4-0 vector 3 quad) (the-as uint128 0)) - (let ((s3-0 (new 'stack 'matrix))) + (let ((s3-0 (new 'stack-no-clear 'matrix))) (set! (-> s3-0 vector 0 quad) (the-as uint128 0)) (set! (-> s3-0 vector 1 quad) (the-as uint128 0)) (set! (-> s3-0 vector 2 quad) (the-as uint128 0)) diff --git a/goalc/CMakeLists.txt b/goalc/CMakeLists.txt index 232d7c3b99..e3890937dc 100644 --- a/goalc/CMakeLists.txt +++ b/goalc/CMakeLists.txt @@ -12,6 +12,7 @@ add_library(compiler compiler/CompilerSettings.cpp compiler/CodeGenerator.cpp compiler/StaticObject.cpp + compiler/compilation/Asm.cpp compiler/compilation/Atoms.cpp compiler/compilation/CompilerControl.cpp compiler/compilation/Block.cpp @@ -35,8 +36,6 @@ add_library(compiler regalloc/Allocator.cpp regalloc/allocate.cpp regalloc/allocate_common.cpp - compiler/Compiler.cpp - compiler/compilation/Asm.cpp ) target_link_libraries(compiler common Zydis) diff --git a/goalc/compiler/Compiler.cpp b/goalc/compiler/Compiler.cpp index 3a810026e9..901d4e37be 100644 --- a/goalc/compiler/Compiler.cpp +++ b/goalc/compiler/Compiler.cpp @@ -24,6 +24,11 @@ Compiler::Compiler(std::unique_ptr repl) for (auto& builtin : g_goal_forms) { m_symbol_info.add_builtin(builtin.first); } + + // load auto-complete history, only if we are running in the interactive mode. + if (m_repl) { + m_repl->load_history(); + } } ReplStatus Compiler::execute_repl() { diff --git a/goalc/compiler/Compiler.h b/goalc/compiler/Compiler.h index 35bf7f6eca..6b5146a769 100644 --- a/goalc/compiler/Compiler.h +++ b/goalc/compiler/Compiler.h @@ -312,6 +312,7 @@ class Compiler { std::vector> args); u8 ftf_fsf_to_blend_mask(u8 val); emitter::Register::VF_ELEMENT ftf_fsf_to_vector_element(u8 val); + int get_size_for_size_of(const goos::Object& form, const goos::Object& rest); template void throw_compiler_error(const goos::Object& code, const std::string& str, Args&&... args) { @@ -539,6 +540,7 @@ class Compiler { Val* compile_declare_type(const goos::Object& form, const goos::Object& rest, Env* env); Val* compile_none(const goos::Object& form, const goos::Object& rest, Env* env); Val* compile_defenum(const goos::Object& form, const goos::Object& rest, Env* env); + Val* compile_size_of(const goos::Object& form, const goos::Object& rest, Env* env); }; extern const std::unordered_map< diff --git a/goalc/compiler/Util.cpp b/goalc/compiler/Util.cpp index 30132bb1ee..67b2000902 100644 --- a/goalc/compiler/Util.cpp +++ b/goalc/compiler/Util.cpp @@ -214,6 +214,11 @@ bool Compiler::try_getting_constant_integer(const goos::Object& in, int64_t* out return true; } } + + if (head_sym->name == "size-of") { + *out = get_size_for_size_of(in, in.as_pair()->cdr); + return true; + } } } @@ -227,7 +232,6 @@ bool Compiler::try_getting_constant_integer(const goos::Object& in, int64_t* out } } - // todo, try more things like constants before giving up. return false; } diff --git a/goalc/compiler/compilation/Atoms.cpp b/goalc/compiler/compilation/Atoms.cpp index f51b6fb83f..5f731309be 100644 --- a/goalc/compiler/compilation/Atoms.cpp +++ b/goalc/compiler/compilation/Atoms.cpp @@ -172,6 +172,7 @@ const std::unordered_map< {"method-of-object", &Compiler::compile_method_of_object}, {"declare-type", &Compiler::compile_declare_type}, {"none", &Compiler::compile_none}, + {"size-of", &Compiler::compile_size_of}, // LAMBDA {"lambda", &Compiler::compile_lambda}, diff --git a/goalc/compiler/compilation/Type.cpp b/goalc/compiler/compilation/Type.cpp index 5f3363aaa0..873fa4e092 100644 --- a/goalc/compiler/compilation/Type.cpp +++ b/goalc/compiler/compilation/Type.cpp @@ -812,6 +812,10 @@ Val* Compiler::compile_stack_new(const goos::Object& form, throw_compiler_error(form, "Cannot create a dynamically sized stack array"); } + if (constant_count <= 0) { + throw_compiler_error(form, "Cannot create a stack array with size {}", constant_count); + } + if (!rest->is_empty_list()) { // got extra arguments throw_compiler_error(form, "New array form got more arguments than expected"); @@ -1134,4 +1138,34 @@ bool GoalEnum::operator==(const GoalEnum& other) const { bool GoalEnum::operator!=(const GoalEnum& other) const { return !(*this == other); +} + +int Compiler::get_size_for_size_of(const goos::Object& form, const goos::Object& rest) { + auto args = get_va(form, rest); + va_check(form, args, {goos::ObjectType::SYMBOL}, {}); + + if (!m_ts.fully_defined_type_exists(args.unnamed.at(0).as_symbol()->name)) { + throw_compiler_error( + form, "The type {} given to size-of could not be found, or was not fully defined", + args.unnamed.at(0).print()); + } + + auto type = m_ts.lookup_type(args.unnamed.at(0).as_symbol()->name); + auto as_value = dynamic_cast(type); + auto as_structure = dynamic_cast(type); + + if (as_value) { + return as_value->get_load_size(); + + } else if (as_structure) { + return as_structure->get_size_in_memory(); + + } else { + throw_compiler_error(form, "The type {} does not have a size.", args.unnamed.at(0).print()); + return -1; + } +} + +Val* Compiler::compile_size_of(const goos::Object& form, const goos::Object& rest, Env* env) { + return compile_integer(get_size_for_size_of(form, rest), env); } \ No newline at end of file diff --git a/test/decompiler/reference/euler_REF.gc b/test/decompiler/reference/euler_REF.gc index 6e8d96be4a..bc6279198e 100644 --- a/test/decompiler/reference/euler_REF.gc +++ b/test/decompiler/reference/euler_REF.gc @@ -16,7 +16,7 @@ ;; Used lq/sq (defun eul->matrix ((arg0 matrix) (arg1 euler-angles)) (matrix-identity! arg0) - (let ((s5-0 (new 'stack 'vector))) + (let ((s5-0 (new 'stack-no-clear 'vector))) (set! (-> s5-0 quad) (-> arg1 quad)) (if (= (logand (the int (-> s5-0 data 3)) 1) 1) (let ((f0-2 (-> s5-0 data 0))) @@ -492,7 +492,7 @@ ;; definition for function eul->quat (defun eul->quat ((arg0 quaternion) (arg1 euler-angles)) - (let ((s5-0 (new 'stack 'matrix))) + (let ((s5-0 (new 'stack-no-clear 'matrix))) (eul->matrix s5-0 arg1) (matrix->quaternion arg0 s5-0) ) @@ -501,7 +501,7 @@ ;; definition for function quat->eul (defun quat->eul ((arg0 euler-angles) (arg1 quaternion) (arg2 int)) - (let ((s5-0 (new 'stack 'matrix))) + (let ((s5-0 (new 'stack-no-clear 'matrix))) (quaternion->matrix s5-0 arg1) (matrix->eul arg0 s5-0 arg2) ) diff --git a/test/decompiler/reference/matrix_REF.gc b/test/decompiler/reference/matrix_REF.gc index b1efadf14b..317776e914 100644 --- a/test/decompiler/reference/matrix_REF.gc +++ b/test/decompiler/reference/matrix_REF.gc @@ -157,7 +157,7 @@ ;; definition for function matrixp*! ;; Used lq/sq (defun matrixp*! ((dst matrix) (src1 matrix) (src2 matrix)) - (let ((temp-mat (new 'stack 'matrix))) + (let ((temp-mat (new 'stack-no-clear 'matrix))) (set! (-> temp-mat vector 0 quad) (the-as uint128 0)) (set! (-> temp-mat vector 1 quad) (the-as uint128 0)) (set! (-> temp-mat vector 2 quad) (the-as uint128 0)) @@ -225,7 +225,7 @@ ;; definition for function vector3s-matrix*! ;; Used lq/sq (defun vector3s-matrix*! ((dst vector3s) (vec vector3s) (mat matrix)) - (let ((temp-vec3 (new 'stack 'vector))) + (let ((temp-vec3 (new 'stack-no-clear 'vector))) (set! (-> temp-vec3 quad) (the-as uint128 0)) (let ((v1-0 temp-vec3)) (set! (-> v1-0 data 0) (-> vec data 0)) @@ -244,7 +244,7 @@ ;; definition for function vector3s-rotate*! ;; Used lq/sq (defun vector3s-rotate*! ((dst vector3s) (vec vector3s) (mat matrix)) - (let ((temp-vec3 (new 'stack 'vector))) + (let ((temp-vec3 (new 'stack-no-clear 'vector))) (set! (-> temp-vec3 quad) (the-as uint128 0)) (let ((v1-0 temp-vec3)) (set! (-> v1-0 data 0) (-> vec data 0)) @@ -660,12 +660,12 @@ ;; definition for function matrix-rotate-zyx! ;; Used lq/sq (defun matrix-rotate-zyx! ((dst matrix) (rot-xyz-deg vector)) - (let ((temp-mat (new 'stack 'matrix))) + (let ((temp-mat (new 'stack-no-clear 'matrix))) (set! (-> temp-mat vector 0 quad) (the-as uint128 0)) (set! (-> temp-mat vector 1 quad) (the-as uint128 0)) (set! (-> temp-mat vector 2 quad) (the-as uint128 0)) (set! (-> temp-mat vector 3 quad) (the-as uint128 0)) - (let ((rot-mat (new 'stack 'matrix))) + (let ((rot-mat (new 'stack-no-clear 'matrix))) (set! (-> rot-mat vector 0 quad) (the-as uint128 0)) (set! (-> rot-mat vector 1 quad) (the-as uint128 0)) (set! (-> rot-mat vector 2 quad) (the-as uint128 0)) @@ -683,12 +683,12 @@ ;; definition for function matrix-rotate-xyz! ;; Used lq/sq (defun matrix-rotate-xyz! ((dst matrix) (rot-xyz-deg vector)) - (let ((temp-mat (new 'stack 'matrix))) + (let ((temp-mat (new 'stack-no-clear 'matrix))) (set! (-> temp-mat vector 0 quad) (the-as uint128 0)) (set! (-> temp-mat vector 1 quad) (the-as uint128 0)) (set! (-> temp-mat vector 2 quad) (the-as uint128 0)) (set! (-> temp-mat vector 3 quad) (the-as uint128 0)) - (let ((rot-mat (new 'stack 'matrix))) + (let ((rot-mat (new 'stack-no-clear 'matrix))) (set! (-> rot-mat vector 0 quad) (the-as uint128 0)) (set! (-> rot-mat vector 1 quad) (the-as uint128 0)) (set! (-> rot-mat vector 2 quad) (the-as uint128 0)) @@ -706,12 +706,12 @@ ;; definition for function matrix-rotate-zxy! ;; Used lq/sq (defun matrix-rotate-zxy! ((dst matrix) (rot-xyz-deg vector)) - (let ((temp-mat (new 'stack 'matrix))) + (let ((temp-mat (new 'stack-no-clear 'matrix))) (set! (-> temp-mat vector 0 quad) (the-as uint128 0)) (set! (-> temp-mat vector 1 quad) (the-as uint128 0)) (set! (-> temp-mat vector 2 quad) (the-as uint128 0)) (set! (-> temp-mat vector 3 quad) (the-as uint128 0)) - (let ((rot-mat (new 'stack 'matrix))) + (let ((rot-mat (new 'stack-no-clear 'matrix))) (set! (-> rot-mat vector 0 quad) (the-as uint128 0)) (set! (-> rot-mat vector 1 quad) (the-as uint128 0)) (set! (-> rot-mat vector 2 quad) (the-as uint128 0)) @@ -729,12 +729,12 @@ ;; definition for function matrix-rotate-yxz! ;; Used lq/sq (defun matrix-rotate-yxz! ((dst matrix) (rot-xyz-deg vector)) - (let ((temp-mat (new 'stack 'matrix))) + (let ((temp-mat (new 'stack-no-clear 'matrix))) (set! (-> temp-mat vector 0 quad) (the-as uint128 0)) (set! (-> temp-mat vector 1 quad) (the-as uint128 0)) (set! (-> temp-mat vector 2 quad) (the-as uint128 0)) (set! (-> temp-mat vector 3 quad) (the-as uint128 0)) - (let ((rot-mat (new 'stack 'matrix))) + (let ((rot-mat (new 'stack-no-clear 'matrix))) (set! (-> rot-mat vector 0 quad) (the-as uint128 0)) (set! (-> rot-mat vector 1 quad) (the-as uint128 0)) (set! (-> rot-mat vector 2 quad) (the-as uint128 0)) @@ -752,12 +752,12 @@ ;; definition for function matrix-rotate-yzx! ;; Used lq/sq (defun matrix-rotate-yzx! ((dst matrix) (rot-xyz-deg vector)) - (let ((temp-mat (new 'stack 'matrix))) + (let ((temp-mat (new 'stack-no-clear 'matrix))) (set! (-> temp-mat vector 0 quad) (the-as uint128 0)) (set! (-> temp-mat vector 1 quad) (the-as uint128 0)) (set! (-> temp-mat vector 2 quad) (the-as uint128 0)) (set! (-> temp-mat vector 3 quad) (the-as uint128 0)) - (let ((rot-mat (new 'stack 'matrix))) + (let ((rot-mat (new 'stack-no-clear 'matrix))) (set! (-> rot-mat vector 0 quad) (the-as uint128 0)) (set! (-> rot-mat vector 1 quad) (the-as uint128 0)) (set! (-> rot-mat vector 2 quad) (the-as uint128 0)) @@ -774,9 +774,9 @@ ;; definition for function matrix-rotate-yxy! (defun matrix-rotate-yxy! ((dst matrix) (rots-deg vector)) - (let ((sincos-input (new 'stack 'vector)) - (sin-vec (new 'stack 'vector)) - (cos-vec (new 'stack 'vector)) + (let ((sincos-input (new 'stack-no-clear 'vector)) + (sin-vec (new 'stack-no-clear 'vector)) + (cos-vec (new 'stack-no-clear 'vector)) ) (let ((v1-0 sincos-input)) (set! (-> v1-0 data 0) (-> rots-deg data 0)) @@ -820,7 +820,7 @@ (defun matrix-rotate-yx! ((dst matrix) (rot-y-deg float) (rot-x-deg float)) (matrix-rotate-y! dst rot-y-deg) (let ((t9-1 matrix-rotate-x!) - (a0-2 (new 'stack 'matrix)) + (a0-2 (new 'stack-no-clear 'matrix)) ) (set! (-> a0-2 vector 0 quad) (the-as uint128 0)) (set! (-> a0-2 vector 1 quad) (the-as uint128 0)) diff --git a/test/decompiler/reference/quaternion_REF.gc b/test/decompiler/reference/quaternion_REF.gc index bb9440e4b1..c794890bbb 100644 --- a/test/decompiler/reference/quaternion_REF.gc +++ b/test/decompiler/reference/quaternion_REF.gc @@ -615,7 +615,7 @@ (vf6 :class vf) (vf7 :class vf) ) - (let ((v1-0 (new 'stack 'matrix))) + (let ((v1-0 (new 'stack-no-clear 'matrix))) (set! (-> v1-0 vector 0 quad) (the-as uint128 0)) (set! (-> v1-0 vector 1 quad) (the-as uint128 0)) (set! (-> v1-0 vector 2 quad) (the-as uint128 0)) @@ -740,7 +740,7 @@ ) ) (else - (let ((s5-0 (new 'stack 'vector))) + (let ((s5-0 (new 'stack-no-clear 'vector))) (sincos-rad! (the-as (pointer float) s5-0) f30-0) (let ((f0-6 (/ (-> s5-0 data 0) f30-0))) (set! (-> arg0 x) (* (-> arg1 x) f0-6)) @@ -798,7 +798,7 @@ (f28-0 (/ 1.0 f1-6)) ) (let ((f0-7 (atan-series-rad f0-6)) - (s2-0 (new 'stack 'vector)) + (s2-0 (new 'stack-no-clear 'vector)) ) (set! (-> s2-0 data 0) (* (- 1.0 arg3) f0-7)) (set! (-> s2-0 data 1) (* (* arg3 f0-7) f30-0)) @@ -871,9 +871,9 @@ (vf7 :class vf) ) (.lvf vf0 (new 'static 'vector :x 0.0 :y 0.0 :z 0.0 :w 1.0)) - (let ((s4-0 (new 'stack 'vector)) - (gp-0 (new 'stack 'vector)) - (s5-0 (new 'stack 'vector)) + (let ((s4-0 (new 'stack-no-clear 'vector)) + (gp-0 (new 'stack-no-clear 'vector)) + (s5-0 (new 'stack-no-clear 'vector)) ) (vector-rad<-vector-deg/2! s4-0 arg1) (vector-sincos-rad! gp-0 s5-0 s4-0) @@ -899,7 +899,7 @@ ;; definition for function vector-x-quaternion! ;; Used lq/sq (defun vector-x-quaternion! ((arg0 vector) (arg1 quaternion)) - (let ((s5-0 (new 'stack 'matrix))) + (let ((s5-0 (new 'stack-no-clear 'matrix))) (set! (-> s5-0 vector 0 quad) (the-as uint128 0)) (set! (-> s5-0 vector 1 quad) (the-as uint128 0)) (set! (-> s5-0 vector 2 quad) (the-as uint128 0)) @@ -913,7 +913,7 @@ ;; definition for function vector-y-quaternion! ;; Used lq/sq (defun vector-y-quaternion! ((arg0 vector) (arg1 quaternion)) - (let ((s5-0 (new 'stack 'matrix))) + (let ((s5-0 (new 'stack-no-clear 'matrix))) (set! (-> s5-0 vector 0 quad) (the-as uint128 0)) (set! (-> s5-0 vector 1 quad) (the-as uint128 0)) (set! (-> s5-0 vector 2 quad) (the-as uint128 0)) @@ -927,7 +927,7 @@ ;; definition for function vector-z-quaternion! ;; Used lq/sq (defun vector-z-quaternion! ((arg0 vector) (arg1 quaternion)) - (let ((s5-0 (new 'stack 'matrix))) + (let ((s5-0 (new 'stack-no-clear 'matrix))) (set! (-> s5-0 vector 0 quad) (the-as uint128 0)) (set! (-> s5-0 vector 1 quad) (the-as uint128 0)) (set! (-> s5-0 vector 2 quad) (the-as uint128 0)) @@ -940,7 +940,7 @@ ;; definition for function quaternion-y-angle (defun quaternion-y-angle ((arg0 quaternion)) - (let ((v1-1 (vector-z-quaternion! (new 'stack 'vector) arg0))) + (let ((v1-1 (vector-z-quaternion! (new 'stack-no-clear 'vector) arg0))) (atan (-> v1-1 data 0) (-> v1-1 data 2)) ) ) @@ -960,7 +960,7 @@ quaternion-rotate-local-x! ((arg0 quaternion) (arg1 quaternion) (arg2 float)) (let ((t9-0 quaternion-vector-angle!) - (a0-1 (new 'stack 'quaternion)) + (a0-1 (new 'stack-no-clear 'quaternion)) ) (set! (-> a0-1 vec quad) (the-as uint128 0)) (let ((a2-1 (t9-0 a0-1 (new 'static 'vector :x 1.0 :w 1.0) arg2))) @@ -975,7 +975,7 @@ quaternion-rotate-local-y! ((arg0 quaternion) (arg1 quaternion) (arg2 float)) (let ((t9-0 quaternion-vector-angle!) - (a0-1 (new 'stack 'quaternion)) + (a0-1 (new 'stack-no-clear 'quaternion)) ) (set! (-> a0-1 vec quad) (the-as uint128 0)) (let ((a2-1 (t9-0 a0-1 (new 'static 'vector :y 1.0 :w 1.0) arg2))) @@ -990,7 +990,7 @@ quaternion-rotate-local-z! ((arg0 quaternion) (arg1 quaternion) (arg2 float)) (let ((t9-0 quaternion-vector-angle!) - (a0-1 (new 'stack 'quaternion)) + (a0-1 (new 'stack-no-clear 'quaternion)) ) (set! (-> a0-1 vec quad) (the-as uint128 0)) (let ((a2-1 (t9-0 a0-1 (new 'static 'vector :z 1.0 :w 1.0) arg2))) @@ -1003,7 +1003,7 @@ ;; Used lq/sq (defun quaternion-rotate-y! ((arg0 quaternion) (arg1 quaternion) (arg2 float)) (let ((t9-0 quaternion-vector-angle!) - (a0-1 (new 'stack 'quaternion)) + (a0-1 (new 'stack-no-clear 'quaternion)) ) (set! (-> a0-1 vec quad) (the-as uint128 0)) (let ((a1-2 (t9-0 a0-1 (new 'static 'vector :y 1.0 :w 1.0) arg2))) @@ -1016,11 +1016,11 @@ ;; Used lq/sq (defun quaternion-rotate-x! ((arg0 quaternion) (arg1 quaternion) (arg2 float)) (let ((s4-0 quaternion-vector-angle!) - (s3-0 (new 'stack 'quaternion)) + (s3-0 (new 'stack-no-clear 'quaternion)) ) (set! (-> s3-0 vec quad) (the-as uint128 0)) (let ((t9-0 vector-x-quaternion!) - (a0-1 (new 'stack 'vector)) + (a0-1 (new 'stack-no-clear 'vector)) ) (set! (-> a0-1 quad) (the-as uint128 0)) (let ((a1-3 (s4-0 s3-0 (t9-0 a0-1 arg1) arg2))) @@ -1034,11 +1034,11 @@ ;; Used lq/sq (defun quaternion-rotate-z! ((arg0 quaternion) (arg1 quaternion) (arg2 float)) (let ((s4-0 quaternion-vector-angle!) - (s3-0 (new 'stack 'quaternion)) + (s3-0 (new 'stack-no-clear 'quaternion)) ) (set! (-> s3-0 vec quad) (the-as uint128 0)) (let ((t9-0 vector-z-quaternion!) - (a0-1 (new 'stack 'vector)) + (a0-1 (new 'stack-no-clear 'vector)) ) (set! (-> a0-1 quad) (the-as uint128 0)) (let ((a1-3 (s4-0 s3-0 (t9-0 a0-1 arg1) arg2))) @@ -1055,8 +1055,8 @@ (defun quaternion-delta-y ((arg0 quaternion) (arg1 quaternion)) (local-vars (f0-1 float)) (let ((gp-0 acos)) - (let* ((s5-0 (vector-z-quaternion! (new 'stack 'vector) arg0)) - (v1-1 (vector-z-quaternion! (new 'stack 'vector) arg1)) + (let* ((s5-0 (vector-z-quaternion! (new 'stack-no-clear 'vector) arg0)) + (v1-1 (vector-z-quaternion! (new 'stack-no-clear 'vector) arg1)) (f0-0 (-> s5-0 data 0)) (f1-0 (-> s5-0 data 1)) (f2-0 (-> s5-0 data 2)) @@ -1076,9 +1076,9 @@ (defun quaternion-rotate-y-to-vector! ((arg0 quaternion) (arg1 quaternion) (arg2 quaternion) (arg3 float)) - (let ((s5-0 (new 'stack 'quaternion))) + (let ((s5-0 (new 'stack-no-clear 'quaternion))) (let ((t9-0 vector-xz-normalize!) - (a0-1 (new 'stack 'vector)) + (a0-1 (new 'stack-no-clear 'vector)) ) (set! (-> a0-1 data 0) (-> arg2 x)) (set! (-> a0-1 data 1) 0.0) @@ -1087,7 +1087,10 @@ (let ((s0-0 (t9-0 a0-1 1.0))) (quaternion-from-two-vectors-max-angle! s5-0 - (vector-z-quaternion! (the-as vector (new 'stack 'quaternion)) arg1) + (vector-z-quaternion! + (the-as vector (new 'stack-no-clear 'quaternion)) + arg1 + ) s0-0 arg3 ) @@ -1102,12 +1105,12 @@ (let ((a1-2 (quaternion-vector-angle! - (new 'stack 'quaternion) + (new 'stack-no-clear 'quaternion) (new 'static 'vector :y 1.0 :w 1.0) arg2 ) ) - (s4-0 (new 'stack 'matrix)) + (s4-0 (new 'stack-no-clear 'matrix)) ) (quaternion->matrix s4-0 a1-2) (vector-matrix*! arg0 arg1 s4-0) @@ -1153,8 +1156,8 @@ ;; definition for function quaternion-xz-angle (defun quaternion-xz-angle ((arg0 quaternion)) - (let ((gp-0 (new 'stack 'matrix)) - (s5-0 (new 'stack 'vector)) + (let ((gp-0 (new 'stack-no-clear 'matrix)) + (s5-0 (new 'stack-no-clear 'vector)) ) (quaternion->matrix gp-0 arg0) (let ((v1-1 s5-0)) diff --git a/test/decompiler/reference/sync-info_REF.gc b/test/decompiler/reference/sync-info_REF.gc index e327aa2878..a7f4a0ca6e 100644 --- a/test/decompiler/reference/sync-info_REF.gc +++ b/test/decompiler/reference/sync-info_REF.gc @@ -593,7 +593,7 @@ (vf6 :class vf) ) (.lvf vf0 (new 'static 'vector :x 0.0 :y 0.0 :z 0.0 :w 1.0)) - (let ((s5-0 (new 'stack 'vector))) + (let ((s5-0 (new 'stack-no-clear 'vector))) (cond (arg0 (let ((a0-1 s5-0)) diff --git a/test/decompiler/reference/transform_REF.gc b/test/decompiler/reference/transform_REF.gc index ec52bc2878..32503515e2 100644 --- a/test/decompiler/reference/transform_REF.gc +++ b/test/decompiler/reference/transform_REF.gc @@ -48,12 +48,12 @@ ;; definition for function transform-matrix-calc! ;; Used lq/sq (defun transform-matrix-calc! ((tf transform) (dst-mat matrix)) - (let ((s4-0 (new 'stack 'matrix))) + (let ((s4-0 (new 'stack-no-clear 'matrix))) (set! (-> s4-0 vector 0 quad) (the-as uint128 0)) (set! (-> s4-0 vector 1 quad) (the-as uint128 0)) (set! (-> s4-0 vector 2 quad) (the-as uint128 0)) (set! (-> s4-0 vector 3 quad) (the-as uint128 0)) - (let ((s3-0 (new 'stack 'matrix))) + (let ((s3-0 (new 'stack-no-clear 'matrix))) (set! (-> s3-0 vector 0 quad) (the-as uint128 0)) (set! (-> s3-0 vector 1 quad) (the-as uint128 0)) (set! (-> s3-0 vector 2 quad) (the-as uint128 0)) @@ -77,12 +77,12 @@ (defun transform-matrix-parent-calc! ((tf transform) (dst-mat matrix) (inv-scale vector)) - (let ((s4-0 (new 'stack 'matrix))) + (let ((s4-0 (new 'stack-no-clear 'matrix))) (set! (-> s4-0 vector 0 quad) (the-as uint128 0)) (set! (-> s4-0 vector 1 quad) (the-as uint128 0)) (set! (-> s4-0 vector 2 quad) (the-as uint128 0)) (set! (-> s4-0 vector 3 quad) (the-as uint128 0)) - (let ((s3-0 (new 'stack 'matrix))) + (let ((s3-0 (new 'stack-no-clear 'matrix))) (set! (-> s3-0 vector 0 quad) (the-as uint128 0)) (set! (-> s3-0 vector 1 quad) (the-as uint128 0)) (set! (-> s3-0 vector 2 quad) (the-as uint128 0)) diff --git a/test/decompiler/test_FormExpressionBuild2.cpp b/test/decompiler/test_FormExpressionBuild2.cpp index eecac1f8e2..c4d17131b2 100644 --- a/test/decompiler/test_FormExpressionBuild2.cpp +++ b/test/decompiler/test_FormExpressionBuild2.cpp @@ -40,7 +40,7 @@ TEST_F(FormRegressionTest, MatrixPMult) { std::string type = "(function matrix matrix matrix matrix)"; std::string expected = "(begin\n" - " (let ((s5-0 (new (quote stack) (quote matrix))))\n" + " (let ((s5-0 (new (quote stack-no-clear) (quote matrix))))\n" " (set! (-> s5-0 vector 0 quad) (the-as uint128 0))\n" " (set! (-> s5-0 vector 1 quad) (the-as uint128 0))\n" " (set! (-> s5-0 vector 2 quad) (the-as uint128 0))\n" @@ -93,7 +93,7 @@ TEST_F(FormRegressionTest, VectorXQuaternionWithCast) { std::string type = "(function quaternion quaternion quaternion)"; std::string expected = "(begin\n" - " (let ((s5-0 (new (quote stack) (quote matrix))))\n" + " (let ((s5-0 (new (quote stack-no-clear) (quote matrix))))\n" " (set! (-> s5-0 vector 0 quad) (the-as uint128 0))\n" " (set! (-> s5-0 vector 1 quad) (the-as uint128 0))\n" " (set! (-> s5-0 vector 2 quad) (the-as uint128 0))\n" diff --git a/test/goalc/source_templates/with_game/test-size-of.gc b/test/goalc/source_templates/with_game/test-size-of.gc new file mode 100644 index 0000000000..3e40be7775 --- /dev/null +++ b/test/goalc/source_templates/with_game/test-size-of.gc @@ -0,0 +1,9 @@ +(format #t "size of dma-bucket is ~d~%" (size-of dma-bucket)) +(format #t "size of ints: ~d ~d ~d~%" (size-of uint16) (size-of pointer) (size-of uint128)) + +;; note - this makes some assumptions about how the OpenGOAL compiler will lay things out +;; on the stack. +(let ((x (new 'stack 'array 'uint8 (size-of dma-bucket))) + (y (new 'stack 'array 'uint 1))) + (format #t "size of stack array is ~d~%" (&- y x)) + ) diff --git a/test/goalc/test_with_game.cpp b/test/goalc/test_with_game.cpp index 68d9aa13df..5c29be4707 100644 --- a/test/goalc/test_with_game.cpp +++ b/test/goalc/test_with_game.cpp @@ -394,6 +394,13 @@ TEST_F(WithGameTests, StaticBoxedArray) { {"4 asdf \"test\" (a b) 0 object 12 12\n0\n"}); } +TEST_F(WithGameTests, SizeOf) { + runner.run_static_test(env, testCategory, "test-size-of.gc", + {"size of dma-bucket is 16\n" + "size of ints: 2 4 16\n" + "size of stack array is 16\n0\n"}); +} + TEST_F(WithGameTests, Trig) { runner.run_static_test(env, testCategory, "test-trig.gc", {"2.0000\n" // 2 deg