Пример #1
0
def repeat(n, seq):
    if n < 1:
        return None
    elif n == 1:
        return seq
    else:
        label(seq)
        return [LoadRepeat(n)] + seq + [Repeat(label(seq))]
Пример #2
0
def repeat(n, seq):
	if n < 1:
		return None
	elif n == 1:
		return seq
	else:
		label(seq)
		return [LoadRepeat(n)] + seq + [Repeat(label(seq))]
Пример #3
0
def qif(mask, ifSeq, elseSeq=None):
	if elseSeq:
		endlabel(elseSeq) # make sure to populate label of elseSeq before using it
		return [CmpEq(mask), Goto(label(ifSeq))] + elseSeq + [Goto(endlabel(ifSeq))] + ifSeq
	else:
		endlabel(ifSeq)
		return [CmpNeq(mask), Goto(endlabel(ifSeq))] + ifSeq
Пример #4
0
def qif(mask, ifSeq, elseSeq=None):
    if elseSeq:
        return [CmpEq(mask), Goto(label(ifSeq))
                ] + elseSeq + [Goto(endlabel(ifSeq))] + ifSeq
    else:
        endlabel(ifSeq)
        return [CmpNeq(mask), Goto(endlabel(ifSeq))] + ifSeq
Пример #5
0
def compile_sequences(seqs, channels=None):
    '''
    Main function to convert sequences to miniLL's and waveform libraries.
    '''
    # all sequences should start with a WAIT
    for seq in seqs:
        if not isinstance(seq[0], ControlFlow.Wait):
            seq.insert(0, ControlFlow.Wait())
    # last sequence should end with a GOTO back to the first sequence
    if not isinstance(seqs[-1][-1], ControlFlow.Goto):
        seqs[-1].append(ControlFlow.Goto(label(seqs[0])))

    resolve_offsets(seqs)

    wfLib = {}
    # use seqs[0] as prototype in case we were not given a set of channels
    miniLL, wfLib = compile_sequence(seqs[0], wfLib, channels)
    linkLists = {chan: [LL] for chan, LL in miniLL.items()}
    for seq in seqs[1:]:
        miniLL, wfLib = compile_sequence(seq, wfLib, channels)
        for chan in linkLists.keys():
            linkLists[chan].append(miniLL[chan])


    #Print a message so for the experiment we know how many sequences there are
    print('Compiled {} sequences.'.format(len(seqs)))
    return linkLists, wfLib
Пример #6
0
def compile_sequences(seqs, channels=None):
    '''
    Main function to convert sequences to miniLL's and waveform libraries.
    '''
    # all sequences should start with a WAIT
    for seq in seqs:
        if not isinstance(seq[0], ControlFlow.Wait):
            seq.insert(0, ControlFlow.Wait())
    # last sequence should end with a GOTO back to the first sequence
    if not isinstance(seqs[-1][-1], ControlFlow.Goto):
        seqs[-1].append(ControlFlow.Goto(label(seqs[0])))

    resolve_offsets(seqs)

    wfLib = {}
    # use seqs[0] as prototype in case we were not given a set of channels
    miniLL, wfLib = compile_sequence(seqs[0], wfLib, channels)
    linkLists = {chan: [LL] for chan, LL in miniLL.items()}
    for seq in seqs[1:]:
        miniLL, wfLib = compile_sequence(seq, wfLib, channels)
        for chan in linkLists.keys():
            linkLists[chan].append(miniLL[chan])

    #Print a message so for the experiment we know how many sequences there are
    print('Compiled {} sequences.'.format(len(seqs)))
    return linkLists, wfLib
Пример #7
0
 def crfunc(*args):
     if args not in target:
         seq[args] = func(*args)
         target[args] = label(seq[args])
     return [Call(target[args])], seq[args] + [
         Return()
     ]  # TODO: update me to only return seq[args] on first call
Пример #8
0
def qif(mask, ifSeq, elseSeq=None):
    if elseSeq:
        endlabel(
            elseSeq)  # make sure to populate label of elseSeq before using it
        return [CmpEq(mask), Goto(label(ifSeq))
                ] + elseSeq + [Goto(endlabel(ifSeq))] + ifSeq
    else:
        endlabel(ifSeq)
        return [CmpNeq(mask), Goto(endlabel(ifSeq))] + ifSeq
Пример #9
0
def resolve_offsets(seqs):
    # create symbol look-up table
    symbols = {}
    for i, seq in enumerate(seqs):
        for j, entry in enumerate(seq):
            if entry.label and entry.label not in symbols:
                symbols[entry.label] = (i, j)
    # re-label targets with offsets
    for seq in seqs:
        for entry in seq:
            if hasattr(entry, 'target') and entry.target and entry.target.offset != 0:
                noOffsetLabel = copy(entry.target)
                noOffsetLabel.offset = 0
                baseidx = symbols[noOffsetLabel]
                targetidx = (baseidx[0], baseidx[1]+entry.target.offset)
                # targets are allowed to point beyond the end of the current sequence
                while targetidx[1] >= len(seqs[targetidx[0]]):
                    targetidx = (targetidx[0]+1, targetidx[1]-len(seqs[targetidx[0]]))
                    assert targetidx[0] < len(seqs), "invalid target"
                entry.target = label(seqs[targetidx[0]][targetidx[1]:])
Пример #10
0
def resolve_offsets(seqs):
    # create symbol look-up table
    symbols = {}
    for i, seq in enumerate(seqs):
        for j, entry in enumerate(seq):
            if entry.label and entry.label not in symbols:
                symbols[entry.label] = (i, j)
    # re-label targets with offsets
    for seq in seqs:
        for entry in seq:
            if hasattr(entry,
                       'target') and entry.target and entry.target.offset != 0:
                noOffsetLabel = copy(entry.target)
                noOffsetLabel.offset = 0
                baseidx = symbols[noOffsetLabel]
                targetidx = (baseidx[0], baseidx[1] + entry.target.offset)
                # targets are allowed to point beyond the end of the current sequence
                while targetidx[1] >= len(seqs[targetidx[0]]):
                    targetidx = (targetidx[0] + 1,
                                 targetidx[1] - len(seqs[targetidx[0]]))
                    assert targetidx[0] < len(seqs), "invalid target"
                entry.target = label(seqs[targetidx[0]][targetidx[1]:])
Пример #11
0
	def crfunc(*args):
		if args not in target:
			seq[args] = func(*args)
			target[args] = label(seq[args])
		return [Call(target[args])], seq[args] + [Return()] # TODO: update me to only return seq[args] on first call
Пример #12
0
def qdowhile(mask, seq):
	return seq + [CmpEq(mask), Goto(label(seq))]
Пример #13
0
 def crfunc(*args):
     if args not in target:
         seq = func(*args) + [Return()]
         target[args] = label(seq)
         qfunction_seq[label(seq)] = seq
     return Call(target[args])
Пример #14
0
def qdowhile(mask, seq):
    return seq + [CmpEq(mask), Goto(label(seq))]