1 # Program to test programmatic code generation through Antimony
5 generator = Antimony::CodeGenerator.get_generator
6 proxy = Antimony::RubyToAstProxy.new generator
8 proxy.add :functions, [:import, :printf]
9 proxy.add :functions, [:export, :main]
11 proxy.add :functions, [:label, :fact]
12 proxy.add_function [:n], [:ifle, [:n, 1],
16 [[:return, [:mul, :n, [:call, :fact, [:sub, :n, 1]]]]]]
18 proxy.add :functions, [:label, :main]
19 proxy.add_function [:argc, :argv],
20 [:call, :printf, "%d\n\x00",
24 generator.write open(generator.output_file_name('fact.sb'), 'wb')