Skip to content

Commit

Permalink
cue/internal/adt: add builtin and import support
Browse files Browse the repository at this point in the history
- Builtin
- BuiltinValidator
- import

Change-Id: I826ce644cd8d5000ca7998b8eaf6c96ecef6fe02
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/6502
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
  • Loading branch information
mpvl committed Jul 19, 2020
1 parent 0f935f8 commit 0cfe411
Show file tree
Hide file tree
Showing 23 changed files with 735 additions and 63 deletions.
10 changes: 9 additions & 1 deletion cue/testdata/basicrewrite/011_list_arithmetic.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ list1: [1]
mul1_0: list1 * 0
mul1_1: 1 * list1
mul1_2: list1 * 2
add1_2: list + list1
e: list * -1
-- out/def --
list: [1, 2, 3]
Expand Down Expand Up @@ -41,6 +42,7 @@ e: _|_ // negative number -1 multiplies list
mul1_0: (〈0;list1〉 * 0)
mul1_1: (1 * 〈0;list1〉)
mul1_2: (〈0;list1〉 * 2)
add1_2: (〈0;list〉 + 〈0;list1〉)
e: (〈0;list〉 * -1)
}
-- out/eval --
Expand Down Expand Up @@ -78,8 +80,14 @@ e: _|_ // negative number -1 multiplies list
0: (int){ 1 }
1: (int){ 1 }
}
add1_2: (#list){
0: (int){ 1 }
1: (int){ 2 }
2: (int){ 3 }
3: (int){ 1 }
}
e: (_|_){
// [eval] cannot convert negative number to uint64:
// ./in.cue:9:9
// ./in.cue:10:9
}
}
2 changes: 1 addition & 1 deletion cue/testdata/basicrewrite/014_disjunctions.txtar
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# DO NOT EDIT; generated by go run testdata/gen.go
#

#name: disjunctions
#evalPartial
-- in.cue --
Expand Down
2 changes: 1 addition & 1 deletion cue/testdata/basicrewrite/017_null.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ call: _|_ // cannot call non-function null (type null)
eq2: (bool){ false }
ne1: (bool){ true }
call: (_|_){
// [eval] cannot call non-function *adt.Null (type nil):
// [eval] cannot call non-function *adt.Null (type null):
// ./in.cue:9:7
}
}
5 changes: 5 additions & 0 deletions cue/testdata/export/020.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,8 @@ a: ""
b: 0
-- out/json --
{"a":"","b":0}
-- out/eval --
(struct){
a: (string){ "" }
b: (int){ 0 }
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ s3: strings.ContainsAny(str, "dd")
-- out/legacy-debug --
<0>{n1: <1>{min: <<2>.max, max: ><2>.min}, n2: -<3>.num, num: <4, n3: +<3>.num, n4: (<3>.num + <3>.num), n5: (<3>.num - <3>.num), n6: (<3>.num * <3>.num), n7: (<3>.num / <3>.num), b1: !<3>.is, is: bool, s1: ""+<3>.str+"", str: string, s2: strings.ContainsAny ("dd"), s3: <4>.ContainsAny (<3>.str,"dd")}
-- out/eval --
(_|_){
// [eval]
(struct){
n1: (struct){
min: (_|_){
// [cycle] cycle error
Expand Down Expand Up @@ -88,11 +87,11 @@ s3: strings.ContainsAny(str, "dd")
// ./in.cue:13:5
}
s2: (_|_){
// [eval] cannot call non-function *adt.SelectorExpr (type nil):
// [incomplete] incomplete value *adt.ImportReference:
// ./in.cue:14:5
}
s3: (_|_){
// [eval] cannot call non-function *adt.SelectorExpr (type nil):
// [incomplete] incomplete value *adt.ImportReference:
// ./in.cue:15:5
}
str: (string){ string }
Expand Down
24 changes: 24 additions & 0 deletions cue/testdata/fulleval/027_len_of_incomplete_types.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,27 @@ v9: 4
v10: 0
-- out/legacy-debug --
<0>{args: [], v1: 0, v2: 0, v3: 0, v4: 1, v5: len ((<1>{a: 3} | <2>{a: 4})), v6: len (('sf' | 'dd')), v7: 2, v8: len (([2] | [1,2])), v9: 4, v10: 0}
-- out/eval --
(struct){
args: (#list){
}
v1: (int){ 0 }
v2: (int){ 0 }
v3: (int){ 0 }
v4: (int){ 1 }
v5: (_|_){
// [incomplete] unresolved disjunction *adt.Disjunction (type struct):
// ./in.cue:6:7
}
v6: (_|_){
// [incomplete] unresolved disjunction *adt.Disjunction (type bytes):
// ./in.cue:7:7
}
v7: (int){ 2 }
v8: (_|_){
// [incomplete] unresolved disjunction *adt.Disjunction (type list):
// ./in.cue:9:7
}
v9: (int){ 4 }
v10: (int){ 0 }
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,21 @@ foo:
{"foo":{"jobs":{"foo":{}}}}
-- out/legacy-debug --
<0>{#Workflow: <1>C{jobs: <2>{[]: <3>(jobID: string)-><4>C{}, }, #JobID: or ([ <5>for k, _ in <6>.jobs yield <5>.k ])}, foo: <7>C{jobs: <8>{[]: <9>(jobID: string)-><10>C{}, foo: <11>C{}}, #JobID: "foo"}}
-- out/eval --
(struct){
#Workflow: (#struct){
jobs: (#struct){
}
#JobID: (_|_){
// [incomplete] empty list in call to or:
// ./in.cue:6:10
}
}
foo: (#struct){
jobs: (#struct){
foo: (#struct){
}
}
#JobID: (string){ "foo" }
}
}
7 changes: 3 additions & 4 deletions cue/testdata/fulleval/044_Issue_#178.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,15 @@ bar: hex.EncodedLen(len)
-- out/legacy-debug --
<0>{foo: <1>.Decode (<2>.data), data: bytes, len: int, bar: <3>.EncodedLen (<2>.len)}
-- out/eval --
(_|_){
// [eval]
(struct){
foo: (_|_){
// [eval] cannot call non-function *adt.SelectorExpr (type nil):
// [incomplete] incomplete value *adt.ImportReference:
// ./in.cue:5:7
}
data: (bytes){ bytes }
len: (int){ int }
bar: (_|_){
// [eval] cannot call non-function *adt.SelectorExpr (type nil):
// [incomplete] incomplete value *adt.ImportReference:
// ./in.cue:9:6
}
}
28 changes: 28 additions & 0 deletions cue/testdata/fulleval/049_alias_reuse_in_nested_scope.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,31 @@ b:
{"b":{"foo":"key","a":{"foo":{}}}}
-- out/legacy-debug --
<0>{#Foo: <1>C{connection: <2>C{[or ([ <3>for k, _ in <4>{} yield <3>.k ])]: <5>(_: string)->or ([ <3>for k, _ in <4>{} yield <3>.k ]), }}, #A: <6>C{foo: "key", a: <7>C{foo: <8>C{["key"]: <9>(_: string)-><10>.foo, }}}, #B: <11>C{foo: string, a: <12>C{foo: <13>C{[string]: <14>(_: string)-><15>.foo, }}}, b: <16>C{foo: "key", a: <17>C{foo: <18>C{["key"]: <19>(_: string)-><20>.foo, }}}}
-- out/eval --
(struct){
#Foo: (#struct){
connection: (#struct){
}
}
#A: (#struct){
foo: (string){ "key" }
a: (#struct){
foo: (#struct){
}
}
}
#B: (#struct){
foo: (string){ string }
a: (#struct){
foo: (#struct){
}
}
}
b: (#struct){
foo: (string){ "key" }
a: (#struct){
foo: (#struct){
}
}
}
}
179 changes: 179 additions & 0 deletions cue/testdata/references/labels.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
-- in.cue --
// Label aliases

// direct
a: [X=string]: X
a: bar: {}

// in struct
b: [X=string]: {X}
b: bar: {}

// in structs
c: [X=string]: X
c: [Y=string]: {{{Y}}}
c: bar: {}

// in sub field
d: [X=string]: name: X
d: bar: {}

// nested
e: [X=string]: [Y=string]: X + Y
e: foo: bar: {}

// Field aliases

bar: 3
f1: C="foo\(bar)": {
name: "xx"
foo: C.name
}

// nested
f1: D="foo\(bar)": E="foo\(bar)baz": {
name: "xx"
a: D["foo\(bar)baz"].name
b: E.name
}

// Combo

c1: C="foo\(bar)": [D=string]: {
name: D
foo: C.x.name
}
c1: foo3: x: _


// TODO: support. Also not yet supported in old implementation.
// c10: {
// C=[string]: {
// name: "x"
// foo: C.name
// }
// }
// c2: c1 & { x: _ }

-- out/eval --
(struct){
a: (struct){
bar: (string){ "bar" }
}
b: (struct){
bar: (string){ "bar" }
}
c: (struct){
bar: (string){ "bar" }
}
d: (struct){
bar: (struct){
name: (string){ "bar" }
}
}
e: (struct){
foo: (struct){
bar: (string){ "foobar" }
}
}
bar: (int){ 3 }
f1: (struct){
foo3: (struct){
name: (string){ "xx" }
foo: (string){ "xx" }
foo3baz: (struct){
name: (string){ "xx" }
a: (string){ "xx" }
b: (string){ "xx" }
}
}
}
c1: (struct){
foo3: (struct){
x: (struct){
name: (string){ "x" }
foo: (string){ "x" }
}
}
}
}
-- out/compile --
--- in.cue
{
a: {
[string]: 〈0;-〉
}
a: {
bar: {}
}
b: {
[string]: {
〈1;-〉
}
}
b: {
bar: {}
}
c: {
[string]: 〈0;-〉
}
c: {
[string]: {
{
{
〈3;-〉
}
}
}
}
c: {
bar: {}
}
d: {
[string]: {
name: 〈1;-〉
}
}
d: {
bar: {}
}
e: {
[string]: {
[string]: (〈1;-〉 + 〈0;-〉)
}
}
e: {
foo: {
bar: {}
}
}
bar: 3
f1: {
"foo\(〈1;bar〉)": {
name: "xx"
foo: 〈1;("foo\(〈1;bar〉)")〉.name
}
}
f1: {
"foo\(〈1;bar〉)": {
"foo\(〈2;bar〉)baz": {
name: "xx"
a: 〈2;("foo\(〈1;bar〉)")〉["foo\(〈3;bar〉)baz"].name
b: 〈1;("foo\(〈2;bar〉)baz")〉.name
}
}
}
c1: {
"foo\(〈1;bar〉)": {
[string]: {
name: 〈1;-〉
foo: 〈2;("foo\(〈1;bar〉)")〉.x.name
}
}
}
c1: {
foo3: {
x: _
}
}
}
21 changes: 21 additions & 0 deletions cue/testdata/references/labelstop.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
TODO: add maching when bulk optional fields are allowed
alongside other fields.
-- in.cue --
{[X=string]: baz: X}
bar: {}
-- out/eval --
(struct){
bar: (struct){
baz: (string){ "bar" }
}
}
-- out/compile --
--- in.cue
{
{
[string]: {
baz: 〈1;-〉
}
}
bar: {}
}

0 comments on commit 0cfe411

Please sign in to comment.