quakeforge/ruamoko/scheme/CompiledCode.r
Brian Koropoff adba6b26dc Scheme updates:
- Boolean type (no support in lexer yet)
	- Conditionals
	- Defines (only work correctly at top level)
	- More core builtins (apply, cons, car, cdr)
	- Variable-argument functions
	- Incremental garbage collection
	- Garbage collection fixes
	- Other misc bugs fixed
2005-05-06 23:25:06 +00:00

86 lines
1.8 KiB
R

#include "CompiledCode.h"
#include "defs.h"
@implementation CompiledCode
- (id) init
{
self = [super init];
constants = [Array new];
instructions = [Array new];
return self;
}
- (void) markReachable
{
[literals mark];
if (constants)
[constants makeObjectsPerformSelector: @selector(mark)];
if (instructions)
[instructions makeObjectsPerformSelector: @selector(mark)];
}
- (void) addInstruction: (Instruction) inst
{
[inst offset: [instructions count]];
if ([inst opcode] != LABEL) {
[instructions addItem: inst];
}
}
- (integer) addConstant: (SchemeObject) c
{
local integer number = [constants count];
[constants addItem: c];
return number;
}
- (void) compile
{
local integer index;
local Instruction inst;
literals = [Frame newWithSize: [constants count] link: NIL];
code = obj_malloc (@sizeof(instruction_t) * [instructions count]);
for (index = 0; index < [constants count]; index++) {
[literals set: index to: (SchemeObject) [constants getItemAt: index]];
}
for (index = 0; index < [instructions count]; index++) {
inst = [instructions getItemAt: index];
[inst emitStruct: code];
}
[instructions release];
[constants release];
instructions = constants = NIL;
}
- (instruction_t []) code
{
return code;
}
- (Frame) literals
{
return literals;
}
- (void) dealloc
{
local Array temp;
if (instructions) {
temp = instructions;
instructions = NIL;
[temp release];
}
if (constants) {
temp = constants;
constants = NIL;
[temp release];
}
if (code) {
obj_free (code);
}
[super dealloc];
}
@end