mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-24 16:52:18 +01:00
Add a nothing built-in literal
This commit is contained in:
1 parent
49627b46f2
commit
d1f1340d47
4 files changed
+12
-5
No files matched your search
@@ -446,7 +446,7 @@ func (g *gen) writeStatementRet(b *buffer, n *a.Ret, depth uint32) error {
|
|||||||
|
|
||||||
b.writes("return ")
|
b.writes("return ")
|
||||||
if g.currFunk.astFunc.Out() == nil {
|
if g.currFunk.astFunc.Out() == nil {
|
||||||
return fmt.Errorf("TODO: allow empty return type (when not suspendible)")
|
b.writes("((wuffs_base__empty_struct){})")
|
||||||
} else if err := g.writeExpr(b, retExpr, depth); err != nil {
|
} else if err := g.writeExpr(b, retExpr, depth); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -308,7 +308,7 @@ func (q *checker) bcheckStatement(n *a.Node) error {
|
|||||||
if q.astFunc.Effect().Coroutine() {
|
if q.astFunc.Effect().Coroutine() {
|
||||||
lTyp = typeExprStatus
|
lTyp = typeExprStatus
|
||||||
} else if lTyp == nil {
|
} else if lTyp == nil {
|
||||||
return fmt.Errorf("TODO: allow returning nothing")
|
lTyp = typeExprEmptyStruct
|
||||||
}
|
}
|
||||||
if _, err := q.bcheckAssignment1(nil, lTyp, t.IDEq, n.Value()); err != nil {
|
if _, err := q.bcheckAssignment1(nil, lTyp, t.IDEq, n.Value()); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
+6
-1
@@ -173,7 +173,7 @@ func (q *checker) tcheckStatement(n *a.Node) error {
|
|||||||
if q.astFunc.Effect().Coroutine() {
|
if q.astFunc.Effect().Coroutine() {
|
||||||
lTyp = typeExprStatus
|
lTyp = typeExprStatus
|
||||||
} else if lTyp == nil {
|
} else if lTyp == nil {
|
||||||
return fmt.Errorf("TODO: allow returning nothing")
|
lTyp = typeExprEmptyStruct
|
||||||
}
|
}
|
||||||
value := n.Value()
|
value := n.Value()
|
||||||
if err := q.tcheckExpr(value, 0); err != nil {
|
if err := q.tcheckExpr(value, 0); err != nil {
|
||||||
@@ -391,6 +391,11 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
|
|||||||
n.SetMType(typeExprBool)
|
n.SetMType(typeExprBool)
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
|
case t.IDNothing:
|
||||||
|
n.SetConstValue(zero)
|
||||||
|
n.SetMType(typeExprEmptyStruct)
|
||||||
|
return nil
|
||||||
|
|
||||||
case t.IDNullptr:
|
case t.IDNullptr:
|
||||||
n.SetConstValue(zero)
|
n.SetConstValue(zero)
|
||||||
n.SetMType(typeExprNullptr)
|
n.SetMType(typeExprNullptr)
|
||||||
|
|||||||
+4
-2
@@ -382,8 +382,9 @@ const (
|
|||||||
|
|
||||||
IDFalse = ID(0xB0)
|
IDFalse = ID(0xB0)
|
||||||
IDTrue = ID(0xB1)
|
IDTrue = ID(0xB1)
|
||||||
IDNullptr = ID(0xB2)
|
IDNothing = ID(0xB2)
|
||||||
IDOk = ID(0xB3)
|
IDNullptr = ID(0xB3)
|
||||||
|
IDOk = ID(0xB4)
|
||||||
|
|
||||||
ID0 = ID(0xC0)
|
ID0 = ID(0xC0)
|
||||||
ID1 = ID(0xC1)
|
ID1 = ID(0xC1)
|
||||||
@@ -702,6 +703,7 @@ var builtInsByID = [nBuiltInIDs]string{
|
|||||||
|
|
||||||
IDFalse: "false",
|
IDFalse: "false",
|
||||||
IDTrue: "true",
|
IDTrue: "true",
|
||||||
|
IDNothing: "nothing",
|
||||||
IDNullptr: "nullptr",
|
IDNullptr: "nullptr",
|
||||||
IDOk: "ok",
|
IDOk: "ok",
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user