From 104f85a8d67d5c01252898534f7d815c9e6d6ba0 Mon Sep 17 00:00:00 2001 From: water Date: Sat, 23 Sep 2023 11:53:51 -0400 Subject: [PATCH] decomp for jak1, methods only --- decompiler/IR2/AtomicOpTypeAnalysis.cpp | 62 ++++- decompiler/IR2/FormExpressionAnalysis.cpp | 19 ++ .../config/jak1/ntsc_v1/type_casts.jsonc | 214 +----------------- decompiler/util/TP_Type.cpp | 6 + decompiler/util/TP_Type.h | 8 + goal_src/jak1/engine/common-obs/nav-enemy.gc | 2 +- goal_src/jak1/engine/common-obs/rigid-body.gc | 8 +- goal_src/jak1/engine/common-obs/sharkey.gc | 2 +- goal_src/jak1/engine/target/logic-target.gc | 2 +- goal_src/jak1/levels/beach/beach-obs.gc | 5 +- goal_src/jak1/levels/beach/beach-rocks.gc | 4 +- goal_src/jak1/levels/citadel/citadel-obs.gc | 18 +- goal_src/jak1/levels/citadel/citadel-sages.gc | 8 +- goal_src/jak1/levels/citadel/citb-plat.gc | 2 +- .../jak1/levels/common/battlecontroller.gc | 7 +- goal_src/jak1/levels/jungle/fisher.gc | 2 +- goal_src/jak1/levels/jungle/hopper.gc | 2 +- goal_src/jak1/levels/jungle/jungle-obs.gc | 5 +- goal_src/jak1/levels/jungle/junglefish.gc | 2 +- goal_src/jak1/levels/jungleb/plant-boss.gc | 5 +- goal_src/jak1/levels/lavatube/lavatube-obs.gc | 5 +- goal_src/jak1/levels/maincave/baby-spider.gc | 2 +- .../jak1/levels/maincave/driller-lurker.gc | 5 +- goal_src/jak1/levels/maincave/gnawer.gc | 5 +- goal_src/jak1/levels/misty/balloonlurker.gc | 5 +- goal_src/jak1/levels/misty/misty-conveyor.gc | 5 +- goal_src/jak1/levels/misty/misty-obs.gc | 7 +- goal_src/jak1/levels/ogre/ogre-obs.gc | 25 +- goal_src/jak1/levels/ogre/ogreboss.gc | 8 +- goal_src/jak1/levels/robocave/cave-trap.gc | 5 +- goal_src/jak1/levels/snow/ice-cube.gc | 2 +- goal_src/jak1/levels/snow/snow-ball.gc | 6 +- goal_src/jak1/levels/snow/snow-bumper.gc | 5 +- goal_src/jak1/levels/snow/snow-obs.gc | 5 +- goal_src/jak1/levels/snow/yeti.gc | 2 +- goal_src/jak1/levels/sunken/bully.gc | 5 +- goal_src/jak1/levels/sunken/helix-water.gc | 5 +- goal_src/jak1/levels/sunken/puffer.gc | 5 +- goal_src/jak1/levels/sunken/qbert-plat.gc | 2 +- .../jak1/levels/sunken/square-platform.gc | 5 +- goal_src/jak1/levels/sunken/steam-cap.gc | 5 +- .../jak1/levels/sunken/sunken-pipegame.gc | 5 +- goal_src/jak1/levels/swamp/billy.gc | 7 +- goal_src/jak1/levels/swamp/kermit.gc | 2 +- goal_src/jak1/levels/swamp/swamp-bat.gc | 5 +- goal_src/jak1/levels/training/training-obs.gc | 2 +- goal_src/jak1/levels/village2/swamp-blimp.gc | 5 +- goal_src/jak1/levels/village2/village2-obs.gc | 2 +- goalc/compiler/Compiler.h | 2 +- goalc/compiler/Env.h | 1 + goalc/compiler/Util.cpp | 11 - goalc/compiler/compilation/Atoms.cpp | 1 + goalc/compiler/compilation/Type.cpp | 14 ++ 53 files changed, 177 insertions(+), 382 deletions(-) diff --git a/decompiler/IR2/AtomicOpTypeAnalysis.cpp b/decompiler/IR2/AtomicOpTypeAnalysis.cpp index 3983b36946..fb7872202c 100644 --- a/decompiler/IR2/AtomicOpTypeAnalysis.cpp +++ b/decompiler/IR2/AtomicOpTypeAnalysis.cpp @@ -93,6 +93,8 @@ TP_Type SimpleAtom::get_type(const TypeState& input, return TP_Type::make_run_function_in_process_function(); } else if (m_string == "set-to-run" && env.func->name() != "enter-state") { return TP_Type::make_set_to_run_function(); + } else if (m_string == "find-parent-method") { + return TP_Type::make_find_parent_method_function(); } // look up the type of the symbol @@ -1355,10 +1357,6 @@ TypeState CallOp::propagate_types_internal(const TypeState& input, in_type = TypeSpec("function", new_arg_types); } - if (in_type.arg_count() < 1) { - throw std::runtime_error("Called a function, but we do not know its type"); - } - if (in_type.arg_count() == 2 && in_type.get_arg(0) == TypeSpec("_varargs_")) { // we're calling a varags function, which is format. We can determine the argument count // by looking at the format string, if we can get it. @@ -1418,12 +1416,64 @@ TypeState CallOp::propagate_types_internal(const TypeState& input, arg_type.print()); } } + + bool use_normal_last_arg = true; + + if (in_tp.kind == TP_Type::Kind::FIND_PARENT_METHOD_FUNCTION) { + bool can_use_call_parent = true; + // should be calling this from a method: + if (env.func->guessed_name.kind != FunctionName::FunctionKind::METHOD) { + can_use_call_parent = false; + lg::warn( + "Can't use call-parent-method because find-parent-method was called in {}, which isn't a " + "method.", + env.func->name()); + } + // should call something like: + // (find-parent-method sharkey 39) + const auto& type_arg = input.get(Register(Reg::GPR, Reg::A0)); + if (can_use_call_parent && type_arg.kind != TP_Type::Kind::TYPE_OF_TYPE_NO_VIRTUAL) { + lg::warn( + "Can't use call-parent-method because the first argument to find-parent-method is a {}, " + "which should be a type", + type_arg.print()); + can_use_call_parent = false; + } + + if (can_use_call_parent && type_arg.get_type_objects_typespec() != env.func->method_of_type) { + lg::warn( + "Can't use call-parent-method because the first argument type is wrong: got {}, but " + "expected {}", + type_arg.get_type_objects_typespec().print(), env.func->method_of_type); + can_use_call_parent = false; + } + const auto& id_arg = input.get(Register(Reg::GPR, Reg::A1)); + if (can_use_call_parent && !id_arg.is_integer_constant(env.func->guessed_name.method_id)) { + lg::warn( + "Can't use call-parent-method because the second argument is wrong: got {}, but expected " + "a constant integer {}", + id_arg.print(), env.func->guessed_name.method_id); + can_use_call_parent = false; + } + + if (can_use_call_parent) { + end_types.get(Register(Reg::GPR, Reg::V0)) = TP_Type::make_from_ts(env.func->type); + use_normal_last_arg = false; + } + } + + if (use_normal_last_arg) { + end_types.get(Register(Reg::GPR, Reg::V0)) = TP_Type::make_from_ts(in_type.last_arg()); + } + + if (in_type.arg_count() < 1) { + throw std::runtime_error("Called a function, but we do not know its type"); + } + // set the call type! m_call_type = in_type; m_call_type_set = true; - end_types.get(Register(Reg::GPR, Reg::V0)) = TP_Type::make_from_ts(in_type.last_arg()); - if (in_tp.kind == TP_Type::Kind::NON_OBJECT_NEW_METHOD && in_type.last_arg() == TypeSpec("array")) { // array new: diff --git a/decompiler/IR2/FormExpressionAnalysis.cpp b/decompiler/IR2/FormExpressionAnalysis.cpp index 13b2f7f2d7..68e3e113d8 100644 --- a/decompiler/IR2/FormExpressionAnalysis.cpp +++ b/decompiler/IR2/FormExpressionAnalysis.cpp @@ -3892,6 +3892,25 @@ void FunctionCallElement::update_from_stack(const Env& env, } } + // detect call-parent-method + { + const auto& guessed_name = env.func->guessed_name; + if (guessed_name.kind == FunctionName::FunctionKind::METHOD) { + auto mr_find_parent = + match(Matcher::func(Matcher::symbol("find-parent-method"), + {Matcher::symbol(env.func->method_of_type), + Matcher::integer(env.func->guessed_name.method_id)}), + unstacked.at(0) + + ); + if (mr_find_parent.matched) { + new_form = pool.alloc_element( + GenericOperator::make_function(pool.form("call-parent-method")), + arg_forms); + } + } + } + result->push_back(new_form); } diff --git a/decompiler/config/jak1/ntsc_v1/type_casts.jsonc b/decompiler/config/jak1/ntsc_v1/type_casts.jsonc index 703f0a0378..b1379ba07f 100644 --- a/decompiler/config/jak1/ntsc_v1/type_casts.jsonc +++ b/decompiler/config/jak1/ntsc_v1/type_casts.jsonc @@ -515,7 +515,6 @@ "(method 10 shadow-control)": [[1, "v1", "int"]], "(method 0 fact-info-enemy)": [[[3, 92], "gp", "fact-info-enemy"]], "(method 0 fact-info)": [ - //[16, "t9", "(function string none)"], ["_stack_", 16, "res-tag"], [[32, 43], "v1", "(pointer int32)"], [86, "gp", "fact-info"] @@ -1569,8 +1568,7 @@ ], "(method 7 rigid-body-platform)": [ - [5, "v1", "int"], - [14, "t9", "(function process-drawable int process-drawable)"] + [5, "v1", "int"] ], "(method 10 rigid-body)": [[50, "v1", "vector"]], @@ -1651,8 +1649,7 @@ "(method 7 nav-enemy)": [ [5, "v1", "int"], - [10, "v1", "int"], - [19, "t9", "(function process-drawable int none)"] + [10, "v1", "int"] ], "(enter nav-enemy-patrol nav-enemy)": [[8, "v1", "int"]], @@ -1972,8 +1969,6 @@ [87, "s4", "swingpole"] ], - "(method 10 target)": [[[10, 13], "t9", "(function process-drawable none)"]], - "draw-history": [[[99, 101], "v1", "int"]], "(method 9 attack-info)": [ @@ -2232,12 +2227,9 @@ "(method 7 beach-rock)": [ [5, "v1", "int"], - [10, "v1", "int"], - [19, "t9", "(function process-drawable int none)"] + [10, "v1", "int"] ], - "(method 10 beach-rock)": [[21, "t9", "(function process-drawable none)"]], - "(code falling beach-rock)": [ [138, "gp", "handle"], [150, "gp", "handle"], @@ -2306,8 +2298,6 @@ "(code bouncer-fire)": [[17, "v1", "art-joint-anim"]], - "(method 39 hopper)": [[16, "t9", "(function nav-enemy none)"]], - "(code nav-enemy-idle hopper)": [ [16, "v1", "art-joint-anim"], [70, "v1", "art-joint-anim"] @@ -2323,8 +2313,6 @@ [105, "v1", "art-joint-anim"] ], - "(method 39 junglefish)": [[12, "t9", "(function nav-enemy none)"]], - "(code nav-enemy-patrol junglefish)": [ [27, "v1", "art-joint-anim"], [107, "v1", "art-joint-anim"], @@ -2402,8 +2390,6 @@ [329, "v1", "art-joint-anim"] ], - "(method 39 sharkey)": [[71, "t9", "(function nav-enemy none)"]], - "(code nav-enemy-patrol sharkey)": [[27, "v1", "art-joint-anim"]], "(code nav-enemy-attack sharkey)": [[144, "v1", "art-joint-anim"]], @@ -2896,10 +2882,6 @@ "(event square-platform-master-idle)": [[6, "a0", "square-platform-button"]], - "(method 7 square-platform)": [ - [24, "t9", "(function baseplat int baseplat)"] - ], - "(method 11 square-platform)": [ ["_stack_", 16, "res-tag"], ["_stack_", 32, "res-tag"], @@ -2925,10 +2907,6 @@ [3, "t9", "(function none :behavior qbert-plat)"] ], - "(method 23 qbert-plat)": [ - [9, "t9", "(function rigid-body-platform float none)"] - ], - "(code keg-on-paddle)": [ [5, "a0", "keg"], // i have learned that parent does not always equal the parent type! [16, "v1", "process-drawable"] @@ -2954,14 +2932,6 @@ "keg-init-by-other": [[142, "v1", "process-drawable"]], - "(method 7 keg-conveyor)": [ - [14, "t9", "(function process-drawable int process-drawable)"] - ], - - "(method 7 swamp-bat)": [ - [26, "t9", "(function process-drawable int process-drawable)"] - ], - "(code swamp-bat-slave-die)": [[21, "v1", "swamp-bat"]], // these casts should not be required @@ -2987,8 +2957,6 @@ "(code spiderwebs-bounce)": [[80, "v1", "art-joint-anim"]], - "(method 39 baby-spider)": [[37, "t9", "(function nav-enemy none)"]], - "(code baby-spider-hatching)": [[14, "v1", "art-joint-anim"]], "(code nav-enemy-attack baby-spider)": [[14, "v1", "art-joint-anim"]], @@ -3058,10 +3026,6 @@ [230, "v1", "baby-spider"] ], - "(method 7 cave-trap)": [ - [14, "t9", "(function process-drawable int process-drawable)"] - ], - "(method 57 ice-cube)": [ [16, "v1", "collide-shape-prim-group"], [26, "v1", "collide-shape-prim-group"] @@ -3092,8 +3056,6 @@ [238, "v1", "art-joint-anim"] ], - "(method 7 yeti-slave)": [[14, "t9", "(function nav-enemy int nav-enemy)"]], - "(method 21 yeti)": [[5, "s5", "(pointer yeti-slave)"]], "(code idle assistant-lavatube-start)": [ @@ -3239,14 +3201,6 @@ [[53, 136], "gp", "(pointer nav-enemy)"] ], - "(method 7 battlecontroller)": [ - [29, "t9", "(function process-drawable int process-drawable)"] - ], - - "(method 10 battlecontroller)": [ - [13, "t9", "(function process-drawable none)"] - ], - "(method 27 battlecontroller)": [ ["_stack_", 16, "res-tag"], [182, "v0", "(pointer int32)"] @@ -3710,8 +3664,6 @@ [79, "v1", "float"] ], - "(method 38 fisher)": [[33, "t9", "(function fisher none)"]], - "(enter fisher-done)": [ [137, "f0", "float"], [148, "f0", "float"], @@ -4096,10 +4048,6 @@ [101, "s2", "handle"] ], - "(method 7 cavegeyserrock)": [ - [14, "t9", "(function process-drawable int process-drawable)"] - ], - "(trans junglesnake-wake)": [[15, "v1", "collide-shape-prim-group"]], "(trans junglesnake-attack)": [[15, "v1", "collide-shape-prim-group"]], @@ -4140,10 +4088,6 @@ [191, "v1", "art-joint-anim"] ], - "(method 7 flutflutegg)": [ - [14, "t9", "(function process-drawable int process-drawable)"] - ], - "(event flutflutegg-idle)": [[30, "gp", "process-drawable"]], "(event flutflutegg-physics)": [[37, "gp", "process-drawable"]], @@ -4164,10 +4108,6 @@ "(method 26 warp-gate-switch)": [[60, "v1", "art-joint-anim"]], - "(method 31 warp-gate-switch)": [ - [61, "t9", "(function basebutton symbol none)"] - ], - "(code basebutton-going-down warp-gate-switch)": [ [79, "v0", "(state basebutton)"], [81, "t9", "(function none :behavior basebutton)"] @@ -4177,24 +4117,6 @@ "(code idle warp-gate)": [[35, "a0", "symbol"]], - "(method 21 citb-arm)": [[7, "t9", "(function citb-arm-section none)"]], - - "(method 21 citb-arm-shoulder)": [ - [7, "t9", "(function citb-arm-section none)"] - ], - - "(method 21 citb-arm-a)": [[14, "t9", "(function citb-arm none)"]], - - "(method 21 citb-arm-b)": [[14, "t9", "(function citb-arm none)"]], - - "(method 21 citb-arm-c)": [[14, "t9", "(function citb-arm none)"]], - - "(method 21 citb-arm-d)": [[14, "t9", "(function citb-arm none)"]], - - "(method 21 citb-arm-shoulder-a)": [[14, "t9", "(function citb-arm none)"]], - - "(method 21 citb-arm-shoulder-b)": [[14, "t9", "(function citb-arm none)"]], - "(method 26 citb-button)": [[31, "v1", "art-joint-anim"]], "(code citb-coil-break)": [[19, "v1", "art-joint-anim"]], @@ -4223,10 +4145,6 @@ [11, "t9", "(function none :behavior battlecontroller)"] ], - "(method 27 citb-battlecontroller)": [ - [7, "t9", "(function battlecontroller none)"] - ], - "(code eggtop-close)": [ [108, "v1", "art-joint-anim"], [176, "v1", "art-joint-anim"] @@ -4246,10 +4164,6 @@ "(event precurbridge-active)": [[4, "gp", "touching-shapes-entry"]], - "(method 7 jngpusher)": [ - [14, "t9", "(function process-drawable int process-drawable)"] - ], - "(method 11 lurkerm-piston)": [ ["_stack_", 16, "res-tag"], ["_stack_", 32, "res-tag"], @@ -4268,10 +4182,6 @@ "(code mis-bone-bridge-fall)": [[50, "v1", "art-joint-anim"]], - "(method 23 bone-platform)": [ - [9, "t9", "(function rigid-body-platform basic none)"] - ], - "mistycam-spawn": [ [[68, 76], "v1", "handle"], [80, "v1", "pov-camera"], @@ -4283,10 +4193,6 @@ [34, "gp", "handle"] ], - "(method 27 misty-battlecontroller)": [ - [7, "t9", "(function battlecontroller none)"] - ], - "(code boat-fuelcell-spawn)": [[50, "gp", "handle"]], "(code pov-camera-playing village2cam)": [ @@ -4294,10 +4200,6 @@ [65, "v1", "art-joint-anim"] ], - "(method 23 pontoon)": [ - [9, "t9", "(function rigid-body-platform basic none)"] - ], - "fireboulder-disable-blocking-collision": [ [5, "v1", "collide-shape-prim-group"], [14, "v1", "collide-shape-prim-group"] @@ -4425,32 +4327,6 @@ "(trans spike-idle)": [[70, "v1", "float"]], - "(method 23 ogre-plat)": [ - [9, "t9", "(function rigid-body-platform basic none)"] - ], - - "(method 31 ogre-step)": [[23, "t9", "(function ogre-plat none)"]], - - "(method 31 ogre-step-a)": [[25, "t9", "(function ogre-step none)"]], - - "(method 31 ogre-step-b)": [[25, "t9", "(function ogre-step none)"]], - - "(method 31 ogre-step-c)": [[25, "t9", "(function ogre-step none)"]], - - "(method 31 ogre-step-d)": [[25, "t9", "(function ogre-step none)"]], - - "(method 31 ogre-isle)": [[17, "t9", "(function ogre-plat none)"]], - - "(method 31 ogre-isle-b)": [[31, "t9", "(function ogre-isle none)"]], - - "(method 31 ogre-isle-c)": [[31, "t9", "(function ogre-isle none)"]], - - "(method 31 ogre-isle-d)": [[37, "t9", "(function ogre-isle none)"]], - - "(method 7 ogre-bridge)": [ - [26, "t9", "(function process-drawable int process-drawable)"] - ], - "(code ogre-bridge-activate)": [[33, "v1", "art-joint-anim"]], "(code water-vol-idle ogre-lava)": [[36, "v1", "art-joint-anim"]], @@ -4489,10 +4365,6 @@ [346, "v1", "art-joint-anim"] ], - "(method 7 snow-fort-gate)": [ - [19, "t9", "(function process-drawable int process-drawable)"] - ], - "(code snow-button-activate)": [[25, "v1", "art-joint-anim"]], "(code snow-button-deactivate)": [[26, "v1", "art-joint-anim"]], @@ -4501,10 +4373,6 @@ [62, "t9", "(function none :behavior plat)"] ], - "(method 7 darkecobarrel)": [ - [14, "t9", "(function darkecobarrel-base int darkecobarrel-base)"] - ], - "(event darkecobarrel-mover-move)": [[76, "v1", "process-drawable"]], "(code darkecobarrel-mover-move)": [ @@ -4531,10 +4399,6 @@ "(method 11 training-cam)": [[21, "s5", "entity-actor"]], - "(method 23 tra-pontoon)": [ - [9, "t9", "(function rigid-body-platform float none)"] - ], - "(event idle scarecrow-a)": [ [75, "v1", "process-drawable"], [135, "gp", "target"], @@ -4768,10 +4632,6 @@ "command-get-camera": [[27, "gp", "symbol"]], - "(method 7 plant-boss)": [ - [47, "t9", "(function process-drawable int process-drawable)"] - ], - "(code plant-boss-arm-hit)": [[88, "v1", "art-joint-anim"]], "(code plant-boss-arm-die)": [ @@ -4850,8 +4710,6 @@ "(code plant-boss-back-arms-hit)": [[149, "v1", "art-joint-anim"]], - "(method 7 ice-cube)": [[24, "t9", "(function nav-enemy int nav-enemy)"]], - "(code ice-cube-appear)": [[14, "v1", "art-joint-anim"]], "(code ice-cube-tired)": [ @@ -4905,12 +4763,6 @@ [22, "v1", "collide-shape-prim-group"] ], - "(method 7 billy)": [ - [26, "t9", "(function process-drawable int process-drawable)"] - ], - - "(method 38 billy)": [[33, "t9", "(function nav-enemy none)"]], - "(enter nav-enemy-victory billy-rat)": [[4, "v0", "(state nav-enemy)"]], "(code billy-rat-salivate)": [[43, "v1", "art-joint-anim"]], @@ -5014,14 +4866,6 @@ "(post idle citb-sage)": [[3, "t9", "(function none :behavior citb-sage)"]], - "(method 44 red-sagecage)": [[35, "t9", "(function citb-sage none)"]], - - "(method 44 blue-sagecage)": [[35, "t9", "(function citb-sage none)"]], - - "(method 44 yellow-sagecage)": [[35, "t9", "(function citb-sage none)"]], - - "(method 44 green-sagecage)": [[35, "t9", "(function citb-sage none)"]], - "(method 43 red-sagecage)": [[24, "v1", "float"]], "(method 43 blue-sagecage)": [[24, "v1", "float"]], @@ -5107,10 +4951,6 @@ "sun-iris-door-init-by-other": [[97, "v1", "art-joint-anim"]], - "(method 7 steam-cap)": [ - [19, "t9", "(function process-drawable int process-drawable)"] - ], - "(method 11 steam-cap)": [ ["_stack_", 16, "res-tag"], [139, "v0", "(pointer float)"] @@ -5924,10 +5764,6 @@ "(code snow-bumper-inactive-idle)": [[19, "v1", "art-joint-anim"]], - "(method 7 snow-bumper)": [ - [14, "t9", "(function process-drawable int process-drawable)"] - ], - "(method 11 snow-bumper)": [ ["_stack_", 16, "res-tag"], [216, "v0", "(pointer float)"] @@ -5965,10 +5801,6 @@ "(method 31 puffer)": [[16, "v1", "(array collide-shape-prim)"]], - "(method 7 puffer)": [ - [14, "t9", "(function process-drawable int process-drawable)"] - ], - "(method 11 puffer)": [ ["_stack_", 16, "res-tag"], [213, "v0", "(pointer float)"] @@ -5984,10 +5816,6 @@ "(code driller-lurker-die)": [[28, "v1", "art-joint-anim"]], - "(method 7 driller-lurker)": [ - [24, "t9", "(function process-drawable int process-drawable)"] - ], - "(method 11 driller-lurker)": [ ["_stack_", 16, "res-tag"], [373, "v0", "(pointer float)"] @@ -6012,8 +5840,6 @@ [90, "v1", "art-joint-anim"] ], - "(method 39 kermit)": [[7, "t9", "(function nav-enemy none)"]], - "(code falling gnawer-falling-segment)": [ [16, "v1", "art-joint-anim"], [70, "v1", "art-joint-anim"] @@ -6035,8 +5861,6 @@ "(event gnawer-run)": [[54, "a2", "touching-shapes-entry"]], - "(method 7 gnawer)": [[19, "t9", "(function nav-enemy int nav-enemy)"]], - "(code gnawer-give-fuel-cell)": [ [43, "v0", "maincavecam"], [64, "v1", "maincavecam"] @@ -6064,10 +5888,6 @@ [124, "v1", "art-joint-anim"] ], - "(method 7 swamp-blimp)": [ - [19, "t9", "(function process-drawable int process-drawable)"] - ], - "(code swamp-tetherrock-break)": [ [238, "s4", "handle"], [261, "s4", "handle"], @@ -6117,10 +5937,6 @@ [47, "v1", "vector"] ], - "(method 23 citb-chain-plat)": [ - [9, "t9", "(function rigid-body-platform float none)"] - ], - "(code citb-firehose-blast)": [ [10, "v1", "art-joint-anim"], [86, "v1", "art-joint-anim"], @@ -6194,10 +6010,6 @@ [69, "v1", "art-joint-anim"] ], - "(method 7 balloonlurker)": [ - [29, "t9", "(function process-drawable int process-drawable)"] - ], - "(code balloonlurker-pilot-die)": [[58, "v1", "art-joint-anim"]], "(code orbit-plat-bottom-idle)": [ @@ -6269,10 +6081,6 @@ "(trans bully-stop-spinning)": [[10, "v1", "collide-shape-prim-group"]], - "(method 7 bully)": [ - [14, "t9", "(function process-drawable int process-drawable)"] - ], - "(enter seagull-idle)": [[20, "v1", "float"]], "seagull-init-by-other": [[96, "v1", "float"]], @@ -6389,10 +6197,6 @@ "joint-mod-tracker-callback": [[[3, 99], "s4", "joint-mod-tracker"]], - "(method 7 snow-ball)": [ - [26, "t9", "(function process-drawable int process-drawable)"] - ], - "(method 11 mistycannon)": [ ["_stack_", 16, "res-tag"], ["_stack_", 32, "res-tag"], @@ -6420,10 +6224,6 @@ "(method 21 helix-water)": [[27, "a0", "process-drawable"]], - "(method 7 helix-water)": [ - [14, "t9", "(function process-drawable int process-drawable)"] - ], - "(code helix-button-activate)": [[58, "v1", "(pointer sunkencam)"]], "(code target-flut-jump)": [[137, "v1", "float"]], @@ -6520,10 +6320,6 @@ [[407, 409], "v1", "(pointer sunken-pipegame-button)"] ], - "(method 7 sunken-pipegame)": [ - [33, "t9", "(function process-drawable int process-drawable)"] - ], - "(code sunken-pipegame-begin-play)": [ [179, "v1", "float"], [260, "v1", "float"], @@ -6898,10 +6694,6 @@ "ogreboss-shoot-boulder": [[41, "a1", "process-drawable"]], - "(method 7 ogreboss-super-boulder)": [ - [14, "t9", "(function process-drawable int process-drawable)"] - ], - "ogreboss-bounce-boulder-init-by-other": [[112, "v1", "float"]], "(code ogreboss-stage3-shuffle)": [ diff --git a/decompiler/util/TP_Type.cpp b/decompiler/util/TP_Type.cpp index 601e8f0a9d..60d6c1730f 100644 --- a/decompiler/util/TP_Type.cpp +++ b/decompiler/util/TP_Type.cpp @@ -82,6 +82,8 @@ std::string TP_Type::print() const { return ""; case Kind::GET_ART_BY_NAME_METHOD: return ""; + case Kind::FIND_PARENT_METHOD_FUNCTION: + return ""; case Kind::SYMBOL: return fmt::format("", m_str); case Kind::INVALID: @@ -146,6 +148,7 @@ bool TP_Type::operator==(const TP_Type& other) const { case Kind::RUN_FUNCTION_IN_PROCESS_FUNCTION: case Kind::SET_TO_RUN_FUNCTION: case Kind::GET_ART_BY_NAME_METHOD: + case Kind::FIND_PARENT_METHOD_FUNCTION: return true; case Kind::INVALID: default: @@ -215,6 +218,9 @@ TypeSpec TP_Type::typespec() const { case Kind::SET_TO_RUN_FUNCTION: // give a general function so we can't call it normally. return TypeSpec("function"); + case Kind::FIND_PARENT_METHOD_FUNCTION: + // hard-coded here. Needed so that we can properly analyze reg use for the call. + return TypeSpec("function", {TypeSpec("type"), TypeSpec("int"), TypeSpec("function")}); case Kind::GET_ART_BY_NAME_METHOD: return m_ts; case Kind::SYMBOL: diff --git a/decompiler/util/TP_Type.h b/decompiler/util/TP_Type.h index f8ffe87e7b..1898f3c9a7 100644 --- a/decompiler/util/TP_Type.h +++ b/decompiler/util/TP_Type.h @@ -44,6 +44,7 @@ class TP_Type { SET_TO_RUN_FUNCTION, GET_ART_BY_NAME_METHOD, SYMBOL, + FIND_PARENT_METHOD_FUNCTION, INVALID } kind = Kind::UNINITIALIZED; TP_Type() = default; @@ -78,6 +79,7 @@ class TP_Type { case Kind::SET_TO_RUN_FUNCTION: case Kind::GET_ART_BY_NAME_METHOD: case Kind::NON_OBJECT_NEW_METHOD: + case Kind::FIND_PARENT_METHOD_FUNCTION: case Kind::SYMBOL: return false; case Kind::UNINITIALIZED: @@ -323,6 +325,12 @@ class TP_Type { return result; } + static TP_Type make_find_parent_method_function() { + TP_Type result; + result.kind = Kind::FIND_PARENT_METHOD_FUNCTION; + return result; + } + const TypeSpec& get_objects_typespec() const { ASSERT(kind == Kind::TYPESPEC || kind == Kind::INTEGER_CONSTANT_PLUS_VAR); return m_ts; diff --git a/goal_src/jak1/engine/common-obs/nav-enemy.gc b/goal_src/jak1/engine/common-obs/nav-enemy.gc index 91c2b5c00f..53a3ceb926 100644 --- a/goal_src/jak1/engine/common-obs/nav-enemy.gc +++ b/goal_src/jak1/engine/common-obs/nav-enemy.gc @@ -50,7 +50,7 @@ (if (nonzero? (-> obj rand-gen)) (set! (-> obj rand-gen) (the-as random-generator (+ (the-as int (-> obj rand-gen)) arg0))) ) - (the-as nav-enemy ((the-as (function process-drawable int none) (find-parent-method nav-enemy 7)) obj arg0)) + (call-parent-method obj arg0) ) (defmethod new-patrol-point! nav-enemy ((obj nav-enemy)) diff --git a/goal_src/jak1/engine/common-obs/rigid-body.gc b/goal_src/jak1/engine/common-obs/rigid-body.gc index 390da65635..8af52a1392 100644 --- a/goal_src/jak1/engine/common-obs/rigid-body.gc +++ b/goal_src/jak1/engine/common-obs/rigid-body.gc @@ -319,13 +319,7 @@ (the-as rigid-body-control-point-inline-array (+ (the-as int (-> obj control-point-array)) arg0)) ) ) - (the-as - rigid-body-platform - ((the-as (function process-drawable int process-drawable) (find-parent-method rigid-body-platform 7)) - obj - arg0 - ) - ) + (call-parent-method obj arg0) ) (defmethod rigid-body-platform-method-22 rigid-body-platform ((obj rigid-body-platform) (arg0 vector) (arg1 float)) diff --git a/goal_src/jak1/engine/common-obs/sharkey.gc b/goal_src/jak1/engine/common-obs/sharkey.gc index 321c3ee9d9..cd752b1f36 100644 --- a/goal_src/jak1/engine/common-obs/sharkey.gc +++ b/goal_src/jak1/engine/common-obs/sharkey.gc @@ -146,7 +146,7 @@ nav-enemy-default-event-handler (set! (-> obj last-y) f28-0) ) ) - ((the-as (function nav-enemy none) (find-parent-method sharkey 39)) obj) + (call-parent-method obj) 0 (none) ) diff --git a/goal_src/jak1/engine/target/logic-target.gc b/goal_src/jak1/engine/target/logic-target.gc index f7619f7f97..d88dfb17da 100644 --- a/goal_src/jak1/engine/target/logic-target.gc +++ b/goal_src/jak1/engine/target/logic-target.gc @@ -2045,7 +2045,7 @@ (defmethod deactivate target ((obj target)) (set-zero! *camera-smush-control*) - ((the-as (function process-drawable none) (find-parent-method target 10)) obj) + (call-parent-method obj) (none) ) diff --git a/goal_src/jak1/levels/beach/beach-obs.gc b/goal_src/jak1/levels/beach/beach-obs.gc index c72eb2525a..6d831933c6 100644 --- a/goal_src/jak1/levels/beach/beach-obs.gc +++ b/goal_src/jak1/levels/beach/beach-obs.gc @@ -962,10 +962,7 @@ (if (nonzero? (-> obj wobbler)) (&+! (-> obj wobbler) arg0) ) - (the-as - flutflutegg - ((the-as (function process-drawable int process-drawable) (find-parent-method flutflutegg 7)) obj arg0) - ) + (call-parent-method obj arg0) ) ;; WARN: Function (method 20 flutflutegg) has a return type of none, but the expression builder found a return statement. diff --git a/goal_src/jak1/levels/beach/beach-rocks.gc b/goal_src/jak1/levels/beach/beach-rocks.gc index 8f25dd65ec..bffb7e2fb2 100644 --- a/goal_src/jak1/levels/beach/beach-rocks.gc +++ b/goal_src/jak1/levels/beach/beach-rocks.gc @@ -255,7 +255,7 @@ (if (nonzero? (-> obj part-landing)) (set! (-> obj part-landing) (the-as sparticle-launch-control (+ (the-as int (-> obj part-landing)) arg0))) ) - (the-as beach-rock ((the-as (function process-drawable int none) (find-parent-method beach-rock 7)) obj arg0)) + (call-parent-method obj arg0) ) (defmethod deactivate beach-rock ((obj beach-rock)) @@ -265,7 +265,7 @@ (if (nonzero? (-> obj part-landing)) (kill-and-free-particles (-> obj part-landing)) ) - ((the-as (function process-drawable none) (find-parent-method beach-rock 10)) obj) + (call-parent-method obj) (none) ) diff --git a/goal_src/jak1/levels/citadel/citadel-obs.gc b/goal_src/jak1/levels/citadel/citadel-obs.gc index 0f80652bec..c645018b3c 100644 --- a/goal_src/jak1/levels/citadel/citadel-obs.gc +++ b/goal_src/jak1/levels/citadel/citadel-obs.gc @@ -180,7 +180,7 @@ ) (defmethod setup-new-process! citb-arm ((obj citb-arm)) - ((the-as (function citb-arm-section none) (find-parent-method citb-arm 21)) obj) + (call-parent-method obj) (set! (-> obj draw origin-joint-index) (the-as uint 4)) (set-vector! (-> obj cull-dir-local) 0.0 0.0 -1.0 1.0) (set! (-> obj cull-dot) (cos 5461.3335)) @@ -198,7 +198,7 @@ (defmethod setup-new-process! citb-arm-shoulder ((obj citb-arm-shoulder)) - ((the-as (function citb-arm-section none) (find-parent-method citb-arm-shoulder 21)) obj) + (call-parent-method obj) (set! (-> obj draw origin-joint-index) (the-as uint 4)) (set-vector! (-> obj cull-dir-local) 1.0 0.0 1.0 1.0) (set! (-> obj cull-dot) (cos 8374.045)) @@ -262,7 +262,7 @@ (defmethod setup-new-process! citb-arm-a ((obj citb-arm-a)) (initialize-skeleton obj *citb-arm-a-sg* '()) - ((the-as (function citb-arm none) (find-parent-method citb-arm-a 21)) obj) + (call-parent-method obj) (set! (-> obj root-override root-prim local-sphere z) -184320.0) 0 (none) @@ -270,7 +270,7 @@ (defmethod setup-new-process! citb-arm-b ((obj citb-arm-b)) (initialize-skeleton obj *citb-arm-b-sg* '()) - ((the-as (function citb-arm none) (find-parent-method citb-arm-b 21)) obj) + (call-parent-method obj) (set! (-> obj root-override root-prim local-sphere z) -225280.0) 0 (none) @@ -278,7 +278,7 @@ (defmethod setup-new-process! citb-arm-c ((obj citb-arm-c)) (initialize-skeleton obj *citb-arm-c-sg* '()) - ((the-as (function citb-arm none) (find-parent-method citb-arm-c 21)) obj) + (call-parent-method obj) (set! (-> obj root-override root-prim local-sphere z) -266240.0) 0 (none) @@ -286,7 +286,7 @@ (defmethod setup-new-process! citb-arm-d ((obj citb-arm-d)) (initialize-skeleton obj *citb-arm-d-sg* '()) - ((the-as (function citb-arm none) (find-parent-method citb-arm-d 21)) obj) + (call-parent-method obj) (set! (-> obj root-override root-prim local-sphere z) -307200.0) 0 (none) @@ -294,14 +294,14 @@ (defmethod setup-new-process! citb-arm-shoulder-a ((obj citb-arm-shoulder-a)) (initialize-skeleton obj *citb-arm-shoulder-a-sg* '()) - ((the-as (function citb-arm none) (find-parent-method citb-arm-shoulder-a 21)) (the-as citb-arm obj)) + (call-parent-method obj) 0 (none) ) (defmethod setup-new-process! citb-arm-shoulder-b ((obj citb-arm-shoulder-b)) (initialize-skeleton obj *citb-arm-shoulder-b-sg* '()) - ((the-as (function citb-arm none) (find-parent-method citb-arm-shoulder-b 21)) (the-as citb-arm obj)) + (call-parent-method obj) 0 (none) ) @@ -1550,7 +1550,7 @@ ) (defmethod battlecontroller-method-27 citb-battlecontroller ((obj citb-battlecontroller)) - ((the-as (function battlecontroller none) (find-parent-method citb-battlecontroller 27)) obj) + (call-parent-method obj) (set! (-> obj activate-distance) 143360.0) 0 (none) diff --git a/goal_src/jak1/levels/citadel/citadel-sages.gc b/goal_src/jak1/levels/citadel/citadel-sages.gc index afa88204f5..9671cc2d0d 100644 --- a/goal_src/jak1/levels/citadel/citadel-sages.gc +++ b/goal_src/jak1/levels/citadel/citadel-sages.gc @@ -515,7 +515,7 @@ ) ) (set! (-> obj sound-name) "redsage-fires") - ((the-as (function citb-sage none) (find-parent-method red-sagecage 44)) obj) + (call-parent-method obj) (the-as symbol 0) ) @@ -633,7 +633,7 @@ ) ) (set! (-> obj sound-name) "bluesage-fires") - ((the-as (function citb-sage none) (find-parent-method blue-sagecage 44)) obj) + (call-parent-method obj) (the-as symbol 0) ) @@ -746,7 +746,7 @@ ) ) (set! (-> obj sound-name) "yellsage-fire") - ((the-as (function citb-sage none) (find-parent-method yellow-sagecage 44)) obj) + (call-parent-method obj) (the-as symbol 0) ) @@ -826,7 +826,7 @@ ) ) (set! (-> obj sound-name) "greensage-fires") - ((the-as (function citb-sage none) (find-parent-method green-sagecage 44)) obj) + (call-parent-method obj) (the-as symbol 0) ) diff --git a/goal_src/jak1/levels/citadel/citb-plat.gc b/goal_src/jak1/levels/citadel/citb-plat.gc index 31e5b86808..631c39999b 100644 --- a/goal_src/jak1/levels/citadel/citb-plat.gc +++ b/goal_src/jak1/levels/citadel/citb-plat.gc @@ -434,7 +434,7 @@ ) (defmethod rigid-body-platform-method-23 citb-chain-plat ((obj citb-chain-plat) (arg0 float)) - ((the-as (function rigid-body-platform float none) (find-parent-method citb-chain-plat 23)) obj arg0) + (call-parent-method obj arg0) (rigid-body-platform-method-27 obj (-> obj orig-trans)) 0 (none) diff --git a/goal_src/jak1/levels/common/battlecontroller.gc b/goal_src/jak1/levels/common/battlecontroller.gc index 742c451b09..81fdafa2e0 100644 --- a/goal_src/jak1/levels/common/battlecontroller.gc +++ b/goal_src/jak1/levels/common/battlecontroller.gc @@ -590,10 +590,7 @@ battlecontroller-default-event-handler (if (nonzero? (-> obj path-spawn)) (&+! (-> obj path-spawn) arg0) ) - (the-as - battlecontroller - ((the-as (function process-drawable int process-drawable) (find-parent-method battlecontroller 7)) obj arg0) - ) + (call-parent-method obj arg0) ) (defmethod deactivate battlecontroller ((obj battlecontroller)) @@ -603,7 +600,7 @@ battlecontroller-default-event-handler (battlecontroller-off) (set! pp gp-0) ) - ((the-as (function process-drawable none) (find-parent-method battlecontroller 10)) obj) + (call-parent-method obj) 0 (none) ) diff --git a/goal_src/jak1/levels/jungle/fisher.gc b/goal_src/jak1/levels/jungle/fisher.gc index 433dd30652..c064fa65e8 100644 --- a/goal_src/jak1/levels/jungle/fisher.gc +++ b/goal_src/jak1/levels/jungle/fisher.gc @@ -1175,7 +1175,7 @@ (go (method-of-object obj play-anim)) ) (else - ((the-as (function fisher none) (find-parent-method fisher 38)) obj) + (call-parent-method obj) ) ) (none) diff --git a/goal_src/jak1/levels/jungle/hopper.gc b/goal_src/jak1/levels/jungle/hopper.gc index 7d13d6b8ba..86a2367384 100644 --- a/goal_src/jak1/levels/jungle/hopper.gc +++ b/goal_src/jak1/levels/jungle/hopper.gc @@ -32,7 +32,7 @@ nav-enemy-default-event-handler (set! (-> v1-1 settings bot-plane w) (- (- (-> obj shadow-min-y) (-> obj collide-info trans y)))) ) 0 - ((the-as (function nav-enemy none) (find-parent-method hopper 39)) obj) + (call-parent-method obj) 0 (none) ) diff --git a/goal_src/jak1/levels/jungle/jungle-obs.gc b/goal_src/jak1/levels/jungle/jungle-obs.gc index 60339c45b5..79abaa641e 100644 --- a/goal_src/jak1/levels/jungle/jungle-obs.gc +++ b/goal_src/jak1/levels/jungle/jungle-obs.gc @@ -1085,10 +1085,7 @@ (if (nonzero? (-> obj back-prim)) (&+! (-> obj back-prim) arg0) ) - (the-as - jngpusher - ((the-as (function process-drawable int process-drawable) (find-parent-method jngpusher 7)) obj arg0) - ) + (call-parent-method obj arg0) ) (defskelgroup *jngpusher-sg* jngpusher 0 2 ((1 (meters 999999))) :bounds (static-spherem 0 0 0 10)) diff --git a/goal_src/jak1/levels/jungle/junglefish.gc b/goal_src/jak1/levels/jungle/junglefish.gc index 30aac41a49..9033cd21e7 100644 --- a/goal_src/jak1/levels/jungle/junglefish.gc +++ b/goal_src/jak1/levels/jungle/junglefish.gc @@ -25,7 +25,7 @@ nav-enemy-default-event-handler (defmethod common-post junglefish ((obj junglefish)) (water-control-method-10 (-> obj water)) - ((the-as (function nav-enemy none) (find-parent-method junglefish 39)) obj) + (call-parent-method obj) 0 (none) ) diff --git a/goal_src/jak1/levels/jungleb/plant-boss.gc b/goal_src/jak1/levels/jungleb/plant-boss.gc index bbfe83a661..a347eafeac 100644 --- a/goal_src/jak1/levels/jungleb/plant-boss.gc +++ b/goal_src/jak1/levels/jungleb/plant-boss.gc @@ -67,10 +67,7 @@ (&+! (-> obj death-prim v1-8) arg0) ) ) - (the-as - plant-boss - ((the-as (function process-drawable int process-drawable) (find-parent-method plant-boss 7)) obj arg0) - ) + (call-parent-method obj arg0) ) (deftype plant-boss-arm (process-drawable) diff --git a/goal_src/jak1/levels/lavatube/lavatube-obs.gc b/goal_src/jak1/levels/lavatube/lavatube-obs.gc index 64d6521205..3ab16b9037 100644 --- a/goal_src/jak1/levels/lavatube/lavatube-obs.gc +++ b/goal_src/jak1/levels/lavatube/lavatube-obs.gc @@ -403,10 +403,7 @@ (if (nonzero? (-> obj spawn-array)) (&+! (-> obj spawn-array) arg0) ) - (the-as - darkecobarrel - ((the-as (function darkecobarrel-base int darkecobarrel-base) (find-parent-method darkecobarrel 7)) obj arg0) - ) + (call-parent-method obj arg0) ) (defskelgroup *darkecobarrel-sg* darkecobarrel darkecobarrel-lod0-jg darkecobarrel-idle-ja diff --git a/goal_src/jak1/levels/maincave/baby-spider.gc b/goal_src/jak1/levels/maincave/baby-spider.gc index 0f9318cfb8..889af5e276 100644 --- a/goal_src/jak1/levels/maincave/baby-spider.gc +++ b/goal_src/jak1/levels/maincave/baby-spider.gc @@ -232,7 +232,7 @@ baby-spider-default-event-handler (vector-z-quaternion! (new-stack-vector0) (-> obj collide-info quat)) (-> obj up-vector) ) - ((the-as (function nav-enemy none) (find-parent-method baby-spider 39)) obj) + (call-parent-method obj) (none) ) diff --git a/goal_src/jak1/levels/maincave/driller-lurker.gc b/goal_src/jak1/levels/maincave/driller-lurker.gc index 9b826fc6d9..b5e865b6c3 100644 --- a/goal_src/jak1/levels/maincave/driller-lurker.gc +++ b/goal_src/jak1/levels/maincave/driller-lurker.gc @@ -954,10 +954,7 @@ (if (nonzero? (-> obj sound2)) (&+! (-> obj sound2) arg0) ) - (the-as - driller-lurker - ((the-as (function process-drawable int process-drawable) (find-parent-method driller-lurker 7)) obj arg0) - ) + (call-parent-method obj arg0) ) (defmethod deactivate driller-lurker ((obj driller-lurker)) diff --git a/goal_src/jak1/levels/maincave/gnawer.gc b/goal_src/jak1/levels/maincave/gnawer.gc index 72cbf34d27..9c916eb3b6 100644 --- a/goal_src/jak1/levels/maincave/gnawer.gc +++ b/goal_src/jak1/levels/maincave/gnawer.gc @@ -1313,10 +1313,7 @@ (if (nonzero? (-> obj sound2)) (&+! (-> obj sound2) arg0) ) - (the-as - gnawer - ((the-as (function nav-enemy int nav-enemy) (find-parent-method gnawer 7)) (the-as nav-enemy obj) arg0) - ) + (call-parent-method obj arg0) ) (defmethod init-from-entity! gnawer ((obj gnawer) (arg0 entity-actor)) diff --git a/goal_src/jak1/levels/misty/balloonlurker.gc b/goal_src/jak1/levels/misty/balloonlurker.gc index 665cd82d00..c2ff45eeb1 100644 --- a/goal_src/jak1/levels/misty/balloonlurker.gc +++ b/goal_src/jak1/levels/misty/balloonlurker.gc @@ -816,10 +816,7 @@ (if (nonzero? (-> obj mine 1)) (&+! (-> obj mine 1) arg0) ) - (the-as - balloonlurker - ((the-as (function process-drawable int process-drawable) (find-parent-method balloonlurker 7)) obj arg0) - ) + (call-parent-method obj arg0) ) (defstate balloonlurker-pilot-idle (balloonlurker-pilot) diff --git a/goal_src/jak1/levels/misty/misty-conveyor.gc b/goal_src/jak1/levels/misty/misty-conveyor.gc index caa1f8be3a..1c3c6896d9 100644 --- a/goal_src/jak1/levels/misty/misty-conveyor.gc +++ b/goal_src/jak1/levels/misty/misty-conveyor.gc @@ -562,10 +562,7 @@ (if (nonzero? (-> obj pivot)) (&+! (-> obj pivot) arg0) ) - (the-as - keg-conveyor - ((the-as (function process-drawable int process-drawable) (find-parent-method keg-conveyor 7)) obj arg0) - ) + (call-parent-method obj arg0) ) ;; WARN: Function (method 11 keg-conveyor) has a return type of none, but the expression builder found a return statement. diff --git a/goal_src/jak1/levels/misty/misty-obs.gc b/goal_src/jak1/levels/misty/misty-obs.gc index b53a52833b..563bffdc36 100644 --- a/goal_src/jak1/levels/misty/misty-obs.gc +++ b/goal_src/jak1/levels/misty/misty-obs.gc @@ -1578,10 +1578,7 @@ ) (defmethod rigid-body-platform-method-23 bone-platform ((obj bone-platform) (arg0 float)) - ((the-as (function rigid-body-platform basic none) (find-parent-method bone-platform 23)) - obj - (the-as basic arg0) - ) + (call-parent-method obj arg0) (rigid-body-platform-method-27 obj (-> obj anchor-point)) 0 (none) @@ -1760,7 +1757,7 @@ ) (defmethod battlecontroller-method-27 misty-battlecontroller ((obj misty-battlecontroller)) - ((the-as (function battlecontroller none) (find-parent-method misty-battlecontroller 27)) obj) + (call-parent-method obj) (set! (-> obj misty-ambush-collision-hack) #t) 0 (none) diff --git a/goal_src/jak1/levels/ogre/ogre-obs.gc b/goal_src/jak1/levels/ogre/ogre-obs.gc index 4de1c6266f..f631b03634 100644 --- a/goal_src/jak1/levels/ogre/ogre-obs.gc +++ b/goal_src/jak1/levels/ogre/ogre-obs.gc @@ -440,7 +440,7 @@ (defmethod rigid-body-platform-method-23 ogre-plat ((obj ogre-plat) (arg0 float)) - ((the-as (function rigid-body-platform basic none) (find-parent-method ogre-plat 23)) obj (the-as basic arg0)) + (call-parent-method obj arg0) (rigid-body-platform-method-27 obj (-> obj anchor-point)) 0 (none) @@ -607,7 +607,7 @@ (set! (-> obj float-y-offset) 0.0) (+! (-> obj root-overlay trans y) (-> obj idle-y-offset)) (rigid-body-platform-method-29 obj *ogre-step-constants*) - ((the-as (function ogre-plat none) (find-parent-method ogre-step 31)) obj) + (call-parent-method obj) (let ((a0-5 (entity-actor-lookup (-> obj entity) 'alt-actor 0))) (if (and a0-5 (logtest? (-> a0-5 extra perm status) (entity-perm-status complete))) (set! (-> obj active) #t) @@ -665,7 +665,7 @@ (defmethod rigid-body-platform-method-31 ogre-step-a ((obj ogre-step-a)) (set-vector! (-> obj root-overlay root-prim local-sphere) 0.0 12288.0 0.0 20480.0) (initialize-skeleton obj *ogre-step-a-sg* '()) - ((the-as (function ogre-step none) (find-parent-method ogre-step-a 31)) obj) + (call-parent-method obj) 0 (none) ) @@ -673,7 +673,7 @@ (defmethod rigid-body-platform-method-31 ogre-step-b ((obj ogre-step-b)) (set-vector! (-> obj root-overlay root-prim local-sphere) 0.0 12288.0 0.0 20480.0) (initialize-skeleton obj *ogre-step-b-sg* '()) - ((the-as (function ogre-step none) (find-parent-method ogre-step-b 31)) obj) + (call-parent-method obj) 0 (none) ) @@ -681,7 +681,7 @@ (defmethod rigid-body-platform-method-31 ogre-step-c ((obj ogre-step-c)) (set-vector! (-> obj root-overlay root-prim local-sphere) 0.0 12288.0 0.0 26624.0) (initialize-skeleton obj *ogre-step-c-sg* '()) - ((the-as (function ogre-step none) (find-parent-method ogre-step-c 31)) obj) + (call-parent-method obj) 0 (none) ) @@ -689,7 +689,7 @@ (defmethod rigid-body-platform-method-31 ogre-step-d ((obj ogre-step-d)) (set-vector! (-> obj root-overlay root-prim local-sphere) 0.0 12288.0 0.0 20480.0) (initialize-skeleton obj *ogre-step-b-sg* '()) - ((the-as (function ogre-step none) (find-parent-method ogre-step-d 31)) obj) + (call-parent-method obj) 0 (none) ) @@ -734,7 +734,7 @@ (set! (-> obj idle-y-offset) -6144.0) (set! (-> obj float-y-offset) 4096.0) (rigid-body-platform-method-29 obj *ogre-isle-constants*) - ((the-as (function ogre-plat none) (find-parent-method ogre-isle 31)) obj) + (call-parent-method obj) (set! (-> obj active) #t) 0 (none) @@ -771,7 +771,7 @@ (+! (-> obj root-overlay trans x) -8192.0) (set-vector! (-> obj root-overlay root-prim local-sphere) 0.0 8192.0 0.0 24576.0) (initialize-skeleton obj *ogre-isle-b-sg* '()) - ((the-as (function ogre-isle none) (find-parent-method ogre-isle-b 31)) obj) + (call-parent-method obj) 0 (none) ) @@ -780,7 +780,7 @@ (+! (-> obj root-overlay trans x) -8192.0) (set-vector! (-> obj root-overlay root-prim local-sphere) 0.0 8192.0 0.0 24576.0) (initialize-skeleton obj *ogre-isle-b-sg* '()) - ((the-as (function ogre-isle none) (find-parent-method ogre-isle-c 31)) obj) + (call-parent-method obj) 0 (none) ) @@ -790,7 +790,7 @@ (+! (-> obj root-overlay trans z) -8192.0) (set-vector! (-> obj root-overlay root-prim local-sphere) 0.0 8192.0 0.0 22528.0) (initialize-skeleton obj *ogre-isle-d-sg* '()) - ((the-as (function ogre-isle none) (find-parent-method ogre-isle-d 31)) obj) + (call-parent-method obj) 0 (none) ) @@ -825,10 +825,7 @@ (&+! (-> obj joint-mod-array v1-0) arg0) ) ) - (the-as - ogre-bridge - ((the-as (function process-drawable int process-drawable) (find-parent-method ogre-bridge 7)) obj arg0) - ) + (call-parent-method obj arg0) ) (defbehavior ogre-bridge-update-joints ogre-bridge () diff --git a/goal_src/jak1/levels/ogre/ogreboss.gc b/goal_src/jak1/levels/ogre/ogreboss.gc index 9c1ad166e0..84b9889531 100644 --- a/goal_src/jak1/levels/ogre/ogreboss.gc +++ b/goal_src/jak1/levels/ogre/ogreboss.gc @@ -751,13 +751,7 @@ (if (nonzero? (-> obj joint)) (&+! (-> obj joint) arg0) ) - (the-as - ogreboss-super-boulder - ((the-as (function process-drawable int process-drawable) (find-parent-method ogreboss-super-boulder 7)) - obj - arg0 - ) - ) + (call-parent-method obj arg0) ) (defstate ogreboss-super-boulder-killed-player (ogreboss-super-boulder) diff --git a/goal_src/jak1/levels/robocave/cave-trap.gc b/goal_src/jak1/levels/robocave/cave-trap.gc index a394ceb36a..b60d011485 100644 --- a/goal_src/jak1/levels/robocave/cave-trap.gc +++ b/goal_src/jak1/levels/robocave/cave-trap.gc @@ -287,10 +287,7 @@ (if (nonzero? (-> obj alt-actors)) (&+! (-> obj alt-actors) arg0) ) - (the-as - cave-trap - ((the-as (function process-drawable int process-drawable) (find-parent-method cave-trap 7)) obj arg0) - ) + (call-parent-method obj arg0) ) (defmethod init-from-entity! cave-trap ((obj cave-trap) (arg0 entity-actor)) diff --git a/goal_src/jak1/levels/snow/ice-cube.gc b/goal_src/jak1/levels/snow/ice-cube.gc index 3318ec0ae7..b10cd45c0e 100644 --- a/goal_src/jak1/levels/snow/ice-cube.gc +++ b/goal_src/jak1/levels/snow/ice-cube.gc @@ -588,7 +588,7 @@ (if (nonzero? (-> obj part4)) (&+! (-> obj part4) arg0) ) - (the-as ice-cube ((the-as (function nav-enemy int nav-enemy) (find-parent-method ice-cube 7)) obj arg0)) + (call-parent-method obj arg0) ) (defmethod init-from-entity! ice-cube ((obj ice-cube) (arg0 entity-actor)) diff --git a/goal_src/jak1/levels/snow/snow-ball.gc b/goal_src/jak1/levels/snow/snow-ball.gc index 8ae5cd4d70..2d94388d85 100644 --- a/goal_src/jak1/levels/snow/snow-ball.gc +++ b/goal_src/jak1/levels/snow/snow-ball.gc @@ -560,11 +560,7 @@ (&+! (-> obj path v1-0) arg0) ) ) - (the-as snow-ball ((the-as (function process-drawable int process-drawable) (find-parent-method snow-ball 7)) - (the-as process-drawable obj) - arg0 - ) - ) + (call-parent-method obj arg0) ) (defmethod init-from-entity! snow-ball ((obj snow-ball) (arg0 entity-actor)) diff --git a/goal_src/jak1/levels/snow/snow-bumper.gc b/goal_src/jak1/levels/snow/snow-bumper.gc index 999f271666..48747445a4 100644 --- a/goal_src/jak1/levels/snow/snow-bumper.gc +++ b/goal_src/jak1/levels/snow/snow-bumper.gc @@ -299,10 +299,7 @@ (if (nonzero? (-> obj part2)) (&+! (-> obj part2) arg0) ) - (the-as - snow-bumper - ((the-as (function process-drawable int process-drawable) (find-parent-method snow-bumper 7)) obj arg0) - ) + (call-parent-method obj arg0) ) (defmethod init-from-entity! snow-bumper ((obj snow-bumper) (arg0 entity-actor)) diff --git a/goal_src/jak1/levels/snow/snow-obs.gc b/goal_src/jak1/levels/snow/snow-obs.gc index d779f8d4e6..d6be52aa83 100644 --- a/goal_src/jak1/levels/snow/snow-obs.gc +++ b/goal_src/jak1/levels/snow/snow-obs.gc @@ -1001,10 +1001,7 @@ (if (nonzero? (-> obj part3)) (&+! (-> obj part3) arg0) ) - (the-as - snow-fort-gate - ((the-as (function process-drawable int process-drawable) (find-parent-method snow-fort-gate 7)) obj arg0) - ) + (call-parent-method obj arg0) ) (defmethod init-from-entity! snow-fort-gate ((obj snow-fort-gate) (arg0 entity-actor)) diff --git a/goal_src/jak1/levels/snow/yeti.gc b/goal_src/jak1/levels/snow/yeti.gc index 9a0dcd3995..5c3fdf4e1f 100644 --- a/goal_src/jak1/levels/snow/yeti.gc +++ b/goal_src/jak1/levels/snow/yeti.gc @@ -541,7 +541,7 @@ (if (nonzero? (-> obj part2)) (&+! (-> obj part2) arg0) ) - (the-as yeti-slave ((the-as (function nav-enemy int nav-enemy) (find-parent-method yeti-slave 7)) obj arg0)) + (call-parent-method obj arg0) ) (defbehavior yeti-slave-init-by-other yeti-slave ((arg0 entity) (arg1 yeti) (arg2 vector) (arg3 vector) (arg4 symbol)) diff --git a/goal_src/jak1/levels/sunken/bully.gc b/goal_src/jak1/levels/sunken/bully.gc index 30c470e364..bd74258285 100644 --- a/goal_src/jak1/levels/sunken/bully.gc +++ b/goal_src/jak1/levels/sunken/bully.gc @@ -734,10 +734,7 @@ (if (nonzero? (-> obj neck)) (&+! (-> obj neck) arg0) ) - (the-as - bully - ((the-as (function process-drawable int process-drawable) (find-parent-method bully 7)) obj arg0) - ) + (call-parent-method obj arg0) ) (defmethod init-from-entity! bully ((obj bully) (arg0 entity-actor)) diff --git a/goal_src/jak1/levels/sunken/helix-water.gc b/goal_src/jak1/levels/sunken/helix-water.gc index 7874d2f722..226191fd21 100644 --- a/goal_src/jak1/levels/sunken/helix-water.gc +++ b/goal_src/jak1/levels/sunken/helix-water.gc @@ -669,10 +669,7 @@ (if (nonzero? (-> obj alt-actors)) (&+! (-> obj alt-actors) arg0) ) - (the-as - helix-water - ((the-as (function process-drawable int process-drawable) (find-parent-method helix-water 7)) obj arg0) - ) + (call-parent-method obj arg0) ) (defmethod init-from-entity! helix-water ((obj helix-water) (arg0 entity-actor)) diff --git a/goal_src/jak1/levels/sunken/puffer.gc b/goal_src/jak1/levels/sunken/puffer.gc index d270382a66..beaac8f258 100644 --- a/goal_src/jak1/levels/sunken/puffer.gc +++ b/goal_src/jak1/levels/sunken/puffer.gc @@ -1059,10 +1059,7 @@ (if (nonzero? (-> obj neck)) (&+! (-> obj neck) arg0) ) - (the-as - puffer - ((the-as (function process-drawable int process-drawable) (find-parent-method puffer 7)) obj arg0) - ) + (call-parent-method obj arg0) ) (defmethod init-from-entity! puffer ((obj puffer) (arg0 entity-actor)) diff --git a/goal_src/jak1/levels/sunken/qbert-plat.gc b/goal_src/jak1/levels/sunken/qbert-plat.gc index f6e64d3565..e217bf65a4 100644 --- a/goal_src/jak1/levels/sunken/qbert-plat.gc +++ b/goal_src/jak1/levels/sunken/qbert-plat.gc @@ -280,7 +280,7 @@ ) (defmethod rigid-body-platform-method-23 qbert-plat ((obj qbert-plat) (arg0 float)) - ((the-as (function rigid-body-platform float none) (find-parent-method qbert-plat 23)) obj arg0) + (call-parent-method obj arg0) (rigid-body-platform-method-27 obj (-> obj anchor-point)) 0 (none) diff --git a/goal_src/jak1/levels/sunken/square-platform.gc b/goal_src/jak1/levels/sunken/square-platform.gc index ffb03c3118..170dacf41e 100644 --- a/goal_src/jak1/levels/sunken/square-platform.gc +++ b/goal_src/jak1/levels/sunken/square-platform.gc @@ -404,10 +404,7 @@ (if (nonzero? (-> obj part4)) (&+! (-> obj part4) arg0) ) - (the-as - square-platform - ((the-as (function baseplat int baseplat) (find-parent-method square-platform 7)) obj arg0) - ) + (call-parent-method obj arg0) ) (defmethod init-from-entity! square-platform ((obj square-platform) (arg0 entity-actor)) diff --git a/goal_src/jak1/levels/sunken/steam-cap.gc b/goal_src/jak1/levels/sunken/steam-cap.gc index d0340feda8..c9a02389fd 100644 --- a/goal_src/jak1/levels/sunken/steam-cap.gc +++ b/goal_src/jak1/levels/sunken/steam-cap.gc @@ -650,10 +650,7 @@ (if (nonzero? (-> obj part3)) (&+! (-> obj part3) arg0) ) - (the-as - steam-cap - ((the-as (function process-drawable int process-drawable) (find-parent-method steam-cap 7)) obj arg0) - ) + (call-parent-method obj arg0) ) (defmethod deactivate steam-cap ((obj steam-cap)) diff --git a/goal_src/jak1/levels/sunken/sunken-pipegame.gc b/goal_src/jak1/levels/sunken/sunken-pipegame.gc index 7fef3ba56a..0ad10455a2 100644 --- a/goal_src/jak1/levels/sunken/sunken-pipegame.gc +++ b/goal_src/jak1/levels/sunken/sunken-pipegame.gc @@ -913,10 +913,7 @@ ) ) ) - (the-as - sunken-pipegame - ((the-as (function process-drawable int process-drawable) (find-parent-method sunken-pipegame 7)) obj arg0) - ) + (call-parent-method obj arg0) ) (defmethod init-from-entity! sunken-pipegame ((obj sunken-pipegame) (arg0 entity-actor)) diff --git a/goal_src/jak1/levels/swamp/billy.gc b/goal_src/jak1/levels/swamp/billy.gc index 737abba7cf..ee659d1197 100644 --- a/goal_src/jak1/levels/swamp/billy.gc +++ b/goal_src/jak1/levels/swamp/billy.gc @@ -43,10 +43,7 @@ (&+! (-> obj path-data v1-0) arg0) ) ) - (the-as - billy - ((the-as (function process-drawable int process-drawable) (find-parent-method billy 7)) obj arg0) - ) + (call-parent-method obj arg0) ) (deftype billy-snack (process-drawable) @@ -438,7 +435,7 @@ (go (method-of-object obj play-anim)) ) (else - ((the-as (function nav-enemy none) (find-parent-method billy 38)) (the-as nav-enemy obj)) + (call-parent-method obj) ) ) (none) diff --git a/goal_src/jak1/levels/swamp/kermit.gc b/goal_src/jak1/levels/swamp/kermit.gc index 8c14f71eb2..e8e056ee40 100644 --- a/goal_src/jak1/levels/swamp/kermit.gc +++ b/goal_src/jak1/levels/swamp/kermit.gc @@ -829,7 +829,7 @@ nav-enemy-default-event-handler (defmethod common-post kermit ((obj kermit)) - ((the-as (function nav-enemy none) (find-parent-method kermit 39)) obj) + (call-parent-method obj) (when (-> obj charged-up) ) 0 diff --git a/goal_src/jak1/levels/swamp/swamp-bat.gc b/goal_src/jak1/levels/swamp/swamp-bat.gc index 445a3feb2d..010a78bc3a 100644 --- a/goal_src/jak1/levels/swamp/swamp-bat.gc +++ b/goal_src/jak1/levels/swamp/swamp-bat.gc @@ -62,10 +62,7 @@ (&+! (-> obj path-list v1-0) arg0) ) ) - (the-as - swamp-bat - ((the-as (function process-drawable int process-drawable) (find-parent-method swamp-bat 7)) obj arg0) - ) + (call-parent-method obj arg0) ) (deftype swamp-bat-slave (process-drawable) diff --git a/goal_src/jak1/levels/training/training-obs.gc b/goal_src/jak1/levels/training/training-obs.gc index cbc7f31596..cd58914544 100644 --- a/goal_src/jak1/levels/training/training-obs.gc +++ b/goal_src/jak1/levels/training/training-obs.gc @@ -242,7 +242,7 @@ ) (defmethod rigid-body-platform-method-23 tra-pontoon ((obj tra-pontoon) (arg0 float)) - ((the-as (function rigid-body-platform float none) (find-parent-method tra-pontoon 23)) obj arg0) + (call-parent-method obj arg0) (rigid-body-platform-method-27 obj (-> obj anchor-point)) 0 (none) diff --git a/goal_src/jak1/levels/village2/swamp-blimp.gc b/goal_src/jak1/levels/village2/swamp-blimp.gc index 600c12e5c7..2bff059ad8 100644 --- a/goal_src/jak1/levels/village2/swamp-blimp.gc +++ b/goal_src/jak1/levels/village2/swamp-blimp.gc @@ -585,10 +585,7 @@ (if (nonzero? (-> obj bag)) (&+! (-> obj bag) arg0) ) - (the-as - swamp-blimp - ((the-as (function process-drawable int process-drawable) (find-parent-method swamp-blimp 7)) obj arg0) - ) + (call-parent-method obj arg0) ) (defstate swamp-tetherrock-die (swamp-tetherrock) diff --git a/goal_src/jak1/levels/village2/village2-obs.gc b/goal_src/jak1/levels/village2/village2-obs.gc index c75d61fe59..aa662cdc95 100644 --- a/goal_src/jak1/levels/village2/village2-obs.gc +++ b/goal_src/jak1/levels/village2/village2-obs.gc @@ -183,7 +183,7 @@ ) (defmethod rigid-body-platform-method-23 pontoon ((obj pontoon) (arg0 float)) - ((the-as (function rigid-body-platform basic none) (find-parent-method pontoon 23)) obj (the-as basic arg0)) + (call-parent-method obj arg0) (rigid-body-platform-method-27 obj (-> obj anchor-point)) 0 (none) diff --git a/goalc/compiler/Compiler.h b/goalc/compiler/Compiler.h index de54236d25..a7574378b8 100644 --- a/goalc/compiler/Compiler.h +++ b/goalc/compiler/Compiler.h @@ -246,7 +246,6 @@ class Compiler { TypeSpec parse_typespec(const goos::Object& src, Env* env); bool is_local_symbol(const goos::Object& obj, Env* env); - emitter::HWRegKind get_preferred_reg_kind(const TypeSpec& ts); Val* compile_real_function_call(const goos::Object& form, RegVal* function, const std::vector& args, @@ -705,6 +704,7 @@ class Compiler { Val* compile_size_of(const goos::Object& form, const goos::Object& rest, Env* env); ConstPropResult const_prop_size_of(const goos::Object& form, const goos::Object& rest, Env* env); Val* compile_psize_of(const goos::Object& form, const goos::Object& rest, Env* env); + Val* compile_current_method_id(const goos::Object& form, const goos::Object& rest, Env* env); // State Val* compile_define_state_hook(const goos::Object& form, const goos::Object& rest, Env* env); diff --git a/goalc/compiler/Env.h b/goalc/compiler/Env.h index b9f36a01a9..3b8bf610c0 100644 --- a/goalc/compiler/Env.h +++ b/goalc/compiler/Env.h @@ -240,6 +240,7 @@ class FunctionEnv : public DeclareEnv { int segment = -1; std::string method_of_type_name = "#f"; + std::optional method_id; bool is_asm_func = false; bool asm_func_saved_regs = false; TypeSpec asm_func_return_type; diff --git a/goalc/compiler/Util.cpp b/goalc/compiler/Util.cpp index 04513cf664..43aba0804f 100644 --- a/goalc/compiler/Util.cpp +++ b/goalc/compiler/Util.cpp @@ -316,17 +316,6 @@ bool Compiler::is_local_symbol(const goos::Object& obj, Env* env) { return false; } -emitter::HWRegKind Compiler::get_preferred_reg_kind(const TypeSpec& ts) { - switch (m_ts.lookup_type(ts)->get_preferred_reg_class()) { - case RegClass::GPR_64: - return emitter::HWRegKind::GPR; - case RegClass::FLOAT: - return emitter::HWRegKind::XMM; - default: - throw std::runtime_error("Unknown preferred register kind"); - } -} - bool Compiler::is_none(Val* in) { return dynamic_cast(in); } diff --git a/goalc/compiler/compilation/Atoms.cpp b/goalc/compiler/compilation/Atoms.cpp index 0d24c01c64..537860e9f7 100644 --- a/goalc/compiler/compilation/Atoms.cpp +++ b/goalc/compiler/compilation/Atoms.cpp @@ -212,6 +212,7 @@ const std::unordered_map< {"none", {"", &Compiler::compile_none}}, {"size-of", {"", &Compiler::compile_size_of}}, {"psize-of", {"", &Compiler::compile_psize_of}}, + {"current-method-id", {"", &Compiler::compile_current_method_id}}, // LAMBDA {"lambda", {"", &Compiler::compile_lambda}}, diff --git a/goalc/compiler/compilation/Type.cpp b/goalc/compiler/compilation/Type.cpp index 0cd071c417..c52d8f8253 100644 --- a/goalc/compiler/compilation/Type.cpp +++ b/goalc/compiler/compilation/Type.cpp @@ -492,6 +492,8 @@ Val* Compiler::compile_defmethod(const goos::Object& form, const goos::Object& _ auto new_func_env = std::make_unique(env, lambda.debug_name, &m_goos.reader); new_func_env->set_segment(env->function_env()->segment_for_static_data()); new_func_env->method_of_type_name = symbol_string(type_name); + new_func_env->method_id = + m_ts.lookup_method(symbol_string(type_name), symbol_string(method_name)).id; // set up arguments if (lambda.params.size() > 8) { @@ -1467,3 +1469,15 @@ Compiler::ConstPropResult Compiler::const_prop_size_of(const goos::Object& form, Val* Compiler::compile_psize_of(const goos::Object& form, const goos::Object& rest, Env* env) { return compile_integer((get_size_for_size_of(form, rest) + 0xf) & ~0xf, env); } + +Val* Compiler::compile_current_method_id(const goos::Object& form, + const goos::Object& rest, + Env* env) { + auto args = get_va(form, rest); + va_check(form, args, {}, {}); + auto* fe = env->function_env(); + if (!fe->method_id) { + throw_compiler_error(form, "current-method-id wasn't called from a method."); + } + return compile_integer(*fe->method_id, env); +} \ No newline at end of file