Ejemplo n.º 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())
Ejemplo n.º 2
0
 def is_open(self) -> core.DBool:
     return self.operate(
         core.Operation(
             "core",
             "Box",
             core.opTuple("is_open", [])
         )
     )
Ejemplo n.º 3
0
 def query(self, arg: core.DStr) -> core.DStr:
     return self.operate(
         core.Operation(
             "core",
             "Box",
             core.opTuple("query", [arg])
         )
     )
Ejemplo n.º 4
0
 def op(self, arg: core.DStr) -> None:
     return self.operate(
         core.Operation(
             "core",
             "Box",
             core.opTuple("op", [arg])
         )
     )
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 7
0
def DictProperty() -> core.Property:
    return core.Property("DP", {"0/1": "on", "0/2": "off", "0/3": "on"})
Ejemplo n.º 8
0
def ListProperty() -> core.Property:
    return core.Property("LP", ["0/1", "0/2", "0/3"])
Ejemplo n.º 9
0
def trivialOP() -> core.Operation:
    return core.Operation("S", "D", dtyp.opTuple("OP", "ARG"))
Ejemplo n.º 10
0
def spec3() -> core.OpSpec:
    return core.OpSpec("SP3", [("A3", core.DInt), ("A4", core.DStr)],
                       ("R", core.DStr))
Ejemplo n.º 11
0
 def startup(self) -> core.Operation:
     return core.Operation("core", "ND", core.opTuple("startup", None))
Ejemplo n.º 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()
Ejemplo n.º 13
0
 def get(self) -> core.DStr:
     return self.operate(
         core.Operation("core", "Box", core.opTuple("get", [])))
Ejemplo n.º 14
0
    def put(self, candy: str) -> core.DNone:
        arg = core.DStr(candy)

        return self.operate(
            core.Operation("core", "Box", core.opTuple("put", [arg])))
Ejemplo n.º 15
0
 def close(self) -> core.DNone:
     return self.operate(
         core.Operation("core", "Box", core.opTuple("close", [])))
Ejemplo n.º 16
0
 def open(self) -> core.DNone:
     return self.operate(
         core.Operation("core", "Box", core.opTuple("open", [])))
Ejemplo n.º 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):
    """
Ejemplo n.º 18
0
 def send(self, package: bytes, port: int) -> core.Operation:
     return core.Operation("core", "ND",
                           core.opTuple("send", [package, port]))
Ejemplo n.º 19
0
def Trivial() -> core.Message:
    return core.Message("S", "D", "MSG")
Ejemplo n.º 20
0
 def __eq__(self, o: 'Var') -> core.DBool:
     return core.DBool(self.ident == o.ident)
Ejemplo n.º 21
0
 def shutdown(self) -> core.Operation:
     return core.Operation("core", "ND", core.opTuple("shutdown", None))
Ejemplo n.º 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:
Ejemplo n.º 23
0
def spec2() -> core.OpSpec:
    return core.OpSpec("SP2", [("A1", core.DStr), ("A2", core.DStr)],
                       ("R", core.DStr))
Ejemplo n.º 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()
Ejemplo n.º 25
0
 def routeTbl(self) -> da_typ.DA_DICT:
     query = core.Query("core", "ND", ("route", None, da_typ.DA_DICT))
     return self.operate(query)
Ejemplo n.º 26
0
def spec1() -> core.OpSpec:
    return core.OpSpec("SP1", [("A1", core.DInt), ("A2", core.DStr)],
                       ("R", core.DStr))
Ejemplo n.º 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):
    """