chsasank / llama.lisp

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

error: expected top-level entity. Error Reporting for this has to be better #45

Closed adi-lb-phoenix closed 4 months ago

adi-lb-phoenix commented 4 months ago

Error Reporting for this has to be better I think. It will be easier for the programmer, if they know what went wrong here. The output does not mention the address of the error or point out what exactly is top-level entity, where can i look for it etc. This is the error received after passing the input to ```bash ../brilisp/run.sh {args}````

Command executed :

guile ../../utils/sexp-json.scm < matrix_multiplication.sexp | python3 ../../c-lisp.py | python3 ../../brilisp.py | bash ../brilisp/run.sh {args}

output received :

/tmp/tmp.S2WusYakI5.ll:1:1: error: expected top-level entity
1 error generated.
../brilisp/run.sh: line 9: /tmp/tmp.h9LjlvqGpu.out: Permission denied

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


(c-lisp

    (define ((fprint float) (n  float) ))

    (define ((arr-print void) (arr (ptr int)) (len int))
        (declare (i int))
        (for ((set i 0) (lt i len) (set i (add i 1))) 
            (call fprint (load (ptradd arr i)))
         ) 
    ) 

 ;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 mat_mul xout x w n d)
        (call arr-print xout 100)
        ;(call fprint xout)
        (ret) 
    )
)
GlowingScrewdriver commented 4 months ago

The command you're using is wrong. You missed out llvm.py. You should be running

guile ../../utils/sexp-json.scm < now.sexp | python3 ../../c-lisp.py | python3 ../../brilisp.py | python ../../llvm.py | bash ../brilisp/run.sh

Admittedly, we are in dire need of a decent driver. This kind of mistake will be avoided once we have that in place