-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
plain testing, constvals revamp, slice revamp
it turns out we need the zero value of indexing.I to be decodable. This commit does not quite achieve this, but fixes numerous bugs and provides a better model of slices // Slices are modelled as follows. // // Each slice `s` has a principal pointer `ptr(s)` stored in object.loc, and a Len and a Cap // which are of type indexing.I, and a single memory.Loc "elem" representing // what is stored in the slice. // // Each slice has 0 or more slots. A slot is a triple (p, m, i) such that // 1. p = &m // 2. p = ptr(s) + i // // For the moment, we set ptr(s) == &nil to guarantee that nil derefs // are considered possible. When indexing gets richer, perhaps we // can do more.
- Loading branch information
1 parent
ad59631
commit dff995e
Showing
11 changed files
with
251 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright 2021 The pal authors (see AUTHORS) | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package indexing | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/go-air/pal/internal/plain" | ||
"github.com/go-air/pal/xtruth" | ||
) | ||
|
||
func TestConstVals(t *testing.T) { | ||
idx := ConstVals() | ||
z := idx.Zero() | ||
o := idx.One() | ||
v := idx.FromInt64(32) | ||
w := idx.Var() | ||
var err error | ||
for _, i := range [...]I{z, o, v, w} { | ||
err = plain.TestRoundTrip(i, true) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
} | ||
switch x := idx.Equal(z, idx.Zero()); x { | ||
case xtruth.True: | ||
default: | ||
t.Errorf("%s == %s => %s\n", z, idx.Zero(), x) | ||
} | ||
switch x := idx.Equal(o, idx.One()); x { | ||
case xtruth.True: | ||
default: | ||
t.Errorf("%s == %s => %s\n", o, idx.One(), x) | ||
} | ||
switch x := idx.Equal(v, idx.FromInt64(32)); x { | ||
case xtruth.True: | ||
default: | ||
t.Errorf("%s == %s => %s\n", v, idx.FromInt64(32), x) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2021 The pal authors (see AUTHORS) | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package objects | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/go-air/pal/internal/plain" | ||
) | ||
|
||
func clobMap(c plain.Coder) { | ||
a := c.(*Map) | ||
a.loc = 0 | ||
a.typ = 0 | ||
a.key = 0 | ||
a.elem = 0 | ||
} | ||
|
||
func TestMap(t *testing.T) { | ||
a := &Map{} | ||
a.loc = 3 | ||
a.typ = 7 | ||
a.key = 17 | ||
a.elem = 5 | ||
if err := plain.TestRoundTripClobber(a, clobMap, false); err != nil { | ||
t.Error(err) | ||
} | ||
} |
Oops, something went wrong.