11const jacsFactory = require ( "./vm" )
22const fs = require ( "fs" )
33const path = require ( "path" )
4+ const child_process = require ( "child_process" )
45
56const ctest = "compiler/compiler-tests"
6- const samples = "compiler/ samples"
7+ const samples = "samples"
78const rtest = "compiler/run-tests"
89const distPath = "built"
910let verbose = false
11+ let useC = false
1012
1113let jacsHost
1214async function getHost ( ) {
@@ -31,6 +33,8 @@ async function getHost() {
3133async function compile ( buf ) {
3234 const jacscript = require ( "./compiler" )
3335 const res = jacscript . compile ( await getHost ( ) , buf . toString ( "utf8" ) )
36+ if ( ! res . success )
37+ throw new Error ( "compilation failed" )
3438 return res . binary
3539}
3640
@@ -85,6 +89,15 @@ async function runTest(fn) {
8589}
8690
8791async function runServer ( fn ) {
92+ if ( useC ) {
93+ const prog = await readCompiled ( fn )
94+ const compfn = distPath + "/compiled.jacs"
95+ fs . writeFileSync ( compfn , prog )
96+ child_process . spawn ( distPath + "/jdcli" , [ "8082" , compfn ] , {
97+ stdio : "inherit"
98+ } )
99+ return
100+ }
88101 const inst = await jacsFactory ( )
89102 await inst . setupNodeTcpSocketTransport ( require , "localhost" , 8082 )
90103 inst . jacsStart ( )
@@ -104,9 +117,19 @@ function readdir(folder) {
104117
105118async function main ( ) {
106119 const args = process . argv . slice ( 2 )
107- if ( args [ 0 ] == "-v" ) {
108- args . shift ( )
109- verbose = true
120+
121+ while ( true ) {
122+ if ( args [ 0 ] == "-v" ) {
123+ args . shift ( )
124+ verbose = true
125+ continue
126+ }
127+ if ( args [ 0 ] == "-c" ) {
128+ args . shift ( )
129+ useC = true
130+ continue
131+ }
132+ break
110133 }
111134
112135 let testMode = false
0 commit comments