mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 00:32:11 +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 ")
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -308,7 +308,7 @@ func (q *checker) bcheckStatement(n *a.Node) error {
|
||||
if q.astFunc.Effect().Coroutine() {
|
||||
lTyp = typeExprStatus
|
||||
} 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 {
|
||||
return err
|
||||
|
||||
+6
-1
@@ -173,7 +173,7 @@ func (q *checker) tcheckStatement(n *a.Node) error {
|
||||
if q.astFunc.Effect().Coroutine() {
|
||||
lTyp = typeExprStatus
|
||||
} else if lTyp == nil {
|
||||
return fmt.Errorf("TODO: allow returning nothing")
|
||||
lTyp = typeExprEmptyStruct
|
||||
}
|
||||
value := n.Value()
|
||||
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)
|
||||
return nil
|
||||
|
||||
case t.IDNothing:
|
||||
n.SetConstValue(zero)
|
||||
n.SetMType(typeExprEmptyStruct)
|
||||
return nil
|
||||
|
||||
case t.IDNullptr:
|
||||
n.SetConstValue(zero)
|
||||
n.SetMType(typeExprNullptr)
|
||||
|
||||
+4
-2
@@ -382,8 +382,9 @@ const (
|
||||
|
||||
IDFalse = ID(0xB0)
|
||||
IDTrue = ID(0xB1)
|
||||
IDNullptr = ID(0xB2)
|
||||
IDOk = ID(0xB3)
|
||||
IDNothing = ID(0xB2)
|
||||
IDNullptr = ID(0xB3)
|
||||
IDOk = ID(0xB4)
|
||||
|
||||
ID0 = ID(0xC0)
|
||||
ID1 = ID(0xC1)
|
||||
@@ -702,6 +703,7 @@ var builtInsByID = [nBuiltInIDs]string{
|
||||
|
||||
IDFalse: "false",
|
||||
IDTrue: "true",
|
||||
IDNothing: "nothing",
|
||||
IDNullptr: "nullptr",
|
||||
IDOk: "ok",
|
||||
|
||||
|
||||
Reference in new issue
Block a user