[project] Generate syscalls from new interface DSL
This change adds a new interface DSL for specifying objects (with methods) and interfaces (that expose objects, and optionally have their own methods). Significant changes: - Add the new scripts/definitions Python module to parse the DSL - Add the new definitions directory containing DSL definition files - Use cog to generate syscall-related code in kernel and libj6 - Unify ordering of pointer + length pairs in interfaces
This commit is contained in:
60
src/kernel/syscall.h.cog
Normal file
60
src/kernel/syscall.h.cog
Normal file
@@ -0,0 +1,60 @@
|
||||
#pragma once
|
||||
// vim: ft=cpp
|
||||
|
||||
#include <stdint.h>
|
||||
#include "j6/types.h"
|
||||
|
||||
struct cpu_state;
|
||||
|
||||
/*[[[cog code generation
|
||||
from definitions.context import Context
|
||||
|
||||
ctx = Context(definitions_path)
|
||||
ctx.parse("syscalls.def")
|
||||
syscalls = ctx.interfaces["syscalls"]
|
||||
|
||||
]]]*/
|
||||
/// [[[end]]]
|
||||
|
||||
enum class syscall : uint64_t
|
||||
{
|
||||
/*[[[cog code generation
|
||||
|
||||
for id, scope, method in syscalls.methods:
|
||||
if scope:
|
||||
name = f"{scope.name}_{method.name}"
|
||||
else:
|
||||
name = method.name
|
||||
cog.outl(f"{name:20} = {id},")
|
||||
|
||||
]]]*/
|
||||
//[[[end]]]
|
||||
};
|
||||
|
||||
void syscall_initialize();
|
||||
extern "C" void syscall_enable();
|
||||
|
||||
namespace syscalls
|
||||
{
|
||||
/*[[[cog code generation
|
||||
|
||||
for id, scope, method in syscalls.methods:
|
||||
if scope:
|
||||
name = f"{scope.name}_{method.name}"
|
||||
else:
|
||||
name = method.name
|
||||
|
||||
args = []
|
||||
if method.constructor:
|
||||
args.append("j6_handle_t *handle")
|
||||
elif not method.static:
|
||||
args.append("j6_handle_t handle")
|
||||
|
||||
for param in method.params:
|
||||
for type, suffix in param.type.c_names(param.options):
|
||||
args.append(f"{type} {param.name}{suffix}")
|
||||
|
||||
cog.outl(f"""j6_status_t {name} ({", ".join(args)});""")
|
||||
]]]*/
|
||||
//[[[end]]]
|
||||
}
|
||||
Reference in New Issue
Block a user