chsasank / llama.lisp

Lisp dialect designed for HPC and AI
GNU Lesser General Public License v2.1
15 stars 6 forks source link

KeyError: 'print' . #42

Closed adi-lb-phoenix closed 4 months ago

adi-lb-phoenix commented 4 months ago

Command executed :

 guile ../../utils/sexp-json.scm < matrix_multiplication.sexp | python3 ../../c-lisp.py 

Output received :

Error in statement: ['call', 'print', ['call', 'mat_mul', 'xout', 'x', 'w', 'n', 'd']]
Traceback (most recent call last):
  File "/home/aadithya.bhat/c_lisp/bril/bril-txt/llama.lisp/src/backend/tests/llama2.c/../../c-lisp.py", line 430, in <module>
    json.dump(brilisp_code_generator.c_lisp(json.loads(sys.stdin.read())), sys.stdout)
  File "/home/aadithya.bhat/c_lisp/bril/bril-txt/llama.lisp/src/backend/tests/llama2.c/../../c-lisp.py", line 58, in c_lisp
    return ["brilisp"] + [self.gen_function(fn) for fn in prog[1:]]
  File "/home/aadithya.bhat/c_lisp/bril/bril-txt/llama.lisp/src/backend/tests/llama2.c/../../c-lisp.py", line 58, in <listcomp>
    return ["brilisp"] + [self.gen_function(fn) for fn in prog[1:]]
  File "/home/aadithya.bhat/c_lisp/bril/bril-txt/llama.lisp/src/backend/tests/llama2.c/../../c-lisp.py", line 93, in gen_function
    *self.gen_compound_stmt(func[2:], new_scope=False),
  File "/home/aadithya.bhat/c_lisp/bril/bril-txt/llama.lisp/src/backend/tests/llama2.c/../../c-lisp.py", line 256, in gen_compound_stmt
    instr_list += self.gen_stmt(s)
  File "/home/aadithya.bhat/c_lisp/bril/bril-txt/llama.lisp/src/backend/tests/llama2.c/../../c-lisp.py", line 119, in gen_stmt
    raise e
  File "/home/aadithya.bhat/c_lisp/bril/bril-txt/llama.lisp/src/backend/tests/llama2.c/../../c-lisp.py", line 114, in gen_stmt
    return self.gen_expr(stmt)
  File "/home/aadithya.bhat/c_lisp/bril/bril-txt/llama.lisp/src/backend/tests/llama2.c/../../c-lisp.py", line 411, in gen_expr
    return self.gen_call_expr(expr, res_sym)
  File "/home/aadithya.bhat/c_lisp/bril/bril-txt/llama.lisp/src/backend/tests/llama2.c/../../c-lisp.py", line 304, in gen_call_expr
    ["set", [res_sym, self.function_types[name][0]], ["call", name, *arg_syms]]
KeyError: 'print'

This is the code that was written in c-lisp (matrix_multiplication.sexp)


(c-lisp

    (define ((fprint void) (n (ptr float)) ))

 ;x is 10 , xout and w is 100 . d is 10 . n is 10
    (define ((mat_mul void) (xout (ptr float)) (x (ptr float)) (w (ptr float)) (n int) (d int)) 
        (declare (i int))
        (for ( (set i 0) (lt i d) (set i (add i 1)) )
            (declare (val float))
            (set val 0.0)
            (declare (j int))
            (for ((set j 0) (lt j n) (set j (add j 1)))
               (set val (fadd val (fmul (load (ptradd w (add (mul i n) j))) (load (ptradd x j)))))
            )
            (store (ptradd xout i) val)
        )
        (ret)  
    )

    (define ((main void))
        (declare (xout (ptr float)))
        (declare (x (ptr float)))
        (declare (w (ptr float)))
        (declare (n int ))
        (declare (d int))

        (set xout (alloc float 100))
        (set x (alloc float 10))
        (set w (alloc float 100))
        (set n 10)
        (set d 10)
        (call print(call mat_mul xout x w n d))

    )
)
GlowingScrewdriver commented 4 months ago

This is because the print isn't defined.

I'll modify C-Lisp to catch and report this error.

GlowingScrewdriver commented 4 months ago

Fixed by #49. Can we close?

adi-lb-phoenix commented 4 months ago

@GlowingScrewdriver yes.