Skip to content

Commit c2158fe

Browse files
committed
[[ Cleanup ]] Refactor the processor to reuse code
This patch refactors `the processor` to reuse code between platforms and also between LCS and LCB. A new `MCSInfo` api was implemented in libfoundation with `MCSInfoGetArchitecture` returning a string based architecture definitions in `foundation.h`. Additionally `the processor` documentation was updated to clarify returned values in emulated environments and to disassociate the returned values with particular operating systems to reduce maintenance.
1 parent a5ebc82 commit c2158fe

23 files changed

+106
-115
lines changed

docs/dictionary/function/processor.lcdoc

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,38 @@ Syntax: the processor
77
Syntax: processor()
88

99
Summary:
10-
<return|Returns> a <string> describing the system's CPU chip.
10+
<return|Returns> a <string> describing the system's architecture.
1111

1212
Introduced: 1.0
1313

14-
OS: mac, windows, ios, android
14+
OS: mac, windows, linux, ios, android, html5
1515

1616
Platforms: desktop, server, mobile
1717

1818
Example:
1919
the processor
2020

2121
Example:
22-
if the processor is "ARM" then ...
22+
if the processor is "arm" then ...
2323

2424
Returns (enum):
2525

26-
- x86: Windows systems (any architecture) and Mac OS X and Linux
27-
systems with a 32 bit processor.
28-
- x86_64: Mac and Linux systems running a 64 bit processor
29-
- i386: iOS Simulator.
30-
- ARM: iOS and Android Devices and the Android simulator
31-
26+
- x86: x86 32 bit architecure
27+
- x86_64: x86 64 bit architecure
28+
- arm: arm 32 bit architecture
29+
- arm64: arm 64 bit architecture
30+
- js: HTML 5
3231

3332
Description:
34-
Use the <processor> function to determine which microprocessor the
35-
device has.
33+
Use the <processor> function to determine the system architecture. The system
34+
architecture may either be emulated or the architecture of the host CPU. For
35+
example, when running the application in an android emulator the <processor>
36+
will return the emulated architecture rather than the architecture of the host
37+
CPU.
38+
39+
>*Note:* Some operating systems have emulators built in. For example, Windows
40+
> has WOW64 which allows x86 executables to run under x86_64 versions of
41+
> Windows.
3642

3743
References: machine (function), platform (function), return (glossary),
3844
string (keyword)

engine/src/dsklnx.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -765,19 +765,6 @@ class MCLinuxDesktop: public MCSystemInterface
765765
return MCStringCreateWithNativeChars((const char_t *)u.machine, MCCStringLength(u.machine), r_string);
766766
}
767767

768-
virtual MCNameRef GetProcessor(void)
769-
{
770-
#if defined(__X86_64__)
771-
return MCN_x86_64;
772-
#elif defined(__ARM__)
773-
return MCN_arm;
774-
#elif defined(__i386__)
775-
return MCN_x86;
776-
#else
777-
# error "One of __X86_64__, __ARM__ or __i386__ must be defined"
778-
#endif
779-
}
780-
781768
virtual bool GetAddress(MCStringRef& r_address)
782769
{
783770
struct utsname u;

engine/src/dskmac.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3014,16 +3014,8 @@ struct MCMacDesktop: public MCSystemInterface, public MCMacSystemService
30143014

30153015
return MCStringCopy(MCNameGetString(MCN_unknown), r_string); //in case model name can't be read
30163016
}
3017-
virtual MCNameRef GetProcessor(void)
3018-
{
3019-
//get machine processor
3020-
#ifdef __64_BIT__
3021-
return MCN_x86_64;
3022-
#else
3023-
return MCN_x86;
3024-
#endif
3025-
}
3026-
virtual bool GetAddress(MCStringRef& r_address)
3017+
3018+
virtual bool GetAddress(MCStringRef& r_address)
30273019
{
30283020
static struct utsname u;
30293021
uname(&u);

engine/src/dskw32.cpp

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1613,21 +1613,10 @@ struct MCWindowsDesktop: public MCSystemInterface, public MCWindowsSystemService
16131613

16141614
virtual bool GetMachine(MCStringRef& r_string)
16151615
{
1616-
r_string = MCValueRetain(MCNameGetString(GetProcessor()));
1616+
r_string = MCValueRetain(MCS_getprocessor());
16171617
return true;
16181618
}
16191619

1620-
virtual MCNameRef GetProcessor(void)
1621-
{
1622-
#if defined _M_IX86
1623-
return MCN_x86;
1624-
#elif defined _M_AMD64
1625-
return MCN_x86_64;
1626-
#else
1627-
# error Unknown processor
1628-
#endif
1629-
}
1630-
16311620
virtual bool GetAddress(MCStringRef& r_address)
16321621
{
16331622
if (!wsainit())

engine/src/em-system.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,6 @@ MCEmscriptenSystem::GetMachine(MCStringRef & r_string)
194194
return MCStringCopy(kMCEmptyString, r_string);
195195
}
196196

197-
MCNameRef
198-
MCEmscriptenSystem::GetProcessor()
199-
{
200-
return kMCEmptyName;
201-
}
202-
203197
bool
204198
MCEmscriptenSystem::GetAddress(MCStringRef & r_address)
205199
{

engine/src/em-system.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ class MCEmscriptenSystem: public MCSystemInterface
5555
/* ---------- System information */
5656
virtual bool GetVersion(MCStringRef & r_string);
5757
virtual bool GetMachine(MCStringRef & r_string);
58-
virtual MCNameRef GetProcessor(void);
5958
virtual bool GetAddress(MCStringRef & r_address);
6059

6160
/* ---------- Engine process information */

engine/src/exec-engine.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@ void MCEngineEvalMachine(MCExecContext& ctxt, MCStringRef& r_string)
157157
ctxt.Throw();
158158
}
159159

160-
void MCEngineEvalProcessor(MCExecContext& ctxt, MCNameRef& r_name)
160+
void MCEngineEvalProcessor(MCExecContext& ctxt, MCStringRef& r_string)
161161
{
162-
r_name = MCValueRetain(MCS_getprocessor());
162+
r_string = MCValueRetain(MCS_getprocessor());
163163
}
164164

165165
void MCEngineEvalSystemVersion(MCExecContext& ctxt, MCStringRef& r_string)

engine/src/exec.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2975,7 +2975,7 @@ void MCEngineEvalBuildNumber(MCExecContext& ctxt, integer_t& r_build_number);
29752975
void MCEngineEvalPlatform(MCExecContext& ctxt, MCNameRef& r_name);
29762976
void MCEngineEvalEnvironment(MCExecContext& ctxt, MCNameRef& r_name);
29772977
void MCEngineEvalMachine(MCExecContext& ctxt, MCStringRef& r_string);
2978-
void MCEngineEvalProcessor(MCExecContext& ctxt, MCNameRef& r_name);
2978+
void MCEngineEvalProcessor(MCExecContext& ctxt, MCStringRef& r_string);
29792979
void MCEngineEvalSystemVersion(MCExecContext& ctxt, MCStringRef& r_string);
29802980

29812981
void MCEngineEvalCommandNames(MCExecContext& ctxt, MCStringRef& r_string);

engine/src/funcs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1241,7 +1241,7 @@ class MCPopulationVariance : public MCParamFunctionCtxt<MCMathEvalPopulationVari
12411241
virtual ~MCPopulationVariance(){}
12421242
};
12431243

1244-
class MCProcessor : public MCConstantFunctionCtxt<MCNameRef, MCEngineEvalProcessor>
1244+
class MCProcessor : public MCConstantFunctionCtxt<MCStringRef, MCEngineEvalProcessor>
12451245
{
12461246
public:
12471247
};

engine/src/mblandroid.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ struct MCAndroidSystem: public MCSystemInterface
3636

3737
virtual bool GetVersion(MCStringRef& r_string);
3838
virtual bool GetMachine(MCStringRef& r_string);
39-
virtual MCNameRef GetProcessor(void);
4039
virtual bool GetAddress(MCStringRef& r_address);
4140

4241
virtual uint32_t GetProcessId(void);

0 commit comments

Comments
 (0)