예제 #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,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))
예제 #3
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