//
//  EXPConstant.m
//  Expression
//
//  Created by Ashley on 28/02/2006.
//  Copyright 2006 __MyCompanyName__. All rights reserved.
//

#import "EXPExpression.h"
#import "EXPConstant.h"

@implementation EXPConstant

- (id) initWithName:(NSString *) name
{
//	printf("EXPConstant initWithName: %s\n", [name UTF8String]);
	[super init];
	[self setName:name];
	return self;
}


- (id) init
{
	[self initWithName:nil];
	return self;
}

- (void) setName:(NSString *) name
{
	[_name release];
	[name retain];
	_name = name;
}

- (NSString *) name
{
	return _name;
}

- (double) result
{
	return _value;
}

- (void) setValue:(double) value
{
	_value = value;
}

- (double) value
{
	return _value;
}

- (BOOL) compile:(EXPStackMachine *)machine error:(NSError **)err opcode:(unsigned int)opcode
{
	[machine putUInt:(opcode + IMODE)];
	[machine putDouble:[self value]];
	return YES;
}

- (BOOL) isSimple
{
	return YES;
}

- (void) dump
{
	printf("Constant = %g retain count = %d\n", [self value], [self retainCount]);
}

- (NSString *)description
{
	return [NSString stringWithFormat:@"%g", [self value]];
}

/* - (id) retain
{
	printf("EXPConstant retain: value = %g\n", [self value]);
	return [super retain];
} */

- (void) dealloc
{
//	printf("EXPConstant - (void)dealloc\n");
	[_name release];
	[super dealloc];
}

@end
