Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
39a2e82e
Commit
39a2e82e
authored
Apr 15, 2010
by
Evan Shaw
Committed by
Robert Griesemer
Apr 15, 2010
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
exp/eval: Implement x[lo:]
R=golang-dev, gri CC=golang-dev
https://golang.org/cl/908044
parent
a318f9d3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
6 deletions
+23
-6
src/pkg/exp/eval/expr.go
src/pkg/exp/eval/expr.go
+8
-6
src/pkg/exp/eval/expr_test.go
src/pkg/exp/eval/expr_test.go
+15
-0
No files found.
src/pkg/exp/eval/expr.go
View file @
39a2e82e
...
@@ -589,14 +589,16 @@ func (a *exprCompiler) compile(x ast.Expr, callCtx bool) *expr {
...
@@ -589,14 +589,16 @@ func (a *exprCompiler) compile(x ast.Expr, callCtx bool) *expr {
return
ei
.
compileIndexExpr
(
l
,
r
)
return
ei
.
compileIndexExpr
(
l
,
r
)
case
*
ast
.
SliceExpr
:
case
*
ast
.
SliceExpr
:
end
:=
x
.
End
var
hi
*
expr
if
end
==
nil
{
// TODO: set end to len(x.X)
panic
(
"unimplemented"
)
}
arr
:=
a
.
compile
(
x
.
X
,
false
)
arr
:=
a
.
compile
(
x
.
X
,
false
)
lo
:=
a
.
compile
(
x
.
Index
,
false
)
lo
:=
a
.
compile
(
x
.
Index
,
false
)
hi
:=
a
.
compile
(
end
,
false
)
if
x
.
End
==
nil
{
// End was omitted, so we need to compute len(x.X)
ei
:=
&
exprInfo
{
a
.
compiler
,
x
.
Pos
()}
hi
=
ei
.
compileBuiltinCallExpr
(
a
.
block
,
lenType
,
[]
*
expr
{
arr
})
}
else
{
hi
=
a
.
compile
(
x
.
End
,
false
)
}
if
arr
==
nil
||
lo
==
nil
||
hi
==
nil
{
if
arr
==
nil
||
lo
==
nil
||
hi
==
nil
{
return
nil
return
nil
}
}
...
...
src/pkg/exp/eval/expr_test.go
View file @
39a2e82e
...
@@ -85,6 +85,15 @@ var exprTests = []test{
...
@@ -85,6 +85,15 @@ var exprTests = []test{
RErr
(
"s[-i]"
,
"negative index"
),
RErr
(
"s[-i]"
,
"negative index"
),
RErr
(
"s[3]"
,
"index 3 exceeds"
),
RErr
(
"s[3]"
,
"index 3 exceeds"
),
Val
(
"ai[0:2]"
,
vslice
{
varray
{
1
,
2
},
2
,
2
}),
Val
(
"ai[0:1]"
,
vslice
{
varray
{
1
,
2
},
1
,
2
}),
Val
(
"ai[0:]"
,
vslice
{
varray
{
1
,
2
},
2
,
2
}),
Val
(
"ai[i:]"
,
vslice
{
varray
{
2
},
1
,
1
}),
Val
(
"sli[0:2]"
,
vslice
{
varray
{
1
,
2
,
3
},
2
,
3
}),
Val
(
"sli[0:i]"
,
vslice
{
varray
{
1
,
2
,
3
},
1
,
3
}),
Val
(
"sli[1:]"
,
vslice
{
varray
{
2
,
3
},
1
,
2
}),
CErr
(
"1(2)"
,
"cannot call"
),
CErr
(
"1(2)"
,
"cannot call"
),
CErr
(
"fn(1,2)"
,
"too many"
),
CErr
(
"fn(1,2)"
,
"too many"
),
CErr
(
"fn()"
,
"not enough"
),
CErr
(
"fn()"
,
"not enough"
),
...
@@ -112,8 +121,14 @@ var exprTests = []test{
...
@@ -112,8 +121,14 @@ var exprTests = []test{
Val
(
"len(s)"
,
3
),
Val
(
"len(s)"
,
3
),
Val
(
"len(ai)"
,
2
),
Val
(
"len(ai)"
,
2
),
Val
(
"len(&ai)"
,
2
),
Val
(
"len(&ai)"
,
2
),
Val
(
"len(ai[0:])"
,
2
),
Val
(
"len(ai[1:])"
,
1
),
Val
(
"len(ai[2:])"
,
0
),
Val
(
"len(aai)"
,
2
),
Val
(
"len(aai)"
,
2
),
Val
(
"len(sli)"
,
2
),
Val
(
"len(sli)"
,
2
),
Val
(
"len(sli[0:])"
,
2
),
Val
(
"len(sli[1:])"
,
1
),
Val
(
"len(sli[2:])"
,
0
),
// TODO(austin) Test len of map
// TODO(austin) Test len of map
CErr
(
"len(0)"
,
opTypes
),
CErr
(
"len(0)"
,
opTypes
),
CErr
(
"len(i)"
,
opTypes
),
CErr
(
"len(i)"
,
opTypes
),
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment