Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

Commit

Permalink
internal/core/compile: add new compiler
Browse files Browse the repository at this point in the history
compile: compiler, but still needs support for builtins and imports

debug: debug representation of internal structures

runtime: just string uniquing functionality for now

cuetxtar: added txtar support, including auto --update and --todo
support.

Change-Id: Idadf6045867b55381f0b3e0da3bc772fa40f7a04
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/5840
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 6a08830 commit 1f42c81
Show file tree
Hide file tree
Showing 175 changed files with 5,931 additions and 391 deletions.
2 changes: 1 addition & 1 deletion cue/ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ type BinaryExpr struct {
// Useful for ASTs generated by code other than the CUE parser.
func NewBinExpr(op token.Token, operands ...Expr) Expr {
if len(operands) == 0 {
panic("must specify at least one expression")
return nil
}
expr := operands[0]
for _, e := range operands[1:] {
Expand Down
6 changes: 3 additions & 3 deletions cue/resolve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2457,7 +2457,7 @@ func TestFullEval(t *testing.T) {
`c1: (<2>{a: 1, b: 2} | <3>{a: 2, b: 1}), ` +
`c2: (<4>{a: 2, b: 1} | <5>{a: 1, b: 2})}`,
}, {
desc: "don't convert incomplete errors to non-incomplete",
desc: "dont convert incomplete errors to non-incomplete",
in: `
import "strings"
Expand Down Expand Up @@ -2865,7 +2865,7 @@ func TestFullEval(t *testing.T) {
`c1: <1>{bar: <2>{baz: 2}, baz: 2}, ` +
`c2: _|_(conflicting values {bar: 1} and 1 (mismatched types struct and int))}`,
}, {
desc: "don't bind to string labels",
desc: "dont bind to string labels",
in: `
x: 1
y: {
Expand All @@ -2875,7 +2875,7 @@ func TestFullEval(t *testing.T) {
`,
out: `<0>{x: 1, y: <1>{x: 2, z: 1}}`,
}, {
desc: "don't pass incomplete values to builtins",
desc: "dont pass incomplete values to builtins",
in: `
import "encoding/json"
Expand Down
9 changes: 9 additions & 0 deletions cue/testdata/basicrewrite/000_errors.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,12 @@ d: false
e: true
-- out/legacy-debug --
<0>{a: _|_(from source), b: _|_(from source), c: true, d: false, e: true}
-- out/compile --
--- in.cue
{
a: (_|_ & _|_)
b: (null & _|_)
c: (〈0;b〉.a == _|_)
d: (_|_ != 〈0;b〉.a)
e: (_|_ == _|_)
}
21 changes: 21 additions & 0 deletions cue/testdata/basicrewrite/001_regexp.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,24 @@ e2: _|_ // invalid operation "foo" !~ true (mismatched types string and bool)
e3: _|_ // conflicting values !="a" and <5 (mismatched types string and number)
-- out/legacy-debug --
<0>{c1: true, c2: true, c3: false, c4: true, b1: "a", b2: "foo", b3: _|_((=~"[a-z]{4}" & "foo"):invalid value "foo" (does not match =~"[a-z]{4}")), b4: "foo", s1: =~"c", s2: (!="b" & =~"[a-z]"), e1: _|_(("foo" =~ 1):invalid operation "foo" =~ 1 (mismatched types string and int)), e2: _|_(("foo" !~ true):invalid operation "foo" !~ true (mismatched types string and bool)), e3: _|_((!="a" & <5):conflicting values !="a" and <5 (mismatched types string and number))}
-- out/compile --
--- in.cue
{
c1: ("a" =~ "a")
c2: ("foo" =~ "[a-z]{3}")
c3: ("foo" =~ "[a-z]{4}")
c4: ("foo" !~ "[a-z]{4}")
b1: =~"a"
b1: "a"
b2: =~"[a-z]{3}"
b2: "foo"
b3: =~"[a-z]{4}"
b3: "foo"
b4: !~"[a-z]{4}"
b4: "foo"
s1: (!="b" & =~"c")
s2: (!="b" & =~"[a-z]")
e1: ("foo" =~ 1)
e2: ("foo" !~ true)
e3: (!="a" & <5)
}
27 changes: 27 additions & 0 deletions cue/testdata/basicrewrite/002_arithmetic.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,30 @@ e7: _|_ // invalid operation 2 quo 2.0 (mismatched types int and float)
e8: _|_ // invalid operation 1.0 mod 1 (mismatched types float and int)
-- out/legacy-debug --
<0>{i1: 1, i2: 2, sum: 1, div1: 4.00000000000000000000000, div2: 4.00000000000000000000000, div3: 1., divZero: _|_((1.0 / 0):division by zero), div00: _|_((0 / 0):division undefined), b: true, add: 5.00000000000000000000000, idiv00: _|_((0 div 0):division by zero), imod00: _|_((0 mod 0):division by zero), iquo00: _|_((0 quo 0):division by zero), irem00: _|_((0 rem 0):division by zero), v1: 5.0000000000e+11, v2: true, v3: 0.666666666666666666666667, v5: 0, e0: _|_((2 + "a"):invalid operation 2 + "a" (mismatched types int and string)), e5: _|_((1.0 div 2):invalid operation 1.0 div 2 (mismatched types float and int)), e6: _|_((2 rem 2.0):invalid operation 2 rem 2.0 (mismatched types int and float)), e7: _|_((2 quo 2.0):invalid operation 2 quo 2.0 (mismatched types int and float)), e8: _|_((1.0 mod 1):invalid operation 1.0 mod 1 (mismatched types float and int))}
-- out/compile --
--- in.cue
{
i1: (1 & int)
i2: (2 & int)
sum: (-1 + +2)
div1: ((2.0 / 3) * 6)
div2: ((2 / 3) * 6)
div3: (1.00 / 1.00)
divZero: (1.0 / 0)
div00: (0 / 0)
b: (1 != 4)
add: (〈0;div1〉 + 1.0)
idiv00: (0 div 0)
imod00: (0 mod 0)
iquo00: (0 quo 0)
irem00: (0 rem 0)
v1: (1000000000000 / 2.0)
v2: (2.0 == 2)
v3: (2.0 / 3.0)
v5: (〈0;i1〉 div 〈0;i2〉)
e0: (2 + "a")
e5: (1.0 div 2)
e6: (2 rem 2.0)
e7: (2 quo 2.0)
e8: (1.0 mod 1)
}
28 changes: 28 additions & 0 deletions cue/testdata/basicrewrite/003_integer-specific_arithmetic.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,31 @@ me1: _|_ // invalid operation 2.0 mod 1 (mismatched types float and int)
me2: _|_ // invalid operation 2 mod 1.0 (mismatched types int and float)
-- out/legacy-debug --
<0>{q1: 2, q2: -2, q3: -2, q4: 2, qe1: _|_((2.0 quo 1):invalid operation 2.0 quo 1 (mismatched types float and int)), qe2: _|_((2 quo 1.0):invalid operation 2 quo 1.0 (mismatched types int and float)), r1: 1, r2: 1, r3: -1, r4: -1, re1: _|_((2.0 rem 1):invalid operation 2.0 rem 1 (mismatched types float and int)), re2: _|_((2 rem 1.0):invalid operation 2 rem 1.0 (mismatched types int and float)), d1: 2, d2: -2, d3: -3, d4: 3, de1: _|_((2.0 div 1):invalid operation 2.0 div 1 (mismatched types float and int)), de2: _|_((2 div 1.0):invalid operation 2 div 1.0 (mismatched types int and float)), m1: 1, m2: 1, m3: 1, m4: 1, me1: _|_((2.0 mod 1):invalid operation 2.0 mod 1 (mismatched types float and int)), me2: _|_((2 mod 1.0):invalid operation 2 mod 1.0 (mismatched types int and float))}
-- out/compile --
--- in.cue
{
q1: (5 quo 2)
q2: (5 quo -2)
q3: (-5 quo 2)
q4: (-5 quo -2)
qe1: (2.0 quo 1)
qe2: (2 quo 1.0)
r1: (5 rem 2)
r2: (5 rem -2)
r3: (-5 rem 2)
r4: (-5 rem -2)
re1: (2.0 rem 1)
re2: (2 rem 1.0)
d1: (5 div 2)
d2: (5 div -2)
d3: (-5 div 2)
d4: (-5 div -2)
de1: (2.0 div 1)
de2: (2 div 1.0)
m1: (5 mod 2)
m2: (5 mod -2)
m3: (-5 mod 2)
m4: (-5 mod -2)
me1: (2.0 mod 1)
me2: (2 mod 1.0)
}
10 changes: 10 additions & 0 deletions cue/testdata/basicrewrite/004_booleans.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,13 @@ f: false
e: _|_ // conflicting values true and false
-- out/legacy-debug --
<0>{t: true, f: false, e: _|_(true:conflicting values true and false)}
-- out/compile --
--- in.cue
{
t: true
t: !false
f: false
f: !〈0;t〉
e: true
e: !true
}
10 changes: 10 additions & 0 deletions cue/testdata/basicrewrite/005_boolean_arithmetic.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,13 @@ e: true
f: _|_ // conflicting values true and false
-- out/legacy-debug --
<0>{a: true, b: true, c: false, d: true, e: true, f: _|_(true:conflicting values true and false)}
-- out/compile --
--- in.cue
{
a: (true && true)
b: (true || false)
c: (false == true)
d: (false != true)
e: (true & true)
f: (true & false)
}
12 changes: 12 additions & 0 deletions cue/testdata/basicrewrite/006_basic_type.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,15 @@ e: "4"
f: true
-- out/legacy-debug --
<0>{a: 1, b: 1, c: 1.0, d: _|_((int & float):conflicting values int and float (mismatched types int and float)), e: "4", f: true}
-- out/compile --
--- in.cue
{
a: (1 & int)
b: (number & 1)
c: 1.0
c: float
d: (int & float)
e: ("4" & string)
f: true
f: bool
}
12 changes: 12 additions & 0 deletions cue/testdata/basicrewrite/007_strings_and_bytes.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,15 @@ e0: _|_ // invalid operation "a" + '' (mismatched types string and bytes)
e1: _|_ // invalid operation 'b' + "c" (mismatched types bytes and string)
-- out/legacy-debug --
<0>{s0: "foobar", s1: "abcabcabc", s2: "abcabc", b0: 'foobar', b1: 'abcabcabc', b2: 'abcabc', e0: _|_(("a" + ''):invalid operation "a" + '' (mismatched types string and bytes)), e1: _|_(('b' + "c"):invalid operation 'b' + "c" (mismatched types bytes and string))}
-- out/compile --
--- in.cue
{
s0: ("foo" + "bar")
s1: (3 * "abc")
s2: ("abc" * 2)
b0: ('foo' + 'bar')
b1: (3 * 'abc')
b2: ('abc' * 2)
e0: ("a" + '')
e1: ('b' + "c")
}
6 changes: 6 additions & 0 deletions cue/testdata/basicrewrite/008_escaping.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,9 @@ b: |-
{"a":"foo\nbar","b":"foo\nbar"}
-- out/legacy-debug --
<0>{a: "foo\nbar", b: "foo\nbar"}
-- out/compile --
--- in.cue
{
a: "foo\nbar"
b: 〈0;a〉
}
18 changes: 18 additions & 0 deletions cue/testdata/basicrewrite/009_reference.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,21 @@ e:
{"a":2,"b":2,"d":{"d":3,"e":3},"e":{"e":{"v":1},"f":{"v":1}}}
-- out/legacy-debug --
<0>{a: 2, b: 2, d: <1>{d: 3, e: 3}, e: <2>{e: <3>{v: 1}, f: <4>{v: 1}}}
-- out/compile --
--- in.cue
{
a: 〈0;b〉
b: 2
d: {
d: 3
e: 〈0;d〉
}
e: {
e: {
v: 1
}
f: {
v: 〈1;e〉.v
}
}
}
50 changes: 50 additions & 0 deletions cue/testdata/basicrewrite/010_lists.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,53 @@ e5: [1, 2, 4, _|_, // invalid value 8 (out of bound <=5)
]
-- out/legacy-debug --
<0>{list: [1,2,3], index: 2, unify: [1,2,3], e: _|_(([] & 4):conflicting values [] and 4 (mismatched types list and int)), e2: _|_("d":invalid list index "d" (type string)), e3: _|_(-1:invalid list index -1 (index must be non-negative)), e4: [1,2,4,_|_((<=5 & 8):invalid value 8 (out of bound <=5))], e5: [1,2,4,_|_((<=5 & 8):invalid value 8 (out of bound <=5))]}
-- out/compile --
--- in.cue
{
list: [
1,
2,
3,
]
index: [
1,
2,
3,
][1]
unify: ([
1,
2,
3,
] & [
_,
2,
3,
])
e: ([] & 4)
e2: [
3,
]["d"]
e3: [
3,
][-1]
e4: ([
1,
2,
...(>=4 & <=5),
] & [
1,
2,
4,
8,
])
e5: ([
1,
2,
4,
8,
] & [
1,
2,
...(>=4 & <=5),
])
}
19 changes: 19 additions & 0 deletions cue/testdata/basicrewrite/011_list_arithmetic.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,22 @@ mul1_2: [1, 1]
e: _|_ // negative number -1 multiplies list
-- out/legacy-debug --
<0>{list: [1,2,3], mul0: [], mul1: [1,2,3], mul2: [1,2,3,1,2,3], list1: [1], mul1_0: [], mul1_1: [1], mul1_2: [1,1], e: _|_((<1>.list * -1):negative number -1 multiplies list)}
-- out/compile --
--- in.cue
{
list: [
1,
2,
3,
]
mul0: (〈0;list〉 * 0)
mul1: (〈0;list〉 * 1)
mul2: (2 * 〈0;list〉)
list1: [
1,
]
mul1_0: (〈0;list1〉 * 0)
mul1_1: (1 * 〈0;list1〉)
mul1_2: (〈0;list1〉 * 2)
e: (〈0;list〉 * -1)
}
31 changes: 31 additions & 0 deletions cue/testdata/basicrewrite/012_selecting.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,34 @@ g: {
h: _|_ // invalid operation: [3].b (type list does not support selection)
-- out/legacy-debug --
<0>{obj: <1>{a: 1, b: 2}, index: 2, mulidx: 3, e: _|_(4:invalid struct index 4 (type int)), f: <2>{a: 1}.b, g: <3>{a: 1}["b"], h: _|_([3]:invalid operation: [3].b (type list does not support selection))}
-- out/compile --
--- in.cue
{
obj: {
a: 1
b: 2
}
index: {
a: 1
b: 2
}["b"]
mulidx: {
a: 1
b: {
a: 1
b: 3
}
}["b"]["b"]
e: {
a: 1
}[4]
f: {
a: 1
}.b
g: {
a: 1
}["b"]
h: [
3,
].b
}
42 changes: 42 additions & 0 deletions cue/testdata/basicrewrite/013_obj_unify.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,45 @@ o4: {
e: _|_ // conflicting values 1 and {a: 3} (mismatched types int and struct)
-- out/legacy-debug --
<0>{o1: <1>{a: 1, b: 2}, o2: <2>{a: 1, b: 2}, o3: <3>{a: 1, b: 2}, o4: <4>{a: 1, b: 2}, e: _|_((1 & <5>{a: 3}):conflicting values 1 and {a: 3} (mismatched types int and struct))}
-- out/compile --
--- in.cue
{
o1: ({
a: 1
} & {
b: 2
})
o2: ({
a: 1
b: 2
} & {
b: 2
})
o3: ({
a: 1
} & {
a: 1
b: 2
})
o4: ({
a: 1
} & {
b: 2
})
o4: ({
a: 1
b: 2
} & {
b: 2
})
o4: ({
a: 1
} & {
a: 1
b: 2
})
e: 1
e: {
a: 3
}
}

0 comments on commit 1f42c81

Please sign in to comment.