
var cobs = require('../..'),
    http = require('http'),
    fs = require('fs');

function compileFile(filename) {
    var text = fs.readFileSync(filename).toString();
    var parser = new cobs.Parser(text);
    var program = parser.parseProgram();
    program.text = program.command.compile(program);
    return program;
};

var program = compileFile('./factorial.cob');

http.createServer(function(req, res) {
    var runtime = {
        display: function() {
            if (arguments && arguments.length)
                for (var k = 0; k < arguments.length; k++)
                    if (arguments[k])
                        res.write(arguments[k].toString());
                        
            res.write('\r\n');
        }
    }
    
    cobs.run(program.text, runtime, program);
    
    res.end();
}).listen(8000);

console.log('Server started, listening at port 8000');

var cobs = require('../..'),
    http = require('http'),
    fs = require('fs');

function compileFile(filename) {
    return cobs.compileProgramFile(filename);
};

var program = compileFile('./factorial.cob');

http.createServer(function(req, res) {
    var runtime = {
        display: function() {
            if (arguments && arguments.length)
                for (var k = 0; k < arguments.length; k++)
                    if (arguments[k])
                        res.write(arguments[k].toString());
                        
            res.write('\r\n');
        }
    }

    program.run(runtime);
    
    res.end();
}).listen(8000);

console.log('Server started, listening at port 8000');
Refactor factorial web sample to use compileProgramFile
Refactor factorial web sample to use compileProgramFile
