Exemple #1
0
    def generateCode(self, gst, ist, lst, cref, blo, bli):
	self.given.generateCode(gst, ist, lst, cref, blo, bli)
	temp = TemporaryEntry(blo)
	temp.storeCode(bli)
	oldTemp = lst['@']
	lst['@'] = temp
	self.expr.generateCode(gst, ist, lst, cref, blo, bli)
	lst['@'] = oldTemp
Exemple #2
0
    def generateCode(self,gSym,iSym,lSym,cref,blocko,blocki):
	if self.resizable:
	    blocki.add_instruction('Int %i'%(len(self.list)))
	    blocki.add_instruction('Global $ArrayList')
	    blocki.add_instruction("MCall 1 'newWithCapacity:'")
	else:
	    blocki.add_instruction('Alloc %i'%(len(self.list)+1))
	    blocki.add_instruction('Dup')
	    blocki.add_instruction('ChMTable %PrimitiveArray')
	temporary = TemporaryEntry(blocko)
	temporary.storeCode(blocki)
	if not self.resizable:
	    blocki.add_instruction('Int %i'%(len(self.list)))
	    blocki.add_instruction('Int 0')
	    temporary.loadCode(blocki)
	    blocki.add_instruction("StoreInstInd")
	    i = 0
	for expr in self.list:
	    expr.generateCode(gSym,iSym,lSym,cref,blocko,blocki)
	    if not self.resizable:
		blocki.add_instruction('Int %d' % (i+1))
	    temporary.loadCode(blocki)
	    if self.resizable:
		blocki.add_instruction("MCall 1 'addLast:'")
	    else:
		blocki.add_instruction("StoreInstInd")
		i += 1
	    if self.resizable:
		blocki.add_instruction("Pop")
	temporary.loadCode(blocki)