Ejemplo n.º 1
0
	def WRITE(self, BYTE):
		# Check if there is a value at the current address
		if RAM().ADDRESS[ADDR().PEEK()]:
			RAM().ADDRESS[ADDR().PEEK()] = BYTE # Write to Address
			DEBUG().MSG('BUS', 'DATA', 'WRITE', DATA)
		else:
			DEBUG().MSG('BUS', 'DATA', 'WRITE', 'NO ADDRESS')
Ejemplo n.º 2
0
	def READ(self): # Read Function
		# Check if there is a value at the current address
		if RAM().ADDRESS[ADDR().PEEK()]:
			DATA = RAM().ADDRESS[ADDR().PEEK()] # Assign the value from address
		else:
			DATA = 0 # If no value assign 0
		DEBUG().MSG('BUS', 'DATA', 'READ', DATA)
		return DATA # Return the value
Ejemplo n.º 3
0
 def DECODE(self):  # Decode Procedure
     #self.IR = hex(self.IR)[2:].zfill(2) # Remove 0x and fill with 0
     CMD = int.from_bytes(self.IR[:1], byteorder='little')
     VAL = int.from_bytes(self.IR[1:], byteorder='little')
     self.IR = [CMD, VAL]
     #print(int.from_bytes(self.IR, byteorder='little'))
     DEBUG().MSG('CPU', 'DECODE', 'IR', self.IR)
     BUS().POP()  # Pop Address from the BUS
Ejemplo n.º 4
0
    def PRINT(self, OPERATION):
        if OPERATION == 0:
            OUT = self.IR
            DEBUG().MSG('CPU', 'PNT', 'IR', self.IR)
        elif OPERATION == 1:
            OUT = self.IR[1:]
            DEBUG().MSG('CPU', 'PNT', 'IR CMD', self.IR[1:])
        elif OPERATION == 2:
            OUT = self.IR[:1]
            DEBUG().MSG('CPU', 'PNT', 'IR VAL', self.IR[:1])
        elif OPERATION == 3:
            OUT = self.PC
            DEBUG().MSG('CPU', 'PNT', 'PC', self.PC)
        elif OPERATION == 4:
            OUT = self.AC
            DEBUG().MSG('CPU', 'PNT', 'AC', self.AC)
        else:
            OUT = 'ERROR'

        sys.stdout.write(OUT)
Ejemplo n.º 5
0
    def classify_effect_tokens(effect):
        DEBUG('classifying effect tokens')
        # build bigrams
        bigrams = []
        # remove uninteresting tokens
        effect_tokens = [et for et in effect if OracleTextParser.is_token_interesting(et)]
        # take the list of two consecutive elements
        bigrams = list(map(list, zip(effect_tokens, effect_tokens[1:])))
        bigrams = ['{} {}'.format(bg[0], bg[1]) for bg in bigrams]

        return {
            'bigrams': bigrams,
            'effect': effect,
            'tokens': [w.text for w in effect],
            'nouns': [w.text for w in effect if OracleTextParser.is_token_nounish(w)],
            'verbs': [w.text for w in effect if w.pos_ == "VERB"],
            'phrases': [phrase.text for phrase in effect.noun_chunks],
        }
Ejemplo n.º 6
0
    def LOAD(self, BIN):
        DEBUG().MSG('CPU', 'LOAD', 'BIN', BIN)
        DATA = open(BIN, "rb")
        BUS().CLEAR()
        BYTE = DATA.readlines()

        counter = []

        for BIT in BYTE[0]:
            counter.append(BIT)

            if len(counter) == 2:
                CMD = (counter[0]).to_bytes(2, byteorder='little')
                VAL = (counter[1]).to_bytes(2, byteorder='little')
                BUS().LOAD(CMD[:1] + VAL[:1])
                counter.clear()

        self.RUN()


# Commands
#  0 HEX: 00 | ASM: END - End Operation
#  1 HEX: 01 | ASM: LOD - Load into Accumulator
#  2 HEX: 02 | ASM: STR - Store Accumulator in Address
#  3 HEX: 03 | ASM: ADD - Add to Accumulator
#  4 HEX: 04 | ASM: SUB - Sub from Accumulator
#  5 HEX: 05 | ASM: JMP - Jump to Address
#  6 HEX: 06 | ASM: PNT	- Print to Console
#  7 HEX: 07 | ASM: --
#  8 HEX: 08 | ASM: --
#  9 HEX: 09 | ASM: --
# 10 HEX: 0A | ASM: --
# 11 HEX: 0B | ASM: --
# 12 HEX: 0C | ASM: --
# 13 HEX: 0D | ASM: --
# 14 HEX: 0E | ASM: NUM - Number
# 15 HEX: 0F | ASM: NOP - No Operation
Ejemplo n.º 7
0
 def RUN(self):  # Run Procedure
     #DEBUG().DEBUG(BUG) # Enable / Disable Debug Messages
     DEBUG().MSG('CPU', 'RUN', 'CMD', 'DEBUG')
     DEBUG().MSG('CPU', 'RUN', 'CMD', 'START')
     self.CLOCK()  # Start the Clock Cycle
Ejemplo n.º 8
0
 def COUNT(self):  # Count Procedure
     # Take the current Step value and convert into a Binary number
     # and store it into the Program Counter as the next Address
     #self.PC = bin(self.STEP)[2:].zfill(8) # Binary Counter
     self.PC += 1  # Increment the Program Counter by 1
     DEBUG().MSG('CPU', 'COUNT', 'PC', self.PC)
Ejemplo n.º 9
0
	def RECEIVE(self): # Receive Function
		BYTE = DATA().READ() # Read bytes from RAM
		DEBUG().MSG('BUS', 'RECEIVE', 'DATA', BYTE)
		return BYTE # Return the bytes
Ejemplo n.º 10
0
	def POP(self): # Pop Function
		DEBUG().MSG('BUS', 'ADDR', 'POP', self.PEEK())
		self.ADDRESS.pop() # Remove the last address from the address register
Ejemplo n.º 11
0
 def is_token_interesting(token):
     DEBUG("checking if token is interesting: " + token.text + " " + str(token.pos_))
     return OracleTextParser.is_token_nounish(token) or token.pos_ in ['ADJ', 'VERB', 'ADV', 'ADP']
Ejemplo n.º 12
0
	def CLEAR(self):
		RAM().ADDRESS.clear() # Clear all values from RAM
		DEBUG().MSG('BUS', 'DATA', 'CLEAR', 0)
Ejemplo n.º 13
0
	def SEND(self, BYTE):	# Send Function
		DATA().WRITE(BYTE) # Write bytes to RAM
		DEBUG().MSG('BUS', 'SEND', 'DATA', BYTE)
Ejemplo n.º 14
0
	def LOAD(self, BYTE):
		#RAM().ADDRESS.append(bytes(BYTE)) # Add Byte to next RAM Address
		RAM().ADDRESS.append(BYTE)
		DEBUG().MSG('BUS', 'DATA', 'LOAD', BYTE)
Ejemplo n.º 15
0
	def PUSH(self, BYTE): # Push Function
		self.ADDRESS.append(BYTE) # Append the current byte the address register
		DEBUG().MSG('BUS', 'ADDR', 'PUSH', BYTE)
Ejemplo n.º 16
0
 def EXECUTE(self):  # Execute Procedure
     if self.IR[0] == 0:
         DEBUG().MSG('CPU', 'EXECUTE', 'CMD', 'END')  # END OPERATION
         self.END = 1
     elif self.IR[0] == 15:
         DEBUG().MSG('CPU', 'EXECUTE', 'CMD', 'NOP')  # NO OPERATION
         pass
     elif self.IR[0] == 14:
         DEBUG().MSG('CPU', 'EXECUTE', 'CMD', 'NUM')  # NUMBER
         DEBUG().MSG('CPU', 'JMP', 'PC', self.IR[1])
     elif self.IR[0] == 1:
         DEBUG().MSG('CPU', 'EXECUTE', 'CMD', 'LOD')  # LOAD
         BUS().PUSH(self.IR[1])  # Push Address to BUS
         self.AC = int.from_bytes(
             BUS().RECEIVE()[1:],
             byteorder='little')  # Add to Accumulator from RAM
         DEBUG().MSG('CPU', 'LOD', 'AC', self.AC)
         BUS().POP()  # Pop Address from BUS
     elif self.IR[0] == 2:
         DEBUG().MSG('CPU', 'EXECUTE', 'CMD', 'STR')  # STORE
         BUS().PUSH(self.IR[1])  # Push Address to BUS
         self.WRITE()  # Write Accumulator to RAM
         DEBUG().MSG('CPU', 'STR', 'AC', self.AC)
         BUS().POP()  # Pop Address from BUS
     elif self.IR[0] == 3:
         DEBUG().MSG('CPU', 'EXECUTE', 'CMD', 'ADD')  # ADD
         BUS().PUSH(self.IR[1])  # Push Address to BUS
         self.AC += int.from_bytes(
             BUS().RECEIVE()[1:],
             byteorder='little')  # Add to Accumulator from RAM
         DEBUG().MSG('CPU', 'ADD', 'AC', self.AC)
         BUS().POP()  # Pop Address from BUS
     elif self.IR[0] == 4:
         DEBUG().MSG('CPU', 'EXECUTE', 'CMD', 'SUB')  # SUB
         BUS().PUSH(self.IR[1])  # Push Address to BUS
         self.AC -= int.from_bytes(
             BUS().RECEIVE()[1:],
             byteorder='little')  # Sub from Accumulator from RAM
         DEBUG().MSG('CPU', 'SUB', 'AC', self.AC)
         BUS().POP()  # Pop Address from BUS
     elif self.IR[0] == 5:
         DEBUG().MSG('CPU', 'EXECUTE', 'CMD', 'JMP')  # JUMP
         self.PC = int.from_bytes(
             self.IR[1:],
             byteorder='little') - 1  # Change Program Counter value
         DEBUG().MSG('CPU', 'JMP', 'PC', self.PC + 1)
     elif self.IR[0] == 6:
         DEBUG().MSG('CPU', 'EXECUTE', 'CMD', 'PNT')  # PRINT
         self.PRINT(self.IR[1])
         BUS().POP()  # Pop Address from BUS
Ejemplo n.º 17
0
 def get_cost_and_effect_from_action(action):
     cost_effect_parts = action.split(':')
     if (len(cost_effect_parts) == 1):
         cost_effect_parts = ['', cost_effect_parts[0]]
     DEBUG(cost_effect_parts[0])
     return cost_effect_parts[0].strip(' '), ':'.join(cost_effect_parts[1:]).strip(' ')