Skip to content

Commit

Permalink
Adding more generated constants to C compatibility headers.
Browse files Browse the repository at this point in the history
  • Loading branch information
asoffer committed Nov 18, 2023
1 parent 6c12252 commit b33de60
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 2 deletions.
47 changes: 45 additions & 2 deletions toolchain/stdlib/compat/c/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,36 @@ generated_ic_library(
deps = [],
)

ic_library(
generated_ic_library(
name = "locale",
srcs = ["locale.template.ic"],
includes = ["locale.h"],
symbols = {
"LC_ALL": "int",
"LC_COLLATE": "int",
"LC_CTYPE": "int",
"LC_MONETARY": "int",
"LC_NUMERIC": "int",
"LC_TIME": "int",
},
deps = [],
)

generated_ic_library(
name = "stdio",
srcs = ["stdio.ic"],
srcs = ["stdio.template.ic"],
includes = ["stdio.h"],
symbols = {
"BUFSIZ": "int",
"EOF": "int",
"FOPEN_MAX": "int",
"FILENAME_MAX": "int",
"L_tmpnam": "int",
"SEEK_CUR": "int",
"SEEK_END": "int",
"SEEK_SET": "int",
"TMP_MAX": "int",
},
deps = [":types"],
)

Expand All @@ -74,3 +101,19 @@ generated_ic_library(
":types",
],
)

ic_library(
name = "test_build",
srcs = ["test.ic"],
testonly = True,
visibility = ["//visibility:private"],
deps = [
":ctype",
":limits",
":locale",
":string",
":stdio",
":types",
":time",
],
)
13 changes: 13 additions & 0 deletions toolchain/stdlib/compat/c/locale.template.ic
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// This module provides an interface to functions in the <locale.h> C-header file.

let lconv ::= builtin.opaque()
let LC_ALL ::= {{{LC_ALL}}}
let LC_COLLATE ::= {{{LC_COLLATE}}}
let LC_CTYPE ::= {{{LC_CTYPE}}}
let LC_MONETARY ::= {{{LC_MONETARY}}}
let LC_NUMERIC ::= {{{LC_NUMERIC}}}
let LC_TIME ::= {{{LC_TIME}}}

// Additionally, the <locale.h> C-header defines the constant `NULL`, for which
// there is no corresponding value in this module. For such uses, prefer the
// Icarus native `null` constant.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@ let c ::= import "std.compat.c.types"

let FILE ::= builtin.opaque()
let fpos_t ::= builtin.opaque()
let size_t ::= c.unsigned_long // TODO: Generate this.

let _IOFBF ::= null
let _IOLBF ::= null
let _IONBF ::= null

let BUFSIZ ::= {{{BUFSIZ}}}
// let EOF ::= {{{EOF}}} TODO: Enable when negation is support
let FOPEN_MAX ::= {{{FOPEN_MAX}}}
let FILENAME_MAX ::= {{{FILENAME_MAX}}}
let L_tmpnam ::= {{{L_tmpnam}}}
let SEEK_CUR ::= {{{SEEK_CUR}}}
let SEEK_END ::= {{{SEEK_END}}}
let SEEK_SET ::= {{{SEEK_SET}}}
let TMP_MAX ::= {{{TMP_MAX}}}

let fopen ::= builtin.foreign("fopen", ([*]char, [*]char) -> *FILE)
let freopen ::= builtin.foreign("freopen", ([*]char, [*]char, *FILE) -> *FILE)
Expand Down Expand Up @@ -42,3 +57,7 @@ let remove ::= builtin.foreign("remove", [*]char -> c.int)
let rename ::= builtin.foreign("rename", ([*]char, [*]char) -> c.int)
let tmpfile ::= builtin.foreign("tmpfile", () -> *FILE)
let tmpnam ::= builtin.foreign("tmpnam", [*]char -> [*]char)

// Additionally, the <time.h> C-header defines the constant `NULL`, for which
// there is no corresponding value in this module. For such uses, prefer the
// Icarus native `null` constant.
Empty file.

0 comments on commit b33de60

Please sign in to comment.