#!/usr/bin/python
#
#   This is the Robotics Language compiler
#
#   Created on: June 22, 2017
#       Author: Gabriel A. D. Lopes
#      Licence: Apache 2.0
#    Copyright: 2014-2017 Robot Care Systems BV, The Hague, The Netherlands. All rights reserved.
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.

import os
import sys
import RoboticsLanguage
from subprocess import call

if __name__ == "__main__":

  path = os.path.dirname(os.path.abspath(RoboticsLanguage.__file__))

  def compile(path, name, command_line_parameters=sys.argv[1:]):
    print('Compiling ' + name + '...')

    call(['rol', path + name] + command_line_parameters)

    # if call(['rol', path+name] + command_line_parameters):
    #   return sys.exit(1)

  compile(path + '/Examples/', 'helloworld.rol')

  compile(path + '/Transformers/Base/Examples/', 'functions.rol')
  compile(path + '/Transformers/Base/Examples/', 'precedence.rol')
  compile(path + '/Transformers/Base/Examples/', 'types.rol')

  compile(path + '/Transformers/ROS/Examples/', 'echo.rol')
  compile(path + '/Transformers/ROS/Examples/', 'signals.rol')

  # compile(path,'dutch.rol',['--language','nl','--remove-cache'])
  # compile(path,'portuguese.rol',['--language','pt','--remove-cache'])
