예제 #1
0
    def __call__(self, state, scope, pos, paramTypes, *args):
        if len(args) == 1:
            x, = args
            if x < 0:
                raise PFARuntimeException("negative number",
                                          self.errcodeBase + 1, self.name, pos)
            else:
                return "{0:x}".format(x)

        else:
            x, width, zeroPad = args
            if x < 0:
                raise PFARuntimeException("negative number",
                                          self.errcodeBase + 1, self.name, pos)
            if not zeroPad:
                if width < 0:
                    formatStr = "{0:<" + str(-width) + "x}"
                elif width == 0:
                    formatStr = ""
                else:
                    formatStr = "{0:" + str(width) + "x}"
            else:
                if width < 0:
                    raise PFARuntimeException(
                        "negative width cannot be used with zero-padding",
                        self.errcodeBase + 0, self.name, pos)
                elif width == 0:
                    formatStr = ""
                else:
                    formatStr = "{0:0" + str(width) + "x}"
            return formatStr.format(x)
예제 #2
0
 def __call__(self, state, scope, pos, paramTypes, m, n, lessThan):
     if len(m) == 0:
         raise PFARuntimeException("empty map", self.errcodeBase + 0,
                                   self.name, pos)
     elif n < 0:
         raise PFARuntimeException("n < 0", self.errcodeBase + 1, self.name,
                                   pos)
     else:
         return argLowestN(m, n, toLt(state, scope, lessThan))
예제 #3
0
 def __call__(self, state, scope, pos, paramTypes, m, n):
     if len(m) == 0:
         raise PFARuntimeException("empty map", self.errcodeBase + 0,
                                   self.name, pos)
     elif n < 0:
         raise PFARuntimeException("n < 0", self.errcodeBase + 1, self.name,
                                   pos)
     else:
         return argLowestN(
             m, n, lambda x, y: compare(
                 jsonNodeToAvroType(paramTypes[0]).values, x, y) < 0)
예제 #4
0
파일: core.py 프로젝트: z-cankova/hadrian
def checkForOverflow(paramType, out, code1, code2, fcnName, pos):
    if paramType == "int":
        if math.isnan(out) or out < INT_MIN_VALUE or out > INT_MAX_VALUE:
            raise PFARuntimeException("int overflow", code1, fcnName, pos)
        else:
            return out
    elif paramType == "long":
        if math.isnan(out) or out < LONG_MIN_VALUE or out > LONG_MAX_VALUE:
            raise PFARuntimeException("long overflow", code2, fcnName, pos)
        else:
            return out
    else:
        return out
예제 #5
0
파일: change.py 프로젝트: z-cankova/hadrian
    def __call__(self, state, scope, pos, paramTypes, predicate, history):
        numEvents = history["numEvents"]
        numRuns = history["numRuns"]
        currentRun = history["currentRun"]
        longestRun = history["longestRun"]

        if numEvents < 0 or numRuns < 0 or currentRun < 0 or longestRun < 0:
            raise PFARuntimeException("counter out of range",
                                      self.errcodeBase + 0, self.name, pos)

        if predicate:
            numEvents += 1
            if currentRun == 0:
                numRuns += 1
            currentRun += 1
            if currentRun > longestRun:
                longestRun = currentRun
        else:
            currentRun = 0

        return dict(history,
                    numEvents=numEvents,
                    numRuns=numRuns,
                    currentRun=currentRun,
                    longestRun=longestRun)
예제 #6
0
파일: core.py 프로젝트: z-cankova/hadrian
 def __call__(self, state, scope, pos, paramTypes, x, y):
     out = powLikeJava(x, y)
     if paramTypes[-1] == "int":
         if math.isnan(out) or out < INT_MIN_VALUE or out > INT_MAX_VALUE:
             raise PFARuntimeException("int overflow", self.errcodeBase + 0,
                                       self.name, pos)
         else:
             return int(out)
     elif paramTypes[-1] == "long":
         if math.isnan(out) or out < LONG_MIN_VALUE or out > LONG_MAX_VALUE:
             raise PFARuntimeException("long overflow",
                                       self.errcodeBase + 1, self.name, pos)
         else:
             return int(out)
     else:
         return out
예제 #7
0
파일: core.py 프로젝트: z-cankova/hadrian
 def __call__(self, state, scope, pos, paramTypes, x, y):
     if y == 0:
         if paramTypes[-1] == "int" or paramTypes[-1] == "long":
             raise PFARuntimeException("integer division by zero",
                                       self.errcodeBase + 0, self.name, pos)
         else:
             return float("nan")
     else:
         return x % y
예제 #8
0
 def __call__(self, state, scope, pos, paramTypes, *args):
     fcn = args[-1]
     maps = args[:-1]
     keys = maps[0].keys()
     for m in maps:
         if keys != m.keys():
             raise PFARuntimeException("misaligned maps",
                                       self.errcodeBase + 0, self.name, pos)
     out = {}
     for k in keys:
         out[k] = callfcn(state, scope, fcn, [k] + [x[k] for x in maps])
     return out
예제 #9
0
파일: core.py 프로젝트: z-cankova/hadrian
 def __call__(self, state, scope, pos, paramTypes, x, y):
     if y == 0:
         if paramTypes[-1] == "int" or paramTypes[-1] == "long":
             raise PFARuntimeException("integer division by zero",
                                       self.errcodeBase + 0, self.name, pos)
         else:
             return float("nan")
     else:
         if not math.isnan(x) and not math.isinf(x) and math.isinf(y):
             return x
         else:
             out = x % y
             if x < 0 and out > 0:
                 return out - abs(y)
             elif x > 0 and out < 0:
                 return out + abs(y)
             else:
                 return out
예제 #10
0
    def __call__(self, state, scope, pos, paramTypes, *args):
        if len(args) == 1 and paramTypes[0] in ("int", "long"):
            x, = args
            return "{0:d}".format(x)

        elif len(args) == 3 and paramTypes[0] in ("int", "long"):
            x, width, zeroPad = args
            if not zeroPad:
                if width < 0:
                    formatStr = "{0:<" + str(-width) + "d}"
                elif width == 0:
                    formatStr = ""
                else:
                    formatStr = "{0:" + str(width) + "d}"
            else:
                if width < 0:
                    raise PFARuntimeException(
                        "negative width cannot be used with zero-padding",
                        self.errcodeBase + 0, self.name, pos)
                elif width == 0:
                    formatStr = ""
                else:
                    formatStr = "{0:0" + str(width) + "d}"
            return formatStr.format(x)

        else:
            if len(args) == 3:
                x, width, precision = args
                minNoExp, maxNoExp = 0.0001, 100000
            else:
                x, width, precision, minNoExp, maxNoExp = args

            if width is None:
                widthStr = ""
            else:
                if isinstance(width, dict):
                    width = width["int"]
                if width < 0:
                    widthStr = "<" + str(-width)
                else:
                    widthStr = str(width)

            if precision is None:
                precisionStr = ".6"
            else:
                if isinstance(precision, dict):
                    precision = precision["int"]
                if precision < 0:
                    raise PFARuntimeException("negative precision",
                                              self.errcodeBase + 1, self.name,
                                              pos)
                else:
                    precisionStr = "." + str(precision)

            if x == 0.0: x = 0.0  # drop sign bit from zero

            v = abs(x)
            if v == 0.0 or (v >= minNoExp and v <= maxNoExp):
                conv = "f"
            else:
                conv = "e"

            formatStr = "{0:" + widthStr + precisionStr + conv + "}"
            result = formatStr.format(x)

            if precision is None:
                m = re.search("\.[0-9]+?(0+) *$", result)
                if m is None:
                    m = re.search("\.[0-9]+?(0+)e", result)
                if m is not None:
                    start, end = m.regs[1]
                    numChanged = end - start
                    result = result[:start] + result[end:]
                    if width is not None:
                        if width < 0:
                            actual, target = len(result), -width
                            if actual < target:
                                result = result + (" " * (target - actual))
                        elif width == 0:
                            result = ""
                        else:
                            actual, target = len(result), width
                            if actual < target:
                                result = (" " * (target - actual)) + result

            return result
예제 #11
0
파일: core.py 프로젝트: z-cankova/hadrian
 def __call__(self, state, scope, pos, paramTypes, x, y):
     if y == 0:
         raise PFARuntimeException("integer division by zero",
                                   self.errcodeBase + 0, self.name, pos)
     else:
         return int(x / float(y))