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

#import "EXPExpression.h"
#import "EXPConstant.h"
#import "EXPVirtualMachine.h"
#import "EXPError.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:(EXPVirtualMachine *)machine error:(EXPError *)err opcode:(unsigned int)opcode
{
	[machine putOpcode:opcode mode:IMM];
	[machine putDouble:[self value]];
	return YES;
}  */

- (BOOL) isSimple
{
	return YES;
}

- (BOOL) isConstant
{
	return YES;
}

- (BOOL) isTypeCompatible
{
	return YES;
}

- (NSString *)elementType
{
	return @"constant";
}

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

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

/* - (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