Skip to content

Commit

Permalink
fix pointer set to #f in static (#864)
Browse files Browse the repository at this point in the history
  • Loading branch information
water111 authored Sep 29, 2021
1 parent 7ebbe81 commit b1e987c
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 8 deletions.
29 changes: 22 additions & 7 deletions decompiler/util/data_decompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -667,14 +667,29 @@ goos::Object decompile_structure(const TypeSpec& type,
obj_words, labels, label.target_segment,
field_start, ts, field, words, file));
} else {
if (obj_words.at(field_start / 4).kind != LinkedWord::PLAIN_DATA) {
continue;
}
std::vector<u8> bytes_out;
for (int byte_idx = field_start; byte_idx < field_end; byte_idx++) {
bytes_out.push_back(obj_words.at(byte_idx / 4).get_byte(byte_idx % 4));
if (field.type().base_type() == "pointer") {
if (obj_words.at(field_start / 4).kind != LinkedWord::SYM_PTR) {
continue;
}

if (obj_words.at(field_start / 4).symbol_name != "#f") {
lg::warn("Got a weird symbol in a pointer field: {}",
obj_words.at(field_start / 4).symbol_name);
continue;
}

field_defs_out.emplace_back(field.name(), pretty_print::to_symbol("#f"));

} else {
if (obj_words.at(field_start / 4).kind != LinkedWord::PLAIN_DATA) {
continue;
}
std::vector<u8> bytes_out;
for (int byte_idx = field_start; byte_idx < field_end; byte_idx++) {
bytes_out.push_back(obj_words.at(byte_idx / 4).get_byte(byte_idx % 4));
}
field_defs_out.emplace_back(field.name(), decompile_value(field.type(), bytes_out, ts));
}
field_defs_out.emplace_back(field.name(), decompile_value(field.type(), bytes_out, ts));
}
}

Expand Down
1 change: 0 additions & 1 deletion goal_src/engine/gfx/texture.gc
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,6 @@
;; allocate the common and near segments
(allocate-segment! obj (-> obj segment-common) COMMON_SEGMENT_WORDS) ;; ~0.5 MB
(allocate-segment! obj (-> obj segment-near) NEAR_SEGMENT_WORDS) ;; ~1.6 MB.
(format #t "near segment is at ~D to ~d~%" (-> obj segment-near dest) (+ (-> obj segment-near dest) (-> obj segment-near size)))

;; Allocate the random crap
(set! *sky-base-vram-word* (allocate-vram-words! obj SPECIAL_VRAM_WORDS))
Expand Down
14 changes: 14 additions & 0 deletions goalc/compiler/compilation/Static.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,20 @@ void Compiler::compile_static_structure_inline(const goos::Object& form,
assert(sr.reference()->get_addr_offset() == 0);
structure->add_pointer_record(field_offset, sr.reference(),
sr.reference()->get_addr_offset());
} else if (field_info.type.base_type() == "pointer") {
auto sr = compile_static(field_value, env);
if (!sr.is_symbol() || sr.symbol_name() != "#f") {
throw_compiler_error(form, "Invalid definition of field {}", field_info.field.name());
}
structure->add_symbol_record(sr.symbol_name(), field_offset);
auto deref_info = m_ts.get_deref_info(m_ts.make_pointer_typespec(field_info.type));
assert(deref_info.mem_deref);
assert(deref_info.can_deref);
assert(deref_info.load_size == 4);
// the linker needs to see a -1 in order to know to insert a symbol pointer
// instead of just the symbol table offset.
u32 linker_val = 0xffffffff;
memcpy(structure->data.data() + field_offset, &linker_val, 4);
}

else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(deftype false-in-static-pointer (basic)
((foo (pointer process)))
)

(define *false-in-static-pointer* (new 'static 'false-in-static-pointer :foo #f))
(format #t "~A~%" (-> *false-in-static-pointer* foo))
5 changes: 5 additions & 0 deletions test/goalc/test_with_game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,11 @@ TEST_F(WithGameTests, MethodCallForwardDeclared) {
{"4 12\n0\n"});
}

TEST_F(WithGameTests, PointerInStatic) {
shared_compiler->runner.run_static_test(env, testCategory, "test-false-in-static-pointer.gc",
{"#f\n0\n"});
}

namespace Mips2C {
namespace test_func {
extern u64 execute(void*);
Expand Down

0 comments on commit b1e987c

Please sign in to comment.