Exemple #1
0
def Close(modid, key, nofent):
    ##  VAR obj: ORB.Object;
    ##    i, comsize, nofimps, nofptrs, size: LONGINT;
    ##    name: ORS.Ident;
    ##    F: Files.File; R: Files.Rider;

    #  (*exit code*)
    if version == 0:
        Put1(Mov, 0, 0, 0)
        Put3(BR, 7, 0)  # (*RISC-0*)
    else:
        Put2(Ldr, LNK, SP, 0)
        Put1(Add, SP, SP, 4)
        Put3(BR, 7, LNK)

    obj = ORB.topScope.next
    nofimps = 0
    comsize = 4
    nofptrs = 0

    while obj != None:
        if (obj.class_ == ORB.Mod) and (obj.dsc != ORB.system):
            nofimps += 1  # (*count imports*)
        elif ((obj.exno != 0) and (obj.class_ == ORB.Const)
              and (obj.type_.form == ORB.Proc) and (obj.type_.nofpar == 0)
              and (obj.type_.base == ORB.noType)):
            i = len(obj.name)  # (*count commands*)
            ##      while obj.name[i] != 0x0:
            ##        i += 1
            i = (i + 4) / 4 * 4
            comsize += i + 4
        elif obj.class_ == ORB.Var:
            nofptrs += NofPtrs(obj.type_)  # (*count pointers*)

        obj = obj.next

    size = varsize + strx + comsize + (
        pc + nofimps + nofent + nofptrs +
        1) * 4  # (*varsize includes type_ descriptors*)

    name = ORB.MakeFileName(modid, ".rsc")  # (*write code file*)

    R = Files.New(name)
    ##  Files.Set(R, F, 0)
    Files.WriteString(R, modid)
    Files.WriteInt(R, key)
    Files.WriteByte(R, version)
    Files.WriteInt(R, size)

    obj = ORB.topScope.next
    while (obj != None) and (obj.class_ == ORB.Mod):  # (*imports*)
        if obj.dsc != ORB.system:
            Files.WriteString(R, obj.orgname)  # removed cast : (ORB.Module)
            Files.WriteInt(R, obj.val)
        obj = obj.next

    Files.Write(R, 0x0)
    Files.WriteInt(R, tdx * 4)

    i = 0
    while i < tdx:
        Files.WriteInt(R, data[i])
        i += 1  # (*type_ descriptors*)

    Files.WriteInt(R, varsize - tdx * 4)  # (*data*)
    Files.WriteInt(R, strx)

    for i in range(strx):
        Files.WriteString(R, str_[i])  # (*strings*)

    Files.WriteInt(R, pc)  # (*code len_*)
    for i in range(pc):
        Files.WriteInt(R, code[i])  # (*program*)

    obj = ORB.topScope.next
    while obj != None:  # (*commands*)
        if ((obj.exno != 0) and (obj.class_ == ORB.Const)
                and (obj.type_.form == ORB.Proc) and (obj.type_.nofpar == 0)
                and (obj.type_.base == ORB.noType)):
            Files.WriteString(R, obj.name)
            Files.WriteInt(R, obj.val)
        obj = obj.next

    Files.Write(R, 0x0)
    Files.WriteInt(R, nofent)
    Files.WriteInt(R, entry)

    obj = ORB.topScope.next
    while obj != None:  # (*entries*)
        if obj.exno != 0:
            if (obj.class_ == ORB.Const) and (obj.type_.form == ORB.Proc) or (
                    obj.class_ == ORB.Var):
                Files.WriteInt(R, obj.val)
            elif obj.class_ == ORB.Typ:
                if obj.type_.form == ORB.Record:
                    Files.WriteInt(R, obj.type_.len_ % 0x10000)
                elif (obj.type_.form
                      == ORB.Pointer) and ((obj.type_.base.typobj == None) or
                                           (obj.type_.base.typobj.exno == 0)):
                    Files.WriteInt(R, obj.type_.base.len_ % 0x10000)

        obj = obj.next

    obj = ORB.topScope.next
    while obj != None:  # (*pointer variables*)
        if obj.class_ == ORB.Var:
            FindPtrs(R, obj.type_, obj.val)
        obj = obj.next

    Files.WriteInt(R, -1)
    Files.WriteInt(R, fixorgP)
    Files.WriteInt(R, fixorgD)
    Files.WriteInt(R, fixorgT)
    Files.WriteInt(R, entry)
    Files.Write(R, "O")
Exemple #2
0
def Write(R, x):
    if x < 0:
        x += 0x100
    Files.WriteByte(R, x)  # (* -128 <= x < 128 *)