Example #1
0
 def _ord(char):
   """Char -> Int"""
   res = charset.ord(char)
   if res is not None:
     return res
   else:
     raise InvalidCharError(char)
 def try_alf_word(self):
     if self.get() == '"':
         # exactly five mix-chars in inverted or
         self.next()
         if self.get() == '"':
             s = ""
         else:
             s = self.get()
             if self.look() != '"':
                 raise UnquotedStringError(self.line.argument)
             self.next()
     else:
         # less than six mix-chars not in inverted
         s = self.line.argument.rstrip('\n\r')
         self.ct = len(self.tokens) - 1
         if s is None:
             s = ""
     s = s[:5]
     while len(s) < 5:
         s += " "
     # now s - string with len = 5
     word = Memory.positive_zero()
     for i in xrange(1, 6):
         word[i] = charset.ord(s[i - 1])
         if word[i] is None:
             raise InvalidCharError(s[i - 1])
     return Memory.mix2dec(word)
Example #3
0
 def _ord(char):
     """Char -> Int"""
     res = charset.ord(char)
     if res is not None:
         return res
     else:
         raise InvalidCharError(char)
Example #4
0
    def try_alf_word(self):
        if self.get() == '"':
            # exactly five mix-chars in inverted or
            self.next()
            if self.get() == '"':
                s = ""
            else:
                s = self.get()
                if self.look() != '"':
                    raise UnquotedStringError(self.line.argument)
                self.next()
        else:
            # less than six mix-chars not in inverted
            s = self.line.argument.rstrip('\n\r')
            self.ct = len(self.tokens) - 1
            if s is None:
                s = ""

        s = s[:5]
        while len(s) < 5:
            s += " "
        # now s - string with len = 5

        word = Memory.positive_zero()
        for i in xrange(1, 6):
            word[i] = charset.ord(s[i - 1])
            if word[i] is None:
                raise InvalidCharError(s[i - 1])
        return Memory.mix2dec(word)
Example #5
0
def str2word(line, type, content_type, allow_mesgBox = False):
  line = line.upper()
  word = Word()
  if len(line) == 0:
    return word
  if line[0] in "+-" and type != STR: # text - always is positive :)
    word[0] = 1 if line[0] == '+' else -1
    line = line[1:]
  else:
    word[0] = 1
  # now line - unsigned part of string

  if type == WORD:
    # take number from the end of line and put tham to the edn of word,
    # if there are not enough nums - zeros putted
    nums = line.split()
    nums = [0] * (5 - len(nums)) + nums # set len(nums) to 5
    len_nums = len(nums)
    for byte in range(5, 0, -1):
      word[byte] = min(63, int(nums[byte - 1]))

  elif type == INT:
    i = int(line)
    if content_type == BASIC and i >= 1073741824: # = 64 ** 5
      i = 1073741824 - 1
    elif content_type != BASIC and i >= 4096: # = 64 ** 2
      i = 4096 - 1
    word[1 if content_type == BASIC else 4 :5] = i

  elif type == STR:
    # if len(line) < 5
    if content_type == BASIC:
      # 1) spaces added to the end if it's basic mem cell
      line = line + " " * (5 - len(line)) # set len(line) to 5
    else:
      # 2) rI or rJ: 3 spaces added to the start and some spaces added to the end
      line = "   " + line + " " * (2 - len(line)) # set len(line) to 5
    for byte in range(1, 6):
      assert( line[byte - 1] != '?')
      word[byte] = charset.ord(line[byte - 1])
  return word
Example #6
0
def str2word(line, type, content_type, allow_mesgBox=False):
    line = line.upper()
    word = Word()
    if len(line) == 0:
        return word
    if line[0] in "+-" and type != STR:  # text - always is positive :)
        word[0] = 1 if line[0] == '+' else -1
        line = line[1:]
    else:
        word[0] = 1
    # now line - unsigned part of string

    if type == WORD:
        # take number from the end of line and put tham to the edn of word,
        # if there are not enough nums - zeros putted
        nums = line.split()
        nums = [0] * (5 - len(nums)) + nums  # set len(nums) to 5
        len_nums = len(nums)
        for byte in xrange(5, 0, -1):
            word[byte] = min(63, int(nums[byte - 1]))

    elif type == INT:
        i = int(line)
        if content_type == BASIC and i >= 1073741824:  # = 64 ** 5
            i = 1073741824 - 1
        elif content_type != BASIC and i >= 4096:  # = 64 ** 2
            i = 4096 - 1
        word[1 if content_type == BASIC else 4:5] = i

    elif type == STR:
        # if len(line) < 5
        if content_type == BASIC:
            # 1) spaces added to the end if it's basic mem cell
            line = line + " " * (5 - len(line))  # set len(line) to 5
        else:
            # 2) rI or rJ: 3 spaces added to the start and some spaces added to the end
            line = "   " + line + " " * (2 - len(line))  # set len(line) to 5
        for byte in xrange(1, 6):
            assert (line[byte - 1] != '?')
            word[byte] = charset.ord(line[byte - 1])
    return word