harmonize integer behavior when reading strings

This commit is contained in:
Jeremiah Orians 2020-10-17 13:50:25 -04:00
parent c4a636c99d
commit 39915de931
No known key found for this signature in database
GPG Key ID: 5410E91C14959E87
12 changed files with 90 additions and 8 deletions

View File

@ -46,7 +46,8 @@ char* parse_string(char* string);
int escape_lookup(char* c);
int numerate_string(char *a);
void require(int bool, char* error);
/* Host touchy function will need custom on 64bit systems*/
int fixup_int32(int a);
struct token_list* emit(char *s, struct token_list* head)
{
@ -446,7 +447,7 @@ void primary_expr_number()
{
if((KNIGHT_POSIX == Architecture) || (KNIGHT_NATIVE == Architecture))
{
int size = numerate_string(global_token->s);
int size = fixup_int32(numerate_string(global_token->s));
if((32767 > size) && (size > -32768))
{
emit_out("LOADI R0 ");

22
functions/fixup.c Normal file
View File

@ -0,0 +1,22 @@
/* Copyright (C) 2016 Jeremiah Orians
* This file is part of M2-Planet.
*
* M2-Planet is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* M2-Planet is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with M2-Planet. If not, see <http://www.gnu.org/licenses/>.
*/
/* This only works for 32bit architectures */
int fixup_int32(int a)
{
return a;
}

View File

@ -34,6 +34,7 @@ M2-Planet: bin results cc.h cc_reader.c cc_strings.c cc_types.c cc_core.c cc.c
functions/number_pack.c \
functions/string.c \
functions/require.c \
functions/fixup.c \
cc_reader.c \
cc_strings.c \
cc_types.c \
@ -52,6 +53,7 @@ M2-minimal: bin results cc.h cc_reader.c cc_strings.c cc_types.c cc_core.c cc-mi
functions/number_pack.c \
functions/string.c \
functions/require.c \
functions/fixup.c \
cc_reader.c \
cc_strings.c \
cc_types.c \

View File

@ -0,0 +1,28 @@
/* Copyright (C) 2016 Jeremiah Orians
* This file is part of M2-Planet.
*
* M2-Planet is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* M2-Planet is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with M2-Planet. If not, see <http://www.gnu.org/licenses/>.
*/
int fixup_int32(int a)
{
if(0 != (0x80000000 & a))
{
a = a << 32;
a = a >> 32;
}
return a;
}

View File

@ -0,0 +1,24 @@
/* Copyright (C) 2016 Jeremiah Orians
* This file is part of M2-Planet.
*
* M2-Planet is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* M2-Planet is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with M2-Planet. If not, see <http://www.gnu.org/licenses/>.
*/
/* Only works for AMD64 with the value in RAX */
int fixup_int32(int a)
{
asm("LOAD_EFFECTIVE_ADDRESS_rax %8"
"LOAD_INTEGER"
"MOVESX");
}

View File

@ -169,8 +169,8 @@ c22dabd4d371e23ed10389080eaa241f31a3822f08c64c934776c80b2e376a51 test/results/t
6eb826151abe3ea2d7c1f16079e61f1b80d651a20f8341fbb77574f7b5c41fb3 test/results/test0106-knight-native-binary
61cdce452cb287467efbf315da67f3d107f5d3a9c3cf5b086bf51dcc67d78971 test/results/test0106-knight-posix-binary
55804110c3b2d5a5e5130a8ed11f0888f4460ee32ad6a86fde877ec914624a6d test/results/test0106-x86-binary
33408d9b3370af357dd4cbdbbe8afaa8ef2b3d178dd889bb18b4d332ea073e5c test/results/test1000-aarch64-binary
20c40ff607486a267e7d97efb3b085ada3ab047d7275d2cce3bab1e5fbfeceb7 test/results/test1000-amd64-binary
79aa352c954cbf5a8ad97a2065114342acd20ae71ee33af1adb73eedb380557f test/results/test1000-armv7l-binary
4b513e582ab3686c996052930a6af88d2ad176a81223f8d3d99e6617ba501277 test/results/test1000-knight-posix-binary
8f89602bc7e66f4c228f97c04054b2d8613b81dabed3796bd9486f98756de806 test/results/test1000-x86-binary
b952f44841f440020baa6ef5243ec223fb85f7a1f2326c0b40ee16b65dbebe49 test/results/test1000-aarch64-binary
23875877e8721ed56c3e0ef625ac264bd39d9ed594905adebf1c2e933e33cca5 test/results/test1000-amd64-binary
ef705712c741acb90464ab58154c16832658a980bc7a55c48aea64e59ea93ebc test/results/test1000-armv7l-binary
7d7b4dbeea3aac3a91fb093ddd4b37baf8898ddf5f8f2af8006529f737b75a93 test/results/test1000-knight-posix-binary
3b8bec2a562ac0a5c6a623563ad7622a987b24e47937885d1f21d2ea17871e34 test/results/test1000-x86-binary

View File

@ -30,6 +30,7 @@ set -ex
-f functions/number_pack.c \
-f functions/string.c \
-f functions/require.c \
-f test/common_aarch64/functions/fixup.c \
-f cc.h \
-f cc_reader.c \
-f cc_strings.c \

View File

@ -29,6 +29,7 @@ set -ex
-f functions/number_pack.c \
-f functions/string.c \
-f functions/require.c \
-f test/common_amd64/functions/fixup.c \
-f cc.h \
-f cc_reader.c \
-f cc_strings.c \

View File

@ -29,6 +29,7 @@ set -ex
-f functions/number_pack.c \
-f functions/string.c \
-f functions/require.c \
-f functions/fixup.c \
-f cc.h \
-f cc_reader.c \
-f cc_strings.c \

View File

@ -29,6 +29,7 @@ set -ex
-f functions/number_pack.c \
-f functions/string.c \
-f functions/require.c \
-f functions/fixup.c \
-f cc.h \
-f cc_reader.c \
-f cc_strings.c \

View File

@ -29,6 +29,7 @@ set -ex
-f functions/number_pack.c \
-f functions/string.c \
-f functions/require.c \
-f functions/fixup.c \
-f cc.h \
-f cc_reader.c \
-f cc_strings.c \

View File

@ -1 +1 @@
c3442a08ff63c1520c84e6f4cc3e97e379e0d87fedd300b14c5f38f0fce65e55 test/test1000/proof
df2c542a46a5367f62b3a573256942bc139fdcd5cd49547b43257ab889c50bad test/test1000/proof