Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions spec/chip.typ
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@
#let render_chip_padding_table(chip, config) = {
// Whether `var` is a preprocessed variable.
let is_preprocessed(var) = {
config.variables.types
let type = config.variables.types
.filter(t => t.label == var.type)
.all(t => t.at("preprocessed", default: false))
type.len() > 0 and type.all(t => t.at("preprocessed", default: false))
}
Comment thread
erik-3milabs marked this conversation as resolved.

let instantiated_vars = config.variables.categories.instantiated.map(c => chip.variables.at(c, default: ())).flatten()
Expand Down
3 changes: 3 additions & 0 deletions spec/expr.typ
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
// <expr> ::= () ; ""
// | var ; str(var)
// | int ; int
// | ["arr", expr, ...] ; [expr, ...]
// | ["idx", expr1, expr2] ; expr1[expr2]
// | ["not", expr] ; !expr
// | ["+", expr1, expr2, ...] ; expr1 + expr2 + ...
Expand Down Expand Up @@ -91,6 +92,7 @@
// Typeset an expression as code
#let expr_to_code = make_expr_formatter(
(
"arr": (pp, rec, e) => `[` + e.slice(1).map(rec.with(PREC.MAX)).join(`, `) + `]`,
"idx": (pp, rec, e) => rec(PREC.MIN, e.at(1)) + `[` + rec(PREC.MAX, e.at(2)) + `]`,
"not": (pp, rec, e) => cwrap(rec(PREC.not, 1) + ` - ` + rec(PREC.not, e.at(1)), pp < PREC.not),
"+": (pp, rec, e) => cwrap(e.slice(1).map(rec.with(PREC.add)).join(` + `), pp < PREC.add),
Expand Down Expand Up @@ -149,6 +151,7 @@
// Typeset an expression as math
#let expr_to_math = make_expr_formatter(
(
"arr": (pp, rec, e) => $[#e.slice(1).map(rec.with(PREC.MAX)).join($, $)]$,
"idx": (pp, rec, e) => {
let (val, idxs) = flat_idxs(e)
$#rec(PREC.idx, val)_(#idxs.map(idx => rec(PREC.idx, idx)).join($, $))$
Expand Down
2 changes: 1 addition & 1 deletion spec/src/branch.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pad = 0
name = "next_pc_high"
type = ["Half", 3]
desc = "The upper part of the next pc"
pad = 0 # TODO(#128): improve handling for arrays
pad = ["arr", 0, 0, 0]

[[variables.output]]
name = "next_pc_low"
Expand Down
6 changes: 3 additions & 3 deletions spec/src/shift.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,19 @@ pad = 1
name = "X"
type = ["Half", 5]
desc = "scratch variable."
pad = 0 # TODO: array
pad = ["arr", 0, 0, 0, 0, 0]

[[variables.auxiliary]]
name = "Y"
type = ["Half", 4]
desc = "scratch variable."
pad = 0 # TODO: array
pad = ["arr", 0, 0, 0, 0]

[[variables.auxiliary]]
name = "limb_shift"
type = ["Bit", 4]
desc = "One-hot vector indicating whether $floor.l #`shift` / 16 floor.r equiv i mod s$, where $s = 2$ when $#`word_instr` = 1$ and $4$ otherwise."
pad = 0 # TODO: array
pad = ["arr", 0, 0, 0, 0]

# Virtual

Expand Down
3 changes: 3 additions & 0 deletions spec/tooling/chip.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def get_const(self) -> int:
type Expr = (
LitExpr
| VarExpr
| ArrExpr
| IdxExpr
| CastExpr
| MulExpr
Expand Down Expand Up @@ -303,6 +304,8 @@ def build_expr(config: Optional["Config"], data: object) -> Expr:
x.isidentifier(), f"Invalid identifier name for variable {x!r}"
)
return VarExpr(x)
case ["arr", *elems]:
return ArrExpr([build_expr(config, e) for e in elems])
case ["idx", x, y]:
return IdxExpr(build_expr(config, x), build_expr(config, y))
case ["cast", x, t]:
Expand Down