Пример #1
0
Ref makeSysFn( CodeGen codegen, std::string fn_name, Ref default_value ) {

	SysMap::iterator smit = SysMap::systemFunctionsMap().find( fn_name );
	if ( smit == SysMap::systemFunctionsMap().end() ) {
		return default_value;
	}
	SysInfo & info = smit->second;
	
	Ref x = info.coreFunctionObject;
	if ( x != NULL ) return x;

	codegen->vmiFUNCTION( fn_name, info.in_arity.count(), info.out_arity.count() );
	
	//	We have two different kinds of system functions. Those that are
	//	implemented as native instructions and those that are implemented
	//	by hand-written functions.
	//
	//	The test that distinguishes them is unsatisfactory because it fails
	//	to distinguish an omitted something from a genuine choice.
	//	REFACTOR.
	//
	if ( info.isSysCall() ) {
		//	Hand-written function.
		codegen->vmiSYS_CALL( info.syscall );	
	} else if ( info.isVMOp() ) {
		//	Native instruction.
		codegen->vmiINSTRUCTION( info.instruction );
	} else {
		throw SystemError( "Internal error" );
	}
	codegen->vmiSYS_RETURN();
	Ref r = codegen->vmiENDFUNCTION( false );
	
	info.coreFunctionObject = r;
	return r;
	
}