[video member=pervognsen stream_platform=twitch project=bitwise title="Domain-Specific Languages In Python, Part 3" vod_platform=youtube id=hP6UY6F6a0w annotator=Miblo]
[0:09][Recap and set the stage for the day][:speech]
[1:46][Review the bit-oriented nature of our DSL (domain-specific :language) rattle, and its lack of abstraction facilities][:research]
[6:18][A few words on the :simulation speed advantage from keeping things as bit-vectors][:language :speech]
[8:00][Consider allowing a circuit component connection-oriented way of expressing things, in addition to the language's current expression-oriented way][:language :speech]
[9:38][Consider supporting "module", in Verilog parlance][:language :speech]
[11:35][An example \@module][:language :speech]
[17:34][An example nested \@module][:language :speech]
[25:00][Note the addition of ordered dictionaries in Python 3.6][:language :speech]
[29:52][Set up to implement modules][:language :speech]
[32:15][Dive into implementing modules, starting by introducing Bit and BitVector classes, and memo() to memoise the result of bits()][:language]
[36:08][Demo the utility of \@memo][:language :speech]
[37:30][Establish the syntax bit\[8\] which comes out equal to bits(8) due to memoisation][:language]
[39:20][Define __and__() in the Node class, introducing check_same_type()][:language]
[42:32][Introduce BinaryNode class][:language]
[43:55][Introduce as_node() and ConstantNode class][:language]
[48:41][Introduce cast() in the Bit and BitVector classes, and __repr__() in Bit, BitVector and ConstantNode][:language]
[52:31][Test as_node()][:language :run]
[54:34][Define __rand__() in Node, and introduce InputNode class][:language]
[55:53][Demo usage of an InputNode, and a trick for doing embedded DSL in Python][:language :speech]
[57:21][Introduce input()][:language]
[57:57][Introduce Module class, using Python's new __init_subclass__][:language]
[59:00][Introduce Adder class using Module class, and walk us through what happens when Python executes this[ref
    site="Python 3.7.0 documentation"
    page="3. Data model"
    url=https://docs.python.org/3/reference/datamodel.html#customizing-class-creation]][:language]
[1:00:49][Change Adder and Module to use a metaclass, also defining __repr__ in the InputNode class][:language]
[1:06:28][Demo the utility of this Module metaclass, noting the alternative way of doing this with a decorator][:language :run]
[1:07:11][Introduce module() to be used as a decorator][:language]
[1:09:09][Demo this decorator-based solution, remove Module class, and walk through how decorators work][:language :programming :run]
[1:11:16][Add an optional name to the Node class][:language]
[1:13:11][Suppress the types in our expression representation][:language]
[1:13:42][:Run it to see the expressions in our Adder class][:language]
[1:14:20][Review module() and consider the need to create module instance nodes][:language :research]
[1:15:23][Introduce Module class, OutputNode class and output(), and enable module() to fill out _inputs and _outputs][:language]
[1:18:48][Test the module inputs and outputs][:language :run]
[1:20:20][Introduce the notion of _connections in the Module class][:language]
[1:25:35][:Run it to see the output][:language]
[1:25:42][Implement our Adder8 and Adder16 modules sketched out earlier][:language]
[1:27:54][:Run it to see the inputs and outputs of our modules][:language]
[1:28:20][Enable __init__() in the Module class to check_same_type()][:language]
[1:30:25][Test plugging a 16-bit node into an 8-bit input and hit a TypeError as expected][:language :run]
[1:30:41][Break][:admin]
[1:31:01][:afk]
[1:31:54][Return][:admin]
[1:32:12][Implement type checking, adding __getitem__() to the Node class, and introducing IndexNode class][:language]
[1:39:50][Print Adder8._nodes][:language :run]
[1:40:22][Test the type checking, fixing IndexNode to correctly detect out of bounds indices][:language :programming :run]
[1:41:02][Implement bit slicing, introducing SliceNode class][:language]
[1:47:57][Test the bit slicing][:language :run]
[1:48:40][Compose error message for check_same_type()][:"error handling"]
[1:48:59][Trigger that out-of-bounds error and continue to test the bit slicing][:language :run]
[1:49:33][Test partial connections, noting that it's picking up the template rather than the instance version of the node][:language :run]
[1:51:37][Make module() delete its own template version of the nodes, and __init__() in the Module class to fill in the real instance nodes, introducing ModuleInputNode class][:language]
[1:59:39][:Run it to see our partial connection][:language]
[2:00:46][Enable module() to handle partial connections for Modules, renaming "nodes" to "definitions"][:language]
[2:05:17][:Run it to see some uninitialised data][:language]
[2:05:41][Define __repr__() in the Module class][:language]
[2:07:49][:Run it to see our Adder8 module all correctly printed out][:language]
[2:09:08][Summarise the day's work on syntactic sugar, type checking and modules][:language :speech]
[2:09:45][That's enough for today, with a glimpse into the future on additional semantic checking][:speech]
[/video]
