#include "ObjProGui/yacintfc.h"
#include "ObjProUsr/block.h"
#include "ObjProComGui/cgidbg.h"

void Block::ctor()
{
}

ErrCode Block::kernel(int32 k)
{
	int32 i,b,e;
	// TheLog << "Limit = " << Limit << "\n" ;
	switch (the_convert_type) {
default:
 	   State.Error("unsupported arithmetic conversion");
    	return FatalError;
case undefined:
		State.Error("`", GetName(), "' not initialized");
		return FatalError ;
case no_conversion:
		for (i = 0 ; i <k ; i++ )
		for (b = 0 ; b < TargetNode::GetBlockSize(); b++) 
		for (e = 0; e < TargetNode::GetEltSize(); e++)
					WriteInteger(ReadInteger()) ;
		return OK ;
case float_to_int:
		for (i = 0 ; i <k ; i++ )
		for (b = 0 ; b < TargetNode::GetBlockSize(); b++) 
		for (e = 0; e < TargetNode::GetEltSize(); e++) {
			float test = (MachWordCast) ReadWord();
			int warn=0 ;
			if (test > MachWord::max_int_positive) test =
				MachWord::max_int_positive,warn=1;
			else if (test < MachWord::min_int_negative) test = 
				MachWord::min_int_negative,warn=1;
			if (warn) MachWord::hard_limit_warn();
			WriteInteger((int32)test) ;
		}
		return OK ;
case int_to_float:
		for (i = 0 ; i <k ; i++ )
		for (b = 0 ; b < TargetNode::GetBlockSize(); b++) 
		for (e = 0; e < TargetNode::GetEltSize(); e++)
			WriteWord((int)(ReadInteger())) ;
		return OK ;
	}
}

