Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

documentation generator, dup/pipe syscalls

  • Loading branch information...
commit f0b0d04a42bc627a50a03f9f46f065471db6e5df 1 parent c64b0c8
@charliesome authored
View
8 Makefile
@@ -4,7 +4,8 @@ CFLAGS=-m32 -Wall -Wextra -iquote inc -g -Wno-unused-parameter -nostdlib \
LDFLAGS=-nostdlib -static
-kernel: twostroke/LICENSE libc/libc.a vm/libjsvm.a kernel/hdd.img
+all: twostroke/LICENSE libc/libc.a vm/libjsvm.a kernel/hdd.img \
+ docs/syscalls.md
twostroke/LICENSE:
git submodule update --init
@@ -20,9 +21,14 @@ kernel/hdd.img:
.PHONY: libc/libc.a vm/libjsvm.a kernel/hdd.img
+docs/syscalls.md: kernel/js/kernel/process.js scripts/generate-syscall-docs.rb
+ @ruby scripts/generate-syscall-docs.rb > $@
+ @echo " doc $@"
+
clean:
rm -f userland
rm -f *.o
+ rm -f docs/*.md
make -C libc clean
make -C vm clean
make -C kernel clean
View
26 kernel/js/kernel/process.js
@@ -80,7 +80,14 @@ Process = (function() {
g.OS.stdin = 0;
g.OS.stdout = 1;
g.OS.stderr = 2;
+
+ // Yields control to another process
+ //
+ // callback: A function the operating system should return control to
g.OS.yield = vm.exposeFunction(function(callback) {
+ if(typeof callback !== "function") {
+ throw self.createSystemError("expected 'callback' to be a function");
+ }
self.enqueueCallback(callback);
});
g.OS.argv = vm.createArray();
@@ -281,6 +288,25 @@ Process = (function() {
g.OS.exit = vm.exposeFunction(function() {
self.kill();
});
+ g.OS.dup = vm.exposeFunction(function(src, dest) {
+ if(typeof src !== "number") {
+ throw self.createSystemError("expected 'src' to be a number");
+ }
+ if(!self.fds[src]) {
+ throw self.createSystemError("bad file descriptor");
+ }
+ if(typeof dest === "undefined") {
+ return self.appendFileDescriptor(self.fds[src]);
+ }
+ if(typeof dest !== "number") {
+ throw self.createSystemError("expected 'dest' to be a number");
+ }
+ self.fds[dest] = self.fds[src];
+ return dest;
+ });
+ g.OS.pipe = vm.exposeFunction(function() {
+ return self.appendFileDescriptor(new Pipe());
+ });
};
Process.prototype.enqueueCallback = function(callback, args) {
View
39 scripts/generate-syscall-docs.rb
@@ -0,0 +1,39 @@
+# coding: utf-8
+
+puts "# JSOS System Calls"
+
+lines = File.readlines "kernel/js/kernel/process.js"
+
+SYSCALL_RE = %r{g\.OS\.(?<name>[a-z0-9_]+) =}i
+ARGS_RE = %r{exposeFunction\(function\((?<args>[a-z0-9_,\s]*)\)}
+DOC_COMMENT_RE = %r{^\s+(//(?<comment>.*))?$}
+DOC_FIELD_RE = %r{^\s*(?<field_name>[a-z0-9_]+):}
+
+lines.each_with_index.select { |line, idx| line =~ SYSCALL_RE }.each do |defn, line|
+ syscall = defn.match(SYSCALL_RE)[:name]
+ next unless defn.include? "exposeFunction"
+
+ # extract arguments out of function
+ args = defn.match(ARGS_RE)[:args].split(",").map(&:strip)
+
+ # find doc comments
+ comment = lines[0...line].reverse_each.take_while { |s| s =~ DOC_COMMENT_RE }.reverse.map { |s| s.match(DOC_COMMENT_RE)[:comment] || "" }
+
+ description, *fields_raw = comment.slice_before { |l| l =~ DOC_FIELD_RE }.to_a
+ description ||= ["undocumented"]
+ fields = Hash[fields_raw.map { |x| x.join(" ").match(DOC_FIELD_RE) }.map { |md| [md[:field_name].intern, md.post_match.strip] }]
+
+ str = "### #{syscall}(#{args.map { |a| "`#{a}`" }.join ", "})\n\n"
+ description.each do |l|
+ str << "> #{l.strip}\n"
+ end
+ str << "\n"
+ if fields.any?
+ fields.each do |k, v|
+ str << "> **#{k}:** #{v}\n\n"
+ end
+ end
+ str << "[Source](../kernel/js/kernel/process.js#L#{line + 1})\n\n"
+
+ puts str
+end

0 comments on commit f0b0d04

Please sign in to comment.
Something went wrong with that request. Please try again.