|
1 | 1 | // Copyright 2025 The Hulo Authors. All rights reserved. |
2 | 2 | // Use of this source code is governed by a MIT-style |
3 | 3 | // license that can be found in the LICENSE file. |
| 4 | + |
4 | 5 | package interpreter |
5 | 6 |
|
6 | 7 | import ( |
@@ -83,7 +84,7 @@ func (e *Environment) GetVariableInfo(name string) (*VariableInfo, bool) { |
83 | 84 | // Set 设置变量值(兼容旧接口) |
84 | 85 | func (e *Environment) Set(name string, obj object.Value) object.Value { |
85 | 86 | // 默认使用 var 作用域 |
86 | | - return e.SetWithScope(name, obj, token.LET, false) |
| 87 | + return e.SetWithScope(name, obj, token.VAR, false) |
87 | 88 | } |
88 | 89 |
|
89 | 90 | // SetWithScope 根据作用域设置变量 |
@@ -188,8 +189,8 @@ func (e *Environment) IsReadOnly(name string) bool { |
188 | 189 | } |
189 | 190 |
|
190 | 191 | // 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) |
193 | 194 |
|
194 | 195 | // 添加 const 变量 |
195 | 196 | for name, info := range e.consts { |
@@ -218,3 +219,14 @@ func (e *Environment) GetAll() map[string]interface{} { |
218 | 219 |
|
219 | 220 | return result |
220 | 221 | } |
| 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