File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -78,6 +78,8 @@ int disassemble_instruction(Chunk* chunk, int offset)
7878 return jump_instruction ("OP_JUMP_IF_FALSE" , 1 , chunk , offset );
7979 case OP_LOOP :
8080 return jump_instruction ("OP_JUMP_IF_FALSE" , -1 , chunk , offset );
81+ case OP_CALL :
82+ return byte_instruction ("OP_CALL" , chunk , offset );
8183 case OP_RETURN :
8284 return simple_instruction ("OP_RETURN" , offset );
8385 default :
Original file line number Diff line number Diff line change @@ -71,6 +71,18 @@ static Value peek(int distance)
7171
7272static bool call (ObjFunction * function , int arg_count )
7373{
74+ if (function -> arity != arg_count )
75+ {
76+ runtime_error ("Expected %d arguments but got %d." , function -> arity ,
77+ arg_count );
78+ }
79+ if (vm .frame_count == FRAMES_MAX )
80+ {
81+ // as Java developer i hate this exception,
82+ // but sorry there no way to increase stack size here like jvm does :Joy
83+ runtime_error ("Stack Overflow" );
84+ return false;
85+ }
7486 CallFrame * frame = & vm .frames [vm .frame_count ++ ];
7587 frame -> function = function ;
7688 frame -> ip = function -> chunk .code ;
@@ -321,6 +333,7 @@ InterpretResult interpret(char* source)
321333 return INTERPRET_COMPILE_ERROR ;
322334
323335 push (OBJ_VAL (function ));
336+ call_value (OBJ_VAL (function ), 0 );
324337 CallFrame * frame = & vm .frames [vm .frame_count ++ ];
325338 frame -> function = function ;
326339 frame -> ip = function -> chunk .code ;
You can’t perform that action at this time.
0 commit comments