[Compiler] Support array fields in static objects (#284)

* first part of static inline array fields

* level h
This commit is contained in:
water111
2021-02-25 22:49:46 -05:00
committed by GitHub
parent 791c4abfc0
commit cadd014add
10 changed files with 408 additions and 73 deletions
@@ -0,0 +1,17 @@
(deftype test-basic-for-static-array-field (basic)
((value uint32)
(name string)
(arr basic 12)
(lst pair)
)
)
(let ((test (new 'static 'test-basic-for-static-array-field
:value 12
:arr (new 'static 'array basic 12
"asdf"
"ghjkl"
)
)))
(format #t "~A~%" (-> test arr 1))
)
@@ -0,0 +1,57 @@
(deftype basic-elt (basic)
((name string))
)
(deftype struct-elt (structure)
((thing symbol))
)
(deftype test-basic-for-static-inline-array-field (basic)
((value uint32)
(name string)
(arr basic-elt 12 :inline)
(arr2 struct-elt 3 :inline)
(lst pair)
)
)
(let ((test (new 'static 'test-basic-for-static-inline-array-field
:value 12
:arr (new 'static 'inline-array basic-elt 12
(new 'static 'basic-elt :name "first")
(new 'static 'basic-elt :name "second")
)
:arr2 (new 'static 'inline-array struct-elt 3
(new 'static 'struct-elt :thing 'asdf)
(new 'static 'struct-elt :thing 'two)
)
)))
(format #t "~A ~A~%" (-> test arr 1 name) (-> test arr 0 name))
(format #t "~A #x~X #x~X~%" (-> test arr 1 type) (logand 15 (the int (-> test arr))) (logand 15 (the int (-> test arr 1))))
(format #t "~A~%" (-> test arr2 1 thing))
)
(deftype test-struct-for-static-inline-array-field (structure)
((value uint32)
(name string)
(arr basic-elt 12 :inline)
(arr2 struct-elt 3 :inline)
(lst pair)
)
)
(let ((test (new 'static 'test-struct-for-static-inline-array-field
:value 12
:arr (new 'static 'inline-array basic-elt 12
(new 'static 'basic-elt :name "first")
(new 'static 'basic-elt :name "second")
)
:arr2 (new 'static 'inline-array struct-elt 3
(new 'static 'struct-elt :thing 'asdf)
(new 'static 'struct-elt :thing 'two)
)
)))
(format #t "~A ~A~%" (-> test arr 1 name) (-> test arr 0 name))
(format #t "~A #x~X #x~X~%" (-> test arr 1 type) (logand 15 (the int (-> test arr))) (logand 15 (the int (-> test arr 1))))
(format #t "~A~%" (-> test arr2 1 thing))
)
@@ -0,0 +1,47 @@
(deftype test-basic-for-static-inline (basic)
((value uint32)
(name string)
(thing symbol)
(lst pair)
)
)
(let ((test-arr (new 'static 'inline-array test-basic-for-static-inline 3
(new 'static 'test-basic-for-static-inline :value 12 :name "test-name" :thing 'beans :lst '("asdf" b ( c . d)))
(new 'static 'test-basic-for-static-inline :value 1235 :name "hello")
)
)
)
(format #t "~A ~A #x~X #x~X ~A~%"
(-> test-arr 0 type)
(-> test-arr 1 type)
(logand 15 (the int (-> test-arr 1)))
(logand 15 (the int test-arr))
(-> test-arr 1 name)
)
)
(deftype test-struct-for-static-inline (structure)
((value uint32)
(name string)
(thing symbol)
(lst pair)
)
)
(let ((test-arr (new 'static 'inline-array test-struct-for-static-inline 3
(new 'static 'test-struct-for-static-inline :value 12 :name "test-name" :thing 'beans :lst '("asdf" b ( c . d)))
(new 'static 'test-struct-for-static-inline :value 1235 :name "hello")
)
)
)
(format #t "#x~X #x~X ~A~%"
;;(-> test-arr 0 type)
;;(-> test-arr 1 type)
(logand 15 (the int (-> test-arr 1)))
(logand 15 (the int test-arr))
(-> test-arr 1 name)
)
)
+25
View File
@@ -493,6 +493,31 @@ TEST_F(WithGameTests, StaticArray) {
"0\n"});
}
TEST_F(WithGameTests, StaticInlineArray) {
runner.run_static_test(
env, testCategory, "test-static-inline-array.gc",
{"test-basic-for-static-inline test-basic-for-static-inline #x4 #x4 \"hello\"\n"
"#x0 #x0 \"hello\"\n"
"0\n"});
}
TEST_F(WithGameTests, StaticArrayField) {
runner.run_static_test(env, testCategory, "test-static-array-field.gc",
{"\"ghjkl\"\n"
"0\n"});
}
TEST_F(WithGameTests, StaticFieldInlineArray) {
runner.run_static_test(env, testCategory, "test-static-field-inline-arrays.gc",
{"\"second\" \"first\"\n"
"basic-elt #x4 #x4\n"
"two\n"
"\"second\" \"first\"\n"
"basic-elt #x4 #x4\n"
"two\n"
"0\n"});
}
TEST(TypeConsistency, TypeConsistency) {
Compiler compiler;
compiler.enable_throw_on_redefines();