print_eval(k, command, options)


def run(optimize=True,
        llvmdump=False,
        noexec=False,
        parseonly=False,
        verbose=False):

    options = locals()
    k = codexec.KaleidoscopeEvaluator('basiclib.kal')

    # If some arguments passed in, run that command then exit
    if len(sys.argv) >= 2:
        command = ' '.join(sys.argv[1:]).replace('--', '.')
        run_command(k, command, options)
    else:
        # Enter a REPL loop
        cprint('Type help or a command to be interpreted', 'green')
        command = ""
        while not command in ['exit', 'quit']:
            run_command(k, command, options)
            print("K> ", end="")
            command = input().strip()


if __name__ == '__main__':

    import kal
    kal.run()
            if init is not None:
                init_val = self._codegen(init)
            else:
                init_val = ir.Constant(ir.DoubleType(), 0.0)

            # Create var on stack and initialize it.
            var_addr = self._alloca(name)
            self.builder.store(init_val, var_addr)

            # Put var in symbol table; remember old bindings if any.
            old_bindings.append(self.func_symtab.get(name))
            self.func_symtab[name] = var_addr

        # Now all the vars are in scope. Codegen the body.
        body_val = self._codegen(node.body)

        # Restore the old bindings.
        for i, (name, _) in enumerate(node.vars):
            if old_bindings[i] is not None:
                self.func_symtab[name] = old_bindings[i]
            else:
                del self.func_symtab[name]

        return body_val


if __name__ == '__main__':

    import kal
    kal.run(noexec = True) 
    
        ast = p.parse_toplevel('a * 10 % 5 * 10')
        self._assert_body(ast,
            ['Binary', '*',
                ['Binary', '*',
                    ['Variable', 'a'],
                    ['Binary', '%', ['Number', '10'], ['Number', '5']]],
                ['Number', '10']])

        ast = p.parse_toplevel('a % 20 * 5')
        self._assert_body(ast,
            ['Binary', '*',
                ['Binary', '%', ['Variable', 'a'], ['Number', '20']],
                ['Number', '5']])

    def test_binop_right_associativity(self):
        p = Parser()
        ast = p.parse_toplevel('x = y = 10 + 5')
        self._assert_body(ast,
            ['Binary', '=',
                ['Variable', 'x'],
                ['Binary', '=',
                    ['Variable', 'y'],
                    ['Binary', '+', ['Number', '10'], ['Number', '5']]]])

#---- Typical example use ----#

if __name__ == '__main__':

    import kal
    kal.run(parseonly = True) 
            if init is not None:
                init_val = self._codegen(init)
            else:
                init_val = ir.Constant(ir.DoubleType(), 0.0)

            # Create var on stack and initialize it.
            var_addr = self._alloca(name)
            self.builder.store(init_val, var_addr)

            # Put var in symbol table; remember old bindings if any.
            old_bindings.append(self.func_symtab.get(name))
            self.func_symtab[name] = var_addr

        # Now all the vars are in scope. Codegen the body.
        body_val = self._codegen(node.body)

        # Restore the old bindings.
        for i, (name, _) in enumerate(node.vars):
            if old_bindings[i] is not None:
                self.func_symtab[name] = old_bindings[i]
            else:
                del self.func_symtab[name]

        return body_val


if __name__ == '__main__':

    import kal
    kal.run(noexec=True)
    print(colorama.Style.RESET_ALL, end='')

def run_examples(k, commands, options):
    for command in commands:
        print('K>', command)
        print_eval(k, command, options)    

def run(optimize = True, llvmdump = False, noexec = False, parseonly = False, verbose = False):

    options = locals()
    k = codexec.KaleidoscopeEvaluator('basiclib.kal')

    # If some arguments passed in, run that command then exit        
    if len(sys.argv) >= 2 :
        command = ' '.join(sys.argv[1:]).replace('--', '.')
        run_command(k, command, options)
    else:    
        # Enter a REPL loop
        cprint('Type help or a command to be interpreted', 'green')
        command = ""
        while not command in ['exit', 'quit']:
            run_command(k, command, options)
            print("K> ", end="")
            command = input().strip()

if __name__ == '__main__':

    import kal
    kal.run()