示例#1
0
	inline CPointerClass(bool b):
		AbstractClass(& NS_LANG_C.staticVariables,"pointer", NULL,PRIMITIVE_LAYOUT,CLASS_CPOINTER,true,C_POINTERTYPE){
		NS_LANG_C.staticVariables.addClass(PositionID(0,0,"#pointer"),this);

		LANG_M.addFunction(PositionID(0,0,"#str"),"print")->add(
			new BuiltinInlineFunction(
					new FunctionProto("print",{AbstractDeclaration(this)},&voidClass),
			[](RData& r,PositionID id,const std::vector<const Evaluatable*>& args,const Data* instance) -> Data*{
			assert(args.size()==1);
			r.printf("0x%" PRIXPTR, args[0]->evalV(r, id));
			return &VOID_DATA;
		}), PositionID(0,0,"#int"));
		LANG_M.addFunction(PositionID(0,0,"#str"),"println")->add(
			new BuiltinInlineFunction(
					new FunctionProto("println",{AbstractDeclaration(this)},&voidClass),
			[](RData& r,PositionID id,const std::vector<const Evaluatable*>& args,const Data* instance) -> Data*{
			assert(args.size()==1);
			r.printf("0x%" PRIXPTR "\n", args[0]->evalV(r, id));
			return &VOID_DATA;
		}), PositionID(0,0,"#int"));
	}
示例#2
0
extern int
DumpPosition(const TanBoard anBoard, char *szOutput,
             const evalcontext * pec, cubeinfo * pci, int fOutputMWC,
             int UNUSED(fOutputWinPC), int fOutputInvert, const char *szMatchID)
{

    float aarOutput[2][NUM_ROLLOUT_OUTPUTS];
    positionclass pc = ClassifyPosition(anBoard, pci->bgv);
    int i, nPlies;
    int j;
    evalcontext ec;
    static const char *aszEvaluator[] = {
        N_("Over"),
        N_("Hypergammon-1"),
        N_("Hypergammon-2"),
        N_("Hypergammon-3"),
        N_("Bearoff2"),
        N_("Bearoff-TS"),
        N_("Bearoff1"),
        N_("Bearoff-OS"),
        N_("Race"),
        N_("Crashed"),
        N_("Contact")
    };

    strcpy(szOutput, "");

    sprintf(strchr(szOutput, 0), "%s:\t", _("Position ID"));
    strcat(szOutput, PositionID(anBoard));
    strcat(szOutput, "\n");
    if (szMatchID) {
        sprintf(strchr(szOutput, 0), "%s:\t", _("Match ID"));
        strcat(szOutput, szMatchID);
        strcat(szOutput, "\n");
    }
    strcat(szOutput, "\n");

    sprintf(strchr(szOutput, 0), "%s: \t", _("Evaluator"));
    strcat(szOutput, gettext(aszEvaluator[pc]));
    strcat(szOutput, "\n\n");
    acdf[pc] (anBoard, strchr(szOutput, 0), pci->bgv);
    szOutput = strchr(szOutput, 0);

    sprintf(strchr(szOutput, 0),
            "\n"
            "        %-7s %-7s %-7s %-7s %-7s %-9s %-9s\n",
            _("Win"), _("W(g)"), _("W(bg)"), _("L(g)"), _("L(bg)"),
            (!pci->nMatchTo || (pci->nMatchTo && !fOutputMWC)) ? _("Equity") : _("MWC"), _("Cubeful"));

    nPlies = pec->nPlies > 9 ? 9 : pec->nPlies;

    memcpy(&ec, pec, sizeof(evalcontext));

    for (i = 0; i <= nPlies; i++) {
        szOutput = strchr(szOutput, 0);


        ec.nPlies = i;

        if (GeneralCubeDecisionE(aarOutput, anBoard, pci, &ec, 0) < 0)
            return -1;

        if (!i)
            strcpy(szOutput, _("static"));
        else
            sprintf(szOutput, "%2d %s", i, _("ply"));

        szOutput = strchr(szOutput, 0);

        if (fOutputInvert) {
            InvertEvaluationR(aarOutput[0], pci);
            InvertEvaluationR(aarOutput[1], pci);
            pci->fMove = !pci->fMove;
        }

        /* Print %'s and equities */

        strcat(szOutput, ": ");

        for (j = 0; j < 5; ++j) {
            sprintf(strchr(szOutput, 0), "%-7s ", OutputPercent(aarOutput[0][j]));
        }

        if (pci->nMatchTo)
            sprintf(strchr(szOutput, 0), "%-9s ", OutputEquity(Utility(aarOutput[0], pci), pci, TRUE));
        else
            sprintf(strchr(szOutput, 0), "%-9s ", OutputMoneyEquity(aarOutput[0], TRUE));

        sprintf(strchr(szOutput, 0), "%-9s ", OutputMWC(aarOutput[0][6], pci, TRUE));

        strcat(szOutput, "\n");

        if (fOutputInvert) {
            pci->fMove = !pci->fMove;
        }
    }

    /* if cube is available, output cube action */
    if (GetDPEq(NULL, NULL, pci)) {

        evalsetup es;

        es.et = EVAL_EVAL;
        es.ec = *pec;

        strcat(szOutput, "\n\n");
        strcat(szOutput, OutputCubeAnalysis(aarOutput, NULL, &es, pci));

    }

    return 0;
}
示例#3
0
		exit(1);
	}

	const Data* getLocalData(RData& r, PositionID id, String s, const Data* instance) const override final{
			illegalLocal(id,s);
			exit(1);
	}

	bool noopCast(const AbstractClass* const toCast) const override{
		return false;
	}
	bool hasCast(const AbstractClass* const toCast) const override{
		return hasCast(toCast);
	}
	llvm::Value* castTo(const AbstractClass* const toCast, RData& r, PositionID id, llvm::Value* valueToCast) const override{
		id.compilerError("Scope class cannot be instantiated --- how did this even happen....?");
		exit(1);
	}
	int compare(const AbstractClass* const a, const AbstractClass* const b) const{
		assert(hasCast(a));
		assert(hasCast(b));
		return 0;
	}
};

ScopeClass NS_LANG(&LANG_M, PositionID("#init",0,0), "lang");
ScopeClass NS_LANG_C(&(NS_LANG.staticVariables), PositionID("#init",0,0), "c");
ScopeClass NS_LANG_CPP(&(NS_LANG.staticVariables), PositionID("#init",0,0), "cpp");

#endif /* SCOPECLASS_HPP_ */
示例#4
0
static char *
DrawBoardStd(char *sz, const TanBoard anBoard, int fRoll, char *asz[], char *szMatchID, int nChequers)
{

    char *pch = sz, *pchIn;
    unsigned int x, y;
    unsigned int cOffO = nChequers, cOffX = nChequers;
    TanBoard an;
    static char achX[17] = "     X6789ABCDEF", achO[17] = "     O6789ABCDEF";

    for (x = 0; x < 25; x++) {
        cOffO -= anBoard[0][x];
        cOffX -= anBoard[1][x];
    }

    pch += sprintf(pch, " %-15s %s: ", _("GNU Backgammon"), _("Position ID"));

    if (fRoll)
        strcpy(pch, PositionID((ConstTanBoard) anBoard));
    else {
        for (x = 0; x < 25; x++) {
            an[0][x] = anBoard[1][x];
            an[1][x] = anBoard[0][x];
        }

        strcpy(pch, PositionID((ConstTanBoard) an));
    }

    pch += 14;
    *pch++ = '\n';

    /* match id */

    if (szMatchID && *szMatchID) {
        pch += sprintf(pch, "                 %s   : %s\n", _("Match ID"), szMatchID);
    }

    strcpy(pch, fRoll ? " +13-14-15-16-17-18------19-20-21-22-23-24-+     " :
           " +12-11-10--9--8--7-------6--5--4--3--2--1-+     ");
    pch += 49;

    if (asz[0])
        for (pchIn = asz[0]; *pchIn; pchIn++)
            *pch++ = *pchIn;

    *pch++ = '\n';

    for (y = 0; y < 4; y++) {
        *pch++ = ' ';
        *pch++ = '|';

        for (x = 12; x < 18; x++) {
            *pch++ = ' ';
            *pch++ = anBoard[1][x] > y ? 'X' : anBoard[0][23 - x] > y ? 'O' : ' ';
            *pch++ = ' ';
        }

        *pch++ = '|';
        *pch++ = ' ';
        *pch++ = anBoard[0][24] > y ? 'O' : ' ';
        *pch++ = ' ';
        *pch++ = '|';

        for (; x < 24; x++) {
            *pch++ = ' ';
            *pch++ = anBoard[1][x] > y ? 'X' : anBoard[0][23 - x] > y ? 'O' : ' ';
            *pch++ = ' ';
        }

        *pch++ = '|';
        *pch++ = ' ';

        for (x = 0; x < 3; x++)
            *pch++ = (cOffO > 5 * x + y) ? 'O' : ' ';

        *pch++ = ' ';

        if (y < 2 && asz[y + 1])
            for (pchIn = asz[y + 1]; *pchIn; pchIn++)
                *pch++ = *pchIn;
        *pch++ = '\n';
    }

    *pch++ = ' ';
    *pch++ = '|';

    for (x = 12; x < 18; x++) {
        *pch++ = ' ';
        *pch++ = anBoard[1][x] ? achX[anBoard[1][x]] : achO[anBoard[0][23 - x]];
        *pch++ = ' ';
    }

    *pch++ = '|';
    *pch++ = ' ';
    *pch++ = achO[anBoard[0][24]];
    *pch++ = ' ';
    *pch++ = '|';

    for (; x < 24; x++) {
        *pch++ = ' ';
        *pch++ = anBoard[1][x] ? achX[anBoard[1][x]] : achO[anBoard[0][23 - x]];
        *pch++ = ' ';
    }

    *pch++ = '|';

    *pch++ = ' ';

    for (x = 0; x < 3; x++)
        *pch++ = (cOffO > 5 * x + 4) ? 'O' : ' ';

    *pch++ = '\n';

    *pch++ = fRoll ? 'v' : '^';
    strcpy(pch, "|                  |BAR|                  |     ");
    pch = strchr(pch, 0);

    if (asz[3])
        for (pchIn = asz[3]; *pchIn; pchIn++)
            *pch++ = *pchIn;

    *pch++ = '\n';

    *pch++ = ' ';
    *pch++ = '|';

    for (x = 11; x > 5; x--) {
        *pch++ = ' ';
        *pch++ = anBoard[1][x] ? achX[anBoard[1][x]] : achO[anBoard[0][23 - x]];
        *pch++ = ' ';
    }

    *pch++ = '|';
    *pch++ = ' ';
    *pch++ = achX[anBoard[1][24]];
    *pch++ = ' ';
    *pch++ = '|';

    for (; x < UINT_MAX; x--) {
        *pch++ = ' ';
        *pch++ = anBoard[1][x] ? achX[anBoard[1][x]] : achO[anBoard[0][23 - x]];
        *pch++ = ' ';
    }

    *pch++ = '|';

    *pch++ = ' ';

    for (x = 0; x < 3; x++)
        *pch++ = (cOffX > 5 * x + 4) ? 'X' : ' ';

    *pch++ = '\n';

    for (y = 3; y < UINT_MAX; y--) {
        *pch++ = ' ';
        *pch++ = '|';

        for (x = 11; x > 5; x--) {
            *pch++ = ' ';
            *pch++ = anBoard[1][x] > y ? 'X' : anBoard[0][23 - x] > y ? 'O' : ' ';
            *pch++ = ' ';
        }

        *pch++ = '|';
        *pch++ = ' ';
        *pch++ = anBoard[1][24] > y ? 'X' : ' ';
        *pch++ = ' ';
        *pch++ = '|';

        for (; x < UINT_MAX; x--) {
            *pch++ = ' ';
            *pch++ = anBoard[1][x] > y ? 'X' : anBoard[0][23 - x] > y ? 'O' : ' ';
            *pch++ = ' ';
        }

        *pch++ = '|';
        *pch++ = ' ';

        for (x = 0; x < 3; x++)
            *pch++ = (cOffX > 5 * x + y) ? 'X' : ' ';

        *pch++ = ' ';

        if (y < 2 && asz[5 - y])
            for (pchIn = asz[5 - y]; *pchIn; pchIn++)
                *pch++ = *pchIn;

        *pch++ = '\n';
    }

    strcpy(pch, fRoll ? " +12-11-10--9--8--7-------6--5--4--3--2--1-+     " :
           " +13-14-15-16-17-18------19-20-21-22-23-24-+     ");
    pch += 49;

    if (asz[6])
        for (pchIn = asz[6]; *pchIn; pchIn++)
            *pch++ = *pchIn;

    *pch++ = '\n';
    *pch = 0;

    return sz;
}
示例#5
0
template<typename R, typename... B> SingleFunction* import_cpp_function_h(R (*func)(B...), String name, Scopable* scope=nullptr, String lib="",PositionID id=PositionID("#internalCPP",0,0)){
	const FunctionClass* C = convertClass(R(*)(B...),&NS_LANG_CPP.staticVariables);
	std::vector<AbstractDeclaration> ad;
	for(const auto& a: C->argumentTypes)
		ad.push_back(AbstractDeclaration(a));
	/*std::stringstream nname;
	int idx=0;
	while(idx< name.length()){
		if(name[idx]==':') idx++;
	}
	while(idx < name.length()){
		int st = idx;
		while(idx<name.length() && name[idx]!=':') idx++;
		auto tmp = name.substr(st, idx-st);
		if(idx<name.length() && name[idx]!=':'){
			idx++;
			while(idx<name.length() && name[idx]!=':') idx++;
		} else {

		}
	}*/
	std::stringstream s;
	cerr << (void*)(func) << " or " << (void*)(std::terminate) << " = " << ((void*)func==(void*)std::terminate) << endl << flush;
	if((void*)func == (void*)std::terminate){
		s << "_ZSt9terminatev";
		cerr << name << " is now terminate" << endl << flush;
		name = "terminate";
	} else{
		s << "_Z";
		s << name.length();
		s << name;
		//addMangledToStream<B...>::add(s);
		//TODO
	}
	cerr << name << " vs " << s.str() << endl << flush;
	auto CF = new CompiledFunction(
			new FunctionProto(name, ad, C->returnType, false),
			rdata.getExtern(s.str(), C->returnType, C->argumentTypes, false, lib));
	if(scope){
		scope->addFunction(id, name)->add(CF, id);
	}
	return CF;
};