sporniket / ideas

My backlog of ideas, organized as a bunch of issues
0 stars 0 forks source link

Over-engineered code generator #8

Open sporniket opened 2 years ago

sporniket commented 2 years ago

Python library, inspired by amaranth-hdl, to generate code snippet.

How it would look for a BASIC dialect :

class Var:...
class Int(Var):...
class Ints(Var):...
class Float(Var):...
class Floats(Var):...
class String(Var):...
class Strings(Var):...

class MyCode(Callable):
  def __init__(self, <generator_parameters>):
    self.foo = bar
    //do stuff
    self.a = Int() #int variable initialized with 0
    self.to = Int(10, name="aint") #int variable with actual name "aint" instead of keyword "to"
    self.a2 = Float(10) # float variable, name "a2"
    self.b = Float(10.0) # float variable, name "b"
    self.b2 = Float() # float variable, named "b2", initialized with 0.0
    self.c = String("hello") # string variable
    self.c2 = String("") #
    self.d = Ints(10,25,30) # array up to 3 axis 
    self.d2 = Floats(10,25,30) # array up to 3 axis
    self.d3 = Strings(10,25,30) # array up to 3 axis

  def instanceVariables(self) -> List[Var]:
    return [
      self.varA,
      self.varB,
      ...
    ]

  def classVariables(self) -> List[Var]:
    return [...]

  def doSomething(self, a ,b ,c) -> Sub:
    return Sub([
      Print(a, b, c),
      Return()
    ])

  def doSomethingElse(self) -> To:
    return To(...)