1 # Test case for the code generator API introduced in 0.5.0
5 # Instantiate code generator
6 generator = Voodoo::CodeGenerator.get_generator
8 generator.instance_eval do
9 add :code, [:import, :printf], [:export, :main]
11 # Define format string
12 add :data, [:align], [:label, :format], [:string, "gcd(%d, %d): %d\n\x00"]
15 add :functions, [:align], [:label, :gcd],
18 [[:return, :call, :gcd, :y, :x]]],
19 [:let, :m, :mod, :x, :y],
22 [[:'tail-call', :gcd, :y, :m]]]]
25 add :functions, [:align], [:label, :main]
26 add_function [:argv, :argc],
27 [:let, :x, :call, :gcd, 11, 7],
28 [:call, :printf, :format, 11, 7, :x],
29 [:set, :x, :call, :gcd, 7, 11],
30 [:call, :printf, :format, 7, 11, :x],
31 [:set, :x, :call, :gcd, 33, 27],
32 [:call, :printf, :format, 33, 27, :x],
36 # Let code generator determine output file name
37 outfile = generator.output_file_name 'gcd.voo'
38 File.open(outfile, 'w') { |file| generator.write file }