Esempio n. 1
0
def test_jump():
    global stack
    global frames
    global flowControl

    labelT = instructions.Label('label')
    label = instructions.LABEL([labelT], stack, frames, flowControl)
    label.exec()

    assert flowControl.labelDict['label'] == 1

    flowControl.instructionCounter = 200
    jump = instructions.JUMP([labelT], stack, frames, flowControl)
    jump.exec()

    assert flowControl.labelDict['label'] == 1
    assert flowControl.instructionCounter == 1
Esempio n. 2
0
def test_labels():
    global stack
    global frames
    global flowControl

    label = instructions.Label('novicok')
    flowControl.instructionCounter = 200
    labelInst = instructions.LABEL([label], stack, frames, flowControl)
    labelInst.exec()

    assert flowControl.labelDict['novicok'] == 200

    flowControl.instructionCounter = 1
    call = instructions.CALL([label], stack, frames, flowControl)
    call.exec()

    assert flowControl.positionStack == [1]
    assert flowControl.instructionCounter == 200

    ret = instructions.RETURN([], stack, frames, flowControl)
    ret.exec()

    assert flowControl.positionStack == []
    assert flowControl.instructionCounter == 1
Esempio n. 3
0
def test_label2():
    label = instructions.Label('_123')
    assert label.get_value() == '_123'
Esempio n. 4
0
def test_label1():
    label = instructions.Label('call')
    assert label.get_value() == 'call'
Esempio n. 5
0
def test_jumpifneq():
    global stack
    global frames
    global flowControl

    flowControl = components.FlowControl()

    globalVar1 = instructions.Var('GF@var1', frames)
    globalVar1.define()
    globalVar1.set_value(True)
    globalVar2 = instructions.Var('GF@result1', frames)
    globalVar2.define()
    globalVar2.set_value(False)

    const1 = instructions.Const('int', '4')
    const2 = instructions.Const('int', '5')
    const3 = instructions.Const('string', 'ahoj')
    const4 = instructions.Const('string', 'ahojda')

    labelT = instructions.Label('label')
    label = instructions.LABEL([labelT], stack, frames, flowControl)
    label.exec()

    # Vars bool
    flowControl.instructionCounter = 200
    jumpifneq = instructions.JUMPIFNEQ([labelT, globalVar1, globalVar1], stack, frames, flowControl)
    jumpifneq.exec()

    assert flowControl.instructionCounter == 200

    flowControl.instructionCounter = 200
    jumpifneq = instructions.JUMPIFNEQ([labelT, globalVar1, globalVar2], stack, frames, flowControl)
    jumpifneq.exec()

    assert flowControl.instructionCounter == 0

    # Constants int
    flowControl.instructionCounter = 200
    jumpifneq = instructions.JUMPIFNEQ([labelT, const1, const1], stack, frames, flowControl)
    jumpifneq.exec()

    assert flowControl.instructionCounter == 200

    flowControl.instructionCounter = 200
    jumpifneq = instructions.JUMPIFNEQ([labelT, const1, const2], stack, frames, flowControl)
    jumpifneq.exec()

    assert flowControl.instructionCounter == 0

    # Constants sting
    flowControl.instructionCounter = 200
    jumpifneq = instructions.JUMPIFNEQ([labelT, const3, const3], stack, frames, flowControl)
    jumpifneq.exec()

    assert flowControl.instructionCounter == 200

    flowControl.instructionCounter = 200
    jumpifneq = instructions.JUMPIFNEQ([labelT, const3, const4], stack, frames, flowControl)
    jumpifneq.exec()

    assert flowControl.instructionCounter == 0