forked from M-Labs/nac3
implement timeline functions for RISC-V (WIP)
This commit is contained in:
parent
3dd916b6ac
commit
ba93931758
@ -21,7 +21,7 @@ use parking_lot::RwLock;
|
||||
use nac3core::{
|
||||
codegen::{CodeGenTask, WithCall, WorkerRegistry},
|
||||
symbol_resolver::SymbolResolver,
|
||||
toplevel::{composer::TopLevelComposer, TopLevelContext, TopLevelDef},
|
||||
toplevel::{composer::TopLevelComposer, TopLevelContext, TopLevelDef, GenCall},
|
||||
typecheck::typedef::{FunSignature, FuncArg},
|
||||
};
|
||||
use nac3core::{
|
||||
@ -33,7 +33,7 @@ use crate::symbol_resolver::Resolver;
|
||||
|
||||
mod symbol_resolver;
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
#[derive(PartialEq, Clone, Copy)]
|
||||
enum Isa {
|
||||
RiscV,
|
||||
CortexA9,
|
||||
@ -171,18 +171,57 @@ impl Nac3 {
|
||||
_ => return Err(exceptions::PyValueError::new_err("invalid ISA")),
|
||||
};
|
||||
let primitive: PrimitiveStore = TopLevelComposer::make_primitives().0;
|
||||
let (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(),
|
||||
},
|
||||
)]);
|
||||
let mut builtins = vec![];
|
||||
if isa == Isa::RiscV {
|
||||
builtins.push((
|
||||
"now_mu".into(),
|
||||
FunSignature {
|
||||
args: vec![],
|
||||
ret: primitive.int64,
|
||||
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 {
|
||||
isa,
|
||||
primitive,
|
||||
|
@ -34,7 +34,7 @@ impl TopLevelComposer {
|
||||
/// 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
|
||||
pub fn new(
|
||||
builtins: Vec<(StrRef, FunSignature)>,
|
||||
builtins: Vec<(StrRef, FunSignature, Arc<GenCall>)>,
|
||||
) -> (Self, HashMap<StrRef, DefinitionId>, HashMap<StrRef, Type>) {
|
||||
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)));
|
||||
built_in_ty.insert(name, fun_sig);
|
||||
built_in_id.insert(name, DefinitionId(definition_ast_list.len()));
|
||||
@ -320,11 +320,11 @@ impl TopLevelComposer {
|
||||
name: name.into(),
|
||||
simple_name: name,
|
||||
signature: fun_sig,
|
||||
instance_to_stmt: HashMap::new(),
|
||||
instance_to_symbol: [("".into(), name.into())].iter().cloned().collect(),
|
||||
instance_to_stmt: Default::default(),
|
||||
instance_to_symbol: Default::default(),
|
||||
var_id: Default::default(),
|
||||
resolver: None,
|
||||
codegen_callback: None,
|
||||
codegen_callback: Some(codegen_callback),
|
||||
})),
|
||||
None,
|
||||
));
|
||||
|
@ -1,3 +1,8 @@
|
||||
@extern
|
||||
def output_int(x: int32):
|
||||
...
|
||||
|
||||
|
||||
class A:
|
||||
a: int32
|
||||
b: B
|
||||
|
@ -1,3 +1,8 @@
|
||||
@extern
|
||||
def output_asciiart(x: int32):
|
||||
...
|
||||
|
||||
|
||||
def run() -> int32:
|
||||
minX = -2.0
|
||||
maxX = 1.0
|
||||
|
@ -9,7 +9,7 @@ use nac3core::{
|
||||
codegen::{CodeGenTask, WithCall, WorkerRegistry},
|
||||
symbol_resolver::SymbolResolver,
|
||||
toplevel::{composer::TopLevelComposer, TopLevelDef},
|
||||
typecheck::typedef::{FunSignature, FuncArg},
|
||||
typecheck::typedef::FunSignature,
|
||||
};
|
||||
|
||||
mod basic_symbol_resolver;
|
||||
@ -32,26 +32,7 @@ fn main() {
|
||||
};
|
||||
|
||||
let primitive: PrimitiveStore = TopLevelComposer::make_primitives().0;
|
||||
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 (mut composer, builtins_def, builtins_ty) = TopLevelComposer::new(vec![]);
|
||||
|
||||
let internal_resolver: Arc<ResolverInternal> = ResolverInternal {
|
||||
id_to_type: builtins_ty.into(),
|
||||
|
Loading…
Reference in New Issue
Block a user