File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -113,6 +113,8 @@ int disassemble_instruction(Chunk* chunk, int offset)
113113 return simple_instruction ("OP_RETURN" , offset );
114114 case OP_CLASS :
115115 return constant_instruction ("OP_CLASS" , chunk , offset );
116+ case OP_METHOD :
117+ return constant_instruction ("OP_METHOD" , chunk , offset );
116118 default :
117119 printf ("Uknown opcode %d \n" , instruction );
118120 return offset + 1 ;
Original file line number Diff line number Diff line change @@ -159,6 +159,14 @@ static void close_upvalues(Value* last)
159159 }
160160}
161161
162+ static void define_method (ObjString * name )
163+ {
164+ Value method = peek (0 );
165+ ObjClass * klass = AS_CLASS (peek (1 ));
166+ table_set (& klass -> methods , name , method );
167+ pop ();
168+ }
169+
162170static ObjUpvalue * capture_upvalue (Value * local )
163171{
164172 ObjUpvalue * prev_upvalue = NULL ;
@@ -484,6 +492,9 @@ static InterpretResult run()
484492 case OP_CLASS :
485493 push (OBJ_VAL (new_class (READ_STRING ())));
486494 break ;
495+ case OP_METHOD :
496+ define_method (READ_STRING ());
497+ break ;
487498 }
488499 }
489500
You can’t perform that action at this time.
0 commit comments