[Ports] Merge Nspire port and Fxcg improvements

Close #327
This commit is contained in:
Yaya-Cout
2023-06-06 21:25:07 +02:00
parent a124ed72b5
commit 73450419bb
47 changed files with 4139 additions and 28 deletions

View File

@@ -135,7 +135,7 @@ public:
Expression() : TreeHandle() {}
Expression clone() const;
static Expression Parse(char const * string, Context * context, bool addMissingParenthesis = true);
static Expression ExpressionFromAddress(const void * address, size_t size);
static Expression ExpressionFromAddress(const void * address, size_t size, const void * record=nullptr);
/* Circuit breaker */
typedef bool (*CircuitBreaker)();

View File

@@ -21,7 +21,7 @@ class LayoutNode;
class Integer;
struct IntegerDivision;
#if (defined _3DS) || (defined _FXCG)
#if (defined _3DS) || (defined _FXCG) || defined NSPIRE_NEWLIB
typedef unsigned short half_native_uint_t;
static_assert(sizeof(half_native_uint_t) == sizeof(uint16_t));
typedef int native_int_t;

View File

@@ -38,10 +38,42 @@ Expression Expression::Parse(char const * string, Context * context, bool addPar
return expression;
}
Expression Expression::ExpressionFromAddress(const void * address, size_t size) {
Expression Expression::ExpressionFromAddress(const void * address, size_t size, const void * record) {
if (address == nullptr || size == 0) {
return Expression();
}
#ifdef STRING_STORAGE
// Check that expression was stored as a string in record
size_t i;
const char * ptr=(const char *) address;
for (i=1;i<size && ptr[i];++i){
if (ptr[i]=='"')
break;
}
if (i < 1024 && ptr[0]=='"' && i > 0 && i < size && ptr[i] == '"') {
((char *)ptr)[i] = 0;
Expression e = Expression::Parse(ptr + 1, nullptr);
((char *)ptr)[i] = '"';
address = e.addressInPool();
size = e.size();
if (record) {
const char * name = ((const Ion::Storage::Record *)record)->fullName();
char repl = 0;
int l = strlen(name);
if (strncmp(name+l-4,".seq",4) == 0) {
repl='n';
} else if (strncmp(name+l-5,".func",5) == 0) {
repl='x';
}
if (repl){
e=e.replaceSymbolWithExpression(Symbol::Builder(repl),Symbol::Builder(UCodePointUnknown));
address= e.addressInPool();
size=e.size();
}
}
return Expression(static_cast<ExpressionNode *>(TreePool::sharedPool()->copyTreeFromAddress(address, size))); // must be done before e is destroyed
}
#endif
// Build the Expression in the Tree Pool
return Expression(static_cast<ExpressionNode *>(TreePool::sharedPool()->copyTreeFromAddress(address, size)));
}