diff --git a/src/backend/c-lisp.py b/src/backend/c-lisp.py index 6f69e57..7c741a9 100755 --- a/src/backend/c-lisp.py +++ b/src/backend/c-lisp.py @@ -218,7 +218,7 @@ def is_decl_stmt(self, stmt): return stmt[0] == "declare" def gen_decl_stmt(self, stmt): - if not (len(stmt) == 2 and len(stmt[1]) == 2): + if not len(stmt) == 3: raise CodegenError(f"bad declare statement: {stmt}") name, typ = stmt[1] @@ -328,9 +328,7 @@ def gen_fixed_type_expr(self, expr, res_sym): typ, n_ops = self.fixed_op_types[opcode] if not (len(expr) == n_ops + 1): raise CodegenError(f"`{opcode}` takes only 2 operands: {expr}") - in_syms = [ - random_label(CLISP_PREFIX, [f"inp_{n}"]) for n in range(n_ops) - ] + in_syms = [random_label(CLISP_PREFIX, [f"inp_{n}"]) for n in range(n_ops)] input_instrs = [] for n in range(n_ops): input_instrs += [*self.gen_expr(expr[n + 1], in_syms[n])] @@ -376,8 +374,7 @@ def gen_store_expr(self, expr, res_sym): raise CodegenError(f"Bad store expression: {expr}") val_sym, ptr_sym = [ - random_label(CLISP_PREFIX, [extra]) - for extra in ("val", "ptr") + random_label(CLISP_PREFIX, [extra]) for extra in ("val", "ptr") ] return [ *self.gen_expr(expr[1], res_sym=ptr_sym), diff --git a/src/backend/tests/c-lisp/array-sum.sexp b/src/backend/tests/c-lisp/array-sum.sexp index a21b213..07de442 100644 --- a/src/backend/tests/c-lisp/array-sum.sexp +++ b/src/backend/tests/c-lisp/array-sum.sexp @@ -2,8 +2,8 @@ (define ((print int) (n int))) (define ((arr_sum int) (a (ptr int)) (n int)) - (declare (i int)) - (declare (sum int)) + (declare i int) + (declare sum int) (set sum 0) (for ((set i 0) @@ -13,9 +13,9 @@ (ret sum)) (define ((main void)) - (declare (arr1 (ptr int))) - (declare (arr2 (ptr int))) - (declare (i int)) + (declare arr1 (ptr int)) + (declare arr2 (ptr int)) + (declare i int) (set arr1 (alloc int 10)) (set arr2 (alloc int 10)) @@ -23,7 +23,7 @@ (for ((set i 0) (lt i 10) (set i (add i 1))) - (declare (arr_i (ptr int))) + (declare arr_i (ptr int)) (set arr_i (ptradd arr1 i)) (store arr_i i) (set arr_i (ptradd arr2 i)) diff --git a/src/backend/tests/c-lisp/binary-ops.sexp b/src/backend/tests/c-lisp/binary-ops.sexp index 3dd2d77..5e572f9 100644 --- a/src/backend/tests/c-lisp/binary-ops.sexp +++ b/src/backend/tests/c-lisp/binary-ops.sexp @@ -2,9 +2,9 @@ (define ((print int) (n int))) (define ((main int)) - (declare (five int)) - (declare (twenty int)) - (declare (res bool)) + (declare five int) + (declare twenty int) + (declare res bool) (set five 5) (set twenty 20) diff --git a/src/backend/tests/c-lisp/bisection-rootfind.sexp b/src/backend/tests/c-lisp/bisection-rootfind.sexp index f725b3a..b16481d 100644 --- a/src/backend/tests/c-lisp/bisection-rootfind.sexp +++ b/src/backend/tests/c-lisp/bisection-rootfind.sexp @@ -2,7 +2,7 @@ (define ((fprint float) (n float))) (define ((quad-val float) (a2 float) (a1 float) (a0 float) (x float)) - (declare (val float)) + (declare val float) (set val a0) (set val (fadd val (fmul a1 x))) (set val (fadd val (fmul a2 (fmul x x)))) @@ -12,12 +12,12 @@ (a2 float) (a1 float) (a0 float) ; The quadratic equation is a2(x^2) + a1(x) + a0 = 0 (neg-pt float) (pos-pt float)) ; Known to be > 0 at pos-pt and < 0 at neg-pt - (declare (prev-mid-val float)) + (declare prev-mid-val float) (set prev-mid-val 0.0) - (declare (mid-val float)) - (declare (mid-pt float)) - (declare (loop bool)) + (declare mid-val float) + (declare mid-pt float) + (declare loop bool) (set loop #t) (while loop diff --git a/src/backend/tests/c-lisp/fibonacci-dynamic-prog.sexp b/src/backend/tests/c-lisp/fibonacci-dynamic-prog.sexp index cbb0f6c..ea83ae5 100644 --- a/src/backend/tests/c-lisp/fibonacci-dynamic-prog.sexp +++ b/src/backend/tests/c-lisp/fibonacci-dynamic-prog.sexp @@ -2,10 +2,10 @@ (define ((print int) (n int))) (define ((fib int) (n int)) - (declare (last-2 int)) - (declare (last-1 int)) - (declare (res int)) - (declare (i int)) + (declare last-2 int) + (declare last-1 int) + (declare res int) + (declare i int) (set last-2 0) (set last-1 1) diff --git a/src/backend/tests/c-lisp/first.sexp b/src/backend/tests/c-lisp/first.sexp index 877d387..e7142eb 100644 --- a/src/backend/tests/c-lisp/first.sexp +++ b/src/backend/tests/c-lisp/first.sexp @@ -2,6 +2,6 @@ (define ((print int) (n int))) (define ((main int)) - (declare (res int)) + (declare res int) (set res (call print 5)) (ret 0))) diff --git a/src/backend/tests/c-lisp/gaussian-elimination.sexp b/src/backend/tests/c-lisp/gaussian-elimination.sexp index 8533139..b5e47c0 100644 --- a/src/backend/tests/c-lisp/gaussian-elimination.sexp +++ b/src/backend/tests/c-lisp/gaussian-elimination.sexp @@ -6,10 +6,10 @@ (define ((atoi int) (s (ptr int)))) (define ((row-op void) (mod (ptr float)) (ref (ptr float)) (len int)) ; mod -> mod - factor*ref - (declare (i int)) - (declare (mod_p (ptr float))) - (declare (l float)) - (declare (pv int)) + (declare i int) + (declare mod_p (ptr float)) + (declare l float) + (declare pv int) (for ((set pv 0) (and @@ -37,9 +37,9 @@ (ret)) (define ((gaussian-eli void) (mat (ptr float)) (nrows int) (ncols int)) - (declare (ref-row int)) - (declare (mod-row int)) - (declare (col int)) + (declare ref-row int) + (declare mod-row int) + (declare col int) (for ((set ref-row 0) (lt ref-row (sub nrows 1)) @@ -55,11 +55,11 @@ (ret)) (define ((main void) (argc int) (argv (ptr (ptr int)))) - (declare (input (ptr float))) - (declare (nr int)) - (declare (nc int)) - (declare (sz int)) - (declare (i int)) + (declare input (ptr float)) + (declare nr int) + (declare nc int) + (declare sz int) + (declare i int) (set nr (call atoi (load (ptradd argv 1)))) (set nc (call atoi (load (ptradd argv 2)))) diff --git a/src/backend/tests/c-lisp/insertion-sort.sexp b/src/backend/tests/c-lisp/insertion-sort.sexp index 8af8e6c..995ff0d 100644 --- a/src/backend/tests/c-lisp/insertion-sort.sexp +++ b/src/backend/tests/c-lisp/insertion-sort.sexp @@ -5,15 +5,15 @@ (define ((atoi int) (s (ptr int)))) (define ((swap void) (a (ptr int)) (b (ptr int))) - (declare (tmp int)) + (declare tmp int) (set tmp (load b)) (store b (load a)) (store a tmp) (ret)) (define ((min int) (arr (ptr int)) (n int)) - (declare (i int)) - (declare (idx int)) + (declare i int) + (declare idx int) (set idx 0) (for ((set i 1) @@ -24,9 +24,9 @@ (ret idx)) (define ((insertion-sort void) (arr (ptr int)) (len int)) - (declare (min-idx int)) - (declare (i int)) - (declare (rest-arr (ptr int))) + (declare min-idx int) + (declare i int) + (declare rest-arr (ptr int)) (for ((set i 0) (lt i (sub len 1)) @@ -40,9 +40,9 @@ (ret)) (define ((main void) (argc int) (argv (ptr (ptr int)))) - (declare (input (ptr int))) - (declare (len int)) - (declare (i int)) + (declare input (ptr int)) + (declare len int) + (declare i int) (set len (sub argc 1)) (set input (alloc int len)) diff --git a/src/backend/tests/c-lisp/iteration.sexp b/src/backend/tests/c-lisp/iteration.sexp index 0bec143..70a12ad 100644 --- a/src/backend/tests/c-lisp/iteration.sexp +++ b/src/backend/tests/c-lisp/iteration.sexp @@ -2,7 +2,7 @@ (define ((print int) (n int))) (define ((main int)) - (declare (i int)) + (declare i int) (for ((set i 11) (lt i 11) diff --git a/src/backend/tests/c-lisp/matrix-sum.sexp b/src/backend/tests/c-lisp/matrix-sum.sexp index 4f75b70..fe56d3d 100644 --- a/src/backend/tests/c-lisp/matrix-sum.sexp +++ b/src/backend/tests/c-lisp/matrix-sum.sexp @@ -7,8 +7,8 @@ (ret (add (mul i len) j))) (define ((mat-cons void) (arr (ptr int)) (len int)) - (declare (i int)) - (declare (j int)) + (declare i int) + (declare j int) (for ((set i 0) (lt i len) @@ -22,11 +22,11 @@ (ret)) (define ((mat-add (ptr int)) (a (ptr int)) (b (ptr int)) (len int)) - (declare (i int)) - (declare (j int)) - (declare (idx int)) + (declare i int) + (declare j int) + (declare idx int) - (declare (res (ptr int))) + (declare res (ptr int)) (set res (call malloc (mul (mul len len) 4))) (for ((set i 0) @@ -44,9 +44,9 @@ (ret res)) (define ((main void)) - (declare (in1 (ptr int))) - (declare (in2 (ptr int))) - (declare (out (ptr int))) + (declare in1 (ptr int)) + (declare in2 (ptr int)) + (declare out (ptr int)) (set in1 (alloc int 16)) (call mat-cons in1 4) @@ -55,7 +55,7 @@ (set out (call mat-add in1 in2 4)) - (declare (i int)) + (declare i int) (for ((set i 0) (lt i 16) (set i (add i 1))) diff --git a/src/backend/tests/c-lisp/prime.sexp b/src/backend/tests/c-lisp/prime.sexp index da6b737..0bbda4c 100644 --- a/src/backend/tests/c-lisp/prime.sexp +++ b/src/backend/tests/c-lisp/prime.sexp @@ -4,8 +4,8 @@ (ret (mul i i))) (define ((gcd int) (a int) (b int)) - (declare (big int)) - (declare (small int)) + (declare big int) + (declare small int) (if (gt a b) ((set big a) @@ -20,9 +20,9 @@ (ret (call gcd small (sub big small)))) (define ((is-prime bool) (n int)) - (declare (i int)) - (declare (iter int)) - (declare (not-prime bool)) + (declare i int) + (declare iter int) + (declare not-prime bool) (set not-prime #f) (for ((set i 2) (le (call square i) n) (set i (add i 1))) diff --git a/src/backend/tests/c-lisp/scope.sexp b/src/backend/tests/c-lisp/scope.sexp index c189fb3..ed4e3ca 100644 --- a/src/backend/tests/c-lisp/scope.sexp +++ b/src/backend/tests/c-lisp/scope.sexp @@ -2,17 +2,17 @@ (define ((print int) (n int))) (define ((main void)) - (declare (sum1 int)) + (declare sum1 int) (set sum1 0) - (declare (sum2 int)) + (declare sum2 int) (set sum2 0) - (declare (same-name int)) + (declare same-name int) (for ((set same-name 0) (lt same-name 10) (set same-name (add same-name 1))) - ((declare (same-name int)) + ((declare same-name int) (set same-name 0) (set sum2 (add sum2 same-name))) (set sum1 (add sum1 same-name))) diff --git a/src/backend/tests/c-lisp/sum-square-difference.sexp b/src/backend/tests/c-lisp/sum-square-difference.sexp index b2f72a7..ff65499 100644 --- a/src/backend/tests/c-lisp/sum-square-difference.sexp +++ b/src/backend/tests/c-lisp/sum-square-difference.sexp @@ -2,12 +2,12 @@ (define ((print int) (n int))) (define ((sum-square-diff int) (n int)) - (declare (sum-sq int)) + (declare sum-sq int) (set sum-sq 0) - (declare (sum int)) + (declare sum int) (set sum 0) - (declare (i int)) + (declare i int) (for ((set i 1) (le i n) (set i (add i 1))) (set sum-sq (add sum-sq (mul i i))) (set sum (add sum i))) diff --git a/src/backend/tests/c-lisp/transpose.sexp b/src/backend/tests/c-lisp/transpose.sexp index 47af23f..d9037df 100644 --- a/src/backend/tests/c-lisp/transpose.sexp +++ b/src/backend/tests/c-lisp/transpose.sexp @@ -2,7 +2,7 @@ (define ((print int) (n int))) (define ((swap void) (a (ptr int)) (b (ptr int))) - (declare (tmp int)) + (declare tmp int) (set tmp (load b)) (store b (load a)) (store a tmp) @@ -12,8 +12,8 @@ (ret (add (mul i len) j))) (define ((transpose void) (mat (ptr int)) (len int)) - (declare (i int)) - (declare (j int)) + (declare i int) + (declare j int) (for ((set i 0) (lt i len) @@ -25,8 +25,8 @@ (ret)) (define ((mat-cons void) (arr (ptr int)) (len int)) - (declare (i int)) - (declare (j int)) + (declare i int) + (declare j int) (for ((set i 0) (lt i len) @@ -40,7 +40,7 @@ (ret)) (define ((arr-print void) (arr (ptr int)) (len int)) - (declare (i int)) + (declare i int) (for ((set i 0) (lt i len) @@ -49,7 +49,7 @@ (ret)) (define ((main void)) - (declare (input (ptr int))) + (declare input (ptr int)) (set input (alloc int 25)) (call mat-cons input 5)