<commit_before>#!/usr/bin/env lua

local string_ex = require ("string_ex")
local io        = require ("io")
local argv      = arg
local argc      = table.maxn (argv)

assert (argc == 4)

local size     = argv[1]
local c_type   = argv[2]
local ada_type = argv[3]
local kind     = argv[4]

-- XXX: Not portable!
local size_bits = size * 8

io.write ("  -- "..c_type.."\n")

if kind == "scalar" then
  local high_range = math.pow (2, size_bits - 1) - 1
  local low_range  = -high_range

  io.write ([[
  type ]]..ada_type..[[ is range ]]..low_range..[[ .. ]]..high_range..[[;
  for ]]..ada_type..[['Size use ]]..size_bits..[[;
  pragma Convention (C, ]]..ada_type..[[);
]])
end

if kind == "modular" then
  io.write ([[
  type ]]..ada_type..[[ is mod 2 ** ]]..size_bits..[[;
  for ]]..ada_type..[['Size use ]]..size_bits..[[;
  pragma Convention (C, ]]..ada_type..[[);
]])
end

if kind == "float" then
  io.write ("  type "..ada_type.." is new C.C_float;\n")
end

if kind == "double" then
  io.write ("  type "..ada_type.." is new C.double;\n")
end

if kind == "float_sub" then
  io.write ("  subtype "..ada_type.." is Float_t range 0.0 .. 1.0;\n")
end

if kind == "double_sub" then
  io.write ("  subtype "..ada_type.." is Double_t range 0.0 .. 1.0;\n")
end

if kind == "boolean" then
  io.write ([[
  type ]]..ada_type..[[ is (False, True);
  for ]]..ada_type..[[ use (False => 0, True => 1);
  for ]]..ada_type..[['Size use ]]..size_bits..[[;
  pragma Convention (C, ]]..ada_type..[[);
]])
end

if kind == "access" then
  local target_type = ada_type:gsub ("_Access", "")

  io.write ([[
  type ]]..ada_type..[[ is access all ]]..target_type..[[;
  pragma Convention (C, ]]..ada_type..[[);
]])
end

if kind == "access_constant" then
  local target_type = ada_type:gsub ("_Access_Constant", "")
  io.write ([[
  type ]]..ada_type..[[ is access constant ]]..target_type..[[;
  pragma Convention (C, ]]..ada_type..[[);
]])
end

if kind == "address" then
  io.write ([[
  subtype ]]..ada_type..[[ is System.Address;
]])
end

if kind == "address_access_constant" then<commit_msg>Implement Boolean_t as new Boolean (size mismatch for C enum types).<commit_after>#!/usr/bin/env lua

local string_ex = require ("string_ex")
local io        = require ("io")
local argv      = arg
local argc      = table.maxn (argv)

assert (argc == 4)

local size     = argv[1]
local c_type   = argv[2]
local ada_type = argv[3]
local kind     = argv[4]

-- XXX: Not portable!
local size_bits = size * 8

io.write ("  -- "..c_type.."\n")

if kind == "scalar" then
  local high_range = math.pow (2, size_bits - 1) - 1
  local low_range  = -high_range

  io.write ([[
  type ]]..ada_type..[[ is range ]]..low_range..[[ .. ]]..high_range..[[;
  for ]]..ada_type..[['Size use ]]..size_bits..[[;
  pragma Convention (C, ]]..ada_type..[[);
]])
end

if kind == "modular" then
  io.write ([[
  type ]]..ada_type..[[ is mod 2 ** ]]..size_bits..[[;
  for ]]..ada_type..[['Size use ]]..size_bits..[[;
  pragma Convention (C, ]]..ada_type..[[);
]])
end

if kind == "float" then
  io.write ("  type "..ada_type.." is new C.C_float;\n")
end

if kind == "double" then
  io.write ("  type "..ada_type.." is new C.double;\n")
end

if kind == "float_sub" then
  io.write ("  subtype "..ada_type.." is Float_t range 0.0 .. 1.0;\n")
end

if kind == "double_sub" then
  io.write ("  subtype "..ada_type.." is Double_t range 0.0 .. 1.0;\n")
end

if kind == "boolean" then
  io.write ([[
  type ]]..ada_type..[[ is new Boolean;
  for ]]..ada_type..[['Size use ]]..size_bits..[[;
  pragma Convention (C, ]]..ada_type..[[);
]])
end

if kind == "access" then
  local target_type = ada_type:gsub ("_Access", "")

  io.write ([[
  type ]]..ada_type..[[ is access all ]]..target_type..[[;
  pragma Convention (C, ]]..ada_type..[[);
]])
end

if kind == "access_constant" then
  local target_type = ada_type:gsub ("_Access_Constant", "")
  io.write ([[
  type ]]..ada_type..[[ is access constant ]]..target_type..[[;
  pragma Convention (C, ]]..ada_type..[[);
]])
end

if kind == "address" then
  io.write ([[
  subtype ]]..ada_type..[[ is System.Address;
]])
end

if kind == "address_access_constant" then
{'fraction_non_alphanumeric': 0.2207760906242468, 'fraction_numerical': 0.0091588334538443, 'mean_word_length': 2.8894095595126523, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '719393', 'n_tokens_mistral': 1653, 'n_tokens_neox': 1620, 'n_words': 440}