Replace Tre/False types with a Bool type
This commit is contained in:
parent
c88c7dad96
commit
09a6d92c08
|
@ -25,8 +25,7 @@ type NodeType int
|
||||||
const (
|
const (
|
||||||
Nil NodeType = iota
|
Nil NodeType = iota
|
||||||
Nothing
|
Nothing
|
||||||
True
|
Bool
|
||||||
False
|
|
||||||
Instruction
|
Instruction
|
||||||
Symbol
|
Symbol
|
||||||
Keyword
|
Keyword
|
||||||
|
|
|
@ -23,28 +23,44 @@ import (
|
||||||
"serene-lang.org/bootstrap/pkg/hash"
|
"serene-lang.org/bootstrap/pkg/hash"
|
||||||
)
|
)
|
||||||
|
|
||||||
type False struct {
|
type Bool struct {
|
||||||
Node
|
Node
|
||||||
ExecutionScope
|
ExecutionScope
|
||||||
|
value bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *False) GetType() ast.NodeType {
|
func (t *Bool) GetType() ast.NodeType {
|
||||||
return ast.False
|
return ast.Bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *False) String() string {
|
func (t *Bool) String() string {
|
||||||
|
if t.value {
|
||||||
|
return "true"
|
||||||
|
}
|
||||||
return "false"
|
return "false"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *False) ToDebugStr() string {
|
func (t *Bool) ToDebugStr() string {
|
||||||
return "false"
|
return t.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *False) Hash() uint32 {
|
func (t *Bool) Hash() uint32 {
|
||||||
bytes := []byte("false")
|
bytes := []byte(t.String())
|
||||||
return hash.Of(append([]byte{byte(ast.False)}, bytes...))
|
return hash.Of(append([]byte{byte(ast.Bool)}, bytes...))
|
||||||
}
|
}
|
||||||
|
|
||||||
func MakeFalse(n Node) *False {
|
func (t *Bool) isTrue() bool {
|
||||||
return &False{Node: n}
|
return t.value
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *Bool) isFalse() bool {
|
||||||
|
return !t.value
|
||||||
|
}
|
||||||
|
|
||||||
|
func MakeTrue(n Node) *Bool {
|
||||||
|
return &Bool{Node: n, value: true}
|
||||||
|
}
|
||||||
|
|
||||||
|
func MakeFalse(n Node) *Bool {
|
||||||
|
return &Bool{Node: n, value: false}
|
||||||
}
|
}
|
|
@ -451,13 +451,13 @@ tco:
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if result != ast.False && result != ast.Nil {
|
if (result == ast.Bool && pred.(*Bool).isFalse()) || result == ast.Nil {
|
||||||
// Truthy clause
|
|
||||||
exprs = append([]IExpr{args.Rest().First()}, restOfExprs(exprs, i)...)
|
|
||||||
} else {
|
|
||||||
|
|
||||||
// Falsy clause
|
// Falsy clause
|
||||||
exprs = append([]IExpr{args.Rest().Rest().First()}, restOfExprs(exprs, i)...)
|
exprs = append([]IExpr{args.Rest().Rest().First()}, restOfExprs(exprs, i)...)
|
||||||
|
} else {
|
||||||
|
// Truthy clause
|
||||||
|
exprs = append([]IExpr{args.Rest().First()}, restOfExprs(exprs, i)...)
|
||||||
|
|
||||||
}
|
}
|
||||||
i = 0
|
i = 0
|
||||||
goto body // rewrite
|
goto body // rewrite
|
||||||
|
|
|
@ -1,48 +0,0 @@
|
||||||
/*
|
|
||||||
Serene --- Yet an other Lisp
|
|
||||||
|
|
||||||
Copyright (c) 2020 Sameer Rahmani <lxsameer@gnu.org>
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 2 of the License.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package core
|
|
||||||
|
|
||||||
import (
|
|
||||||
"serene-lang.org/bootstrap/pkg/ast"
|
|
||||||
"serene-lang.org/bootstrap/pkg/hash"
|
|
||||||
)
|
|
||||||
|
|
||||||
type True struct {
|
|
||||||
Node
|
|
||||||
ExecutionScope
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *True) GetType() ast.NodeType {
|
|
||||||
return ast.True
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *True) String() string {
|
|
||||||
return "true"
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *True) ToDebugStr() string {
|
|
||||||
return "true"
|
|
||||||
}
|
|
||||||
func (t *True) Hash() uint32 {
|
|
||||||
bytes := []byte("true")
|
|
||||||
return hash.Of(append([]byte{byte(ast.True)}, bytes...))
|
|
||||||
}
|
|
||||||
func MakeTrue(n Node) *True {
|
|
||||||
return &True{Node: n}
|
|
||||||
}
|
|
Loading…
Reference in New Issue