Fixes from trying to compile idris with the refc backend

* fix doublequoting in constArray
* substitute tildes in names
* Add negate functions
* Add string comparisons

Several things remain, notably missing _argList functions.
This commit is contained in:
Niklas Larsson 2021-04-02 15:02:40 +02:00
parent b27001136b
commit e49916cea9
3 changed files with 76 additions and 3 deletions

View File

@ -61,6 +61,7 @@ showcCleanStringChar '$' = ("_dollar" ++)
showcCleanStringChar ',' = ("_comma" ++) showcCleanStringChar ',' = ("_comma" ++)
showcCleanStringChar '#' = ("_number" ++) showcCleanStringChar '#' = ("_number" ++)
showcCleanStringChar '%' = ("_percent" ++) showcCleanStringChar '%' = ("_percent" ++)
showcCleanStringChar '~' = ("_tilde" ++)
showcCleanStringChar c showcCleanStringChar c
= if c < chr 32 || c > chr 126 = if c < chr 32 || c > chr 126
then (("u" ++ pad (asHex (cast c))) ++) then (("u" ++ pad (asHex (cast c))) ++)
@ -202,7 +203,7 @@ plainOp op args = op ++ "(" ++ (showSep ", " args) ++ ")"
||| Generate scheme for a primitive function. ||| Generate scheme for a primitive function.
cOp : PrimFn arity -> Vect arity String -> String cOp : PrimFn arity -> Vect arity String -> String
cOp (Neg ty) [x] = "-" ++ x cOp (Neg ty) [x] = "negate_" ++ cConstant ty ++ "(" ++ x ++ ")"
cOp StrLength [x] = "stringLength(" ++ x ++ ")" cOp StrLength [x] = "stringLength(" ++ x ++ ")"
cOp StrHead [x] = "head(" ++ x ++ ")" cOp StrHead [x] = "head(" ++ x ++ ")"
cOp StrTail [x] = "tail(" ++ x ++ ")" cOp StrTail [x] = "tail(" ++ x ++ ")"
@ -629,7 +630,7 @@ mutual
makeNonIntSwitchStatementConst ((MkAConstAlt constant caseBody) :: alts) 1 constantArray "multiDoubleCompare" makeNonIntSwitchStatementConst ((MkAConstAlt constant caseBody) :: alts) 1 constantArray "multiDoubleCompare"
_ => pure ("ERROR_NOT_DOUBLE_OR_STRING", "ERROR_NOT_DOUBLE_OR_STRING") _ => pure ("ERROR_NOT_DOUBLE_OR_STRING", "ERROR_NOT_DOUBLE_OR_STRING")
makeNonIntSwitchStatementConst ((MkAConstAlt constant caseBody) :: alts) k constantArray compareFct = do makeNonIntSwitchStatementConst ((MkAConstAlt constant caseBody) :: alts) k constantArray compareFct = do
emit EmptyFC $ constantArray ++ "[" ++ show (k-1) ++ "] = \"" ++ extractConstant constant ++ "\";" emit EmptyFC $ constantArray ++ "[" ++ show (k-1) ++ "] = " ++ extractConstant constant ++ ";"
makeNonIntSwitchStatementConst alts (k+1) constantArray compareFct makeNonIntSwitchStatementConst alts (k+1) constantArray compareFct

View File

@ -40,6 +40,19 @@ Value *sub_double(Value *x, Value *y)
return (Value *)makeDouble(((Value_Double *)x)->d - ((Value_Double *)y)->d); return (Value *)makeDouble(((Value_Double *)x)->d - ((Value_Double *)y)->d);
} }
/* negate */
Value *negate_i32(Value *x)
{
return (Value *)makeInt32(-((Value_Int32 *)x)->i32);
}
Value *negate_i64(Value *x)
{
return (Value *)makeInt64(-((Value_Int64 *)x)->i64);
}
Value *negate_double(Value *x)
{
return (Value *)makeDouble(-((Value_Double *)x)->d);
}
/* mul */ /* mul */
Value *mul_i32(Value *x, Value *y) Value *mul_i32(Value *x, Value *y)
{ {
@ -174,6 +187,18 @@ Value *lt_char(Value *x, Value *y)
} }
} }
Value *lt_string(Value *x, Value *y)
{
if (strcmp(((Value_String *)x)->str, ((Value_String *)y)->str) < 0)
{
return (Value *)makeInt32(1);
}
else
{
return (Value *)makeInt32(0);
}
}
/* gt */ /* gt */
Value *gt_i32(Value *x, Value *y) Value *gt_i32(Value *x, Value *y)
{ {
@ -220,6 +245,18 @@ Value *gt_char(Value *x, Value *y)
} }
} }
Value *gt_string(Value *x, Value *y)
{
if (strcmp(((Value_String *)x)->str, ((Value_String *)y)->str) > 0)
{
return (Value *)makeInt32(1);
}
else
{
return (Value *)makeInt32(0);
}
}
/* eq */ /* eq */
Value *eq_i32(Value *x, Value *y) Value *eq_i32(Value *x, Value *y)
{ {
@ -323,6 +360,18 @@ Value *lte_char(Value *x, Value *y)
} }
} }
Value *lte_string(Value *x, Value *y)
{
if (strcmp(((Value_String *)x)->str, ((Value_String *)y)->str) <= 0)
{
return (Value *)makeInt32(1);
}
else
{
return (Value *)makeInt32(0);
}
}
/* gte */ /* gte */
Value *gte_i32(Value *x, Value *y) Value *gte_i32(Value *x, Value *y)
{ {
@ -335,6 +384,7 @@ Value *gte_i32(Value *x, Value *y)
return (Value *)makeInt32(0); return (Value *)makeInt32(0);
} }
} }
Value *gte_i64(Value *x, Value *y) Value *gte_i64(Value *x, Value *y)
{ {
if (((Value_Int64 *)x)->i64 >= ((Value_Int64 *)y)->i64) if (((Value_Int64 *)x)->i64 >= ((Value_Int64 *)y)->i64)
@ -346,6 +396,7 @@ Value *gte_i64(Value *x, Value *y)
return (Value *)makeInt32(0); return (Value *)makeInt32(0);
} }
} }
Value *gte_double(Value *x, Value *y) Value *gte_double(Value *x, Value *y)
{ {
if (((Value_Double *)x)->d >= ((Value_Double *)y)->d) if (((Value_Double *)x)->d >= ((Value_Double *)y)->d)
@ -357,6 +408,7 @@ Value *gte_double(Value *x, Value *y)
return (Value *)makeInt32(0); return (Value *)makeInt32(0);
} }
} }
Value *gte_char(Value *x, Value *y) Value *gte_char(Value *x, Value *y)
{ {
if (((Value_Char *)x)->c >= ((Value_Char *)y)->c) if (((Value_Char *)x)->c >= ((Value_Char *)y)->c)
@ -368,3 +420,15 @@ Value *gte_char(Value *x, Value *y)
return (Value *)makeInt32(0); return (Value *)makeInt32(0);
} }
} }
Value *gte_string(Value *x, Value *y)
{
if (strcmp(((Value_String *)x)->str, ((Value_String *)y)->str) >= 0)
{
return (Value *)makeInt32(1);
}
else
{
return (Value *)makeInt32(0);
}
}

View File

@ -16,6 +16,11 @@ Value *sub_i32(Value *x, Value *y);
Value *sub_i64(Value *x, Value *y); Value *sub_i64(Value *x, Value *y);
Value *sub_double(Value *x, Value *y); Value *sub_double(Value *x, Value *y);
/* negate */
Value *negate_i32(Value *x);
Value *negate_i64(Value *x);
Value *negate_double(Value *x);
/* mul */ /* mul */
Value *mul_i32(Value *x, Value *y); Value *mul_i32(Value *x, Value *y);
Value *mul_i64(Value *x, Value *y); Value *mul_i64(Value *x, Value *y);
@ -55,12 +60,14 @@ Value *lt_i32(Value *x, Value *y);
Value *lt_i64(Value *x, Value *y); Value *lt_i64(Value *x, Value *y);
Value *lt_double(Value *x, Value *y); Value *lt_double(Value *x, Value *y);
Value *lt_char(Value *x, Value *y); Value *lt_char(Value *x, Value *y);
Value *lt_string(Value *x, Value *y);
/* gt */ /* gt */
Value *gt_i32(Value *x, Value *y); Value *gt_i32(Value *x, Value *y);
Value *gt_i64(Value *x, Value *y); Value *gt_i64(Value *x, Value *y);
Value *gt_double(Value *x, Value *y); Value *gt_double(Value *x, Value *y);
Value *gt_char(Value *x, Value *y); Value *gt_char(Value *x, Value *y);
Value *gt_string(Value *x, Value *y);
/* eq */ /* eq */
Value *eq_i32(Value *x, Value *y); Value *eq_i32(Value *x, Value *y);
@ -74,11 +81,12 @@ Value *lte_i32(Value *x, Value *y);
Value *lte_i64(Value *x, Value *y); Value *lte_i64(Value *x, Value *y);
Value *lte_double(Value *x, Value *y); Value *lte_double(Value *x, Value *y);
Value *lte_char(Value *x, Value *y); Value *lte_char(Value *x, Value *y);
Value *lte_string(Value *x, Value *y);
/* gte */ /* gte */
Value *gte_i32(Value *x, Value *y); Value *gte_i32(Value *x, Value *y);
Value *gte_i64(Value *x, Value *y); Value *gte_i64(Value *x, Value *y);
Value *gte_double(Value *x, Value *y); Value *gte_double(Value *x, Value *y);
Value *gte_char(Value *x, Value *y); Value *gte_char(Value *x, Value *y);
Value *gte_string(Value *x, Value *y);
#endif #endif