SHARE
TWEET

Untitled

a guest Oct 15th, 2019 94 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import stdlib as std
  2. use 'stdlib.sx'
  3.  
  4. class LogicGate:
  5.     @virtual
  6.     def get_state(): bool
  7.    
  8.     @virtual
  9.     def set_state(bool state):
  10.  
  11. class And(LogicGate):
  12.     LogicGate* i0, i1
  13.    
  14.     def get_state(): bool
  15.         return self.i0 and self.i1
  16.    
  17.     def set_state(bool state):
  18.         pass
  19.  
  20. def main(): i32
  21.     And* and_0 = new And()
  22.    
  23.     and_0.i0 = new Input()
  24.     and_0.i1 = new Input()
  25.    
  26.     and_0.i0.set_state(0)
  27.     and_0.i1.set_state(0)
  28.     print("%b & %b = %b\n" %(and_0.i0, and_0.i1, and_0.get_state()))
  29.  
  30.     and_0.i0.set_state(0)
  31.     and_0.i1.set_state(1)
  32.     print("%b & %b = %b\n" %(and_0.i0, and_0.i1, and_0.get_state()))
  33.  
  34.     and_0.i0.set_state(1)
  35.     and_0.i1.set_state(0)
  36.     print("%b & %b = %b\n" %(and_0.i0, and_0.i1, and_0.get_state()))
  37.  
  38.     and_0.i0.set_state(1)
  39.     and_0.i1.set_state(1)
  40.     print("%b & %b = %b\n" %(and_0.i0, and_0.i1, and_0.get_state()))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top