예제 #1
0
    def generateCode(self,stable):
	self.getMethodTable(stable) #ensure method tables initialized
	gvar = Global()  # mixin object reference
	gvar.setName(self.name) # our name
	obj = BytecodeObject(self.name) # class/singleton object
	gvar.setValue(obj) # which the reference points to
	obj.setMTable(self.mixinMethodTable) #mixin objects get mixin mtable
	return [self.mixinMethodTable,obj,gvar]
예제 #2
0
    def generateCode(self,symbolTable):
	test_global = Global()
	store_global = Global()
	test_global.setName('test'+self.name)
	store_global.setName('store'+self.name)

	secondary_block = Block(innerBlock = True)
	secondary_block.add_instruction('Global $store'+self.name)
	secondary_block.add_instruction('Return')

	blocks = []
	self.block.add_instruction('Block #'+secondary_block.getName())
	self.block.add_instruction('Global $test'+self.name)
	self.block.add_instruction("MCall 1 'and:'")
	self.block.add_instruction('Pop')
	self.expr.generateCode(symbolTable,
		{},
		{'_return': None,'@':None,'_blocks':blocks},
		None,
		self.block,
		self.block)
	self.block.add_instruction('Dup')
	self.block.add_instruction('StoreGlobal $store'+self.name)
	self.block.add_instruction('Global $true')
	self.block.add_instruction('StoreGlobal $test'+self.name)
	self.block.add_instruction("Return")
	return [self.block,secondary_block,store_global,test_global]+blocks
예제 #3
0
    def generateCode(self,gSym,iSym,lSym,cref,blocko,blocki):
	global counter
	counter += 1
	arrayObject = ByteArray("str_array"+str(counter))
	vals = []
	for chr in self.value:
	    vals += [ord(chr)]
	arrayObject.setValues(vals)
	stringObject = BytecodeObject("str_object"+str(counter))
	class MTable:
	    def __init__(self,name):
		self.name = name
	stringMTable = MTable("AsciiString")
	stringObject.setMTable(stringMTable)
	stringObject.addIntIVar(len(vals))
	stringObject.addIVar("@"+arrayObject.name)
	stringGlobal = Global()
	stringGlobal.setName("str_global"+str(counter))
	stringGlobal.setValue(stringObject)
	lSym['_blocks'].append(stringGlobal)
	lSym['_blocks'].append(arrayObject)
	lSym['_blocks'].append(stringObject)
	blocki.add_instruction("Global $str_global"+str(counter))
예제 #4
0
    def generateCode(self,stable):
	self.getMethodTable(stable) #ensure method tables initialized
	self.addClassMethod(stable)
	#self.resolveMixins(stable)
	gvar = Global()  # class/singleton object reference
	gvar.setName(self.name) # our name
	obj = BytecodeObject(self.name) # class/singleton object
	gvar.setValue(obj) # which the reference points to
	if self.singleton:
	    obj.setMTable(self.methodTable) #singletons get object mtable
	    return [self.methodTable,obj,gvar]+self.exceptionHandlingBlocks
	else:
	    obj.setMTable(self.classMethodTable) #non-singletons get factory one
	    block = Block(name = '_new_' + self.name) # new method
	    block.add_instruction("Int %i"%\
		    (self.getInstanceVariableCount(stable)))
	    block.add_instruction("Alloc %i"% \
		    self.getInstanceVariableCount(stable))
	    block.add_instruction("Dup")
	    block.add_instruction("ChMTable %%%s"%(self.methodTable.name))
	    block.add_instruction("Return")
	    self.classMethodTable.addMethod('basicNew',block.name)
	    return [self.methodTable,self.classMethodTable,block,obj,gvar]+\
		    self.exceptionHandlingBlocks