Example #1
0
    def compilarPrimitivo(self, instruccion):
        if isinstance(instruccion, Primitivo):
            if instruccion.tipo == Tipos.Booleano:
                if instruccion.trueLabel == '':
                    instruccion.trueLabel = self.generarEtiqueta()

                if instruccion.falseLabel == '':
                    instruccion.falseLabel = self.generarEtiqueta()
                temporal = self.generarTemporal()
                if instruccion.valor is True:
                    self.generarGoto(instruccion.trueLabel)
                    self.agregarEtiqueta(instruccion.trueLabel)
                    self.generarAsignacion(temporal, True)
                else:
                    self.generarGoto(instruccion.falseLabel)
                    self.agregarEtiqueta(instruccion.falseLabel)
                    self.generarAsignacion(temporal, False)
                ret = RetornoOp(temporal, Tipos.Id)
                ret.trueLabel = instruccion.trueLabel
                ret.falseLabel = instruccion.falseLabel
                return ret
            elif instruccion.tipo == Tipos.Id:
                temporal = self.generarTemporal()
                self.generarAsignacion(temporal, instruccion.valor)
                return RetornoOp(temporal, instruccion.tipo)
            elif instruccion.tipo == Tipos.ISQL:
                valor = instruccion.valor
                if valor.find("C3D_") == -1:
                    auxvalor = valor.split("=", 1)
                    temporal = auxvalor[0].replace("\t", "")
                    inst = auxvalor[1]
                    self.generarAsignacion(temporal, inst)
                    self.generarAsignacion("lista", "[" + temporal + "]")
                    temp = self.generarTemporal()
                    self.generarAsignacion(temp, "funcionIntermedia()")
                    ret = RetornoOp(temp, None)
                    return ret
                else:
                    auxvalor = valor
                    auxvalor1 = auxvalor.split("\n")
                    temp = ""
                    for inst in auxvalor1:
                        if inst.find("funcionIntermedia()") == -1:
                            self.codigo3d.append(inst)
                        else:
                            temp = self.generarTemporal()
                            self.generarAsignacion(temp, "funcionIntermedia()")
                    ret = RetornoOp(temp, None)
                    return ret
            else:
                ret = RetornoOp(instruccion.valor, instruccion.tipo)
                return ret
        elif isinstance(instruccion, Llamada):
            return self.compilarLlamada(instruccion)
Example #2
0
    def compilarPrimitivo(self, instruccion):
        if instruccion.tipo == Tipos.Booleano:
            if instruccion.trueLabel == '':
                instruccion.trueLabel = self.generarEtiqueta()

            if instruccion.falseLabel == '':
                instruccion.falseLabel = self.generarEtiqueta()
            temporal = self.generarTemporal()
            if instruccion.valor is True:
                self.generarGoto(instruccion.trueLabel)
                self.agregarEtiqueta(instruccion.trueLabel)
                self.generarAsignacion(temporal, True)
            else:
                self.generarGoto(instruccion.falseLabel)
                self.agregarEtiqueta(instruccion.falseLabel)
                self.generarAsignacion(temporal, False)
            ret = RetornoOp(temporal, Tipos.Id)
            ret.trueLabel = instruccion.trueLabel
            ret.falseLabel = instruccion.falseLabel
            return ret
        else:
            ret = RetornoOp(instruccion.valor, instruccion.tipo)
            return ret