Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat on earth would compell C++ to call this function?
    primarykey
    data
    text
    <p>I'm working on a programming language that uses C++ as it's target language for now. I'm hitting an exceptionally strange backtrace.</p> <pre><code>#1 0x08048d09 in factorial (n=0x8052160) at ir.cpp:35 35 shore::builtin__int * __return = NULL; (gdb) bt #0 shore::builtin__int::__mul__ (this=0x8052160, other=0x8052288) at /home/alex/projects/shore/shore/runtime/int.h:36 #1 0x08048d09 in factorial (n=0x8052160) at ir.cpp:35 #2 0x08048cfa in factorial (n=0x80520b8) at ir.cpp:35 #3 0x08048cfa in factorial (n=0x8052018) at ir.cpp:35 #4 0x08048d6f in main () at ir.cpp:43 </code></pre> <p>Specifically it appears that declaring the type of <strong>return is somehow triggering the __mul</strong> method on builtin__int to be called, and I have no idea why. builtin__int looks like:</p> <pre><code>#ifndef _SHORE_INT_H #define _SHORE_INT_H #include "gc.h" namespace shore { class builtin__int : public shore::Object { public: // Some day this will be arbitrary percision, but not today. long long value; static builtin__int* new_instance(long long value_) { builtin__int* val = new builtin__int(value_); shore::GC::register_object(val); return val; } builtin__int(long long value_) { this-&gt;value = value_; } builtin__bool* __eq__(builtin__int* other) { return builtin__bool::new_instance(this-&gt;value == other-&gt;value); } builtin__int* __add__(builtin__int* other) { return builtin__int::new_instance(this-&gt;value + other-&gt;value); } builtin__int* __sub__(builtin__int* other) { return builtin__int::new_instance(this-&gt;value - other-&gt;value); } builtin__int* __mul__(builtin__int* other) { return builtin__int::new_instance(this-&gt;value * other-&gt;value); } }; } #endif </code></pre> <p>Any ideas as to what on earth is compelling C++ to call the <strong>mul</strong> method?</p> <p>EDIT: Added the source of ir.cpp</p> <pre><code>#include "builtins.h" #include "frame.h" #include "object.h" #include "state.h" std::vector &lt; shore::Frame * &gt;shore::State::frames; shore::GCSet shore::GC::allocated_objects; class factorial__frame: public shore::Frame { public: shore::builtin__int * n; shore::GCSet __get_sub_objects() { shore::GCSet s; s. insert(this-&gt;n); return s; }}; class main__frame: public shore::Frame { public: shore::GCSet __get_sub_objects() { shore::GCSet s; return s; }}; shore::builtin__int * factorial(shore::builtin__int * n) { shore::builtin__int * __return = NULL; factorial__frame frame; shore::State::frames.push_back(&amp;frame); frame.n = NULL; frame.n = n; if (((frame.n)-&gt;__eq__(shore::builtin__int::new_instance(0)))-&gt;value) { __return = shore::builtin__int::new_instance(1); shore::GC::collect(); shore::State::frames.pop_back(); return __return; } __return = (frame.n)-&gt; __mul__(factorial ((frame.n)-&gt; __sub__(shore::builtin__int::new_instance(1)))); shore::GC::collect(); shore::State::frames.pop_back(); return __return; } int main() { main__frame frame; shore::State::frames.push_back(&amp;frame); builtin__print(factorial(shore::builtin__int::new_instance(3))); shore::State::frames.pop_back(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload