Change soft-fail to use the config, rather than env
[rbx.git] / shotgun / lib / primitive_generator.rb
blobb6adab58466544fc9f9629c2f5a219e1eff2989a
1 module PrimitiveGenerator
2   def self.generate(method)
3     @types = [] # clean slate before going
4     code = method.call
5     generate_checks + code
6   end
8   def self.generate_checks
9     arity = @types.length - 1
10     raise "Primitive MUST pop self" unless arity >= 0
11     variables = %w(self t1 t2 t3)
13     rval = "    ARITY(#{arity})\n"
14     while (type = @types.shift)
15       variable = variables.shift
16       rval << "    POP(#{variable}, #{type})\n"
17     end
18     rval
19   end
21   def self.push_type(name)
22     @types ||= []
23     @types << name.to_s.upcase
24   end
26   def method_missing(name, *args, &block)
27     PrimitiveGenerator.push_type(name)
28   end
30   def qfalse
31     PrimitiveGenerator.push_type('FALSE')
32   end
34   def qtrue
35     PrimitiveGenerator.push_type('TRUE')
36   end
38   def qnil
39     PrimitiveGenerator.push_type('NIL')
40   end
41 end