Exemplo n.º 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")
Exemplo n.º 2
0
def Export(modid, newSF, key):
    global Ref
    Ref = Record + 1
    filename = MakeFileName(modid, ".smb")
    R = Files.New(filename)
    #  Files.Set(R, F, 0)
    Files.WriteInt(R, 0)  #(*placeholder*)
    Files.WriteInt(R, 0)  #(*placeholder for key to be inserted at the end*)
    Files.WriteString(R, modid)
    Write(R, versionkey)

    obj = topScope.next
    while obj != None:
        if obj.expo:
            Write(R, obj.class_)
            Files.WriteString(R, obj.name)
            OutType(R, obj.type_)
            if obj.class_ == Typ:
                if obj.type_.form == Record:
                    obj0 = topScope.next  # (*check whether this is base of previously declared pointer types*)
                    while obj0 != obj:
                        if (obj0.type_.form == Pointer) and (
                                obj0.type_.base
                                == obj.type_) and (obj0.type_.ref > 0):
                            Write(R, obj0.type_.ref)
                        obj0 = obj0.next

                Write(R, 0)

            elif obj.class_ == Const:
                if obj.type_.form == Proc:
                    Files.WriteNum(R, obj.exno)
                elif obj.type_.form == Real:
                    Files.WriteInt(R, obj.val)
                else:
                    Files.WriteNum(R, obj.val)

            elif obj.class_ == Var:
                Files.WriteNum(R, obj.exno)
                if obj.type_.form == String:
                    Files.WriteNum(R, obj.val / 0x10000)
                    obj.val = obj.val % 0x10000

        obj = obj.next

    Write(R, 0)
    ##  while True:
    ##    Write(R, 0)
    ##    if Files.Length(F) % 4 == 0:
    ##      break

    for r in range(Record + 1, maxTypTab):  # Double check range! FIXME
        typtab[r] = None


##  Files.Set(R, F, 0)
##  sum = 0; # (* compute key (checksum) *)
##  while not R.eof:
##    Files.ReadInt(R, x)
##    sum = sum + x
##
##  F1 = Files.Old(filename)  # (*sum is new key*)
##  if F1 != None:
##    Files.Set(R1, F1, 4)
##    Files.ReadInt(R1, oldkey)
##  else:
##    oldkey = sum+1
##
##  if sum != oldkey:
##    if newSF:
##      key = sum
##      Files.Set(R, F, 4)
##      Files.WriteInt(R, sum)
##      Files.Register(F) # (*insert checksum*)
##    else:
##      ORS.Mark("new symbol file inhibited")
##
##  else:
##    newSF = False
##    key = sum

    return modid, newSF, key