//
//  EXPOutputItemOp.m
//  dde
//
//  Created by ashley on 25/11/2007.
//  Copyright 2007 __MyCompanyName__. All rights reserved.
//

#import "EXPOutputItemOp.h"
#import "EXPPrintElement.h"
//#import "EXPAssemblerConstants.h"
#import "EXPVirtualMachine.h"

@implementation EXPOutputItemOp

- (void) setPrinter:(id)printer
{
//	[printer retain];
//	[_printer release];
	_printer = printer;
}

- (id) printer
{
	return  _printer;
}

/* - (BOOL) compile:(EXPVirtualMachine *)machine withSeparator:(BOOL)withSeparator error:(EXPError *)error
{
	BOOL success = YES;
	
	EXPPrintElement *printer = [self printer];
	int fileNumber = [printer fileNumber];
	int printOpcode;
	int printCharOpcode;
	int printStringOpcode;
	if (fileNumber<0) {
		printOpcode = PRTA;
		printCharOpcode = PCHR;
		printStringOpcode = PSTR;
	} else {
		printOpcode = FPRTA;
		printCharOpcode = FPCHR;
		printStringOpcode = FPSTR;
	}
	
	EXPExpression *exp = [self left];

	NSArray *indices = [self indices];
		
	unsigned int *branchAddresses;
	unsigned int *loopAddresses;
	int nIndices = [indices count];
	if (nIndices>0) {
		branchAddresses = (unsigned int *)calloc(nIndices, sizeof(unsigned int));
		loopAddresses = (unsigned int *)calloc(nIndices, sizeof(unsigned int));
		compileIndexLoopHeader(machine, nIndices, indices, branchAddresses, loopAddresses);
	}

	if (withSeparator) {
		NSString *separator = [printer separator];
		if (separator==nil) {
			[machine putOpcode:printCharOpcode mode:(INTEGER + IMM)];
			[machine putUInt:(unsigned int)'\t'];
			if (fileNumber>=0) {
				[machine putUInt:fileNumber];
			}
		} else {
			[machine putOpcode:printStringOpcode mode:INTEGER];
			if (fileNumber>=0) {
				[machine putUInt:fileNumber];
			}
			[machine putString:separator withNewLine:NO];
		}
	}
	success = [exp compile:machine error:error];

	[machine putOpcode:printOpcode mode:FLTPOINT];
	if (fileNumber>=0) {
		[machine putUInt:fileNumber];
	}
	

	if (nIndices>0) {
		compileIndexLoopFooter(machine, nIndices, indices, branchAddresses, loopAddresses);
		free(branchAddresses);
		free(loopAddresses);
	}

	return success;
} */

- (NSString *)description
{
	return @"EXPOutputItemOp";
}

@end