runtimejs / runtime

[not maintained] Lightweight JavaScript library operating system for the cloud
http://runtimejs.org
Apache License 2.0
1.93k stars 127 forks source link

Stdio lint and cleanup, few improvements #66

Closed iefserge closed 9 years ago

iefserge commented 9 years ago

Did some stdio lint and cleanup.

Also few improvements:

R = @ArielAbreu Please confirm that it works for you, not very well tested.

facekapow commented 9 years ago

@iefserge The following code:

'use strict';

const runtime = require('runtimejs');

runtime.stdio.defaultStdio.writeLine('hey');

...Produces the following error:

Uncaught exception: /bundle.js:6746: TypeError: memoryBarrier is not a function
TypeError: memoryBarrier is not a function
    at VRing.placeBuffers (/bundle.js:6746:3)
    at fillReceiveQueue (/bundle.js:6338:22)
    at initializeNetworkDevice (/bundle.js:6386:3)
    at Object.driver.init (/bundle.js:6204:14)
    at PciDevice.setDriver (/bundle.js:4151:10)
    at Object.exports.addDriver (/bundle.js:4087:12)
    at Object.62.../../core (/bundle.js:6216:13)
    at s (/bundle.js:1:254)
    at /bundle.js:1:305
    at Object.<anonymous> (/bundle.js:6934:1)
# ...
# And lots more `memoryBarrier` errors on different lines

It may be it's a scope error. Maybe put it inside the VRing function?

iefserge commented 9 years ago

@ArielAbreu memoryBarrier is a native function. Kernel needs to be updated (>= 0.1.11), try npm install runtime-tools@latest

facekapow commented 9 years ago

@iefserge OK! Now printing works, let me test the other things (reading, erroring...).

facekapow commented 9 years ago

@iefserge By 'throw on nested readLine', you mean passing another readLine as the callback for a readline, right? This is still valid:

runtime.stdio.defaultStdio.readLine(function(text) {
  runtime.stdio.defaultStdio.readLine(function(text2) {
    // ...
  });
});

Right?

iefserge commented 9 years ago

nope, that should work.

Code below should throw (trying to read line while reading another line):

runtime.stdio.defaultStdio.readLine(function(text) {});
runtime.stdio.defaultStdio.readLine(function(text2) {});
facekapow commented 9 years ago

@iefserge It works perfectly! Though, writeError should add a newline at the end of the string if given a string: runtime.stdio.defaultStdio.writeError('blah') -> prints: 'blah(otherstuff)' should print: 'blah\n(otherstuff)'. Guess, I overlooked that in my PR. :+1: Looks nice! I also notice (don't know if it's just me) that with the new improvements, the shell loads faster and is ready to accept input faster!

iefserge commented 9 years ago

@ArielAbreu Thanks!

facekapow commented 9 years ago

@iefserge No problem!