Skip to content

Commit e8f3754

Browse files
WalterBrightdlang-bot
authored andcommitted
flesh out How ImportC Works section
1 parent 0c18437 commit e8f3754

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

spec/importc.dd

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,8 +514,21 @@ $(H2 $(LNAME2 other-solutions, Other Solutions))
514514

515515
$(H2 $(LNAME2 internals, How ImportC Works))
516516

517-
$(P This is a description of how ImportC is implemented, intended
518-
to remove the mystery of various design choices.)
517+
$(P ImportC's implementation is based on the idea that D's semantics are very similar
518+
to C's. ImportC gets its own parser, which converts the C syntax into the same AST
519+
(Abstract Syntax Tree) that D uses. The lexer for ImportC is the same as for D, but with
520+
some modifications here and there, such as the keywords and integer literals being different.
521+
Where the semantics of C differ from D, there are adjustments in the semantic analysis
522+
code in the D compiler.)
523+
524+
$(P This co-opting of the D semantic implementation allows ImportC to be able to do things
525+
like handle forward references, CTFE (Compile Time Function Execution), and inlining of C functions
526+
into D code. Being able to handle forward references means it is not necessary to even
527+
write a .h file to be able to import C declarations into D. Being able to perform CTFE is
528+
very handy for testing that ImportC is working without needing to generate an executable.
529+
But, in general, the strong temptation to add D features to ImportC has been resisted.)
530+
531+
$(P The optimizer and code generator are, of course, the same as D uses.)
519532

520533
$(SPEC_SUBNAV_PREV_NEXT betterc, Better C, ob, Live Functions)
521534
)

0 commit comments

Comments
 (0)