Skip to content

Commit

Permalink
Rename GateDef -> Gate
Browse files Browse the repository at this point in the history
  • Loading branch information
itsubaki committed Jul 29, 2023
1 parent dcf03b8 commit 9e42934
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions evaluator/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type Environ struct {
Bit *Bit
Qubit *Qubit
Const Const
GateDef GateDef
Gate Gate
Modifier []ast.Modifier
Decl []ast.Decl
CtrlQArgs []ast.Expr
Expand All @@ -25,7 +25,7 @@ func NewEnviron() *Environ {
Outer: nil,
Bit: NewBit(),
Qubit: NewQubit(),
GateDef: make(map[string]ast.Decl),
Gate: make(map[string]ast.Decl),
Const: make(map[string]object.Object),
Modifier: make([]ast.Modifier, 0),
Decl: make([]ast.Decl, 0),
Expand All @@ -39,18 +39,18 @@ func (e *Environ) NewEnclosed(decl ast.Decl, mod []ast.Modifier) *Environ {
Outer: e,
Bit: NewBit(),
Qubit: NewQubit(),
GateDef: e.GateDef,
Gate: e.Gate,
Const: e.Const,
Modifier: mod,
Decl: append(e.Decl, decl),
}
}

func (e *Environ) String() string {
return fmt.Sprintf("gatedef: %v, const: %v, bit: %v, qubit: %v, modifier: %v, decl: %v", e.GateDef, e.Const, e.Bit, e.Qubit, e.Modifier, e.Decl)
return fmt.Sprintf("gate: %v, const: %v, bit: %v, qubit: %v, modifier: %v, decl: %v", e.Gate, e.Const, e.Bit, e.Qubit, e.Modifier, e.Decl)
}

type GateDef map[string]ast.Decl
type Gate map[string]ast.Decl

type Const map[string]object.Object

Expand Down
2 changes: 1 addition & 1 deletion evaluator/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,5 @@ func ExampleEnviron() {
fmt.Println(env)

// Output:
// gatedef: map[], const: map[], bit: [], map[], qubit: [], map[], modifier: [], decl: []
// gate: map[], const: map[], bit: [], map[], qubit: [], map[], modifier: [], decl: []
}
6 changes: 3 additions & 3 deletions evaluator/evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@ func (e *Evaluator) eval(n ast.Node, env *Environ) (obj object.Object, err error
return &object.Nil{}, e.GenDecl(n, env)

case *ast.GateDecl:
env.GateDef[ast.Must(ast.Ident(n))] = n
env.Gate[ast.Must(ast.Ident(n))] = n
return &object.Nil{}, nil

case *ast.FuncDecl:
env.GateDef[ast.Must(ast.Ident(n))] = n
env.Gate[ast.Must(ast.Ident(n))] = n
return &object.Nil{}, nil

case *ast.IdentExpr:
Expand Down Expand Up @@ -671,7 +671,7 @@ func (e *Evaluator) ModifyU(mod []ast.Modifier, u matrix.Matrix, env *Environ) m
}

func (e *Evaluator) Call(x *ast.CallExpr, outer *Environ) (object.Object, error) {
f, ok := outer.GateDef[x.Name]
f, ok := outer.Gate[x.Name]
if !ok {
return nil, fmt.Errorf("decl=%v not found", x.Name)
}
Expand Down

0 comments on commit 9e42934

Please sign in to comment.