From ba939317581d969d025367f427a404b5224085d1 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Sat, 2 Oct 2021 19:05:35 +0800 Subject: [PATCH] implement timeline functions for RISC-V (WIP) --- nac3artiq/src/lib.rs | 67 ++++++++++++++++++++++++------- nac3core/src/toplevel/composer.rs | 10 ++--- nac3standalone/demo/classes.py | 5 +++ nac3standalone/demo/mandelbrot.py | 5 +++ nac3standalone/src/main.rs | 23 +---------- 5 files changed, 70 insertions(+), 40 deletions(-) diff --git a/nac3artiq/src/lib.rs b/nac3artiq/src/lib.rs index 042a7ce7..a86947df 100644 --- a/nac3artiq/src/lib.rs +++ b/nac3artiq/src/lib.rs @@ -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, diff --git a/nac3core/src/toplevel/composer.rs b/nac3core/src/toplevel/composer.rs index eb085187..f7c08337 100644 --- a/nac3core/src/toplevel/composer.rs +++ b/nac3core/src/toplevel/composer.rs @@ -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)>, ) -> (Self, HashMap, HashMap) { 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, )); diff --git a/nac3standalone/demo/classes.py b/nac3standalone/demo/classes.py index b2c534c4..ba489b48 100644 --- a/nac3standalone/demo/classes.py +++ b/nac3standalone/demo/classes.py @@ -1,3 +1,8 @@ +@extern +def output_int(x: int32): + ... + + class A: a: int32 b: B diff --git a/nac3standalone/demo/mandelbrot.py b/nac3standalone/demo/mandelbrot.py index a2e00e89..bb133b7d 100644 --- a/nac3standalone/demo/mandelbrot.py +++ b/nac3standalone/demo/mandelbrot.py @@ -1,3 +1,8 @@ +@extern +def output_asciiart(x: int32): + ... + + def run() -> int32: minX = -2.0 maxX = 1.0 diff --git a/nac3standalone/src/main.rs b/nac3standalone/src/main.rs index ed86b1ab..fa51958d 100644 --- a/nac3standalone/src/main.rs +++ b/nac3standalone/src/main.rs @@ -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 { id_to_type: builtins_ty.into(),