Exemple #1
0
Ref * sysNewMethod( Ref * pc, MachineClass * vm ) {
	//	newMethod( name:String, ninputs:Small, noutputs:Small ) -> m:Method
	if ( vm->count != 3 ) throw Ginger::Mishap( "Wrong number of arguments" );
	
	Ref noutputs = vm->fastPop();
	Ref ninputs = vm->fastPop();
	Ref name = vm->fastPop();
	
	if ( !IsSmall( noutputs ) || !IsSmall( ninputs ) ) throw Ginger::Mishap( "Invalid arguments" ).culprit( "#Outputs", refToString( noutputs ) ).culprit( "Inputs", refToString( ninputs ) );
	
	CodeGen codegen = vm->codegen();
	codegen->vmiFUNCTION( 
		name == SYS_ABSENT ? std::string( EMPTY_FN_NAME ) : refToString( name ),
		SmallToLong( ninputs ), 
		SmallToLong( noutputs ) 
	);
	codegen->vmiINVOKE();
	Ref r = codegen->vmiENDFUNCTION( sysMethodKey );
	vm->fastPush( r );	//	No check needed, as stack has room for 3.
	return pc;
}