Skip to content

Commit

Permalink
compileMatrixLit: todo
Browse files Browse the repository at this point in the history
  • Loading branch information
xushiwei committed Apr 8, 2024
1 parent 884b222 commit 6d00f53
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
10 changes: 10 additions & 0 deletions cl/compile_spx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,16 @@ func main() {
`)
}

func _TestMatrix1(t *testing.T) {
gopSpxTest(t, `
echo [
1, 2, 3
4, 5, 6
]
`, ``, `
`)
}

func TestEnvOp(t *testing.T) {
gopSpxTest(t, `
echo ${PATH}, $id
Expand Down
30 changes: 30 additions & 0 deletions cl/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,34 @@ find:
return
}

/*
func compileMatrixLit(ctx *blockCtx, v *ast.MatrixLit) {
cb := ctx.cb
ncol := -1
for _, elts := range v.Elts {
switch n := len(elts); n {
case 1:
elt := elts[0]
if e, ok := elt.(*ast.Ellipsis); ok {
compileExpr(ctx, e.Elt)
panic("TODO") // TODO(xsw): matrixLit with ellipsis
}
fallthrough
default:
if ncol < 0 {
ncol = n
} else if ncol != n {
ctx.handleErrorf(elts[0].Pos(), "inconsistent matrix column count: got %v, want %v", n, ncol)
}
for _, elt := range elts {
compileExpr(ctx, elt)
}
cb.SliceLitEx(...)
}
}
}
*/

func compileEnvExpr(ctx *blockCtx, v *ast.EnvExpr) {
cb := ctx.cb
if ctx.isClass { // in a Go+ class file
Expand Down Expand Up @@ -363,6 +391,8 @@ func compileExpr(ctx *blockCtx, expr ast.Expr, inFlags ...int) {
ctx.cb.Typ(toFuncType(ctx, v, nil, nil), v)
case *ast.EnvExpr:
compileEnvExpr(ctx, v)
/* case *ast.MatrixLit:
compileMatrixLit(ctx, v) */
default:
panic(ctx.newCodeErrorf(v.Pos(), "compileExpr failed: unknown - %T", v))
}
Expand Down

0 comments on commit 6d00f53

Please sign in to comment.