<- Back to shtanton's homepage
aboutsummaryrefslogtreecommitdiff
path: root/walk/atom.go
diff options
context:
space:
mode:
authorCharlie Stanton <charlie@shtanton.xyz>2023-07-19 11:57:59 +0100
committerCharlie Stanton <charlie@shtanton.xyz>2023-07-19 11:57:59 +0100
commit8cf10efe3b5a1bcc70bc6e5590ee63fd5eb00c5b (patch)
tree7a16883c17c2bdcc49b2f9d4f333dfc76c66248f /walk/atom.go
parent3c34366bdd5d817a184d6b1c901d03a16b6faa4b (diff)
downloadstred-go-8cf10efe3b5a1bcc70bc6e5590ee63fd5eb00c5b.tar
Huge refactor to a more value based system, doing away with terminals. Also introduces unit testing
Diffstat (limited to 'walk/atom.go')
-rw-r--r--walk/atom.go38
1 files changed, 19 insertions, 19 deletions
diff --git a/walk/atom.go b/walk/atom.go
index 299c39d..471f030 100644
--- a/walk/atom.go
+++ b/walk/atom.go
@@ -14,78 +14,78 @@ const (
AtomStringTerminal
AtomStringRune
)
-type Atom struct {
+type AtomOLD struct {
Typ AtomType
data uint64
}
-func NewAtomNull() Atom {
- return Atom {
+func NewAtomNull() AtomOLD {
+ return AtomOLD {
Typ: AtomNull,
data: 0,
}
}
-func NewAtomBool(v bool) Atom {
+func NewAtomBool(v bool) AtomOLD {
if v {
- return Atom {
+ return AtomOLD {
Typ: AtomBool,
data: 1,
}
} else {
- return Atom {
+ return AtomOLD {
Typ: AtomBool,
data: 0,
}
}
}
-func (v Atom) Bool() bool {
+func (v AtomOLD) Bool() bool {
if v.Typ != AtomBool {
panic("Tried to use non-bool as bool")
}
return v.data == 1
}
-func NewAtomNumber(v float64) Atom {
- return Atom {
+func NewAtomNumber(v float64) AtomOLD {
+ return AtomOLD {
Typ: AtomNumber,
data: math.Float64bits(v),
}
}
-func (v Atom) Number() float64 {
+func (v AtomOLD) Number() float64 {
if v.Typ != AtomNumber {
panic("Tried to use non-number as number")
}
return math.Float64frombits(v.data)
}
-func NewAtomTerminal(v ValueTerminal) Atom {
- return Atom {
+func NewAtomTerminal(v ValueTerminal) AtomOLD {
+ return AtomOLD {
Typ: AtomTerminal,
data: uint64(v),
}
}
-func (v Atom) Terminal() ValueTerminal {
+func (v AtomOLD) Terminal() ValueTerminal {
if v.Typ != AtomTerminal {
panic("Tried to use non-terminal as terminal")
}
return ValueTerminal(v.data)
}
-func NewAtomStringTerminal() Atom {
- return Atom {
+func NewAtomStringTerminal() AtomOLD {
+ return AtomOLD {
Typ: AtomStringTerminal,
data: 0,
}
}
-func NewAtomStringRune(v rune) Atom {
- return Atom {
+func NewAtomStringRune(v rune) AtomOLD {
+ return AtomOLD {
Typ: AtomStringRune,
data: uint64(v),
}
}
-func (v Atom) StringRune() rune {
+func (v AtomOLD) StringRune() rune {
if v.Typ != AtomStringRune {
panic("Tried to use non-stringrune as stringrune")
}
return rune(v.data)
}
-func (v Atom) String() string {
+func (v AtomOLD) String() string {
switch v.Typ {
case AtomNull:
return "null"