def generate_color_quad(red, green, blue): q1 = quad.Quad() q1.set_quad("color", red, None, None) q2 = quad.Quad() q2.set_quad("color", green, None, None) q3 = quad.Quad() q3.set_quad("color", blue, None, None) state.quads.append(q1) state.quads.append(q2) state.quads.append(q3)
def generate_multiply_m(index, m): q = quad.Quad() # Adds the remaining information to the m variable mn = [m, ["int", 0, [4, 1], "s"]] # "s" special type q.set_quad("mul", mn, index, "t" + str(state.temp_counter)) state.temp_counter += 1 state.quads.append(q) state.operand_stack.append(q.result)
def read_quad(type, var): if (type == var[1][0]): q = quad.Quad() q.set_quad("read", None, type, var) #state.operand_stack.append(q.result) state.quads.append(q) else: print "error tipos incompatiblee"
def generate_dir(d, s): q = quad.Quad() dir = [d, ["int", 0, [4, 1], "s" + s]] q.set_quad("add", dir, state.operand_stack.pop(), "t" + str(state.temp_counter)) state.temp_counter += 1 state.quads.append(q) state.operand_stack.append(q.result)
def generate_param(op1): q = quad.Quad() q.set_quad("param", None, op1, state.param_counter) state.quads.append(q) state.param_counter += 1
def generate_era(func_name, res): q = quad.Quad() q.set_quad("era", None, func_name, res) state.quads.append(q)
def generate_end(func_name): q = quad.Quad() q.set_quad("end", None, func_name, None) state.quads.append(q)
def generate_return(op1): q = quad.Quad() q.set_quad("return", None, op1, None) state.quads.append(q)
def generate_gosub(func_name, index): q = quad.Quad() q.set_quad("gosub", None, func_name, index) state.quads.append(q)
def generate_loop_goto(label): q = quad.Quad() q.set_quad("goto", None, None, label + 1) state.quads.append(q)
def print_quad(printable): q = quad.Quad() q.set_quad("print", None, printable, None) state.quads.append(q)
def generate_length(var, dim): q = quad.Quad() q.set_quad("len", dim, var, "t" + str(state.temp_counter)) state.temp_counter += 1 state.quads.append(q) state.operand_stack.append(q.result)
def generate_draw_quad(type, exp): q = quad.Quad() q.set_quad(type, None, exp, None) state.quads.append(q)
def generate_arc_quad(type, p1, p2): q = quad.Quad() q.set_quad(type, p2, p1, None) state.quads.append(q)
def generate_quad(hierarchy): q = quad.Quad() if (hierarchy == 0): if (state.last_operator == 'u+' or state.last_operator == 'u-' or state.last_operator == 'u!'): q.set_quad(state.operator_stack.pop(), None, state.operand_stack.pop(), "t" + str(state.temp_counter)) set_assign_type(q.result[1][0], 1) state.temp_counter += 1 elif (hierarchy == 1): if (state.last_operator == '*' or state.last_operator == '/'): # id, [type, address, size] q.set_quad(state.operator_stack.pop(), state.operand_stack.pop(), state.operand_stack.pop(), "t" + str(state.temp_counter)) set_assign_type(q.result[1][0], 2) state.temp_counter += 1 elif (hierarchy == 2): if (state.last_operator == '+' or state.last_operator == '-'): q.set_quad(state.operator_stack.pop(), state.operand_stack.pop(), state.operand_stack.pop(), "t" + str(state.temp_counter)) set_assign_type(q.result[1][0], 2) state.temp_counter += 1 elif (hierarchy == 3): if (state.last_operator == '==' or state.last_operator == '<=' or state.last_operator == '>=' or state.last_operator == '<>' or state.last_operator == '<' or state.last_operator == '>'): q.set_quad(state.operator_stack.pop(), state.operand_stack.pop(), state.operand_stack.pop(), "t" + str(state.temp_counter)) set_assign_type(q.result[1][0], 2) state.temp_counter += 1 elif (hierarchy == 4): if (state.last_operator == '&&' or state.last_operator == '||'): q.set_quad(state.operator_stack.pop(), state.operand_stack.pop(), state.operand_stack.pop(), "t" + str(state.temp_counter)) set_assign_type(q.result[1][0], 2) state.temp_counter += 1 elif (hierarchy == 5): if (state.last_operator == '='): q.set_quad(state.operator_stack.pop(), None, state.operand_stack.pop(), state.operand_stack.pop()) set_assign_type( sem.get_type("=", ["", [state.assign_list[0]]], ["", [q.result[1][0]]]), 1) if (q.operator != None): state.quads.append(q) if (q.operator != "="): state.operand_stack.append(q.result) #state.assign_list.append(q.result[1][0]) else: del (q) if (len(state.operator_stack) > 0): state.last_operator = state.operator_stack[-1] if (state.last_operator == '#'): state.last_operator = None else: state.last_operator = None
def generate_else_goto(): q = quad.Quad() q.set_quad("goto", None, None, None) state.quads.append(q)
def generate_verify(index, limit): q = quad.Quad() q.set_quad("ver", None, index, limit) state.quads.append(q)
def generate_if_goto_f(exp): if (exp[1][0][0] != "b"): raise NameError("Boolean expected, '{0}' received".format(exp[1][0])) q = quad.Quad() q.set_quad("gotoFalse", None, exp, None) state.quads.append(q)
def generate_pen_home_quad(type): q = quad.Quad() q.set_quad(type, None, None, None) state.quads.append(q)