implement timeline functions for RISC-V (WIP)

This commit is contained in:
Sebastien Bourdeauducq 2021-10-02 19:05:35 +08:00
parent 3dd916b6ac
commit ba93931758
5 changed files with 70 additions and 40 deletions

View File

@ -21,7 +21,7 @@ use parking_lot::RwLock;
use nac3core::{ use nac3core::{
codegen::{CodeGenTask, WithCall, WorkerRegistry}, codegen::{CodeGenTask, WithCall, WorkerRegistry},
symbol_resolver::SymbolResolver, symbol_resolver::SymbolResolver,
toplevel::{composer::TopLevelComposer, TopLevelContext, TopLevelDef}, toplevel::{composer::TopLevelComposer, TopLevelContext, TopLevelDef, GenCall},
typecheck::typedef::{FunSignature, FuncArg}, typecheck::typedef::{FunSignature, FuncArg},
}; };
use nac3core::{ use nac3core::{
@ -33,7 +33,7 @@ use crate::symbol_resolver::Resolver;
mod symbol_resolver; mod symbol_resolver;
#[derive(Clone, Copy)] #[derive(PartialEq, Clone, Copy)]
enum Isa { enum Isa {
RiscV, RiscV,
CortexA9, CortexA9,
@ -171,18 +171,57 @@ impl Nac3 {
_ => return Err(exceptions::PyValueError::new_err("invalid ISA")), _ => return Err(exceptions::PyValueError::new_err("invalid ISA")),
}; };
let primitive: PrimitiveStore = TopLevelComposer::make_primitives().0; let primitive: PrimitiveStore = TopLevelComposer::make_primitives().0;
let (composer, builtins_def, builtins_ty) = TopLevelComposer::new(vec![( let mut builtins = vec![];
"output_int".into(), if isa == Isa::RiscV {
FunSignature { builtins.push((
args: vec![FuncArg { "now_mu".into(),
name: "x".into(), FunSignature {
ty: primitive.int32, args: vec![],
default_value: None, ret: primitive.int64,
}], vars: HashMap::new(),
ret: primitive.none, },
vars: HashMap::new(), Arc::new(GenCall::new(Box::new(
}, |ctx, _, fun, args| {
)]); unimplemented!();
}
)))
));
builtins.push((
"at_mu".into(),
FunSignature {
args: vec![FuncArg {
name: "t".into(),
ty: primitive.int64,
default_value: None,
}],
ret: primitive.none,
vars: HashMap::new(),
},
Arc::new(GenCall::new(Box::new(
|ctx, _, fun, args| {
unimplemented!();
}
)))
));
builtins.push((
"delay_mu".into(),
FunSignature {
args: vec![FuncArg {
name: "dt".into(),
ty: primitive.int64,
default_value: None,
}],
ret: primitive.none,
vars: HashMap::new(),
},
Arc::new(GenCall::new(Box::new(
|ctx, _, fun, args| {
unimplemented!();
}
)))
));
}
let (composer, builtins_def, builtins_ty) = TopLevelComposer::new(builtins);
Ok(Nac3 { Ok(Nac3 {
isa, isa,
primitive, primitive,

View File

@ -34,7 +34,7 @@ impl TopLevelComposer {
/// return a composer and things to make a "primitive" symbol resolver, so that the symbol /// return a composer and things to make a "primitive" symbol resolver, so that the symbol
/// resolver can later figure out primitive type definitions when passed a primitive type name /// resolver can later figure out primitive type definitions when passed a primitive type name
pub fn new( pub fn new(
builtins: Vec<(StrRef, FunSignature)>, builtins: Vec<(StrRef, FunSignature, Arc<GenCall>)>,
) -> (Self, HashMap<StrRef, DefinitionId>, HashMap<StrRef, Type>) { ) -> (Self, HashMap<StrRef, DefinitionId>, HashMap<StrRef, Type>) {
let mut primitives = Self::make_primitives(); let mut primitives = Self::make_primitives();
@ -311,7 +311,7 @@ impl TopLevelComposer {
} }
} }
for (name, sig) in builtins { for (name, sig, codegen_callback) in builtins {
let fun_sig = unifier.add_ty(TypeEnum::TFunc(RefCell::new(sig))); let fun_sig = unifier.add_ty(TypeEnum::TFunc(RefCell::new(sig)));
built_in_ty.insert(name, fun_sig); built_in_ty.insert(name, fun_sig);
built_in_id.insert(name, DefinitionId(definition_ast_list.len())); built_in_id.insert(name, DefinitionId(definition_ast_list.len()));
@ -320,11 +320,11 @@ impl TopLevelComposer {
name: name.into(), name: name.into(),
simple_name: name, simple_name: name,
signature: fun_sig, signature: fun_sig,
instance_to_stmt: HashMap::new(), instance_to_stmt: Default::default(),
instance_to_symbol: [("".into(), name.into())].iter().cloned().collect(), instance_to_symbol: Default::default(),
var_id: Default::default(), var_id: Default::default(),
resolver: None, resolver: None,
codegen_callback: None, codegen_callback: Some(codegen_callback),
})), })),
None, None,
)); ));

View File

@ -1,3 +1,8 @@
@extern
def output_int(x: int32):
...
class A: class A:
a: int32 a: int32
b: B b: B

View File

@ -1,3 +1,8 @@
@extern
def output_asciiart(x: int32):
...
def run() -> int32: def run() -> int32:
minX = -2.0 minX = -2.0
maxX = 1.0 maxX = 1.0

View File

@ -9,7 +9,7 @@ use nac3core::{
codegen::{CodeGenTask, WithCall, WorkerRegistry}, codegen::{CodeGenTask, WithCall, WorkerRegistry},
symbol_resolver::SymbolResolver, symbol_resolver::SymbolResolver,
toplevel::{composer::TopLevelComposer, TopLevelDef}, toplevel::{composer::TopLevelComposer, TopLevelDef},
typecheck::typedef::{FunSignature, FuncArg}, typecheck::typedef::FunSignature,
}; };
mod basic_symbol_resolver; mod basic_symbol_resolver;
@ -32,26 +32,7 @@ fn main() {
}; };
let primitive: PrimitiveStore = TopLevelComposer::make_primitives().0; let primitive: PrimitiveStore = TopLevelComposer::make_primitives().0;
let (mut composer, builtins_def, builtins_ty) = TopLevelComposer::new(vec![ let (mut composer, builtins_def, builtins_ty) = TopLevelComposer::new(vec![]);
("output_int".into(), FunSignature {
args: vec![FuncArg {
name: "x".into(),
ty: primitive.int32,
default_value: None,
}],
ret: primitive.none,
vars: HashMap::new(),
}),
("output_asciiart".into(), FunSignature {
args: vec![FuncArg {
name: "x".into(),
ty: primitive.int32,
default_value: None,
}],
ret: primitive.none,
vars: HashMap::new(),
})
]);
let internal_resolver: Arc<ResolverInternal> = ResolverInternal { let internal_resolver: Arc<ResolverInternal> = ResolverInternal {
id_to_type: builtins_ty.into(), id_to_type: builtins_ty.into(),