added the code_start_loc field to moo_method_data_t and updated emit_byte_instruction()
to get distance of the instruction being emitted
This commit is contained in:
		@ -2513,7 +2513,20 @@ static MOO_INLINE int emit_byte_instruction (moo_t* moo, moo_oob_t code, const m
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	cc->mth.code.ptr[cc->mth.code.len] = code;
 | 
			
		||||
	if (srcloc) cc->mth.code.locptr[cc->mth.code.len] = srcloc->line;
 | 
			
		||||
	if (srcloc) 
 | 
			
		||||
	{
 | 
			
		||||
		/* store the distance from the method body start */
 | 
			
		||||
		if (srcloc->file == cc->mth.code_start_loc.file && srcloc->line >= cc->mth.code_start_loc.line)
 | 
			
		||||
		{
 | 
			
		||||
			cc->mth.code.locptr[cc->mth.code.len] = srcloc->line - cc->mth.code_start_loc.line;
 | 
			
		||||
		}
 | 
			
		||||
		else
 | 
			
		||||
		{
 | 
			
		||||
			/* i can't record the distance as the method body is not in the same file */
 | 
			
		||||
			/* TODO: warning, error handling? */
 | 
			
		||||
			cc->mth.code.locptr[cc->mth.code.len] = 0;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	cc->mth.code.len++;
 | 
			
		||||
 | 
			
		||||
	return 0;
 | 
			
		||||
@ -4148,7 +4161,7 @@ static int compile_method_name (moo_t* moo, moo_method_data_t* mth)
 | 
			
		||||
 | 
			
		||||
	MOO_ASSERT (moo, mth->tmpr_count == 0);
 | 
			
		||||
 | 
			
		||||
	mth->name_loc = moo->c->tok.loc;
 | 
			
		||||
	mth->name_loc = *TOKEN_LOC(moo);
 | 
			
		||||
	switch (TOKEN_TYPE(moo))
 | 
			
		||||
	{
 | 
			
		||||
		case MOO_IOTOK_IDENT:
 | 
			
		||||
@ -7035,6 +7048,7 @@ static void reset_method_data (moo_t* moo, moo_method_data_t* mth)
 | 
			
		||||
	mth->pfnum = 0;
 | 
			
		||||
	mth->blk_depth = 0;
 | 
			
		||||
	mth->code.len = 0;
 | 
			
		||||
	MOO_MEMSET (&mth->code_start_loc, 0, MOO_SIZEOF(mth->code_start_loc));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int process_method_modifiers (moo_t* moo, moo_method_data_t* mth)
 | 
			
		||||
@ -7309,6 +7323,7 @@ static int __compile_method_definition (moo_t* moo)
 | 
			
		||||
			return -1;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		cc->mth.code_start_loc = *TOKEN_LOC(moo); /* set it to the location of the opening brace */
 | 
			
		||||
		GET_TOKEN (moo);
 | 
			
		||||
 | 
			
		||||
		if (compile_method_temporaries(moo) <= -1 ||
 | 
			
		||||
 | 
			
		||||
@ -533,6 +533,7 @@ struct moo_method_data_t
 | 
			
		||||
 | 
			
		||||
	/* byte code */
 | 
			
		||||
	moo_code_t code;
 | 
			
		||||
	moo_ioloc_t code_start_loc; /* source location of the method body opening brace */
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
typedef struct moo_cunit_class_t moo_cunit_class_t;
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user