⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 avcall.3

📁 c++写的一个脚本解释器
💻 3
字号:
.TH AVCALL 3 "14 January 2001".SH NAMEavcall \- build a C argument list incrementally and call a C function on it..SH SYNOPSIS.B #include <avcall.h>.LP.BI "av_alist " alist ";".LP.BI av_start_ type "(" alist ", " "&func".RI "[["\c.BI ", "\c.I return_type\c.RB "]" ", "\c.I "&return_value"\c.RB "]" ");".LP.BI av_ type "(" alist ", "\c.RI "["\c.IB arg_type ","\c.RI "] "\c.IB value ");".LP.BI "av_call(" alist ");".IX  "av_alist"  ""  "\fLav_alist\fP \(em avcall argument list declaration".IX  "av_start_type()"  ""  "\fLav_start_type()\fP \(em initialize avcall function".IX  "av_type()"  ""  "\fLav_type()\fP \(em push next argument in avcall list".IX  "av_call()"  ""  "\fLav_call()\fP \(em finish avcall argument list and call function".SH DESCRIPTION.LPThis set of macros builds an argument list for a C function and callsthe function on it. It significantly reduces the amount of `glue' coderequired for parsers, debuggers, imbedded interpreters, C extensions toapplication programs and other situations where collections of functionsneed to be called on lists of externally-supplied arguments.Function calling conventions differ considerably on differentmachines and.I avcallattempts to provide some degree of isolation from such architecturedependencies.The interface is like .BR stdarg (3)in reverse. All of the macros return 0 for success, < 0 for failure (e.g., argument list overflow or type-not-supported)..RS 0.TP(1).B #include <avcall.h>.nfand declare the argument list structure.BI "av_alist " alist ;.fi.TP(2)Set any special flags. This is architecture and compiler dependent.Compiler options that affect passing conventions may need to be flaggedby.BR "#define" sbefore the.B "#include <avcall.h>"statement. However, the.I configurescript should have determined which.BR "#define" sare needed and put themat the top of.BR avcall.h ..TP(3)Initialize the alist with the function address and return valuepointer (if any). There is a separate macro for each simple return type([u]char, [u]short, [u]int, [u]long, [u]longlong, float, double, where `u'indicates `unsigned'). The macros for functions returning structures orpointers require an explicit type argument..LPE.g.,.LP.BI "av_start_int (" alist ", " &func ", " &int_return );.LP.BI "av_start_double (" alist ", " &func ", " &double_return );.LP.BI "av_start_void (" alist ", " &func );.LP.nf.BI "av_start_struct (" alist ", " &func ", " struct_type ", " splittable ", ".BI "                 " &struct_return );.fi.LP.nf.BI "av_start_ptr (" alist ", " &func ", " pointer_type ", ".BI "              " &pointer_return );.fi.LPThe.I splittableflag specifies whether the.I struct_typecan be returned in registers such that every struct field fits entirely ina single register. This needs to be specified for structs of size2*sizeof(long). For structs of size <= sizeof(long),.I splittableis ignored and assumed to be 1. For structs of size > 2*sizeof(long),.I splittableis ignored and assumed to be 0. There are some handy macros for this:.nf.BI "av_word_splittable_1 (" type1 ).BI "av_word_splittable_2 (" type1 ", " type2 ).BI "av_word_splittable_3 (" type1 ", " type2 ", " type3 ).BI "av_word_splittable_4 (" type1 ", " type2 ", " type3 ", " type4 ).fiFor a struct with three slots.nf.BI "struct { " "type1 id1" "; " "type2 id2" "; " "type3 id3" "; }".fiyou can specify.I splittableas.BI "av_word_splittable_3 (" type1 ", " type2 ", " type3 ).RB ..TP(4)Push the arguments on to the list in order. Again there is a macrofor each simple built-in type, and the macros for structure and pointerarguments require an extra type argument:.LP.BI "av_int (" alist ", " int_value );.LP.BI "av_double (" alist ", " double_value );.LP.BI "av_struct (" alist ", " struct_or_union_type ", " struct_value );.LP.BI "av_ptr (" alist ", " pointer_type ", " pointer_value );.TP(5)Call the function, set the return value, and tidy up:.LP.BI "av_call (" alist );.RE.SH NOTES(1) Functions whose first declaration is in Kernighan & Ritchie style (i.e.,without a typed argument list) MUST use default K&R C expression promotions(char and short to int, float to double) whether they are compiled by a K&Ror an ANSI compiler, because the true argument types may not be known at thecall point. Such functions typically back-convert their arguments to the declared types on function entry. (In fact, the only way to pass a true char,short or float in K&R C is by an explicit cast: .B func((char)c,(float)f)). Similarly, some K&R compilers (such as Sun cc on the sparc) actuallyreturn a float as a double.Hence, for arguments of functions declared in K&R style you should use.B av_int(\|)and.B av_double(\|)rather than .B av_char(\|),.B av_short(\|)or.B av_float(\|).If you use a K&R compiler, the avcall header files may be able todetect this and define .B av_float(\|),etc, appropriately, but with an ANSI compiler there is no way .I avcallcan know how a function was declared, so you have to correct theargument types yourself.(2) The explicit type arguments of the .B av_struct(\|) and .B av_ptr(\|) macros are typically used to calculate size, alignment, and passingconventions.  This may not be sufficient for some machines with unusualstructure and pointer handling: in this case additional .B av_start_\c.I type\c.B (\|)and .B av_\c.I type\c.B (\|)macros may be defined.(3) The macros.BR av_start_longlong(\|) ,.BR av_start_ulonglong(\|) ,.B av_longlong(\|)and.B av_ulonglong(\|)work only if the C compiler has a working.B long long64-bit integer type.(4) The struct types used in.B av_start_struct(\|)and.B av_struct(\|)must only contain (signed or unsigned) int, long, long long or pointer fields.Struct types containing (signed or unsigned) char, short, float, double orother structs are not supported..SH SEE ALSO.BR stdarg (3),.BR varargs (3)..SH BUGSThe current implementations have been tested on a selection of commoncases but there are probably still many bugs.There are typically built-in limits on the size of the argument-list,which may also include the size of any structure arguments.The decision whether a struct is to be returned in registers or in memoryconsiders only the struct's size and alignment. This is inaccurate: forexample, gcc on m68k-next returns.B "struct { char a,b,c; }"in registers and.B "struct { char a[3]; }"in memory, although both types have the same size and the same alignment..SH NON-BUGSAll information is passed in CPU registers and the stack. The.B avcallpackage is therefore multithread-safe..SH PORTING AVCALLPorts, bug-fixes, and suggestions are most welcome. The macros requiredfor argument pushing are pretty grungy, but it does seem to be possibleto port avcall to a range of machines. Ports to non-standard ornon-32-bit machines are especially welcome so we can sort the interfaceout before it's too late.Knowledge about argument passing conventions can be found in the gccsource, file.RI gcc-2.6.3/config/ cpu / cpu .h,section "Stack layout; function entry, exit and calling."Some of the grunge is usually handled by a C or assembly level glueroutine that actually pushes the arguments, calls the function andunpacks any return value.This is called __builtin_avcall(\|). A precompiled assembler version forpeople without gcc is also made available. The routine should ideallyhave flags for the passing conventions of other compilers.Many of the current routines waste a lot of stack space and generally dohairy things to stack frames - a bit more assembly code would probablyhelp things along quite a bit here..SH AUTHORBill Triggs <Bill.Triggs@inrialpes.fr>. .SH ACKNOWLEDGEMENTSSome initial ideas were stolen from the C interface to the Zelkextensions to Oliver Laumann's Elk scheme interpreter by J.P.Lewis, NECC&C Research, <zilla@ccrl.nj.nec.com> (for Sun4 & SGI), and RoyFeatherstone's <roy@robots.oxford.ac.uk> personal C interface libraryfor Sun[34] & SGI.  I also looked at the machine-dependent parts of theGCC and GDB distributions, and put the gcc asm(\|) extensions to gooduse. Thanks guys!This work was partly supported by EC-ESPRIT Basic Research Action SECOND.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -