Skip to content

Commit

Permalink
* Put determination of platform more in the compile stage of the C code.
Browse files Browse the repository at this point in the history
Merge commit '015ac6b0776124a8a000fc90fbba3bd83b49750f' into HEAD

Conflicts:
	include/euphoria.h
	source/be_execute.c
	source/be_machine.c
	source/c_decl.e
	source/compile.e
  • Loading branch information
shawnpringle committed Sep 20, 2018
2 parents c2cd4ce + 015ac6b commit ffe9abd
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 117 deletions.
10 changes: 10 additions & 0 deletions include/euphoria.h
Original file line number Diff line number Diff line change
Expand Up @@ -456,4 +456,14 @@ extern int in_from_keyb;
extern int TraceOn;
int check_has_console();
extern object eu_sizeof();

#if _WIN32
#define __global_routine __stdcall
#define ONEFORWINDOWS 1
#else
#define __global_routine
#define ONEFORWINDOWS 0
#endif


#endif
2 changes: 1 addition & 1 deletion source/be_execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -5019,7 +5019,7 @@ void do_exec(intptr_t *start_pc)
#ifdef EUNIX
top = 3; // (UNIX, called Linux for backwards compatibility)
#endif
#ifdef EBSD
#ifdef __FreeBSD__
top = 8; // FreeBSD
#endif
#ifdef __APPLE__
Expand Down
4 changes: 2 additions & 2 deletions source/be_machine.c
Original file line number Diff line number Diff line change
Expand Up @@ -3114,7 +3114,7 @@ object machine(object opcode, object x)
#ifdef __APPLE__
return 4;
#else
#ifdef EBSD // FreeBSD by this point
#ifdef __FreeBSD__
return 8;
#else
#ifdef __linux__
Expand All @@ -3126,7 +3126,7 @@ object machine(object opcode, object x)
return 1; // Unknown platform
#endif // _WIN32
#endif // __linux__
#endif // EBSD
#endif // __FreeBSD__
#endif // __APPLE__
#endif // __OpenBSD__
#endif // __NetBSD__
Expand Down
48 changes: 37 additions & 11 deletions source/c_decl.e
Original file line number Diff line number Diff line change
Expand Up @@ -671,13 +671,13 @@ with warning
-- output a C statement with replacements for @ or @1 @2 @3, ... @9
export procedure c_stmt(sequence stmt, object arg, symtab_index lhs_arg = 0)
integer argcount, i

if LAST_PASS = TRUE and Initializing = FALSE then
cfile_size += 1
update_checksum( stmt )

end if


if emit_c_output then
adjust_indent_before(stmt)
end if
Expand All @@ -686,6 +686,7 @@ export procedure c_stmt(sequence stmt, object arg, symtab_index lhs_arg = 0)
arg = {arg}
end if


argcount = 1
i = 1
while i <= length(stmt) and length(stmt) > 0 do
Expand Down Expand Up @@ -747,6 +748,7 @@ export procedure c_stmt0(sequence stmt)
end if
end procedure


function needs_uninit( sequence eentry )
if eentry[S_SCOPE] >= SC_LOCAL
and (eentry[S_SCOPE] <= SC_GLOBAL or eentry[S_SCOPE] = SC_EXPORT or eentry[S_SCOPE] = SC_PUBLIC)
Expand All @@ -760,6 +762,34 @@ function needs_uninit( sequence eentry )
end if
end function

sequence preprocessor_stack = {}

--**
-- output a C preprocessor statement with no arguments and put a new line on the end to the C file
export procedure m_stmtln(sequence stmt)
if length(stmt) > 4 then
if (equal("#else", stmt[1..5]) or equal("#end", stmt[1..4])) and indent >= 4 then
indent -= 4
end if
end if
integer last_nl = find('\n', stmt & '\n')
c_stmt0(stmt[1..last_nl-1])
if length(stmt) > 4 then
if equal("#if", stmt[1..3]) then
preprocessor_stack = append(preprocessor_stack, stmt[4..$])
indent += 4
end if
if equal("#else", stmt[1..5]) then
indent += 4
c_puts(" // " & preprocessor_stack[$])
elsif equal("#end", stmt[1..4]) then
c_puts(" // " & preprocessor_stack[$])
preprocessor_stack = preprocessor_stack[1..$-1]
end if
end if
c_puts("\n")
end procedure

--**
-- emit C declaration for each local and global constant and var
export procedure DeclareFileVars()
Expand Down Expand Up @@ -996,14 +1026,14 @@ procedure declare_prototype( symtab_index s )
c_hputs(ret_type)


if dll_option and TWINDOWS then
if dll_option then
integer scope = SymTab[s][S_SCOPE]
if (scope = SC_PUBLIC
or scope = SC_EXPORT
or scope = SC_GLOBAL)
then
-- declare the global routine as an exported DLL function
c_hputs("__stdcall ")
c_hputs("__global_routine ")
end if
end if

Expand Down Expand Up @@ -1037,8 +1067,8 @@ procedure add_to_routine_list( symtab_index s, integer seq_num, integer first )
c_printf(", %d", SymTab[s][S_FILE_NO])
c_printf(", %d", SymTab[s][S_NUM_ARGS])

if TWINDOWS and dll_option and find( SymTab[s][S_SCOPE], { SC_GLOBAL, SC_EXPORT, SC_PUBLIC} ) then
c_puts(", 1") -- must call with __stdcall convention
if dll_option and find( SymTab[s][S_SCOPE], { SC_GLOBAL, SC_EXPORT, SC_PUBLIC} ) then
c_puts(", ONEFORWINDOWS") -- must call with __stdcall convention
else
c_puts(", 0") -- default: call with normal or __cdecl convention
end if
Expand Down Expand Up @@ -1590,11 +1620,7 @@ export procedure GenerateUserRoutines()
LeftSym = TRUE

-- declare the global routine as an exported DLL function
if TWINDOWS then
c_stmt(ret_type & " __stdcall @(", s)
else
c_stmt(ret_type & "@(", s)
end if
c_stmt(ret_type & " __global_routine @(", s)

else
LeftSym = TRUE
Expand Down
29 changes: 4 additions & 25 deletions source/c_out.e
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ end ifdef

include global.e
include buildsys.e
include std/search.e

--****
-- === gtype values, TRANSLATOR
Expand Down Expand Up @@ -176,7 +177,7 @@ export procedure adjust_indent_before(sequence stmt)

lb = FALSE
rb = FALSE

for p = 1 to length(stmt) do
switch stmt[p] do
case '\n' then
Expand All @@ -196,7 +197,7 @@ export procedure adjust_indent_before(sequence stmt)

end switch
end for

if rb then
if not lb then
indent -= 4
Expand All @@ -217,7 +218,7 @@ end procedure
--**
-- Adjust indent after a statement
export procedure adjust_indent_after(sequence stmt)

for p = 1 to length(stmt) do
switch stmt[p] do
case '\n' then
Expand All @@ -229,26 +230,4 @@ export procedure adjust_indent_after(sequence stmt)
end switch
end for

if length(stmt) < 3 then
return
end if

if not equal("if ", stmt[1..3]) then
return
end if

if length(stmt) < 5 then
return
end if

if not equal("else", stmt[1..4]) then
return
end if

if not find(stmt[5], {" \n"}) then
return
end if

temp_indent = 4

end procedure
Loading

0 comments on commit ffe9abd

Please sign in to comment.