excelCPU icon indicating copy to clipboard operation
excelCPU copied to clipboard

unattractive code in compiler

Open Lil-Ran opened this issue 1 year ago • 0 comments

In compileExcelASM16.py, line 286 has a confusing not(line[1][0]) == line[2][0] , though in fact it means not line[1][0] == line[2][0] and makes sense. For clarity, it is better to use line[2][0] != "R" or not(line[1][0] == line[2][0]) consistent with line 293, to make the code more understandable and maintainable.

Here is the unmodified snippet:

283    elif (opcode == "ROL"):
284        if (not(len(line) == 3)):
285            syntaxError(lineNumber)
286        if (not(line[1][0]) == line[2][0] and line[1][0] == "R"):
287            operand0 = int("1300", 16) + (parseNumber(line[1], lineNumber) * 16) + parseNumber(line[2], lineNumber)
288        else:
289            syntaxError(lineNumber)
290    elif (opcode == "ROR"):
291        if (not(len(line) == 3)):
292            syntaxError(lineNumber)
293        if (not(line[1][0] == line[2][0]) and line[1][0] == "R"):
294            operand0 = int("1400", 16) + (parseNumber(line[1], lineNumber) * 16) + parseNumber(line[2], lineNumber)
295        else:
296            syntaxError(lineNumber)

By the way, line 48 (varUseError message) should print both varName and lineNumber in my understanding, but it receives varName and prints lineNumber now.

47  def varUseError(varName):
48      print(RED + "\tVariable cannot be used like label, var: " + str(lineNumber) + ENDCOLOR)
49      compileResults()

Thanks for your reading.

Lil-Ran avatar Feb 09 '24 07:02 Lil-Ran