nac3artiq: modified demo to use KernelInvariants

This commit is contained in:
pca006132 2021-11-06 22:50:28 +08:00
parent b1e83a1fd4
commit 34cf303e6c
2 changed files with 12 additions and 10 deletions

View File

@ -2,9 +2,9 @@ from min_artiq import *
@nac3 @nac3
class Demo: class Demo:
core: Core core: KernelInvariant[Core]
led0: TTLOut led0: KernelInvariant[TTLOut]
led1: TTLOut led1: KernelInvariant[TTLOut]
def __init__(self): def __init__(self):
self.core = Core() self.core = Core()

View File

@ -3,6 +3,7 @@ from functools import wraps
import sys import sys
from types import SimpleNamespace from types import SimpleNamespace
from numpy import int32, int64 from numpy import int32, int64
from typing import Generic, TypeVar
import nac3artiq import nac3artiq
@ -18,8 +19,10 @@ compiler = nac3artiq.NAC3(core_arguments["target"])
allow_module_registration = True allow_module_registration = True
registered_ids = set() registered_ids = set()
def KernelInvariant(t):
return t T = TypeVar('T')
class KernelInvariant(Generic[T]):
pass
def register_module_of(obj): def register_module_of(obj):
@ -100,7 +103,7 @@ def rtio_input_data(channel: int32) -> int32:
@nac3 @nac3
class Core: class Core:
ref_period: float ref_period: KernelInvariant[float]
def __init__(self): def __init__(self):
self.ref_period = core_arguments["ref_period"] self.ref_period = core_arguments["ref_period"]
@ -146,11 +149,10 @@ class Core:
@nac3 @nac3
class TTLOut: class TTLOut:
core: Core core: KernelInvariant[Core]
channel: int32 channel: KernelInvariant[int32]
target_o: int32 target_o: KernelInvariant[int32]
@portable
def __init__(self, core: Core, channel: int32): def __init__(self, core: Core, channel: int32):
self.core = core self.core = core
self.channel = channel self.channel = channel