diff options
Diffstat (limited to 'src/compiler.cc')
-rw-r--r-- | src/compiler.cc | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/compiler.cc b/src/compiler.cc index 300d84db..0d2d48d6 100644 --- a/src/compiler.cc +++ b/src/compiler.cc @@ -395,6 +395,7 @@ Compiler::Compiler( ) nextPatConsId(0), nextGenericId(1), nextFuncId(0), + nextHostId(0), nextObjectId(1), /* 0 is reserved for no object. */ nextFrameId(0), nextParserId(0), @@ -1093,6 +1094,53 @@ void Compiler::generateOutput( long activeRealm ) if ( !gblLibrary ) fsmGen->writeMain( activeRealm ); + if ( !gblLibrary ) { + for ( FunctionList::Iter hc = inHostList; hc.lte(); hc++ ) { + *outStream << + "Value " << hc->hostCall << "( Program *prg"; + for ( ParameterList::Iter p = *hc->paramList; p.lte(); p++ ) { + *outStream << + ", Value"; + } + *outStream << " );\n"; + } + + *outStream << + "Tree **host_call( Program *prg, long code, Tree **sp )\n" + "{\n" + " Value rtn = 0;\n" + " switch ( code ) {\n"; + + for ( FunctionList::Iter hc = inHostList; hc.lte(); hc++ ) { + *outStream << + " case " << hc->funcId << ": {\n"; + + int pos = 0; + for ( ParameterList::Iter p = *hc->paramList; p.lte(); p++, pos++ ) { + *outStream << + " Value p" << pos << " = vm_pop_value();\n"; + } + + *outStream << + " rtn = " << hc->hostCall << "( prg"; + + pos = 0; + for ( ParameterList::Iter p = *hc->paramList; p.lte(); p++, pos++ ) { + *outStream << + ", p" << pos; + } + *outStream << " );\n" + " break;\n" + " }\n"; + } + + *outStream << + " }\n" + " vm_push_value( rtn );\n" + " return sp;\n" + "}\n"; + } + outStream->flush(); } |