Skip to content

Commit 65561ee

Browse files
committed
improve code
1 parent 4f03ce5 commit 65561ee

32 files changed

Lines changed: 7534 additions & 4167 deletions

internal/interpreter/env.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright 2025 The Hulo Authors. All rights reserved.
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
4+
45
package interpreter
56

67
import (
@@ -83,7 +84,7 @@ func (e *Environment) GetVariableInfo(name string) (*VariableInfo, bool) {
8384
// Set 设置变量值(兼容旧接口)
8485
func (e *Environment) Set(name string, obj object.Value) object.Value {
8586
// 默认使用 var 作用域
86-
return e.SetWithScope(name, obj, token.LET, false)
87+
return e.SetWithScope(name, obj, token.VAR, false)
8788
}
8889

8990
// SetWithScope 根据作用域设置变量
@@ -188,8 +189,8 @@ func (e *Environment) IsReadOnly(name string) bool {
188189
}
189190

190191
// GetAll 获取所有变量的映射
191-
func (e *Environment) GetAll() map[string]interface{} {
192-
result := make(map[string]interface{})
192+
func (e *Environment) GetAll() map[string]any {
193+
result := make(map[string]any)
193194

194195
// 添加 const 变量
195196
for name, info := range e.consts {
@@ -218,3 +219,14 @@ func (e *Environment) GetAll() map[string]interface{} {
218219

219220
return result
220221
}
222+
223+
func (e *Environment) GetType(name string) (object.Type, bool) {
224+
if typ, ok := e.types[name]; ok {
225+
return typ, true
226+
}
227+
return nil, false
228+
}
229+
230+
func (e *Environment) SetType(name string, typ object.Type) {
231+
e.types[name] = typ
232+
}

0 commit comments

Comments
 (0)