@@ -65,7 +65,10 @@ pub enum ByteCode {
6565
6666 /// 函数调用 (函数索引, 参数数量)
6767 Call ( u16 , u8 ) ,
68-
68+
69+ /// 库函数调用 (库名, 函数名, 参数数量)
70+ CallLibrary ( String , String , u8 ) ,
71+
6972 /// 函数返回(返回值在栈顶)
7073 Return ,
7174
@@ -111,15 +114,18 @@ pub struct CompiledFunction {
111114pub struct CompiledProgram {
112115 /// 所有函数
113116 pub functions : HashMap < String , CompiledFunction > ,
114-
117+
115118 /// 主函数入口
116119 pub main_function : String ,
117-
120+
118121 /// 全局常量
119122 pub global_constants : Vec < Value > ,
120-
123+
121124 /// 类定义信息
122125 pub classes : HashMap < String , ClassInfo > ,
126+
127+ /// 导入的库映射
128+ pub imported_libraries : HashMap < String , std:: sync:: Arc < HashMap < String , crate :: interpreter:: library_loader:: LibraryFunction > > > ,
123129}
124130
125131/// 类信息
@@ -158,7 +164,8 @@ impl ByteCode {
158164 ByteCode :: JumpIfFalse ( _) => 0x31 ,
159165 ByteCode :: JumpIfTrue ( _) => 0x32 ,
160166 ByteCode :: Call ( _, _) => 0x40 ,
161- ByteCode :: Return => 0x41 ,
167+ ByteCode :: CallLibrary ( _, _, _) => 0x41 ,
168+ ByteCode :: Return => 0x42 ,
162169 ByteCode :: NewObject ( _) => 0x50 ,
163170 ByteCode :: LoadField ( _) => 0x51 ,
164171 ByteCode :: StoreField ( _) => 0x52 ,
@@ -179,6 +186,7 @@ impl ByteCode {
179186 ByteCode :: JumpIfFalse ( _) |
180187 ByteCode :: JumpIfTrue ( _) |
181188 ByteCode :: Call ( _, _) |
189+ ByteCode :: CallLibrary ( _, _, _) |
182190 ByteCode :: NewObject ( _) |
183191 ByteCode :: LoadField ( _) |
184192 ByteCode :: StoreField ( _)
@@ -207,6 +215,7 @@ impl ByteCode {
207215 ByteCode :: JumpIfFalse ( addr) => format ! ( "JumpIfFalse({})" , addr) ,
208216 ByteCode :: JumpIfTrue ( addr) => format ! ( "JumpIfTrue({})" , addr) ,
209217 ByteCode :: Call ( func_idx, argc) => format ! ( "Call({}, {})" , func_idx, argc) ,
218+ ByteCode :: CallLibrary ( lib_name, func_name, argc) => format ! ( "CallLibrary({}, {}, {})" , lib_name, func_name, argc) ,
210219 ByteCode :: Return => "Return" . to_string ( ) ,
211220 ByteCode :: NewObject ( class) => format ! ( "NewObject({})" , class) ,
212221 ByteCode :: LoadField ( field) => format ! ( "LoadField({})" , field) ,
0 commit comments