mirror of
https://github.com/open-goal/jak-project
synced 2026-08-12 20:03:14 -04:00
Add support for stack integers (#135)
* add support for stack integers * update documentation * revise value type stack variables
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
(let* ((x (new 'stack 'array 'int8 1))
|
||||
(x-addr (the uint x)))
|
||||
(if (and (> x-addr #x7ffff00)
|
||||
(< x-addr #x7ffffff))
|
||||
1
|
||||
0)
|
||||
)
|
||||
@@ -0,0 +1,9 @@
|
||||
(let ((x (new 'stack 'array 'int32 1))
|
||||
(y (new 'stack 'array 'int8 2))
|
||||
(z (new 'stack 'array 'int8 1)))
|
||||
(set! (-> x) 10)
|
||||
(set! (-> z) 0)
|
||||
(set! (-> y) #xfffffffff)
|
||||
(set! (-> y 1) 3)
|
||||
(+ (-> x) (-> y) (-> z) (-> y 1))
|
||||
)
|
||||
@@ -0,0 +1,59 @@
|
||||
;; like test-approx-pi, but using stack variables
|
||||
(start-test "approx-pi-stack")
|
||||
|
||||
(defun test-approx-pi-stack ((res integer))
|
||||
(let ((rad (new 'stack 'array 'int32 1))
|
||||
(count (new 'stack 'array 'uint32 1)))
|
||||
(set! (-> rad) (* res res))
|
||||
(set! (-> count) 0)
|
||||
|
||||
|
||||
(dotimes (x res)
|
||||
(dotimes (y res)
|
||||
(if (> (-> rad) (+ (* x x) (* y y)))
|
||||
(+! (-> count) 1)
|
||||
)
|
||||
)
|
||||
)
|
||||
(* 4.0 (/ (the float (-> count)) (the float (-> rad))))
|
||||
)
|
||||
)
|
||||
|
||||
(let ((approx-pi (test-approx-pi-stack 1000)))
|
||||
(expect-true (> approx-pi 3.14))
|
||||
(expect-true (< approx-pi 3.15))
|
||||
)
|
||||
|
||||
|
||||
(defun test-approx-pi-float-stack ((res float))
|
||||
(let* ((rad (new 'stack 'array 'float 1))
|
||||
(count (new 'stack 'array 'float 1))
|
||||
(x (new 'stack 'array 'float 1))
|
||||
(y (new 'stack 'array 'float 1))
|
||||
(scale (new 'stack 'array 'float 1)))
|
||||
(set! (-> rad) (* res res))
|
||||
(set! (-> count) 0.0)
|
||||
(set! (-> x) 0.0)
|
||||
(set! (-> y) (-> x))
|
||||
(set! (-> scale) (/ 1.0 (-> rad)))
|
||||
|
||||
(while (< (-> x) res)
|
||||
(set! (-> y) 0.0)
|
||||
(while (< (-> y) res)
|
||||
(if (> (-> rad) (+ (* (-> x) (-> x)) (* (-> y) (-> y))))
|
||||
(+! (-> count) (-> scale))
|
||||
)
|
||||
(+! (-> y) 1.0)
|
||||
)
|
||||
(+! (-> x) 1.0)
|
||||
)
|
||||
(* 4.0 (-> count))
|
||||
)
|
||||
)
|
||||
|
||||
(let ((approx-pi (test-approx-pi-float-stack 500.0)))
|
||||
(expect-true (> approx-pi 3.14))
|
||||
(expect-true (< approx-pi 3.15))
|
||||
)
|
||||
|
||||
(finish-test)
|
||||
@@ -29,7 +29,6 @@
|
||||
(while (< x res)
|
||||
(set! y 0.0)
|
||||
(while (< y res)
|
||||
; (format #t "tapf ~f ~f ~f~%" x y res)
|
||||
(if (> rad (+ (* x x) (* y y)))
|
||||
(+! count scale)
|
||||
)
|
||||
|
||||
@@ -68,3 +68,8 @@ TEST_F(VariableTests, Let) {
|
||||
runner.run_static_test(env, testCategory, "let-star.static.gc", {"30\n"});
|
||||
runner.run_static_test(env, testCategory, "mlet.static.gc", {"10\n"});
|
||||
}
|
||||
|
||||
TEST_F(VariableTests, StackVars) {
|
||||
runner.run_static_test(env, testCategory, "stack-ints.gc", {"12\n"});
|
||||
runner.run_static_test(env, testCategory, "stack-ints-2.gc", {"1\n"});
|
||||
}
|
||||
@@ -219,6 +219,11 @@ TEST_F(WithGameTests, ApproxPi) {
|
||||
get_test_pass_string("approx-pi", 4));
|
||||
}
|
||||
|
||||
TEST_F(WithGameTests, ApproxPiStack) {
|
||||
runner.run_static_test(env, testCategory, "test-approx-pi-stack.gc",
|
||||
get_test_pass_string("approx-pi-stack", 4));
|
||||
}
|
||||
|
||||
TEST_F(WithGameTests, DynamicType) {
|
||||
runner.run_static_test(env, testCategory, "test-dynamic-type.gc",
|
||||
get_test_pass_string("dynamic-type", 4));
|
||||
|
||||
Reference in New Issue
Block a user