Skip to content

Commit 8c78f42

Browse files
committed
Enable type casting. Added parsing support for booleans
1 parent 8c69569 commit 8c78f42

File tree

6 files changed

+26
-4
lines changed

6 files changed

+26
-4
lines changed

apotheosis/expression.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package apotheosis
22

33
import (
4+
"github.com/alecthomas/repr"
45
"github.com/sundown/solution/prism"
56

67
"github.com/llir/llvm/ir/value"
@@ -30,7 +31,9 @@ func (env *Environment) newExpression(expr *prism.Expression) value.Value {
3031
return env.CurrentFunction.Params[1]
3132

3233
case prism.Cast, *prism.Cast:
33-
panic("Casts don't exist yet")
34+
repr.Println(expr)
35+
c := env.newCast((*expr).(prism.Cast))
36+
return c
3437
}
3538

3639
panic(expr)

palisade/grammar.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package palisade
22

33
type Expression struct {
4-
Monadic *Monadic `parser:"( @@"`
4+
Bool *[]string `parser:"( @( 'true' | 'false' )"`
5+
Monadic *Monadic `parser:"| @@"`
56
Dyadic *Dyadic `parser:"| @@"`
67
Morphemes *Morpheme `parser:"| @@ )"`
78
}

prism/dapptype.go

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package prism
22

3+
import "fmt"
4+
35
func DeferMonadicApplicationTypes(function *MonadicFunction, y *Expression) {
46
// Enclose all function-side types in a vector if operand is vector and the function is not a vector-function (auto map)
57
if !function.Attrs().DisallowAutoVector &&
@@ -104,6 +106,7 @@ func DeferDyadicApplicationTypes(function *DyadicFunction, x, y *Expression) {
104106
// to is the function-side type which contains the sum type.
105107
func RoundhouseCast(from Expression, otherside Type, to Type) (res *Cast) {
106108
if !to.IsAlgebraic() {
109+
fmt.Println(QueryCast(from.Type(), to))
107110
panic("RoundhouseCast: to is not algebraic")
108111
}
109112

solutions/algebraic.sol

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
@Package dev;
22

33
Main Int → Void {
4-
Println Fn 1.5;
4+
Println Fn 1;
55
}
66

7-
Fn IntInt {
7+
Fn RealReal {
88
← ω;
99
}

subtle/init.go

+14
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,20 @@ func (env Environment) analyseExpression(e *palisade.Expression) prism.Expressio
6666
return env.analyseDyadic(e.Dyadic)
6767
} else if e.Morphemes != nil {
6868
return env.analyseMorphemes(e.Morphemes)
69+
} else if e.Bool != nil {
70+
if len(*e.Bool) == 1 {
71+
return prism.Bool{Value: (*e.Bool)[0] == "true"}
72+
}
73+
74+
vec := make([]prism.Expression, len(*e.Bool))
75+
for i, c := range *e.Bool {
76+
vec[i] = prism.Bool{Value: c == "true"}
77+
}
78+
79+
return prism.Vector{
80+
ElementType: prism.VectorType{Type: prism.BoolType},
81+
Body: &vec,
82+
}
6983
}
7084

7185
prism.Panic("unreachable")

subtle/morpheme.go

+1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ func (env Environment) analyseMorpheme(m *palisade.Morpheme) prism.Expression {
9696
prism.Panic("Unreachable")
9797

9898
}
99+
99100
}
100101

101102
prism.Panic("Other types not implemented")

0 commit comments

Comments
 (0)