2014-05-18 13:46:57 -04:00
USING: alien alien.c-types compiler.tree effects help.markup help.syntax
quotations sequences ;
2014-05-16 12:15:14 -04:00
IN: stack-checker.alien
2014-05-18 13:46:57 -04:00
HELP: alien-node-params
{ $class-description "Base class for the parameter slot of " { $link #alien-node } " nodes. It has the following slots:"
{ $table
{ { $slot "return" } { "a " { $link c-type-name } " which indicates the type of the functions return value." } }
{ { $slot "parameters" } { "a " { $link sequence } " of " { $link c-type-name } " giving the types of the functions parameters." } }
}
} ;
2014-10-13 02:33:27 -04:00
HELP: alien-callback-params
{ $class-description "Class that holds the parameter types and return value type of an alien callback call." }
{ $see-also #alien-callback } ;
2014-05-18 13:46:57 -04:00
HELP: param-prep-quot
{ $values { "params" alien-node-params } { "quot" quotation } }
{ $description "Builds a quotation which coerces values on the stack to the required types for the alien call." }
{ $examples
2014-07-03 15:21:17 -04:00
{ $unchecked-example
2014-06-09 17:15:18 -04:00
"USING: alien.c-types prettyprint stack-checker.alien ;"
2014-05-18 13:46:57 -04:00
"T{ alien-invoke-params { parameters { void* c-string int } } } param-prep-quot ."
2014-06-09 17:15:18 -04:00
"[ [ [ [ ] dip >c-ptr ] dip \\ utf8 string>alien ] dip >fixnum ]"
2014-05-18 13:46:57 -04:00
}
} ;
2014-10-13 02:33:27 -04:00
HELP: callback-parameter-quot
2014-10-19 08:05:06 -04:00
{ $values { "params" alien-node-params } { "quot" quotation } }
2014-10-13 02:33:27 -04:00
{ $description "Builds a quotation which coerces values on the stack to the required types for an alien callback. This word is essentially the opposite to " { $link param-prep-quot } "." }
{ $examples
{ $unchecked-example
"USING: alien.c-types prettyprint stack-checker.alien ;"
"T{ alien-node-params { parameters { c-string } } } callback-parameter-quot ."
"[ { object } declare [ ] dip \ utf8 alien>string ]"
}
} ;
2014-05-16 12:15:14 -04:00
HELP: infer-alien-invoke
{ $description "Appends the necessary SSA nodes for performing an " { $link alien-invoke } " call to the IR tree being constructed." } ;
2014-10-13 02:33:27 -04:00
HELP: wrap-callback-quot
2014-10-19 08:05:06 -04:00
{ $values { "params" alien-node-params } { "quot" quotation } { "quot'" quotation } }
2014-10-13 02:33:27 -04:00
{ $description "Wraps the given quotation in protective packaging so that it becomes suitable to be used as an alien callback. That means that the parameters are unpacked from C types to Factor types and, if the callback returns something, the top data stack item is afterwards converted to a C compatible value." }
{ $examples
"Here a callback that returns the length of a " { $link c-string } " is wrapped:"
{ $unchecked-example
"USING: alien.c-types prettyprint stack-checker.alien ;"
"T{ alien-node-params { return int } { parameters { c-string } } } "
"[ length ] wrap-callback-quot ."
"["
" ["
" { object } declare [ ] dip \ utf8 alien>string"
" length >fixnum"
" ] ["
" dup current-callback eq?"
" [ drop ] [ wait-for-callback ] if"
" ] do-callback"
"]"
}
} ;