지구상에서 C ++ 가이 기능을 부르도록 강요 할 것인가?
-
11-09-2019 - |
문제
현재 C ++를 대상 언어로 사용하는 프로그래밍 언어를 연구하고 있습니다. 나는 예외적으로 이상한 백 트레이스를 때리고 있습니다.
#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
특히 유형을 선언하는 것으로 보입니다 반환은 어떻게 든 __mul을 트리거합니다 buildin__t에 대한 방법은 호출 될 것이며 왜 그런지 모르겠습니다. 내장 __in은 다음과 같습니다.
#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->value = value_;
}
builtin__bool* __eq__(builtin__int* other) {
return builtin__bool::new_instance(this->value == other->value);
}
builtin__int* __add__(builtin__int* other) {
return builtin__int::new_instance(this->value + other->value);
}
builtin__int* __sub__(builtin__int* other) {
return builtin__int::new_instance(this->value - other->value);
}
builtin__int* __mul__(builtin__int* other) {
return builtin__int::new_instance(this->value * other->value);
}
};
}
#endif
지구상에서 C ++가 뮬 방법?
편집 : IR.CPP 소스를 추가했습니다
#include "builtins.h"
#include "frame.h"
#include "object.h"
#include "state.h"
std::vector < shore::Frame * >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->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(&frame);
frame.n = NULL;
frame.n = n;
if (((frame.n)->__eq__(shore::builtin__int::new_instance(0)))->value) {
__return = shore::builtin__int::new_instance(1);
shore::GC::collect();
shore::State::frames.pop_back();
return __return;
}
__return =
(frame.n)->
__mul__(factorial
((frame.n)->
__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(&frame);
builtin__print(factorial(shore::builtin__int::new_instance(3)));
shore::State::frames.pop_back();
}
해결책
약간의 추측 : 라인의 초기화 shore::builtin__int * __return = NULL;
항상 덮어 쓰기 때문에 아무것도하지 않습니다. 컴파일러는 (a)를 어디로로 주문할 수 있습니다. __return
전화를하는 진술서에 의해 할당됩니다 __mul__
그런 다음 (b) 코드를 완전히 제거하십시오. 그러나 디버깅 정보에 소스 라인이 남아있을 수 있으며 링커 나 GDB는 통화 명령이 인근의 여러 소스 라인 중 하나에 속한다고 생각하게되었습니다.
분해를 볼 수 없다면 소스 디버깅을 신뢰하지 마십시오. 컴파일 된 언어 -BAH, HUMBUG. 기타 등등.
다른 팁
이중 밑줄이있는 식별자 이름이 예약되어 있습니다. 컴파일러 생성 이름과 충돌 할 수 있습니다.
번역가가 실패한 것처럼 보이고, GCC (또는 무엇이든)는 Shore :: Buildin__int가 어떤 종류의 가치라고 생각하며, __return을 유형 해안으로 선언하는 대신 __return을 곱하려고합니다. : 내장 __in *...
분명히,이 물건이 컴파일되고 있고 런타임 오류를 주면 곱셈이 당신에게 줄 수있는 모든 유형이 유효한 LHS입니다 ...