当前位置: 首页>>代码示例>>Python>>正文


Python Interpreter.compile方法代码示例

本文整理汇总了Python中interpreter.Interpreter.compile方法的典型用法代码示例。如果您正苦于以下问题:Python Interpreter.compile方法的具体用法?Python Interpreter.compile怎么用?Python Interpreter.compile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在interpreter.Interpreter的用法示例。


在下文中一共展示了Interpreter.compile方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: compiler

# 需要导入模块: from interpreter import Interpreter [as 别名]
# 或者: from interpreter.Interpreter import compile [as 别名]
def compiler():
    text = request.POST.get("text")
    
    interpreter = Interpreter(text)
    interpreter.compile()
    result = str(interpreter)
    return {'result':result}
开发者ID:iurisilvio,项目名称:mipssim,代码行数:9,代码来源:server.py

示例2: test_if_example

# 需要导入模块: from interpreter import Interpreter [as 别名]
# 或者: from interpreter.Interpreter import compile [as 别名]
    def test_if_example(self):
        example = """addi R1,R0,3
                     addi R2,R0,2
                     beq R1,R2,EQ
                     jmp NE
                     EQ:
                     addi R1,R0,5
                     jmp END
                     NE:
                     addi R1,R0,7
                     END:"""

        text = [
            "00100000000000010000000000000011 ; I1: addi R1,R0,3",
            "00100000000000100000000000000010 ; I2: addi R2,R0,2",
            "00010100001000100000000000001000 ; I3: beq R1,R2,8",
            "00001000000000000000000000011000 ; I4: jmp 24",
            "00100000000000010000000000000101 ; I5: addi R1,R0,5",
            "00001000000000000000000000011100 ; I6: jmp 28",
            "00100000000000010000000000000111 ; I7: addi R1,R0,7",
        ]

        interpreter = Interpreter(example)
        interpreter.compile()

        for compiled, correct in zip(interpreter.instructions, text):
            self.assertEqual(compiled, correct)
开发者ID:iurisilvio,项目名称:mipssim,代码行数:29,代码来源:test_interpreter.py

示例3: test_example

# 需要导入模块: from interpreter import Interpreter [as 别名]
# 或者: from interpreter.Interpreter import compile [as 别名]
    def test_example(self):
        example = """addi R10,R0,100
                     sw R0,24(R0)
                     sw R0,28(R0)
                     LOOP:
                     lw R6,28(R0)
                     mul R7,R6,R6
                     lw R1,24(R0)
                     add R9,R1,R7
                     sw R9,24(R0)
                     addi R6,R6,1
                     sw R6,28(R0)
                     ble R6,R10,LOOP"""

        text = [
            "00100000000010100000000001100100 ; I1: addi R10,R0,100",
            "10101100000000000000000000011000 ; I2: sw R0,24(R0)",
            "10101100000000000000000000011100 ; I3: sw R0,28(R0)",
            "10001100000001100000000000011100 ; I4: lw R6,28(R0)",
            "00000000110001100011100000011000 ; I5: mul R7,R6,R6",
            "10001100000000010000000000011000 ; I6: lw R1,24(R0)",
            "00000000001001110100100000100000 ; I7: add R9,R1,R7",
            "10101100000010010000000000011000 ; I8: sw R9,24(R0)",
            "00100000110001100000000000000001 ; I9: addi R6,R6,1",
            "10101100000001100000000000011100 ; I10: sw R6,28(R0)",
            "00011100110010100000000000001100 ; I11: ble R6,R10,12",
        ]
        interpreter = Interpreter(example)
        interpreter.compile()

        for compiled, correct in zip(interpreter.instructions, text):
            self.assertEqual(compiled, correct)
开发者ID:iurisilvio,项目名称:mipssim,代码行数:34,代码来源:test_interpreter.py

示例4: test_jmp_forward

# 需要导入模块: from interpreter import Interpreter [as 别名]
# 或者: from interpreter.Interpreter import compile [as 别名]
 def test_jmp_forward(self):
     code = """jmp label
               label:"""
     interpreter = Interpreter(code)
     interpreter.compile()
     self.assertEqual(len(interpreter.instructions), 1)
     self.assertEqual(interpreter.instructions[0], "00001000000000000000000000000100 ; I1: jmp 4")
     self.assertEqual(interpreter.labels.get("label"), 4)
开发者ID:iurisilvio,项目名称:mipssim,代码行数:10,代码来源:test_interpreter.py

示例5: test_jmp_back

# 需要导入模块: from interpreter import Interpreter [as 别名]
# 或者: from interpreter.Interpreter import compile [as 别名]
 def test_jmp_back(self):
     code = """label:
               jmp label"""
     interpreter = Interpreter(code)
     interpreter.compile()
     self.assertEqual(len(interpreter.instructions), 1)
     self.assertEqual(interpreter.instructions[0], "00001000000000000000000000000000 ; I1: jmp 0")
     self.assertEqual(interpreter.labels.get("label"), 0)
开发者ID:iurisilvio,项目名称:mipssim,代码行数:10,代码来源:test_interpreter.py

示例6: test_bne

# 需要导入模块: from interpreter import Interpreter [as 别名]
# 或者: from interpreter.Interpreter import compile [as 别名]
 def test_bne(self):
     code = """nop
               LOOP:
               bne R1,R2,LOOP"""
     interpreter = Interpreter(code)
     interpreter.compile()
     self.assertEqual(len(interpreter.instructions), 2)
     self.assertEqual(interpreter.instructions[1], "00010000001000100000000000000000 ; I2: bne R1,R2,0")
开发者ID:iurisilvio,项目名称:mipssim,代码行数:10,代码来源:test_interpreter.py

示例7: test_ignoring_label_to_string

# 需要导入模块: from interpreter import Interpreter [as 别名]
# 或者: from interpreter.Interpreter import compile [as 别名]
 def test_ignoring_label_to_string(self):
     """ Bytecode should not have label names."""
     code = """nop
               label:
               nop"""
     interpreter = Interpreter(code)
     interpreter.compile()
     self.assertFalse("label" in str(interpreter))
开发者ID:iurisilvio,项目名称:mipssim,代码行数:10,代码来源:test_interpreter.py

示例8: test_ble

# 需要导入模块: from interpreter import Interpreter [as 别名]
# 或者: from interpreter.Interpreter import compile [as 别名]
 def test_ble(self):
     code = """nop
               LOOP:
               nop
               ble R1,R2,LOOP"""
     interpreter = Interpreter(code)
     interpreter.compile()
     self.assertEqual(len(interpreter.instructions), 3)
     self.assertEqual(interpreter.instructions[2], "00011100001000100000000000000100 ; I3: ble R1,R2,4")
开发者ID:iurisilvio,项目名称:mipssim,代码行数:11,代码来源:test_interpreter.py

示例9: test_label

# 需要导入模块: from interpreter import Interpreter [as 别名]
# 或者: from interpreter.Interpreter import compile [as 别名]
 def test_label(self):
     """A label is just to mark a point, it is ignored in bytecode generation."""
     code = "label:"
     interpreter = Interpreter(code)
     interpreter.compile()
     self.assertEqual(len(interpreter.instructions), 0)
开发者ID:iurisilvio,项目名称:mipssim,代码行数:8,代码来源:test_interpreter.py

示例10: test_sw

# 需要导入模块: from interpreter import Interpreter [as 别名]
# 或者: from interpreter.Interpreter import compile [as 别名]
 def test_sw(self):
     code = "sw R1,24(R0)"
     interpreter = Interpreter(code)
     interpreter.compile()
     self.assertEqual(interpreter.instructions[0], "10101100000000010000000000011000 ; I1: sw R1,24(R0)")
开发者ID:iurisilvio,项目名称:mipssim,代码行数:7,代码来源:test_interpreter.py

示例11: test_sub

# 需要导入模块: from interpreter import Interpreter [as 别名]
# 或者: from interpreter.Interpreter import compile [as 别名]
 def test_sub(self):
     code = "sub R9,R1,R7"
     interpreter = Interpreter(code)
     interpreter.compile()
     self.assertEqual(len(interpreter.instructions), 1)
     self.assertEqual(interpreter.instructions[0], "00000000001001110100100000100010 ; I1: sub R9,R1,R7")
开发者ID:iurisilvio,项目名称:mipssim,代码行数:8,代码来源:test_interpreter.py

示例12: test_nop

# 需要导入模块: from interpreter import Interpreter [as 别名]
# 或者: from interpreter.Interpreter import compile [as 别名]
 def test_nop(self):
     code = "nop"
     interpreter = Interpreter(code)
     interpreter.compile()
     self.assertEqual(interpreter.instructions[0], "00000000000000000000000000000000 ; I1: nop")
开发者ID:iurisilvio,项目名称:mipssim,代码行数:7,代码来源:test_interpreter.py

示例13: test_addi

# 需要导入模块: from interpreter import Interpreter [as 别名]
# 或者: from interpreter.Interpreter import compile [as 别名]
 def test_addi(self):
     code = "addi R6,R5,1"
     interpreter = Interpreter(code)
     interpreter.compile()
     self.assertEqual(len(interpreter.instructions), 1)
     self.assertEqual(interpreter.instructions[0], "00100000101001100000000000000001 ; I1: addi R6,R5,1")
开发者ID:iurisilvio,项目名称:mipssim,代码行数:8,代码来源:test_interpreter.py

示例14: test_uppercase_instruction

# 需要导入模块: from interpreter import Interpreter [as 别名]
# 或者: from interpreter.Interpreter import compile [as 别名]
 def test_uppercase_instruction(self):
     code = "ADD R9,R1,R7"
     interpreter = Interpreter(code)
     interpreter.compile()
     self.assertEqual(interpreter.instructions[0], "00000000001001110100100000100000 ; I1: add R9,R1,R7")
开发者ID:iurisilvio,项目名称:mipssim,代码行数:7,代码来源:test_interpreter.py


注:本文中的interpreter.Interpreter.compile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。