Class: KoiReferenceCompiler::FunctionCall
- Inherits:
-
SyntaxNode
- Object
- SyntaxNode
- KoiReferenceCompiler::FunctionCall
- Defined in:
- lib/koi-reference-compiler/node_extensions/functions/function_call.rb
Instance Attribute Summary
Attributes inherited from SyntaxNode
#elements, #offset, #parent, #text_value
Instance Method Summary collapse
Methods inherited from SyntaxNode
Constructor Details
This class inherits a constructor from KoiReferenceCompiler::SyntaxNode
Instance Method Details
#compile ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/koi-reference-compiler/node_extensions/functions/function_call.rb', line 4 def compile number_of_arguments = self.elements.length - 1 bytecode = [] bytecode.concat( self.elements[2].compile ) if(number_of_arguments > 1) bytecode.concat( self.elements[1].compile ) if(number_of_arguments > 0) function_name = self.elements.first.text_value if( function_name == "print") raise_error unless(number_of_arguments == 1) bytecode << PRINT elsif( function_name == "gets") raise_error unless(number_of_arguments == 0) bytecode << GETS elsif( function_name == "call") raise_error unless(number_of_arguments == 2) bytecode << CALL elsif( function_name == "tailcall") raise_error unless(number_of_arguments == 1 || number_of_arguments == 2) bytecode << TAILCALL elsif( function_name == "return") raise_error unless(number_of_arguments == 0 || number_of_arguments == 1) bytecode << RETURN elsif( function_name == "to_string") raise_error unless(number_of_arguments == 1) bytecode << TO_STRING elsif( function_name == "type_of") raise_error unless(number_of_arguments == 1) bytecode << TYPEOF else raise CompileError, "Unknown function: #{function_name} at offset: #{self.elements.first.offset}" end end |