Skip to content

configurator: add an unsigned int type for C symbol imports #1723

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions src/configurator/v1.ml
Original file line number Diff line number Diff line change
@@ -321,6 +321,7 @@ module C_define = struct
type t =
| Switch
| Int
| Uint
| String
end

@@ -338,7 +339,7 @@ module C_define = struct
List.iter includes ~f:(pr "#include <%s>");
pr "";
Option.iter prelude ~f:(pr "%s");
if has_type Type.Int then (
if (has_type Type.Int) || (has_type Type.Uint) then (
pr {|
#define D0(x) ('0'+(x/1 )%%10)
#define D1(x) ('0'+(x/10 )%%10), D0(x)
@@ -353,16 +354,16 @@ module C_define = struct
|}
);
List.iteri vars ~f:(fun i (name, t) ->
let c_arr_i () =
let b = Buffer.create 8 in
let is = string_of_int i in
for i=0 to String.length is - 1 do
Printf.bprintf b "'%c', " is.[i]
done;
Buffer.contents b
in
match t with
| Type.Int ->
let c_arr_i =
let b = Buffer.create 8 in
let is = string_of_int i in
for i=0 to String.length is - 1 do
Printf.bprintf b "'%c', " is.[i]
done;
Buffer.contents b
in
pr {|
const char s%i[] = {
'B', 'E', 'G', 'I', 'N', '-', %s'-',
@@ -373,7 +374,15 @@ const char s%i[] = {
#endif
'-', 'E', 'N', 'D'
};
|} i c_arr_i name name name
|} i (c_arr_i ()) name name name
| Type.Uint ->
pr {|
const char s%i[] = {
'B', 'E', 'G', 'I', 'N', '-', %s'-',
D9((%s)),
'-', 'E', 'N', 'D'
};
|} i (c_arr_i ()) name
| String ->
pr {|const char *s%i = "BEGIN-%i-" %s "-END";|} i i name;
| Switch ->
@@ -400,7 +409,7 @@ const char *s%i = "BEGIN-%i-false-END";
| Some v -> v in
match t with
| Type.Switch -> Value.Switch (bool_of_string raw_val)
| Int -> Int (int_of_string raw_val)
| Int | Uint -> Int (int_of_string raw_val)
| String -> String raw_val in
(name, value))

1 change: 1 addition & 0 deletions src/configurator/v1.mli
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@ module C_define : sig
type t =
| Switch (** defined/undefined *)
| Int
| Uint
| String
end