示例#1
0
def da_if_transform(insts: dal.InstGrp, body: dal.InstGrp,
                    elseBody: dal.InstGrp) -> None:

    test_result = insts.getFlag(insts.TEST_EXPR)
    assert (isinstance(test_result, core.DBool)
            or isinstance(test_result, dal.Var))

    # Create Jmp instruction
    else_exists = len(elseBody) > 0
    body_exists = len(body) > 0

    if else_exists:
        next_inst_idx = len(elseBody) + 1 + len(insts)

        jmp_inst = dal.JmpTrue(test_result, core.DInt(next_inst_idx))
    else:
        if body_exists:
            next_inst_idx = len(body) + 1 + len(insts)
            jmp_inst = dal.JmpFalse(test_result, core.DInt(next_inst_idx))
        else:
            return

    insts.addInst(jmp_inst)
    insts.addInsts(elseBody.insts())
    insts.addInsts(body.insts())
示例#2
0
 def is_open(self) -> core.DBool:
     return self.operate(
         core.Operation(
             "core",
             "Box",
             core.opTuple("is_open", [])
         )
     )
示例#3
0
 def query(self, arg: core.DStr) -> core.DStr:
     return self.operate(
         core.Operation(
             "core",
             "Box",
             core.opTuple("query", [arg])
         )
     )
示例#4
0
 def op(self, arg: core.DStr) -> None:
     return self.operate(
         core.Operation(
             "core",
             "Box",
             core.opTuple("op", [arg])
         )
     )
示例#5
0
def IfStmt_Case_1() -> bool:
    box = BoxMachinePlus()

    if box.query(DStr("ident")) == "Box":
        v = core.DInt(1)
    else:
        v = core.DInt(2)

    return True
示例#6
0
def da_binOp_Eq_transform(insts: dal.InstGrp, loperand: object,
                          roperand: object) -> Snippet:

    s = Snippet()

    if not da_binOp_need_transformed(loperand, roperand):
        s.value = loperand == roperand
        return s
    else:
        l = insts.getFlag(insts.COMPARETOR_LEFT)
        if l is None:
            l = da_to_python_type(loperand)
        r = insts.getFlag(insts.COMPARETOR_RIGHT)
        if r is None:
            r = da_to_python_type(roperand)

        insts.setFlagWith(insts.COMPARETOR_LEFT, None)
        insts.setFlagWith(insts.COMPARETOR_RIGHT, None)

        ident = insts.new_da_var_ident()
        var = dal.Var(ident)

        eq_inst = dal.Equal(l, r, var)
        insts.addInst(eq_inst)
        s.addInst(var)

        ret = core.DBool()
        ret.compileInfo = 1
        ret.transInfo = TransformInfos()
        ret.transInfo.set_op_ret = var

        s.value = ret

    return s
示例#7
0
def DictProperty() -> core.Property:
    return core.Property("DP", {"0/1": "on", "0/2": "off", "0/3": "on"})
示例#8
0
def ListProperty() -> core.Property:
    return core.Property("LP", ["0/1", "0/2", "0/3"])
示例#9
0
def trivialOP() -> core.Operation:
    return core.Operation("S", "D", dtyp.opTuple("OP", "ARG"))
示例#10
0
def spec3() -> core.OpSpec:
    return core.OpSpec("SP3", [("A3", core.DInt), ("A4", core.DStr)],
                       ("R", core.DStr))
示例#11
0
 def startup(self) -> core.Operation:
     return core.Operation("core", "ND", core.opTuple("startup", None))
示例#12
0
 def __eq__(self, o: 'OInst') -> core.DBool:
     return core.DBool(self._inst_code == o._inst_code) and \
         core.DBool(self._args == o.args()) and \
         self._ret == o.ret()
示例#13
0
 def get(self) -> core.DStr:
     return self.operate(
         core.Operation("core", "Box", core.opTuple("get", [])))
示例#14
0
    def put(self, candy: str) -> core.DNone:
        arg = core.DStr(candy)

        return self.operate(
            core.Operation("core", "Box", core.opTuple("put", [arg])))
示例#15
0
 def close(self) -> core.DNone:
     return self.operate(
         core.Operation("core", "Box", core.opTuple("close", [])))
示例#16
0
 def open(self) -> core.DNone:
     return self.operate(
         core.Operation("core", "Box", core.opTuple("open", [])))
示例#17
0
    def test_SetItem(self, ListProperty, DictProperty) -> None:
        alterTo = ["off", "on", "off"]
        for idx in range(2):
            port = ListProperty[idx]
            DictProperty[port] = alterTo[idx]
        for idx in range(2):
            port = ListProperty[idx]
            assert alterTo[idx] == DictProperty[port]


###############################################################################
#                              Machine TestCases                              #
###############################################################################
# Box Properties
boxProperties = [core.Property("contain", ["10"])]

boxOpSpec = [
    # Open
    core.OpSpec("open", [], ("N/A", core.DType)),
    # Close
    core.OpSpec("close", [], ("N/A", core.DNone)),
    # Put
    core.OpSpec("put", [("Candy", core.DStr)], ("N/A", core.DNone)),
    # Get
    core.OpSpec("get", [], ("Candy", core.DStr))
]


class BoxMachine(core.Machine):
    """
示例#18
0
 def send(self, package: bytes, port: int) -> core.Operation:
     return core.Operation("core", "ND",
                           core.opTuple("send", [package, port]))
示例#19
0
def Trivial() -> core.Message:
    return core.Message("S", "D", "MSG")
示例#20
0
 def __eq__(self, o: 'Var') -> core.DBool:
     return core.DBool(self.ident == o.ident)
示例#21
0
 def shutdown(self) -> core.Operation:
     return core.Operation("core", "ND", core.opTuple("shutdown", None))
示例#22
0
import pytest
import astpretty
import typing as typ
import DevAuto as DA
import DevAuto.Core as core
from DevAuto.Core import DStr
import DevAuto.Translator.translator as trans
from DevAuto import DFunc
from DevAuto.lang_imp import InstGrp
from TestCases.CoreTestCases.devCore_Check import BoxMachine


boxOpSpec = [
    # is_open
    core.OpSpec("is_open", [], ("successed", core.DBool)),
    # op
    core.OpSpec("op", [("arg", core.DStr)], ("ret", core.DNone)),
    # query
    core.OpSpec("query", [("arg", core.DStr)], ("ret", core.DStr))
]


class BoxMachinePlus(BoxMachine, core.Dut):

    def __init__(self) -> None:
        BoxMachine.__init__(self)
        self._operations = self._operations + boxOpSpec
        self.value = 0

    @core.Machine.operation("is_open", boxOpSpec)
    def is_open(self) -> core.DBool:
示例#23
0
def spec2() -> core.OpSpec:
    return core.OpSpec("SP2", [("A1", core.DStr), ("A2", core.DStr)],
                       ("R", core.DStr))
示例#24
0
 def test_BoxMachineOperation(self, boxMachine) -> None:
     assert boxMachine.open() == core.DNone()
     assert boxMachine.close() == core.DNone()
     assert boxMachine.put("123") == core.DNone()
     assert boxMachine.get() == core.DStr()
示例#25
0
 def routeTbl(self) -> da_typ.DA_DICT:
     query = core.Query("core", "ND", ("route", None, da_typ.DA_DICT))
     return self.operate(query)
示例#26
0
def spec1() -> core.OpSpec:
    return core.OpSpec("SP1", [("A1", core.DInt), ("A2", core.DStr)],
                       ("R", core.DStr))
示例#27
0
###############################################################################
#                                TrivialMachine                               #
###############################################################################
class TrivialMachine(core.Machine):
    """
    A machine without properties, operations, it's trivial.
    """
    def __init__(self) -> None:
        core.Machine.__init__(self, "Trivial", [], [])


###############################################################################
#                  BoxMachine, a machine that simulate a box                  #
###############################################################################
# Box Properties
boxProperties = [core.Property("contain", 10)]

boxOpSpec = [
    # Open
    core.OpSpec("open", (), ("N/A", da_typ.DNone)),
    # Close
    core.OpSpec("close", (), ("N/A", da_typ.DNone)),
    # Put
    core.OpSpec("put", (("Candy", da_typ.DSTR)), ("N/A", da_typ.DNone)),
    # Get
    core.OpSpec("get", (), ("Candy", da_typ.DSTR))
]


class BoxMachine(core.Machine):
    """