summaryrefslogtreecommitdiff
path: root/src/compiler.cc
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2015-04-01 10:24:42 -0400
committerAdrian Thurston <thurston@complang.org>2015-04-01 10:24:42 -0400
commit24e144ea5fd1275bf6c864455b2dd4d96e589363 (patch)
tree5c35d484904e32626a862bd5784b882a4f27d4b8 /src/compiler.cc
parent03e0f380a472db828c3bd5ae481a6b1c10fed3d0 (diff)
downloadcolm-24e144ea5fd1275bf6c864455b2dd4d96e589363.tar.gz
first cut of C extensions
Diffstat (limited to 'src/compiler.cc')
-rw-r--r--src/compiler.cc48
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();
}