Rust: Run codegen

This commit is contained in:
Tom Hvitved
2024-10-11 12:00:49 +02:00
parent b284a2a7c0
commit 8cc349e85f
18 changed files with 304 additions and 201 deletions

View File

@@ -1,2 +1,2 @@
mod.rs 4bcb9def847469aae9d8649461546b7c21ec97cf6e63d3cf394e339915ce65d7 4bcb9def847469aae9d8649461546b7c21ec97cf6e63d3cf394e339915ce65d7
top.rs 170c3892b5cbb8be28ae420a92ebab3b96b354c3b7ea2ba96edec64e639e8455 170c3892b5cbb8be28ae420a92ebab3b96b354c3b7ea2ba96edec64e639e8455
top.rs 7c68cdb6a44e3f1ac27601f006a8c583ef1e5f198fd9c30a6710ffade2612d80 7c68cdb6a44e3f1ac27601f006a8c583ef1e5f198fd9c30a6710ffade2612d80

View File

@@ -390,6 +390,42 @@ impl From<trap::Label<Attr>> for trap::Label<Locatable> {
}
}
#[derive(Debug)]
pub struct Callable {
_unused: ()
}
impl trap::TrapClass for Callable {
fn class_name() -> &'static str { "Callable" }
}
impl From<trap::Label<Callable>> for trap::Label<AstNode> {
fn from(value: trap::Label<Callable>) -> Self {
// SAFETY: this is safe because in the dbscheme Callable is a subclass of AstNode
unsafe {
Self::from_untyped(value.as_untyped())
}
}
}
impl From<trap::Label<Callable>> for trap::Label<Element> {
fn from(value: trap::Label<Callable>) -> Self {
// SAFETY: this is safe because in the dbscheme Callable is a subclass of Element
unsafe {
Self::from_untyped(value.as_untyped())
}
}
}
impl From<trap::Label<Callable>> for trap::Label<Locatable> {
fn from(value: trap::Label<Callable>) -> Self {
// SAFETY: this is safe because in the dbscheme Callable is a subclass of Locatable
unsafe {
Self::from_untyped(value.as_untyped())
}
}
}
#[derive(Debug)]
pub struct ClosureBinder {
pub id: trap::TrapId<ClosureBinder>,
@@ -3769,6 +3805,7 @@ impl From<trap::Label<CastExpr>> for trap::Label<Locatable> {
#[derive(Debug)]
pub struct ClosureExpr {
pub id: trap::TrapId<ClosureExpr>,
pub param_list: Option<trap::Label<ParamList>>,
pub attrs: Vec<trap::Label<Attr>>,
pub body: Option<trap::Label<Expr>>,
pub closure_binder: Option<trap::Label<ClosureBinder>>,
@@ -3777,7 +3814,6 @@ pub struct ClosureExpr {
pub is_gen: bool,
pub is_move: bool,
pub is_static: bool,
pub param_list: Option<trap::Label<ParamList>>,
pub ret_type: Option<trap::Label<RetType>>,
}
@@ -3788,8 +3824,11 @@ impl trap::TrapEntry for ClosureExpr {
fn emit(self, id: trap::Label<Self>, out: &mut trap::Writer) {
out.add_tuple("closure_exprs", vec![id.into()]);
if let Some(v) = self.param_list {
out.add_tuple("callable_param_lists", vec![id.into(), v.into()]);
}
for (i, v) in self.attrs.into_iter().enumerate() {
out.add_tuple("closure_expr_attrs", vec![id.into(), i.into(), v.into()]);
out.add_tuple("callable_attrs", vec![id.into(), i.into(), v.into()]);
}
if let Some(v) = self.body {
out.add_tuple("closure_expr_bodies", vec![id.into(), v.into()]);
@@ -3812,9 +3851,6 @@ impl trap::TrapEntry for ClosureExpr {
if self.is_static {
out.add_tuple("closure_expr_is_static", vec![id.into()]);
}
if let Some(v) = self.param_list {
out.add_tuple("closure_expr_param_lists", vec![id.into(), v.into()]);
}
if let Some(v) = self.ret_type {
out.add_tuple("closure_expr_ret_types", vec![id.into(), v.into()]);
}
@@ -3834,6 +3870,15 @@ impl From<trap::Label<ClosureExpr>> for trap::Label<AstNode> {
}
}
impl From<trap::Label<ClosureExpr>> for trap::Label<Callable> {
fn from(value: trap::Label<ClosureExpr>) -> Self {
// SAFETY: this is safe because in the dbscheme ClosureExpr is a subclass of Callable
unsafe {
Self::from_untyped(value.as_untyped())
}
}
}
impl From<trap::Label<ClosureExpr>> for trap::Label<Element> {
fn from(value: trap::Label<ClosureExpr>) -> Self {
// SAFETY: this is safe because in the dbscheme ClosureExpr is a subclass of Element
@@ -8400,8 +8445,9 @@ impl From<trap::Label<ExternCrate>> for trap::Label<Stmt> {
#[derive(Debug)]
pub struct Function {
pub id: trap::TrapId<Function>,
pub abi: Option<trap::Label<Abi>>,
pub param_list: Option<trap::Label<ParamList>>,
pub attrs: Vec<trap::Label<Attr>>,
pub abi: Option<trap::Label<Abi>>,
pub body: Option<trap::Label<BlockExpr>>,
pub generic_param_list: Option<trap::Label<GenericParamList>>,
pub is_async: bool,
@@ -8410,7 +8456,6 @@ pub struct Function {
pub is_gen: bool,
pub is_unsafe: bool,
pub name: Option<trap::Label<Name>>,
pub param_list: Option<trap::Label<ParamList>>,
pub ret_type: Option<trap::Label<RetType>>,
pub visibility: Option<trap::Label<Visibility>>,
pub where_clause: Option<trap::Label<WhereClause>>,
@@ -8423,11 +8468,14 @@ impl trap::TrapEntry for Function {
fn emit(self, id: trap::Label<Self>, out: &mut trap::Writer) {
out.add_tuple("functions", vec![id.into()]);
if let Some(v) = self.abi {
out.add_tuple("function_abis", vec![id.into(), v.into()]);
if let Some(v) = self.param_list {
out.add_tuple("callable_param_lists", vec![id.into(), v.into()]);
}
for (i, v) in self.attrs.into_iter().enumerate() {
out.add_tuple("function_attrs", vec![id.into(), i.into(), v.into()]);
out.add_tuple("callable_attrs", vec![id.into(), i.into(), v.into()]);
}
if let Some(v) = self.abi {
out.add_tuple("function_abis", vec![id.into(), v.into()]);
}
if let Some(v) = self.body {
out.add_tuple("function_bodies", vec![id.into(), v.into()]);
@@ -8453,9 +8501,6 @@ impl trap::TrapEntry for Function {
if let Some(v) = self.name {
out.add_tuple("function_names", vec![id.into(), v.into()]);
}
if let Some(v) = self.param_list {
out.add_tuple("function_param_lists", vec![id.into(), v.into()]);
}
if let Some(v) = self.ret_type {
out.add_tuple("function_ret_types", vec![id.into(), v.into()]);
}
@@ -8490,6 +8535,15 @@ impl From<trap::Label<Function>> for trap::Label<AstNode> {
}
}
impl From<trap::Label<Function>> for trap::Label<Callable> {
fn from(value: trap::Label<Function>) -> Self {
// SAFETY: this is safe because in the dbscheme Function is a subclass of Callable
unsafe {
Self::from_untyped(value.as_untyped())
}
}
}
impl From<trap::Label<Function>> for trap::Label<Element> {
fn from(value: trap::Label<Function>) -> Self {
// SAFETY: this is safe because in the dbscheme Function is a subclass of Element