Skip to content

Commit

Permalink
Finishing up state charts (#14)
Browse files Browse the repository at this point in the history
* fixed the last bug in imports and FINALLY moving onto implementing the rest of state charts

* cleaning up a few things and commenting out a wip test so I can push and backup my work

* Needed to change rule generation to allow for conditional in the run block

* fun plot twist, temp variables in LLVM IR are specific to their variable scope. Adding the function the variable is in to avoid conflicts

* removing some old things

* found a problem with multiconditionals

* so fixes and adjustments to conditionals

* few more bugs with conditionals, almost done.

* praise jesus... fixed many many bugs in conditionals :p

* activating start values on states

* implementing builtins and running the chart

* added system specification level check (reachability)

* tracking down a few remaining bugs with state charts

* improving mutation score, also found a mutant that leaked into source

* oh git never does what I think it will or should

* resolving conflict

* more tweaks for mutant killing

* more ast mutants

* updating tests in listener module

* adding tests to util module

* fixing a flaky test and cleaning up some dead code

* updating README and quick bug on filepaths
  • Loading branch information
mbellotti committed Dec 1, 2022
1 parent 66cd3f3 commit 995598a
Show file tree
Hide file tree
Showing 47 changed files with 2,784 additions and 779 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# syntax=docker/dockerfile:1
FROM golang:1.17
FROM golang:1.18

WORKDIR /go/src/github.com/fault-lang/fault/

Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ There are A LOT of assumptions there, so the pre-alpha development of Fault prio

But then that's part of the fun too. Developing Fault is an opportunity to learn more about how SMT solvers (specifically Z3) work.

### Current Status (11/2/2022)
### Current Status (11/30/2022)
Trying to finish up state charts exposed some problems with conditionals that needed to be addressed, plus some bugs and funny edge cases. But state charts are now done, including a reachability analysis verifying that the system is appropriately specified that I think will be opt-in for now.

#### (11/2/2022)
While working on adding state chart support I finally hit the limit on what the half-assed namespace implementation I started with could support. So I ended up spending the entire month of October writing a preprocesser that annotated the AST with the proper ids for each nameable node, then integrating it into a compiler. It took a long time but the code in the LLVM compilation stage is so much cleaner and neater now. Along the way found some previously unknown bugs and added some more tests to bone up mutation scores (will need more of this later)

#### (9/28/2022)
Expand Down
114 changes: 37 additions & 77 deletions ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (sd *SpecDeclStatement) String() string {
return out.String()
}
func (sd *SpecDeclStatement) Type() string {
return ""
return "SPEC"
}

type SysDeclStatement struct {
Expand All @@ -168,7 +168,7 @@ func (sd *SysDeclStatement) String() string {
return out.String()
}
func (sd *SysDeclStatement) Type() string {
return ""
return "SYSTEM"
}

type ImportStatement struct {
Expand All @@ -194,7 +194,7 @@ func (is *ImportStatement) String() string {
return out.String()
}
func (is *ImportStatement) Type() string {
return ""
return "IMPORT"
}

type ConstantStatement struct {
Expand Down Expand Up @@ -345,9 +345,14 @@ func (i *Invariant) Position() []int { return i.Token.GetPosition() }
func (i *Invariant) String() string {
var out bytes.Buffer

out.WriteString(i.TokenLiteral() + "assert ")
out.WriteString(i.TokenLiteral() + " assert ")
out.WriteString(i.Variable.String())
out.WriteString(i.Conjuction)
if i.Conjuction != "" {
out.WriteString(i.Conjuction)
}
if i.Comparison != "" {
out.WriteString(i.Comparison)
}
out.WriteString(i.Expression.String())

out.WriteString(";")
Expand Down Expand Up @@ -405,7 +410,7 @@ func (ss *StartStatement) String() string {
return out.String()
}
func (ss *StartStatement) Type() string {
return ""
return "START"
}

type Identifier struct {
Expand Down Expand Up @@ -433,7 +438,6 @@ func (i *Identifier) SetId(id []string) {
i.ProcessedName = id
}
func (i *Identifier) Id() []string {
// returns []string{spec, rest_of_the_id}
return []string{i.ProcessedName[0], strings.Join(i.ProcessedName[1:], "_")}
}
func (i *Identifier) IdString() string {
Expand All @@ -447,6 +451,7 @@ type ParameterCall struct {
Token Token
InferredType *Type
Spec string
Scope string
Value []string
ProcessedName []string
}
Expand Down Expand Up @@ -474,7 +479,6 @@ func (p *ParameterCall) SetId(id []string) {
p.ProcessedName = id
}
func (p *ParameterCall) Id() []string {
// returns []string{spec, rest_of_the_id}
return []string{p.ProcessedName[0], strings.Join(p.ProcessedName[1:], "_")}
}
func (p *ParameterCall) IdString() string {
Expand Down Expand Up @@ -532,7 +536,6 @@ func (si *StructInstance) Type() string {
return string(si.Token.Literal)
}
func (si *StructInstance) Id() []string {
// returns []string{spec, rest_of_the_id}
return []string{si.ProcessedName[0], strings.Join(si.ProcessedName[1:], "_")}
}
func (si *StructInstance) SetId(id []string) {
Expand Down Expand Up @@ -569,7 +572,6 @@ func (sp *StructProperty) Type() string {
return string(sp.Value.Type())
}
func (sp *StructProperty) Id() []string {
// returns []string{spec, rest_of_the_id}
return []string{sp.ProcessedName[0], strings.Join(sp.ProcessedName[1:], "_")}
}

Expand All @@ -590,6 +592,7 @@ type Instance struct {
ComplexScope string
Processed *StructInstance
ProcessedName []string
Order []string
}

func (i *Instance) expressionNode() {}
Expand All @@ -610,7 +613,6 @@ func (i *Instance) SetId(id []string) {
i.ProcessedName = id
}
func (i *Instance) Id() []string {
// returns []string{spec, rest_of_the_id}
return []string{i.ProcessedName[0], strings.Join(i.ProcessedName[1:], "_")}
}

Expand Down Expand Up @@ -669,7 +671,6 @@ func (il *IntegerLiteral) SetId(id []string) {
il.ProcessedName = id
}
func (il *IntegerLiteral) Id() []string {
// returns []string{spec, rest_of_the_id}
return []string{il.ProcessedName[0], strings.Join(il.ProcessedName[1:], "_")}
}
func (il *IntegerLiteral) IdString() string {
Expand Down Expand Up @@ -703,7 +704,6 @@ func (fl *FloatLiteral) SetId(id []string) {
fl.ProcessedName = id
}
func (fl *FloatLiteral) Id() []string {
// returns []string{spec, rest_of_the_id}
return []string{fl.ProcessedName[0], strings.Join(fl.ProcessedName[1:], "_")}
}
func (fl *FloatLiteral) IdString() string {
Expand Down Expand Up @@ -737,7 +737,6 @@ func (n *Natural) SetId(id []string) {
n.ProcessedName = id
}
func (n *Natural) Id() []string {
// returns []string{spec, rest_of_the_id}
return []string{n.ProcessedName[0], strings.Join(n.ProcessedName[1:], "_")}
}
func (n *Natural) IdString() string {
Expand Down Expand Up @@ -776,7 +775,6 @@ func (u *Uncertain) Type() string {
}
}
func (u *Uncertain) Id() []string {
// returns []string{spec, rest_of_the_id}
return []string{u.ProcessedName[0], strings.Join(u.ProcessedName[1:], "_")}
}
func (u *Uncertain) SetId(id []string) {
Expand Down Expand Up @@ -819,7 +817,6 @@ func (u *Unknown) Type() string {
}
}
func (u *Unknown) Id() []string {
// returns []string{spec, rest_of_the_id}
return []string{u.ProcessedName[0], strings.Join(u.ProcessedName[1:], "_")}
}
func (u *Unknown) SetId(id []string) {
Expand Down Expand Up @@ -913,7 +910,6 @@ func (b *Boolean) Type() string {
}
}
func (b *Boolean) Id() []string {
// returns []string{spec, rest_of_the_id}
return []string{b.ProcessedName[0], strings.Join(b.ProcessedName[1:], "_")}
}
func (b *Boolean) SetId(id []string) {
Expand Down Expand Up @@ -948,7 +944,6 @@ func (t *This) Type() string {
}
}
func (t *This) Id() []string {
// returns []string{spec, rest_of_the_id}
return []string{t.ProcessedName[0], strings.Join(t.ProcessedName[1:], "_")}
}
func (t *This) SetId(id []string) {
Expand Down Expand Up @@ -1086,19 +1081,23 @@ func (ie *IfExpression) Position() []int { return ie.Token.GetPosition() }
func (ie *IfExpression) String() string {
var out bytes.Buffer

out.WriteString("if")
out.WriteString("if(")
out.WriteString(ie.Condition.String())
out.WriteString(" ")
out.WriteString("){")
out.WriteString(ie.Consequence.String())

if (ie.Elif != &IfExpression{}) && ie.Elif != nil {
out.WriteString("else if")
out.WriteString(ie.Elif.String())
}

if (ie.Alternative != &BlockStatement{}) && ie.Alternative != nil {
out.WriteString("else ")
out.WriteString("}else if(")
out.WriteString(ie.Elif.Condition.String())
out.WriteString("){")
out.WriteString(ie.Elif.Consequence.String())
out.WriteString("}")
} else if (ie.Alternative != &BlockStatement{}) && ie.Alternative != nil {
out.WriteString("}else{")
out.WriteString(ie.Alternative.String())
out.WriteString("}")
} else {
out.WriteString("}")
}

return out.String()
Expand Down Expand Up @@ -1132,7 +1131,6 @@ func (fl *FunctionLiteral) String() string {
}
func (fl *FunctionLiteral) Type() string { return fl.Body.Type() }
func (fl *FunctionLiteral) Id() []string {
// returns []string{spec, rest_of_the_id}
return []string{fl.ProcessedName[0], strings.Join(fl.ProcessedName[1:], "_")}
}
func (fl *FunctionLiteral) SetId(id []string) {
Expand All @@ -1145,46 +1143,6 @@ func (fl *FunctionLiteral) RawId() []string {
return fl.ProcessedName
}

type StateLiteral struct {
Token Token
Parameters []*Identifier
Body *BlockStatement
ProcessedName []string
}

func (sl *StateLiteral) expressionNode() {}
func (sl *StateLiteral) TokenLiteral() string { return sl.Token.Literal }
func (sl *StateLiteral) Position() []int { return sl.Token.GetPosition() }
func (sl *StateLiteral) String() string {
var out bytes.Buffer
params := []string{}
for _, p := range sl.Parameters {
params = append(params, p.String())
}

out.WriteString(sl.TokenLiteral())
out.WriteString("(")
out.WriteString(strings.Join(params, ", "))
out.WriteString(") ")
out.WriteString(sl.Body.String())

return out.String()
}
func (sl *StateLiteral) Type() string { return sl.Body.Type() }
func (sl *StateLiteral) Id() []string {
// returns []string{spec, rest_of_the_id}
return []string{sl.ProcessedName[0], strings.Join(sl.ProcessedName[1:], "_")}
}
func (sl *StateLiteral) SetId(id []string) {
sl.ProcessedName = id
}
func (sl *StateLiteral) IdString() string {
return strings.Join(sl.ProcessedName, "_")
}
func (sl *StateLiteral) RawId() []string {
return sl.ProcessedName
}

type BuiltIn struct {
Token Token
Parameters map[string]Operand
Expand All @@ -1206,11 +1164,11 @@ func (b *BuiltIn) String() string {
out.WriteString(b.Function)
out.WriteString("(")
out.WriteString(strings.Join(params, ", "))
out.WriteString(") ")
out.WriteString(")")

return out.String()
}
func (b *BuiltIn) Type() string { return "builtin" }
func (b *BuiltIn) Type() string { return "BUILTIN" }
func (b *BuiltIn) Id() []string { // returns []string{spec, rest_of_the_id}
return []string{b.ProcessedName[0], strings.Join(b.ProcessedName[1:], "_")}
}
Expand Down Expand Up @@ -1244,7 +1202,6 @@ func (sl *StringLiteral) Type() string {
}
}
func (sl *StringLiteral) Id() []string {
// returns []string{spec, rest_of_the_id}
return []string{sl.ProcessedName[0], strings.Join(sl.ProcessedName[1:], "_")}
}
func (sl *StringLiteral) SetId(id []string) {
Expand Down Expand Up @@ -1283,7 +1240,6 @@ func (ie *IndexExpression) Type() string {
return ie.Left.Type()
}
func (ie *IndexExpression) Id() []string {
// returns []string{spec, rest_of_the_id}
return []string{ie.ProcessedName[0], strings.Join(ie.ProcessedName[1:], "_")}
}
func (ie *IndexExpression) SetId(id []string) {
Expand Down Expand Up @@ -1311,7 +1267,9 @@ func (sl *StockLiteral) String() string {
var out bytes.Buffer

pairs := []string{}
for key, value := range sl.Pairs {
for _, k := range sl.Order {
key := sl.GetPropertyIdent(k)
value := sl.Pairs[key]
pairs = append(pairs, key.String()+":"+value.String())
}

Expand Down Expand Up @@ -1358,7 +1316,9 @@ func (fl *FlowLiteral) String() string {
var out bytes.Buffer

pairs := []string{}
for key, value := range fl.Pairs {
for _, k := range fl.Order {
key := fl.GetPropertyIdent(k)
value := fl.Pairs[key]
pairs = append(pairs, key.String()+":"+value.String())
}

Expand All @@ -1370,7 +1330,6 @@ func (fl *FlowLiteral) String() string {
}
func (fl *FlowLiteral) Type() string { return "FLOW" }
func (fl *FlowLiteral) Id() []string {
// returns []string{spec, rest_of_the_id}
return []string{fl.ProcessedName[0], strings.Join(fl.ProcessedName[1:], "_")}
}
func (fl *FlowLiteral) SetId(id []string) {
Expand Down Expand Up @@ -1406,19 +1365,20 @@ func (cl *ComponentLiteral) String() string {
var out bytes.Buffer

pairs := []string{}
for key, value := range cl.Pairs {
for _, k := range cl.Order {
key := cl.GetPropertyIdent(k)
value := cl.Pairs[key]
pairs = append(pairs, key.String()+":"+value.String())
}

out.WriteString("{")
_, _, _ = out.WriteString, strings.Join, pairs
out.WriteString(strings.Join(pairs, ", "))
out.WriteString("}")

return out.String()
}
func (cl *ComponentLiteral) Type() string { return "COMPONENT" }
func (cl *ComponentLiteral) Id() []string {
// returns []string{spec, rest_of_the_id}
return []string{cl.ProcessedName[0], strings.Join(cl.ProcessedName[1:], "_")}
}
func (cl *ComponentLiteral) SetId(id []string) {
Expand Down

0 comments on commit 995598a

Please sign in to comment.