rem stringlengths 0 322k | add stringlengths 0 2.05M | context stringlengths 8 228k |
|---|---|---|
if isInt(imm): imm = int(imm) elif imm[0:2] == "0x": imm = int(imm[2:], 16) else: print imm + " is not a number. WTF dude." | imm = hexorint(imm) | def parse_branch(instruc = "", word_buf = ""): if instruc == "" or word_buf == "": print "ERROR: someone accidentally the code in parse_branch" return "-1" ins_list = instruc.split(" ") ins_list = sanitize(ins_list) ins = ins_list[0] ins = ins.lower() imm = ins_list[1] if isInt(imm): imm = int(imm) elif imm[0:2] == "0... |
if isInt(regT): | if isInt(regT) or regT[0:2] == "0x": imm = hexorint(regT) | def parse_alu(instruc = "", word_buf = ""): if instruc == "" or word_buf == "": print "ERROR: someone accidentally the code in parse_alu" return "-1" instruc = sanitize(instruc) ins = instruc[0] regD = instruc[1] regS = instruc[2] regT = instruc[3] regD = reg2bin(regD) regS = reg2bin(regS) word_buf += regD word_buf +... |
regT = int(regT) word_buf += int2bin(regT, 5) | word_buf += int2bin(imm, 5) | def parse_alu(instruc = "", word_buf = ""): if instruc == "" or word_buf == "": print "ERROR: someone accidentally the code in parse_alu" return "-1" instruc = sanitize(instruc) ins = instruc[0] regD = instruc[1] regS = instruc[2] regT = instruc[3] regD = reg2bin(regD) regS = reg2bin(regS) word_buf += regD word_buf +... |
imm = int(regT) | imm = hexorint(imm) | def parse_compare(instruc = "", word_buf = ""): if instruc == "" or word_buf == "": print "ERROR: someone accidentally the code in parse_compare" return "-1" blank = "0000" instruc = sanitize(instruc) ins = instruc[0] regS = instruc[1] regT = instruc[2] word_buf += reg2bin(regS) if ins == "cmp": word_buf += "00" eli... |
imm = int(regS) | imm = hexorint(imm) | def parse_jump(instruc = "", word_buf = ""): if instruc == "" or word_buf == "": print "ERROR: someone accidentally the code in parse_jump" return "-1" instruc = sanitize(instruc) ins = instruc[0] regS = instruc[1] if ins == "jsr": word_buf += "1" imm = int(regS) if imm > 2**10 or imm < -(2**10) + 1: print "ERROR: I... |
if regT.isInt(): | if isInt(regT) or regT[0:2] == "0x": | def parse_bool(instruc = "", word_buf = ""): if instruc == "" or word_buf == "": print "ERROR: someone accidentally the code in parse_bool" return "-1" instruc = sanitize(instruc) ins = instruc[0] regD = instruc[1] regS = instruc[2] regT = "" if ins != "not": regT = instruc[3] if ins == "and": if regT.isInt(): word_... |
imm = int(regT) | imm = hexorint(imm) | def parse_bool(instruc = "", word_buf = ""): if instruc == "" or word_buf == "": print "ERROR: someone accidentally the code in parse_bool" return "-1" instruc = sanitize(instruc) ins = instruc[0] regD = instruc[1] regS = instruc[2] regT = "" if ins != "not": regT = instruc[3] if ins == "and": if regT.isInt(): word_... |
imm = int(imm) | imm = hexorint(imm) | def parse_mem(instruc = "", word_buf = ""): if instruc == "" or word_buf == "": print "ERROR: someone accidentally the code in parse_mem" return "-1" instruc = sanitize(instruc) ins = instruc[0] regD = instruc[1] regS = instruc[2] imm = instruc[3] imm = int(imm) if imm > 2**5 or imm < -(2**5) + 1: print "ERROR: Immed... |
imm = int(imm) | imm = hexorint(imm) | def parse_const(instruc = "", word_buf = ""): if instruc == "": print "ERROR: someone accidentally the code in parse_const" return "-1" instruc = sanitize(instruc) ins = instruc[0] regD = instruc[1] imm = instruc[2] imm = int(imm) if ins == "const": if imm > 2**8 or imm < -(2**8) + 1: print "ERROR: Immediate value "... |
if imm > 2**8 or imm < -(2**8) + 1: | if imm > (2**8) or imm < (-(2**8) + 1): print 2**8 print -2**8 print imm > 2**8 print imm < -(2**8) + 1 print imm | def parse_const(instruc = "", word_buf = ""): if instruc == "": print "ERROR: someone accidentally the code in parse_const" return "-1" instruc = sanitize(instruc) ins = instruc[0] regD = instruc[1] imm = instruc[2] imm = int(imm) if ins == "const": if imm > 2**8 or imm < -(2**8) + 1: print "ERROR: Immediate value "... |
if imm.isInt(): imm = int(imm) | if isInt(imm) or imm[0:2] == "0x": imm = hexorint(imm) | def parse_shift(instruc = "", word_buf = ""): if instruc == "" or word_buf == "": print "ERROR: someone accidentally the code in parse_shift" return "-1" instruc = sanitize(instruc) ins = instruc[0] regD = instruc[1] regS = instruc[2] regT = instruc[3] imm = regT if imm.isInt(): imm = int(imm) if imm > 2**4 or imm < ... |
imm = int(imm) | imm = hexorint(imm) | def parse_trap(instruc = "", word_buf = ""): if instruc == "" or word_buf == "": print "ERROR: someone accidentally the code in parse_trap" return "-1" instruc = sanitize(instruc) imm = instruc[1] imm = int(imm) if imm > 2**8 or imm < 0: print "ERROR: Immediate value " + str(imm) +" is out of range." print "IMM in TR... |
instruc = instruc.replace(","," ") instruc = instruc.lower() instruc = instruc.split(" ") for element in instruc: if element.find(" ") != -1: print "element " + element + "had whitespace... sanitizing" element.replace(" ", "") print "sanitized: element" if element == "": instruc.remove(element) | instruc = sanitize(instruc) | def parse_alu(instruc = "", word_buf = ""): if instruc == "" or word_buf == "": print "ERROR: someone accidentally the code in parse_alu" return "-1" instruc = instruc.replace(","," ") instruc = instruc.lower() instruc = instruc.split(" ") #instruc is now a list for element in instruc: if element.find(" ") != -1: prin... |
instruc = instruc.replace(","," ") instruc = instruc.lower() instruc = instruc.split(" ") | instruc = sanitize(instruc) | def parse_compare(instruc = "", word_buf = ""): if instruc == "" or word_buf == "": print "ERROR: someone accidentally the code in parse_compare" return "-1" blank = "0000" instruc = instruc.replace(","," ") instruc = instruc.lower() instruc = instruc.split(" ") #instruc is now a list ins = instruc[0] regS = instruc[... |
instruc = instruc.replace(","," ") instruc = instruc.lower() instruc = instruc.split(" ") | instruc = sanitize(instruc) | def parse_jump(instruc = "", word_buf = ""): if instruc == "" or word_buf == "": print "ERROR: someone accidentally the code in parse_jump" return "-1" instruc = instruc.replace(","," ") instruc = instruc.lower() instruc = instruc.split(" ") #instruc is now a list ins = instruc[0] regS = instruc[1] if ins == "jsr": ... |
instruc = instruc.replace(","," ") instruc = instruc.lower() instruc = instruc.split(" ") | instruc = sanitize(instruc) | def parse_bool(instruc = "", word_buf = ""): if instruc == "" or word_buf == "": print "ERROR: someone accidentally the code in parse_bool" return "-1" instruc = instruc.replace(","," ") instruc = instruc.lower() instruc = instruc.split(" ") #instruc is now a list ins = instruc[0] regD = instruc[1] regS = instruc[2] ... |
instruc = instruc.replace(","," ") instruc = instruc.lower() instruc = instruc.split(" ") | instruc = sanitize(instruc) | def parse_mem(instruc = "", word_buf = ""): if instruc == "" or word_buf == "": print "ERROR: someone accidentally the code in parse_mem" return "-1" instruc = instruc.replace(","," ") instruc = instruc.lower() instruc = instruc.split(" ") #instruc is now a list ins = instruc[0] regD = instruc[1] regS = instruc[2] im... |
if instruc == "" or word_buf == "": | if instruc == "": | def parse_const(instruc = "", word_buf = ""): if instruc == "" or word_buf == "": print "ERROR: someone accidentally the code in parse_const" return "-1" instruc = instruc.replace(","," ") instruc = instruc.lower() instruc = instruc.split(" ") #instruc is now a list ins = instruc[0] regD = instruc[1] imm = instruc[2]... |
instruc = instruc.replace(","," ") instruc = instruc.lower() instruc = instruc.split(" ") | instruc = sanitize(instruc) | def parse_const(instruc = "", word_buf = ""): if instruc == "" or word_buf == "": print "ERROR: someone accidentally the code in parse_const" return "-1" instruc = instruc.replace(","," ") instruc = instruc.lower() instruc = instruc.split(" ") #instruc is now a list ins = instruc[0] regD = instruc[1] imm = instruc[2]... |
imm = int2bin(imm, ) | imm = int2bin(imm, 9) | def parse_const(instruc = "", word_buf = ""): if instruc == "" or word_buf == "": print "ERROR: someone accidentally the code in parse_const" return "-1" instruc = instruc.replace(","," ") instruc = instruc.lower() instruc = instruc.split(" ") #instruc is now a list ins = instruc[0] regD = instruc[1] imm = instruc[2]... |
instruc = instruc.replace(","," ") instruc = instruc.lower() instruc = instruc.split(" ") | instruc = sanitize(instruc) | def parse_shift(instruc = "", word_buf = ""): if instruc == "" or word_buf == "": print "ERROR: someone accidentally the code in parse_shift" return "-1" instruc = instruc.replace(","," ") instruc = instruc.lower() instruc = instruc.split(" ") #instruc is now a list ins = instruc[0] regD = instruc[1] regS = instruc[2... |
instruc = instruc.replace(","," ") instruc = instruc.lower() instruc = instruc.split(" ") | instruc = sanitize(instruc) | def parse_trap(instruc = "", word_buf = ""): if instruc == "" or word_buf == "": print "ERROR: someone accidentally the code in parse_trap" return "-1" instruc = instruc.replace(","," ") instruc = instruc.lower() instruc = instruc.split(" ") #instruc is now a list imm = instruc[1] imm = int(imm) if imm > 2^8 or imm <... |
print "Working on instruction " + ins | def parse(instruc = ""): word_buf = "" instruc = instruc.strip() if instruc.lower() == "ret": instruc = "jmpr r7" instruc_list = instruc.split(" ") word = instruc_list[0] #for word in instruc: ins = word.lower() print "Working on instruction " + ins if ins == "nop": return "0000000000000000" if (ins == "brn" or ins ==... | |
print "Please provide a filename for the assembler to assemble" | print "Please provide a target file for the assembler to assemble" | def main(): #get filename from commandline filename = "" filename = sys.argv[1] if (filename == ""): print "Please provide a filename for the assembler to assemble" sys.exit(0) file = open(filename, "r") output_file = open(filename + ".bin", "wb") for line in file: binary = parse(line) if binary != "-1": print binar... |
print binary B = int(binary[9:16],2) print "***", binary[8:16] | B = int(binary[8:16],2) | def main(): #get filename from commandline filename = "" filename = sys.argv[1] if (filename == ""): print "Please provide a filename for the assembler to assemble" sys.exit(0) file = open(filename, "r") output_file = open(filename + ".bin", "wb") for line in file: binary = parse(line) if binary != "-1": print binar... |
print "***", binary[0:8] | def main(): #get filename from commandline filename = "" filename = sys.argv[1] if (filename == ""): print "Please provide a filename for the assembler to assemble" sys.exit(0) file = open(filename, "r") output_file = open(filename + ".bin", "wb") for line in file: binary = parse(line) if binary != "-1": print binar... | |
imm = 2**7 - 2 + imm | imm = 2**7 + imm | def parse_mem(instruc = "", word_buf = ""): if instruc == "" or word_buf == "": print "ERROR: someone accidentally the code in parse_mem" return "-1" instruc = sanitize(instruc) ins = instruc[0] regD = instruc[1] regS = instruc[2] imm = instruc[3] imm = immToInt(imm) if imm > 2**5 or imm < -(2**5) + 1: print "ERROR: ... |
if imm > (2^8) or imm < -(2^8) + 1: | if imm > (2**8) or imm < -(2**8) + 1: | def parse_branch(instruc = "", word_buf = ""): if instruc == "" or word_buf == "": print "ERROR: someone accidentally the code in parse_branch" return "-1" ins_list = instruc.split(" ") ins_list = sanitize(ins_list) ins = ins_list[0] ins = ins.lower() imm = ins_list[1] imm = int(imm) if imm > (2^8) or imm < -(2^8) + 1... |
print "IMM in BR(nzp) IMM must be greater than -(2^8) + 1 and less than 2^8" | print "IMM in BR(nzp) IMM must be greater than -(2**8) + 1 and less than 2**8" | def parse_branch(instruc = "", word_buf = ""): if instruc == "" or word_buf == "": print "ERROR: someone accidentally the code in parse_branch" return "-1" ins_list = instruc.split(" ") ins_list = sanitize(ins_list) ins = ins_list[0] ins = ins.lower() imm = ins_list[1] imm = int(imm) if imm > (2^8) or imm < -(2^8) + 1... |
if imm > 2^10 or imm < -(2^10) + 1: | if imm > 2**10 or imm < -(2**10) + 1: | def parse_jump(instruc = "", word_buf = ""): if instruc == "" or word_buf == "": print "ERROR: someone accidentally the code in parse_jump" return "-1" instruc = sanitize(instruc) ins = instruc[0] regS = instruc[1] if ins == "jsr": word_buf += "1" imm = int(regS) if imm > 2^10 or imm < -(2^10) + 1: print "ERROR: Imm... |
print "IMM in JSR IMM must be greater than -(2^10) + 1 and less than 2^10" | print "IMM in JSR IMM must be greater than -(2**10) + 1 and less than 2**10" | def parse_jump(instruc = "", word_buf = ""): if instruc == "" or word_buf == "": print "ERROR: someone accidentally the code in parse_jump" return "-1" instruc = sanitize(instruc) ins = instruc[0] regS = instruc[1] if ins == "jsr": word_buf += "1" imm = int(regS) if imm > 2^10 or imm < -(2^10) + 1: print "ERROR: Imm... |
print "IMM in JMP IMM must be greater than -(2^10) + 1 and less than 2^10" | print "IMM in JMP IMM must be greater than -(2**10) + 1 and less than 2**10" | def parse_jump(instruc = "", word_buf = ""): if instruc == "" or word_buf == "": print "ERROR: someone accidentally the code in parse_jump" return "-1" instruc = sanitize(instruc) ins = instruc[0] regS = instruc[1] if ins == "jsr": word_buf += "1" imm = int(regS) if imm > 2^10 or imm < -(2^10) + 1: print "ERROR: Imm... |
if imm > 2^4 or imm < (-2^4 + 1): | if imm > 2**4 or imm < (-2**4 + 1): | def parse_bool(instruc = "", word_buf = ""): if instruc == "" or word_buf == "": print "ERROR: someone accidentally the code in parse_bool" return "-1" instruc = sanitize(instruc) ins = instruc[0] regD = instruc[1] regS = instruc[2] regT = "" if ins != "not": regT = instruc[3] if ins == "and": if regT.isInt(): word_... |
print "IMM in AND Dst, Src, IMM must be greater than -(2^4) + 1 and less than 2^4" | print "IMM in AND Dst, Src, IMM must be greater than -(2**4) + 1 and less than 2**4" | def parse_bool(instruc = "", word_buf = ""): if instruc == "" or word_buf == "": print "ERROR: someone accidentally the code in parse_bool" return "-1" instruc = sanitize(instruc) ins = instruc[0] regD = instruc[1] regS = instruc[2] regT = "" if ins != "not": regT = instruc[3] if ins == "and": if regT.isInt(): word_... |
if imm > 2^5 or imm < -(2^5) + 1: | if imm > 2**5 or imm < -(2**5) + 1: | def parse_mem(instruc = "", word_buf = ""): if instruc == "" or word_buf == "": print "ERROR: someone accidentally the code in parse_mem" return "-1" instruc = sanitize(instruc) ins = instruc[0] regD = instruc[1] regS = instruc[2] imm = instruc[3] imm = int(imm) if imm > 2^5 or imm < -(2^5) + 1: print "ERROR: Immedia... |
print "IMM in LDR/STR Dst, Src, IMM must be greater than -(2^5) + 1 and less than 2^5" | print "IMM in LDR/STR Dst, Src, IMM must be greater than -(2**5) + 1 and less than 2**5" | def parse_mem(instruc = "", word_buf = ""): if instruc == "" or word_buf == "": print "ERROR: someone accidentally the code in parse_mem" return "-1" instruc = sanitize(instruc) ins = instruc[0] regD = instruc[1] regS = instruc[2] imm = instruc[3] imm = int(imm) if imm > 2^5 or imm < -(2^5) + 1: print "ERROR: Immedia... |
print "IMM in CONST Dst, IMM must be greater than -(2^8) + 1 and less than 2^8" | print "IMM in CONST Dst, IMM must be greater than -(2**8) + 1 and less than 2**8" | def parse_const(instruc = "", word_buf = ""): if instruc == "": print "ERROR: someone accidentally the code in parse_const" return "-1" instruc = sanitize(instruc) ins = instruc[0] regD = instruc[1] imm = instruc[2] imm = int(imm) if ins == "const": if imm > 2**8 or imm < -(2**8) + 1: print "ERROR: Immediate value "... |
if imm > 2^8 or imm < 0: | if imm > 2**8 or imm < 0: | def parse_const(instruc = "", word_buf = ""): if instruc == "": print "ERROR: someone accidentally the code in parse_const" return "-1" instruc = sanitize(instruc) ins = instruc[0] regD = instruc[1] imm = instruc[2] imm = int(imm) if ins == "const": if imm > 2**8 or imm < -(2**8) + 1: print "ERROR: Immediate value "... |
print "IMM in HICONST Dst UIMM must be greater than 0 and less than 2^8" | print "IMM in HICONST Dst UIMM must be greater than 0 and less than 2**8" | def parse_const(instruc = "", word_buf = ""): if instruc == "": print "ERROR: someone accidentally the code in parse_const" return "-1" instruc = sanitize(instruc) ins = instruc[0] regD = instruc[1] imm = instruc[2] imm = int(imm) if ins == "const": if imm > 2**8 or imm < -(2**8) + 1: print "ERROR: Immediate value "... |
if imm > 2^4 or imm < 0: | if imm > 2**4 or imm < 0: | def parse_shift(instruc = "", word_buf = ""): if instruc == "" or word_buf == "": print "ERROR: someone accidentally the code in parse_shift" return "-1" instruc = sanitize(instruc) ins = instruc[0] regD = instruc[1] regS = instruc[2] regT = instruc[3] imm = regT if imm.isInt(): imm = int(imm) if imm > 2^4 or imm < 0... |
print "IMM in SLL/SRA/SRL Dst, Src, UIMM must be greater than 0 and less than 2^4" | print "IMM in SLL/SRA/SRL Dst, Src, UIMM must be greater than 0 and less than 2**4" | def parse_shift(instruc = "", word_buf = ""): if instruc == "" or word_buf == "": print "ERROR: someone accidentally the code in parse_shift" return "-1" instruc = sanitize(instruc) ins = instruc[0] regD = instruc[1] regS = instruc[2] regT = instruc[3] imm = regT if imm.isInt(): imm = int(imm) if imm > 2^4 or imm < 0... |
if imm > 2^8 or imm < 0: | if imm > 2**8 or imm < 0: | def parse_trap(instruc = "", word_buf = ""): if instruc == "" or word_buf == "": print "ERROR: someone accidentally the code in parse_trap" return "-1" instruc = sanitize(instruc) imm = instruc[1] imm = int(imm) if imm > 2^8 or imm < 0: print "ERROR: Immediate value " + str(imm) +" is out of range." print "IMM in TRA... |
print "IMM in TRAP UIMM must be greater than 0 and less than 2^8" | print "IMM in TRAP UIMM must be greater than 0 and less than 2**8" | def parse_trap(instruc = "", word_buf = ""): if instruc == "" or word_buf == "": print "ERROR: someone accidentally the code in parse_trap" return "-1" instruc = sanitize(instruc) imm = instruc[1] imm = int(imm) if imm > 2^8 or imm < 0: print "ERROR: Immediate value " + str(imm) +" is out of range." print "IMM in TRA... |
B = int(binary[8:15],2) | B = int(binary[9:16],2) print "***", binary[8:16] | def main(): #get filename from commandline filename = "" filename = sys.argv[1] if (filename == ""): print "Please provide a filename for the assembler to assemble" sys.exit(0) file = open(filename, "r") output_file = open(filename + ".bin", "wb") for line in file: binary = parse(line) if binary != "-1": print binar... |
A = int(binary[0:7],2) | A = int(binary[0:8],2) print "***", binary[0:8] | def main(): #get filename from commandline filename = "" filename = sys.argv[1] if (filename == ""): print "Please provide a filename for the assembler to assemble" sys.exit(0) file = open(filename, "r") output_file = open(filename + ".bin", "wb") for line in file: binary = parse(line) if binary != "-1": print binar... |
def int2bin(n, count=16): return "".join([str((n >> y) & 1) for y in range(count-1, -1, -1)]) | def int2bin(n, count=16): #returns the binary of integer n, using count number of digits return "".join([str((n >> y) & 1) for y in range(count-1, -1, -1)]) | |
def hexorint(q): if isInt(q): return int(q) elif q[0:2] == "0x": return int(q[2:],16) else: print q + " is not a number. WTF dude." exit(0) def imm2bin(imm, numDigits, signed = 0): if signed == 0: if isInt(imm): if(imm < 0): imm = 2**(numDigits + 1) - imm imm = int2bin(imm, numDigits) return imm elif imm[0:2] == "0x"... | def isHex(val): return val[0:2] == "0x" def immToInt(imm): if isHex(imm): imm = int(imm[2:], 16) elif isInt(imm): imm = int(imm) else: print "ERROR: " + imm + " is not a number. WTF Dude" return imm | def isInt(val): ok = 1 try: num = int(val) except ValueError: ok = 0 return ok |
imm = hexorint(imm) | imm = immToInt(imm) | def parse_branch(instruc = "", word_buf = ""): if instruc == "" or word_buf == "": print "ERROR: someone accidentally the code in parse_branch" return "-1" ins_list = instruc.split(" ") ins_list = sanitize(ins_list) ins = ins_list[0] ins = ins.lower() imm = ins_list[1] imm = hexorint(imm) if imm > (2**8) or imm < -(2*... |
imm = imm2bin(imm, 9) | sign = "0" if(imm < 0): imm = 2**10 - 2 + imm imm = int2bin(imm, 9) | def parse_branch(instruc = "", word_buf = ""): if instruc == "" or word_buf == "": print "ERROR: someone accidentally the code in parse_branch" return "-1" ins_list = instruc.split(" ") ins_list = sanitize(ins_list) ins = ins_list[0] ins = ins.lower() imm = ins_list[1] imm = hexorint(imm) if imm > (2**8) or imm < -(2*... |
if isInt(regT) or regT[0:2] == "0x": imm = hexorint(regT) | if isInt(regT) or isHex(regT): | def parse_alu(instruc = "", word_buf = ""): if instruc == "" or word_buf == "": print "ERROR: someone accidentally the code in parse_alu" return "-1" instruc = sanitize(instruc) ins = instruc[0] regD = instruc[1] regS = instruc[2] regT = instruc[3] regD = reg2bin(regD) regS = reg2bin(regS) word_buf += regD word_buf +... |
word_buf += int2bin(imm, 5) | regT = immToInt(regT) word_buf += int2bin(regT, 5) | def parse_alu(instruc = "", word_buf = ""): if instruc == "" or word_buf == "": print "ERROR: someone accidentally the code in parse_alu" return "-1" instruc = sanitize(instruc) ins = instruc[0] regD = instruc[1] regS = instruc[2] regT = instruc[3] regD = reg2bin(regD) regS = reg2bin(regS) word_buf += regD word_buf +... |
imm = int(regT) imm = imm2bin(imm) | imm = immToInt(regT) if(imm < 0): imm = 2**8 - 2 + imm imm = int2bin(imm, 7) else: imm = int2bin(imm, 7) | def parse_compare(instruc = "", word_buf = ""): if instruc == "" or word_buf == "": print "ERROR: someone accidentally the code in parse_compare" return "-1" blank = "0000" instruc = sanitize(instruc) ins = instruc[0] regS = instruc[1] regT = instruc[2] word_buf += reg2bin(regS) if ins == "cmp": word_buf += "00" eli... |
imm = hexorint(imm) | imm = int(regT) | def parse_compare(instruc = "", word_buf = ""): if instruc == "" or word_buf == "": print "ERROR: someone accidentally the code in parse_compare" return "-1" blank = "0000" instruc = sanitize(instruc) ins = instruc[0] regS = instruc[1] regT = instruc[2] word_buf += reg2bin(regS) if ins == "cmp": word_buf += "00" eli... |
imm = hexorint(imm) | imm = immToInt(regS) | def parse_jump(instruc = "", word_buf = ""): if instruc == "" or word_buf == "": print "ERROR: someone accidentally the code in parse_jump" return "-1" instruc = sanitize(instruc) ins = instruc[0] regS = instruc[1] if ins == "jsr": word_buf += "1" imm = hexorint(imm) if imm > 2**10 or imm < -(2**10) + 1: print "ERRO... |
imm = imm2bin(imm, 11) | if imm < 0: imm = 2**12 - 2 + imm imm = int2bin(imm, 11) else: imm = int2bin(imm, 11) | def parse_jump(instruc = "", word_buf = ""): if instruc == "" or word_buf == "": print "ERROR: someone accidentally the code in parse_jump" return "-1" instruc = sanitize(instruc) ins = instruc[0] regS = instruc[1] if ins == "jsr": word_buf += "1" imm = hexorint(imm) if imm > 2**10 or imm < -(2**10) + 1: print "ERRO... |
if isInt(regT) or regT[0:2] == "0x": | if isInt(regT) or isHex(regT): | def parse_bool(instruc = "", word_buf = ""): if instruc == "" or word_buf == "": print "ERROR: someone accidentally the code in parse_bool" return "-1" instruc = sanitize(instruc) ins = instruc[0] regD = instruc[1] regS = instruc[2] regT = "" if ins != "not": regT = instruc[3] if ins == "and": if isInt(regT) or regT... |
imm = hexorint(imm) | imm = immToInt(regT) | def parse_bool(instruc = "", word_buf = ""): if instruc == "" or word_buf == "": print "ERROR: someone accidentally the code in parse_bool" return "-1" instruc = sanitize(instruc) ins = instruc[0] regD = instruc[1] regS = instruc[2] regT = "" if ins != "not": regT = instruc[3] if ins == "and": if isInt(regT) or regT... |
imm = imm2bin(imm, 5) | if imm < 0: imm = 2**6 - 2 + imm imm = "1" + int2bin(imm, 5) else: imm = int2bin(imm, 5) | def parse_bool(instruc = "", word_buf = ""): if instruc == "" or word_buf == "": print "ERROR: someone accidentally the code in parse_bool" return "-1" instruc = sanitize(instruc) ins = instruc[0] regD = instruc[1] regS = instruc[2] regT = "" if ins != "not": regT = instruc[3] if ins == "and": if isInt(regT) or regT... |
imm = hexorint(imm) | imm = immToInt(imm) | def parse_mem(instruc = "", word_buf = ""): if instruc == "" or word_buf == "": print "ERROR: someone accidentally the code in parse_mem" return "-1" instruc = sanitize(instruc) ins = instruc[0] regD = instruc[1] regS = instruc[2] imm = instruc[3] imm = hexorint(imm) if imm > 2**5 or imm < -(2**5) + 1: print "ERROR: ... |
imm = imm2bin(imm, 6) | if imm < 0: imm = 2**7 - 2 + imm imm = int2bin(imm, 6) else: imm = int2bin(imm, 6) | def parse_mem(instruc = "", word_buf = ""): if instruc == "" or word_buf == "": print "ERROR: someone accidentally the code in parse_mem" return "-1" instruc = sanitize(instruc) ins = instruc[0] regD = instruc[1] regS = instruc[2] imm = instruc[3] imm = hexorint(imm) if imm > 2**5 or imm < -(2**5) + 1: print "ERROR: ... |
imm = hexorint(imm) | imm = immToInt(imm) | def parse_const(instruc = "", word_buf = ""): if instruc == "": print "ERROR: someone accidentally the code in parse_const" return "-1" instruc = sanitize(instruc) ins = instruc[0] regD = instruc[1] imm = instruc[2] imm = hexorint(imm) #imm = -15 if ins == "const": if imm > (2**8) or imm < (-(2**8) + 1): print 2**8 p... |
if imm > (2**8) or imm < (-(2**8) + 1): print 2**8 print -2**8 print imm > 2**8 print imm < -(2**8) + 1 print imm | if imm > 2**8 or imm < -(2**8) + 1: | def parse_const(instruc = "", word_buf = ""): if instruc == "": print "ERROR: someone accidentally the code in parse_const" return "-1" instruc = sanitize(instruc) ins = instruc[0] regD = instruc[1] imm = instruc[2] imm = hexorint(imm) #imm = -15 if ins == "const": if imm > (2**8) or imm < (-(2**8) + 1): print 2**8 p... |
imm = imm2bin(imm, 9) | if(imm < 0): imm = 2**9 - 2 + imm imm = int2bin(imm, 9) else: imm = int2bin(imm, 9) | def parse_const(instruc = "", word_buf = ""): if instruc == "": print "ERROR: someone accidentally the code in parse_const" return "-1" instruc = sanitize(instruc) ins = instruc[0] regD = instruc[1] imm = instruc[2] imm = hexorint(imm) #imm = -15 if ins == "const": if imm > (2**8) or imm < (-(2**8) + 1): print 2**8 p... |
if isInt(imm) or imm[0:2] == "0x": imm = hexorint(imm) | if isInt(imm) or isHex(imm): imm = immToInt(imm) | def parse_shift(instruc = "", word_buf = ""): if instruc == "" or word_buf == "": print "ERROR: someone accidentally the code in parse_shift" return "-1" instruc = sanitize(instruc) ins = instruc[0] regD = instruc[1] regS = instruc[2] regT = instruc[3] imm = regT if isInt(imm) or imm[0:2] == "0x": imm = hexorint(imm)... |
imm = hexorint(imm) | imm = immToInt(imm) | def parse_trap(instruc = "", word_buf = ""): if instruc == "" or word_buf == "": print "ERROR: someone accidentally the code in parse_trap" return "-1" instruc = sanitize(instruc) imm = instruc[1] imm = hexorint(imm) if imm > 2**8 or imm < 0: print "ERROR: Immediate value " + str(imm) +" is out of range." print "IMM ... |
if ins == "OMGWTFBBQSAUCE": return "dear god why" | def parse(instruc = ""): word_buf = "" instruc = instruc.strip() if instruc.lower() == "ret": instruc = "jmpr r7" instruc_list = instruc.split(" ") instruc_list = sanitize(instruc_list, 1) word = instruc_list[0] #for word in instruc: ins = word.lower() if ins == "nop": return "0000000000000000" if (ins == "brn" or in... | |
filename = sys.argv[1] | try: filename = sys.argv[1] except IOError: print filename + " does not exist. Please don't make me try and open it." sys.exit(0) | def main(): #get filename from commandline filename = "" filename = sys.argv[1] if (filename == ""): print "Please provide a target file for the assembler to assemble" sys.exit(0) file = open(filename, "r") output_file = open(filename + ".bin", "wb") for line in file: binary = parse(line) if binary != "-1": if binar... |
if binary == "dear god why": i = 0 bin = array('H', [0]) while i < 1000: bin.tofile(output_file) i = i + 1 | print binary | def main(): #get filename from commandline filename = "" filename = sys.argv[1] if (filename == ""): print "Please provide a target file for the assembler to assemble" sys.exit(0) file = open(filename, "r") output_file = open(filename + ".bin", "wb") for line in file: binary = parse(line) if binary != "-1": if binar... |
self._relpath = self.url_to_path(self.request.path) | self.request_path = self.url_to_path(self.request.path) | def initialize(self,request,response): super(DAVHandler, self).initialize(request,response) self._relpath = self.url_to_path(self.request.path) |
path = self._relpath | path = self.request_path | def propfind(self): path = self._relpath depth = self.request.headers.get('depth','0') if depth != '0' and depth != '1': return self.response.set_status(403,'Forbidden') resource = Resource.get_by_path(path) if not resource: return self.response.set_status(404,"Not Found") root = ET.Element('multistatus',{'xmlns':'... |
path = self._relpath | path = self.request_path | def mkcol(self): """Creates a subdirectory, given an absolute path.""" path = self._relpath parent_path = os.path.dirname(path) # check for duplicate if Resource.exists_with_path(path): return self.response.set_status(405,"Method Not Allowed") # fetch parent if parent_path: parent = Resource.get_by_path(parent_path) ... |
path = self._relpath | path = self.request_path | def delete(self): """Deletes a resource at a url. If it's a collection, it must be empty.""" path = self._relpath resource = Resource.get_by_path(path) |
path = self._relpath | path = self.request_path | def move(self): """Moves a resource from one path to another.""" path = self._relpath resource = Resource.get_by_path(path) if not resource: return self.response.set_status(404,"Not Found") |
path = self._relpath | path = self.request_path | def put(self): """Uploads a file.""" path = self._relpath parent_path = os.path.dirname(path) |
path = self._relpath | path = self.request_path | def get(self): """Downloads a file.""" path = self._relpath resource = Resource.get_by_path(path) if not resource: return self.response.set_status(404,"Not Found") if resource.is_collection: template_values = { 'path': path, 'prefix': self._prefix, 'resources': [child for child in resource.children if not child.disp... |
url_tuple = urlparse.urlparse(avatar.url) url = urlparse.urljoin(urllib.unquote(urlparse.urlunparse(url_tuple)), "%s.%s%s" % (name, size, extension)) | base_url = avatar.url | def render(self, context): # If size is not an int, then it's a Variable, so try to resolve it. size = self.size if not isinstance(size, int): size = int(self.size.resolve(context)) |
generic, extension = os.path.splitext(filename) filename = os.path.join(base, "%s.%s%s" % (generic, size, extension)) url = filename.replace(settings.MEDIA_ROOT, settings.MEDIA_URL) url = os.path.normpath(url) | name, extension = os.path.splitext(filename) filename = os.path.join(base, "%s.%s%s" % (name, size, extension)) base_url = filename.replace(settings.MEDIA_ROOT, settings.MEDIA_URL) url_tuple = urlparse.urlparse(base_url) url = urlparse.urljoin(urllib.unquote(urlparse.urlunparse(url_tuple)), "%s.%s%s" % (name, size, ex... | def render(self, context): # If size is not an int, then it's a Variable, so try to resolve it. size = self.size if not isinstance(size, int): size = int(self.size.resolve(context)) |
if not isinstance(self.size, int): self.size = int(self.size.resolve(context)) | size = self.size if not isinstance(size, int): size = int(self.size.resolve(context)) | def render(self, context): # If size is not an int, then it's a Variable, so try to resolve it. if not isinstance(self.size, int): self.size = int(self.size.resolve(context)) |
if not self.size in AVATAR_SIZES: | if not size in AVATAR_SIZES: | def render(self, context): # If size is not an int, then it's a Variable, so try to resolve it. if not isinstance(self.size, int): self.size = int(self.size.resolve(context)) |
filename = os.path.join(base, "%s.%s%s" % (name, self.size, extension)) | filename = os.path.join(base, "%s.%s%s" % (name, size, extension)) | def render(self, context): # If size is not an int, then it's a Variable, so try to resolve it. if not isinstance(self.size, int): self.size = int(self.size.resolve(context)) |
url = urlparse.urljoin(urllib.unquote(urlparse.urlunparse(url_tuple)), "%s.%s%s" % (name, self.size, extension)) | url = urlparse.urljoin(urllib.unquote(urlparse.urlunparse(url_tuple)), "%s.%s%s" % (name, size, extension)) | def render(self, context): # If size is not an int, then it's a Variable, so try to resolve it. if not isinstance(self.size, int): self.size = int(self.size.resolve(context)) |
filename = os.path.join(base, "%s.%s%s" % (generic, self.size, extension)) | filename = os.path.join(base, "%s.%s%s" % (generic, size, extension)) | def render(self, context): # If size is not an int, then it's a Variable, so try to resolve it. if not isinstance(self.size, int): self.size = int(self.size.resolve(context)) |
thumb.thumbnail((self.size, self.size), Image.ANTIALIAS) | thumb.thumbnail((size, size), Image.ANTIALIAS) | def render(self, context): # If size is not an int, then it's a Variable, so try to resolve it. if not isinstance(self.size, int): self.size = int(self.size.resolve(context)) |
if o == "-s": verbose = True elif o in ("-s", "--seed"): | if o in ("-s", "--seed"): | def random_list(dims): if len(dims) == 0: return random.randint(0,100000) list = [] for i in range(dims[-1]): list.append(random_list(dims[0:-1])) return list |
def jacobi_sencil(W,H,Dist): full = np.zeros((W+2,H+2), dtype=np.double, dist=Dist) work = np.zeros((W,H), dtype=np.double, dist=Dist) diff = np.zeros((W,H), dtype=np.double, dist=Dist) | def jacobi_sencil(H,W,Dist): full = np.zeros((H+2,W+2), dtype=np.double, dist=Dist) work = np.zeros((H,W), dtype=np.double, dist=Dist) diff = np.zeros((H,W), dtype=np.double, dist=Dist) | def jacobi_sencil(W,H,Dist): full = np.zeros((W+2,H+2), dtype=np.double, dist=Dist) work = np.zeros((W,H), dtype=np.double, dist=Dist) diff = np.zeros((W,H), dtype=np.double, dist=Dist) cells = full[1:W+1,1:H+1] up = full[1:W+1, 0:H] left = full[0:W, 1:H+1] right = full[2:W+2, 1:H+1] down = full[1:W+1, 2:H+2] for i i... |
cells = full[1:W+1,1:H+1] up = full[1:W+1, 0:H] left = full[0:W, 1:H+1] right = full[2:W+2, 1:H+1] down = full[1:W+1, 2:H+2] | cells = full[1:-1, 1:-1] up = full[1:-1, 0:-2] left = full[0:-2, 1:-1] right = full[2: , 1:-1] down = full[1:-1, 2: ] | def jacobi_sencil(W,H,Dist): full = np.zeros((W+2,H+2), dtype=np.double, dist=Dist) work = np.zeros((W,H), dtype=np.double, dist=Dist) diff = np.zeros((W,H), dtype=np.double, dist=Dist) cells = full[1:W+1,1:H+1] up = full[1:W+1, 0:H] left = full[0:W, 1:H+1] right = full[2:W+2, 1:H+1] down = full[1:W+1, 2:H+2] for i i... |
for i in range(1,W+1): full[i][0]=-273.15 full[i][-1]=-273.15 full[0,:] += 40.0 full[W+1,:] += -273.13 | full[:,0] += -273.15 full[:,-1] += -273.15 full[0,:] += 40.0 full[-1,:] += -273.13 | def jacobi_sencil(W,H,Dist): full = np.zeros((W+2,H+2), dtype=np.double, dist=Dist) work = np.zeros((W,H), dtype=np.double, dist=Dist) diff = np.zeros((W,H), dtype=np.double, dist=Dist) cells = full[1:W+1,1:H+1] up = full[1:W+1, 0:H] left = full[0:W, 1:H+1] right = full[2:W+2, 1:H+1] down = full[1:W+1, 2:H+2] for i i... |
core.multiarray.dnumpy_init() | if not core.multiarray.dnumpy_init(): import sys sys.exit(0) | def pkgload(*packages, **options): loader = PackageLoader(infunc=True) return loader(*packages, **options) |
fname = "%sdistnumpt_test_matrix.npy"%dnumpytest.TmpSetDir | fname = "%sdistnumpt_test_matrix.npy" | def run(): max_ndim = 6 for i in xrange(1,max_ndim+1): src = dnumpytest.random_list(random.sample(xrange(1, 10),i)) A = np.array(src, dtype=float, dist=True) fname = "%sdistnumpt_test_matrix.npy"%dnumpytest.TmpSetDir np.save(fname,A) Bf = np.load(fname, dist=False) Bd = np.load(fname, dist=True) if not dnumpytest.arra... |
except Exception as errer: | except: | def random_list(dims): if len(dims) == 0: return random.randint(0,100000) list = [] for i in range(dims[-1]): list.append(random_list(dims[0:-1])) return list |
msg = "Error message: %s"%errer | msg = "Error message: %s"%sys.exc_info()[1] | def random_list(dims): if len(dims) == 0: return random.randint(0,100000) list = [] for i in range(dims[-1]): list.append(random_list(dims[0:-1])) return list |
try: import zlib except ImportError: return (True, "Test ignored since zlib was not available.\n") | def run(): try: import zlib except ImportError: return (True, "Test ignored since zlib was not available.\n") A = load("%sJacobi_Amatrix.npy"%dnumpytest.DataSetDir, dist=True) B = load("%sJacobi_Bvector.npy"%dnumpytest.DataSetDir, dist=True) C = load("%sJacobi_Cvector.npy"%dnumpytest.DataSetDir, dist=True) result = ja... | |
out = fun(6) | out = fun(size) | def funtest(fun, str): print "*"*100 print "Testing %s"%str if pydebug: r1 = sys.gettotalrefcount() out = fun(6) r2 = sys.gettotalrefcount() if r2-2 != r1: print "Memory leak - totrefcount: from %d to %d"%(r1,r2) else: out = fun(6) if out is None: print "Succes" else: print "Error in %s! Random seed: %d"%(str, seed) fo... |
for i in xrange(1,max_ndim+1): src = random_list([max_ndim,max_ndim,max_ndim]) | for i in xrange(3,max_ndim+3): src = random_list([i,i,i]) | def ufunc(max_ndim): for i in xrange(1,max_ndim+1): src = random_list(random.sample(xrange(1, 10),i)) Ad = np.array(src, dtype=float, dist=True) Af = np.array(src, dtype=float, dist=False) ran = random.randint(0,i-1) if i > 1 and ran > 0: for j in range(0,ran): src = src[0] Bd = np.array(src, dtype=float, dist=True) Bf... |
if A.dist: | if A.dist(): | def jacobi(A, B, tol=0.005, forcedIter=0): '''itteratively solving for matrix A with solution vector B tol = tolerance for dh/h init_val = array of initial values to use in the solver ''' h = zeros(shape(B), float, dist=A.dist()) dmax = 1.0 n = 0 tmp0 = empty(shape(A), float, dist=A.dist()) tmp1 = empty(shape(B), float... |
for i in range(1,max_ndim+1): src = random_list(random.sample(range(1, 10),i)) | for i in xrange(1,max_ndim+1): src = random_list(random.sample(xrange(1, 10),i)) | def ufunc(max_ndim=5): for i in range(1,max_ndim+1): src = random_list(random.sample(range(1, 10),i)) Ad = np.array(src, dtype=float, dist=True) Af = np.array(src, dtype=float, dist=False) ran = random.randint(0,i-1) if i > 1 and ran > 0: for j in range(0,ran): src = src[0] Bd = np.array(src, dtype=float, dist=True) ... |
for i in range(niters): | niters *= 10 for i in xrange(niters): | def diagonal(niters=10): for i in range(niters): src = random_list([random.randint(1, 20), \ random.randint(1, 20)]) Ad = np.array(src, dtype=float, dist=True) Af = np.array(src, dtype=float, dist=False) Cd = Ad.diagonal() Cf = Af.diagonal() if not array_equal(Cd,Cf): print "Error in diagonal!" print Cd print "The dist... |
print "*"*100 print "Testing ufunc" if ufunc(6): print "Succes" else: print "Fail!" | def matmul(niter=2): for m in range(2,niter+2): for n in range(2,niter+2): for k in range(2,niter+2): Asrc = random_list([k,m]) Bsrc = random_list([m,k]) Ad = np.array(Asrc, dtype=float, dist=True) Af = np.array(Asrc, dtype=float, dist=False) Bd = np.array(Bsrc, dtype=float, dist=True) Bf = np.array(Bsrc, dtype=float, ... | |
print "*"*100 print "Testing ufunc reduce (no views)" if ufunc_reduce(6): print "Succes" else: print "Fail!" print "*"*100 print "Testing diagonal (no views)" if diagonal(100): print "Succes" else: print "Fail!" print "*"*100 print "Testing matrix multiplication (no views)" if matmul(6): print "Succes" else: print "F... | funtest(ufunc, "ufunc") funtest(ufunc_reduce, "ufunc reduce (no views)") funtest(diagonal, "diagonal (no views)") funtest(matmul, "matrix multiplication (no views)") | def matmul(niter=2): for m in range(2,niter+2): for n in range(2,niter+2): for k in range(2,niter+2): Asrc = random_list([k,m]) Bsrc = random_list([m,k]) Ad = np.array(Asrc, dtype=float, dist=True) Af = np.array(Asrc, dtype=float, dist=False) Bd = np.array(Bsrc, dtype=float, dist=True) Bf = np.array(Bsrc, dtype=float, ... |
d = dict(zip(s, [1234]*len(s))) self.assertEqual(rencode.loads(rencode.dumps(d)), d) | d = dict(zip(s, ["foo"*120]*len(s))) d2 = {"foo": d, "bar": d, "baz": d} self.assertEqual(rencode.loads(rencode.dumps(d2)), d2) | def test_decode_dict(self): s = "abcdefghijklmnopqrstuvwxyz1234567890" d = dict(zip(s, [1234]*len(s))) self.assertEqual(rencode.loads(rencode.dumps(d)), d) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.