Move more functionality into M2libc

This commit is contained in:
Jeremiah Orians 2021-04-03 22:41:52 -04:00
parent 46cf81af83
commit d80d8a652b
No known key found for this signature in database
GPG Key ID: 6B3A3F198708F894
51 changed files with 251 additions and 631 deletions

4
cc.c
View File

@ -35,7 +35,7 @@ void preprocess();
void program();
void recursive_output(struct token_list* i, FILE* out);
void output_tokens(struct token_list *i, FILE* out);
int numerate_string(char *a);
int strtoint(char *a);
int main(int argc, char** argv)
{
@ -112,7 +112,7 @@ int main(int argc, char** argv)
}
else if(match(argv[i], "--max-string"))
{
MAX_STRING = numerate_string(argv[i+1]);
MAX_STRING = strtoint(argv[i+1]);
require(0 < MAX_STRING, "Not a valid string size\nAbort and fix your --max-string\n");
i = i + 2;
}

View File

@ -40,11 +40,10 @@ int current_count;
int Address_of;
/* Imported functions */
char* number_to_hex(int a, int bytes);
char* numerate_number(int a);
char* int2str(int x, int base, int signed_p);
int strtoint(char *a);
char* parse_string(char* string);
int escape_lookup(char* c);
int numerate_string(char *a);
void require(int bool, char* error);
struct token_list* reverse_list(struct token_list* head);
struct type* mirror_type(struct type* source, char* name);
@ -100,7 +99,7 @@ void line_error_token(struct token_list *token)
require(NULL != token, "EOF reached inside of line_error\n");
fputs(token->filename, stderr);
fputs(":", stderr);
fputs(numerate_number(token->linenumber), stderr);
fputs(int2str(token->linenumber, 10, TRUE), stderr);
fputs(":", stderr);
}
@ -341,7 +340,7 @@ void variable_load(struct token_list* a)
require(NULL != global_token, "incomplete variable load recieved\n");
if((match("FUNCTION", a->type->name) || match("FUNCTION*", a->type->name)) && match("(", global_token->s))
{
function_call(numerate_number(a->depth), TRUE);
function_call(int2str(a->depth, 10, TRUE), TRUE);
return;
}
current_target = a->type;
@ -352,7 +351,7 @@ void variable_load(struct token_list* a)
else if(ARMV7L == Architecture) emit_out("!");
else if(AARCH64 == Architecture) emit_out("SET_X0_FROM_BP\nLOAD_W1_AHEAD\nSKIP_32_DATA\n%");
emit_out(numerate_number(a->depth));
emit_out(int2str(a->depth, 10, TRUE));
if(ARMV7L == Architecture) emit_out(" R0 SUB BP ARITH_ALWAYS");
else if(AARCH64 == Architecture) emit_out("\nSUB_X0_X0_X1\n");
emit_out("\n");
@ -429,7 +428,7 @@ void primary_expr_failure()
void primary_expr_string()
{
char* number_string = numerate_number(current_count);
char* number_string = int2str(current_count, 10, TRUE);
current_count = current_count + 1;
if((KNIGHT_NATIVE == Architecture) || (KNIGHT_POSIX == Architecture)) emit_out("LOADR R0 4\nJUMP 4\n&STRING_");
else if(X86 == Architecture) emit_out("LOAD_IMMEDIATE_eax &STRING_");
@ -491,17 +490,49 @@ void primary_expr_char()
else if(AMD64 == Architecture) emit_out("LOAD_IMMEDIATE_rax %");
else if(ARMV7L == Architecture) emit_out("!");
else if(AARCH64 == Architecture) emit_out("LOAD_W0_AHEAD\nSKIP_32_DATA\n%");
emit_out(numerate_number(escape_lookup(global_token->s + 1)));
emit_out(int2str(escape_lookup(global_token->s + 1), 10, TRUE));
if(ARMV7L == Architecture) emit_out(" R0 LOADI8_ALWAYS");
emit_out("\n");
global_token = global_token->next;
}
int hex2char(int c)
{
if((c >= 0) && (c <= 9)) return (c + 48);
else if((c >= 10) && (c <= 15)) return (c + 55);
else return -1;
}
char* number_to_hex(int a, int bytes)
{
require(bytes > 0, "number to hex must have a positive number of bytes greater than zero\n");
char* result = calloc(1 + (bytes << 1), sizeof(char));
if(NULL == result)
{
fputs("calloc failed in number_to_hex\n", stderr);
exit(EXIT_FAILURE);
}
int i = 0;
int divisor = (bytes << 3);
require(divisor > 0, "unexpected wrap around in number_to_hex\n");
/* Simply collect numbers until divisor is gone */
while(0 != divisor)
{
divisor = divisor - 4;
result[i] = hex2char((a >> divisor) & 0xF);
i = i + 1;
}
return result;
}
void primary_expr_number()
{
if((KNIGHT_POSIX == Architecture) || (KNIGHT_NATIVE == Architecture))
{
int size = numerate_string(global_token->s);
int size = strtoint(global_token->s);
if((32767 > size) && (size > -32768))
{
emit_out("LOADI R0 ");
@ -702,31 +733,31 @@ void postfix_expr_arrow()
if((KNIGHT_POSIX == Architecture) || (KNIGHT_NATIVE == Architecture))
{
emit_out("ADDUI R0 R0 ");
emit_out(numerate_number(i->offset));
emit_out(int2str(i->offset, 10, TRUE));
emit_out("\n");
}
else if(X86 == Architecture)
{
emit_out("LOAD_IMMEDIATE_ebx %");
emit_out(numerate_number(i->offset));
emit_out(int2str(i->offset, 10, TRUE));
emit_out("\nADD_ebx_to_eax\n");
}
else if(AMD64 == Architecture)
{
emit_out("LOAD_IMMEDIATE_rbx %");
emit_out(numerate_number(i->offset));
emit_out(int2str(i->offset, 10, TRUE));
emit_out("\nADD_rbx_to_rax\n");
}
else if(ARMV7L == Architecture)
{
emit_out("!0 R1 LOAD32 R15 MEMORY\n~0 JUMP_ALWAYS\n%");
emit_out(numerate_number(i->offset));
emit_out(int2str(i->offset, 10, TRUE));
emit_out("\n'0' R0 R0 ADD R1 ARITH2_ALWAYS\n");
}
else if(AARCH64 == Architecture)
{
emit_out("LOAD_W1_AHEAD\nSKIP_32_DATA\n%");
emit_out(numerate_number(i->offset));
emit_out(int2str(i->offset, 10, TRUE));
emit_out("\nADD_X0_X1_X0\n");
}
}
@ -772,7 +803,7 @@ void postfix_expr_array()
else if(ARMV7L == Architecture) emit_out("'0' R0 R0 '");
else if(AARCH64 == Architecture) emit_out("LOAD_W2_AHEAD\nSKIP_32_DATA\n%");
emit_out(numerate_number(ceil_log2(current_target->indirect->size)));
emit_out(int2str(ceil_log2(current_target->indirect->size), 10, TRUE));
if(ARMV7L == Architecture) emit_out("' MOVE_ALWAYS");
else if(AARCH64 == Architecture) emit_out("\nLSHIFT_X0_X0_X2");
emit_out("\n");
@ -815,7 +846,7 @@ void unary_expr_sizeof()
else if(AMD64 == Architecture) emit_out("LOAD_IMMEDIATE_rax %");
else if(ARMV7L == Architecture) emit_out("!");
else if(AARCH64 == Architecture) emit_out("LOAD_W0_AHEAD\nSKIP_32_DATA\n%");
emit_out(numerate_number(a->size));
emit_out(int2str(a->size, 10, TRUE));
if(ARMV7L == Architecture) emit_out(" R0 LOADI8_ALWAYS");
emit_out("\n");
}
@ -1222,7 +1253,7 @@ void statement();
/* Evaluate if statements */
void process_if()
{
char* number_string = numerate_number(current_count);
char* number_string = int2str(current_count, 10, TRUE);
current_count = current_count + 1;
emit_out("# IF_");
@ -1278,7 +1309,7 @@ void process_for()
char* nested_break_num = break_target_num;
char* nested_continue_head = continue_target_head;
char* number_string = numerate_number(current_count);
char* number_string = int2str(current_count, 10, TRUE);
current_count = current_count + 1;
break_target_head = "FOR_END_";
@ -1388,7 +1419,7 @@ void process_do()
char* nested_break_num = break_target_num;
char* nested_continue_head = continue_target_head;
char* number_string = numerate_number(current_count);
char* number_string = int2str(current_count, 10, TRUE);
current_count = current_count + 1;
break_target_head = "DO_END_";
@ -1443,7 +1474,7 @@ void process_while()
char* nested_break_num = break_target_num;
char* nested_continue_head = continue_target_head;
char* number_string = numerate_number(current_count);
char* number_string = int2str(current_count, 10, TRUE);
current_count = current_count + 1;
break_target_head = "END_WHILE_";
@ -1839,7 +1870,7 @@ new_type:
require_match("ERROR in CONSTANT with sizeof\nMissing (\n", "(");
struct type* a = type_name();
require_match("ERROR in CONSTANT with sizeof\nMissing )\n", ")");
global_token->prev->s = numerate_number(a->size);
global_token->prev->s = int2str(a->size, 10, TRUE);
global_constant_list->arguments = global_token->prev;
}
else
@ -1888,7 +1919,7 @@ new_type:
global_token = global_token->next->next;
/* length */
size = numerate_string(global_token->s);
size = strtoint(global_token->s);
globals_list = emit("\n'", globals_list);
while (0 != size)
{

View File

@ -18,7 +18,7 @@
#include "gcc_req.h"
void require(int bool, char* error);
int numerate_string(char* a);
int strtoint(char* a);
void line_error_token(struct token_list* list);
struct token_list* eat_token(struct token_list* head);
@ -150,7 +150,7 @@ int macro_variable()
}
int macro_number()
{
int result = numerate_string(macro_token->s);
int result = strtoint(macro_token->s);
eat_current_token();
return result;
}

View File

@ -51,7 +51,20 @@ int preserve_string(int c)
return fgetc(input);
}
void fixup_label()
void copy_string(char* target, char* source, int max)
{
int i = 0;
while(0 != source[i])
{
target[i] = source[i];
i = i + 1;
if(i == max) break;
}
}
void fixup_label()
{
int hold = ':';
int prev;

View File

@ -19,7 +19,6 @@
#include "cc.h"
#include <stdint.h>
int char2hex(int c);
struct token_list* emit(char *s, struct token_list* head);
void require(int bool, char* error);
@ -33,6 +32,15 @@ char upcase(char a)
return a;
}
int char2hex(int c)
{
if (c >= '0' && c <= '9') return (c - 48);
else if (c >= 'a' && c <= 'f') return (c - 87);
else if (c >= 'A' && c <= 'F') return (c - 55);
else return -1;
}
int hexify(int c, int high)
{
int i = char2hex(c);

View File

@ -18,7 +18,7 @@
#include "cc.h"
/* Imported functions */
int numerate_string(char *a);
int strtoint(char *a);
void line_error();
void require(int bool, char* error);
@ -174,7 +174,7 @@ struct type* build_member(struct type* last, int offset)
{
global_token = global_token->next;
require(NULL != global_token, "struct member arrays can not be EOF sized\n");
i->size = member_type->type->size * numerate_string(global_token->s);
i->size = member_type->type->size * strtoint(global_token->s);
if(0 == i->size)
{
fputs("Struct only supports [num] form\n", stderr);

View File

@ -1,40 +0,0 @@
/* 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/>.
*/
// void* malloc(int size);
void* memset(void* ptr, int value, int num)
{
char* s;
for(s = ptr; 0 < num; num = num - 1)
{
s[0] = value;
s = s + 1;
}
}
void* calloc(int count, int size)
{
void* ret = malloc(count * size);
if(NULL == ret) return NULL;
memset(ret, 0, (count * size));
return ret;
}
void free(void* l)
{
return;
}

View File

@ -1,32 +0,0 @@
/* Copyright (C) 2016 Jeremiah Orians
* Copyright (C) 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* 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/>.
*/
#define FALSE 0
// CONSTANT FALSE 0
#define TRUE 1
// CONSTANT TRUE 1
int in_set(int c, char* s)
{
while(0 != s[0])
{
if(c == s[0]) return TRUE;
s = s + 1;
}
return FALSE;
}

View File

@ -1,35 +0,0 @@
/* 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/>.
*/
#define FALSE 0
// CONSTANT FALSE 0
#define TRUE 1
// CONSTANT TRUE 1
int match(char* a, char* b)
{
int i = -1;
do
{
i = i + 1;
if(a[i] != b[i])
{
return FALSE;
}
} while((0 != a[i]) && (0 !=b[i]));
return TRUE;
}

View File

@ -1,48 +0,0 @@
/* 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/>.
*/
#include<stdlib.h>
#include<string.h>
#include<stdio.h>
// void* calloc(int count, int size);
int hex2char(int c);
void require(int bool, char* error);
char* number_to_hex(int a, int bytes)
{
require(bytes > 0, "number to hex must have a positive number of bytes greater than zero\n");
char* result = calloc(1 + (bytes << 1), sizeof(char));
if(NULL == result)
{
fputs("calloc failed in number_to_hex\n", stderr);
exit(EXIT_FAILURE);
}
int i = 0;
int divisor = (bytes << 3);
require(divisor > 0, "unexpected wrap around in number_to_hex\n");
/* Simply collect numbers until divisor is gone */
while(0 != divisor)
{
divisor = divisor - 4;
result[i] = hex2char((a >> divisor) & 0xF);
i = i + 1;
}
return result;
}

View File

@ -1,182 +0,0 @@
/* 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/>.
*/
#include<stdlib.h>
#include<string.h>
#include<stdio.h>
// void* calloc(int count, int size);
#define TRUE 1
//CONSTANT TRUE 1
#define FALSE 0
//CONSTANT FALSE 0
int in_set(int c, char* s);
char* numerate_number(int a)
{
char* result = calloc(16, sizeof(char));
if(NULL == result)
{
fputs("calloc failed in numerate_number\n", stderr);
exit(EXIT_FAILURE);
}
int i = 0;
/* Deal with Zero case */
if(0 == a)
{
result[0] = '0';
return result;
}
/* Deal with negatives */
if(0 > a)
{
result[0] = '-';
i = 1;
a = a * -1;
}
/* Using the largest 10^n number possible in 32bits */
int divisor = 0x3B9ACA00;
/* Skip leading Zeros */
while(0 == (a / divisor)) divisor = divisor / 10;
/* Now simply collect numbers until divisor is gone */
while(0 < divisor)
{
result[i] = ((a / divisor) + 48);
a = a % divisor;
divisor = divisor / 10;
i = i + 1;
}
return result;
}
int char2hex(int c)
{
if (c >= '0' && c <= '9') return (c - 48);
else if (c >= 'a' && c <= 'f') return (c - 87);
else if (c >= 'A' && c <= 'F') return (c - 55);
else return -1;
}
int hex2char(int c)
{
if((c >= 0) && (c <= 9)) return (c + 48);
else if((c >= 10) && (c <= 15)) return (c + 55);
else return -1;
}
int char2dec(int c)
{
if (c >= '0' && c <= '9') return (c - 48);
else return -1;
}
int dec2char(int c)
{
if((c >= 0) && (c <= 9)) return (c + 48);
else return -1;
}
int index_number(char* s, char c)
{
int i = 0;
while(s[i] != c)
{
i = i + 1;
if(0 == s[i]) return -1;
}
return i;
}
int toupper(int c)
{
if(in_set(c, "abcdefghijklmnopqrstuvwxyz")) return (c & 0xDF);
return c;
}
int set_reader(char* set, int mult, char* input)
{
int n = 0;
int i = 0;
int hold;
int negative_p = FALSE;
if(input[0] == '-')
{
negative_p = TRUE;
i = i + 1;
}
while(in_set(input[i], set))
{
n = n * mult;
hold = index_number(set, toupper(input[i]));
/* Input managed to change between in_set and index_number */
if(-1 == hold) return 0;
n = n + hold;
i = i + 1;
}
/* loop exited before NULL and thus invalid input */
if(0 != input[i]) return 0;
if(negative_p)
{
n = 0 - n;
}
return n;
}
int numerate_string(char *a)
{
int result = 0;
/* If NULL string */
if(0 == a[0])
{
result = 0;
}
/* Deal with binary*/
else if ('0' == a[0] && 'b' == a[1])
{
result = set_reader("01", 2, a+2);
}
/* Deal with hex */
else if ('0' == a[0] && 'x' == a[1])
{
result = set_reader("0123456789ABCDEFabcdef", 16, a+2);
}
/* Deal with octal */
else if('0' == a[0])
{
result = set_reader("01234567", 8, a+1);
}
/* Deal with decimal */
else
{
result = set_reader("0123456789", 10, a);
}
/* Deal with sign extension */
if(0 != (0x80000000 & result)) result = (0xFFFFFFFF << 31) | result;
return result;
}

View File

@ -1,29 +0,0 @@
/* Copyright (C) 2016 Jeremiah Orians
* Copyright (C) 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* 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/>.
*/
#include<stdio.h>
#include<stdlib.h>
void require(int bool, char* error)
{
if(!bool)
{
fputs(error, stderr);
exit(EXIT_FAILURE);
}
}

View File

@ -1,37 +0,0 @@
/* 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/>.
*/
#include<stdlib.h>
#include<stdio.h>
void copy_string(char* target, char* source, int max)
{
int i = 0;
while(0 != source[i])
{
target[i] = source[i];
i = i + 1;
if(i == max) break;
}
}
int string_length(char* a)
{
int i = 0;
while(0 != a[i]) i = i + 1;
return i;
}

View File

@ -27,12 +27,7 @@ all: M2-Planet
.NOTPARALLEL:
M2-Planet: bin results cc.h cc_reader.c cc_strings.c cc_types.c cc_core.c cc.c cc_globals.c cc_globals.h
$(CC) $(CFLAGS) \
functions/match.c \
functions/in_set.c \
functions/numerate_number.c \
functions/number_pack.c \
functions/string.c \
functions/require.c \
M2libc/bootstrappable.c \
cc_reader.c \
cc_strings.c \
cc_types.c \
@ -46,12 +41,7 @@ M2-Planet: bin results cc.h cc_reader.c cc_strings.c cc_types.c cc_core.c cc.c c
M2-minimal: bin results cc.h cc_reader.c cc_strings.c cc_types.c cc_core.c cc-minimal.c
$(CC) $(CFLAGS) \
functions/match.c \
functions/in_set.c \
functions/numerate_number.c \
functions/number_pack.c \
functions/string.c \
functions/require.c \
M2libc/bootstrappable.c \
cc_reader.c \
cc_strings.c \
cc_types.c \

View File

@ -106,14 +106,14 @@ d4944bab7eeeb0f0173110aa35c2f9498098257a22af5f53e59e2ba86a64e78e test/results/t
a7220775ac37c772ac1cbb160484ca14434d8be2d6e23b55b2bd596ac4b9268c test/results/test0018-aarch64-binary
7c075fe81dcab0eb626a21abcbb1821ae9056a26d2b6d1fe9a7805fd4cad3624 test/results/test0018-amd64-binary
dec3a29cbac6f1db3bc88eb06c3ba8e8041cef67582d6e87c9c9192c562f4aa7 test/results/test0018-armv7l-binary
8574c6f226f9cf85dcc60c7cf17cc585dff5a4e33b68f492cf0ef481ccd88bdb test/results/test0018-knight-native-binary
3ba5d5d47b6812c31a7daa70c83f4ee2e1fe6c6460736509a18fb1ba196e7a9b test/results/test0018-knight-native-binary
65c080ac9faa024fbc60753b5ae392d1ad02ca73df25f20b914043010ae11fe9 test/results/test0018-knight-posix-binary
ce5f1f72553b68358e0471c60752c13601ab9a105ba2cbf89a02487910e28748 test/results/test0018-x86-binary
1ee8c41a79df0cad1c3726153f20c86af60cf19939f956661d4421074fc4234b test/results/test0019-aarch64-binary
0143e4d23bed51c35c5789545d5fdc6a77cc2f5f334a14df551b30de13995977 test/results/test0019-amd64-binary
e7dac4a88673ebd8aabb94c9a9631e4007dafbbe8e499dab7315afb3f6e8c1a8 test/results/test0019-armv7l-binary
6f888eb277ecfa17b86ce79b5f64e32cc31e411bddb4d1413bf6d2f094b45efa test/results/test0019-knight-posix-binary
07d5280e04d8838666ed64ace909d659ef32156088486c2dfb2636f95e7bfad9 test/results/test0019-x86-binary
a1b46230aa42e39213b8bb175e5bda26be5b8c128185f74d77567c1bef7ffce6 test/results/test0019-aarch64-binary
1322945d031e6b2afd0333ae51c29adede267afe28dcda48ddb7fbcc3bac76a3 test/results/test0019-amd64-binary
cc512a5f0302ba3e2acc9ec4c4b7909e2f73ab40d916591be17a767649936670 test/results/test0019-armv7l-binary
e77fee466e7064cfe68d73cfdfc03aa1d65fe277a75a6fc720ea9c7506a59269 test/results/test0019-knight-posix-binary
66d0a14f261dc2cbf177a69e4714034bb68697992e8417b8bfc18726ee57f53a test/results/test0019-x86-binary
4ff4e38663173f5607e71960bc7a80ada870e7f4586aa343d715f4a7ef257d98 test/results/test0020-aarch64-binary
feeaa62b3f02956b0d7cb1f6725c1d85b40c3d60eb9886b1b065e2eae16f7b62 test/results/test0020-amd64-binary
bea69049075b5af491b406eebaa945a9fcdbbf03effa8cea3b0dc5d067817bba test/results/test0020-armv7l-binary
@ -125,11 +125,11 @@ fda5e33f4a7604e492ee1cfc5e2ce1fe7feee54eb2602cdb8f4204f2e3758ea5 test/results/t
f867449035132f0dff29a49d5e3d8e68e7746661ea3887b0a6abe7a4be5f5e3a test/results/test0021-armv7l-binary
279925432c13666aa1a752d19727e461d6bb86769cacacc3aabc179948967de7 test/results/test0021-knight-posix-binary
4b42d4e9dc7879726127bba27c0b6efda845ecd6638c8dfb8a7783c12d018830 test/results/test0021-x86-binary
7acc51781155c0f8b06b7b452b25752069be6fc294e776a9e67ef6b52a33133f test/results/test0022-aarch64-binary
6fd6c60a27bf0a22ecf4804b58f9fc531db65943d08c9d27153c8ed06b7d614b test/results/test0022-amd64-binary
bc7a5dd55f333a52596227c857d31fe2e3a782d54892cb240600e695dfc80f89 test/results/test0022-armv7l-binary
a0d9319bc7dbb34a0ba941732eb90352b968e258c40d0468b30b620676a60c88 test/results/test0022-knight-posix-binary
2017fcc515d2968e3e2da798a6cbf1873f952007b362a36fb9c77507300a6cf5 test/results/test0022-x86-binary
dc770310f99141fd434d33a1374a0531e016a7c4cb6c2d26c261cc6b94521407 test/results/test0022-aarch64-binary
96cd7713ed099808e75d5de7a98fe4973203471bb179d31a651dc8d782b8a87f test/results/test0022-amd64-binary
58b388806f242b2852765caca23eff1261d51377f977e60c551ceea4ecf77a76 test/results/test0022-armv7l-binary
675eced69e569ced7acc61c87b9d851c2ffc44bf37f50642d7092ea926fd330b test/results/test0022-knight-posix-binary
566fc99d979f0b512ac018669061282f8ac67c8a014a0931de262ca697999b50 test/results/test0022-x86-binary
0e67f64655cac56d7cc282e52dace97dc64a4b6b7bda7c36c6746305b38c8ffb test/results/test0023-aarch64-binary
ee50559200bc0571bf261a704316a19b97130c45ed88ddf0838a1e58e1526d9b test/results/test0023-amd64-binary
8522885e02104a6fa43fb56181453a22f03fa7a7257544b27ef9ecbea21f2d63 test/results/test0023-armv7l-binary
@ -150,37 +150,37 @@ f32c249a1fb11681e87a903cc66427b77a542c1f30e1076bc5e7b89d71355f03 test/results/t
2af5d3418feaf3f4dd0cd815fb80a0e33bd431b65457ef088f48d03c91e2c6a2 test/results/test0100-armv7l-binary
57da8d6fc4a83e5fdaa419a6dd13c9d28394dbdafa54d6c29125c5049e62fdb4 test/results/test0100-knight-posix-binary
5c5f320432b31f2f52298e8fb79d0eb930ea67ac8c8affaa71d819adbdd11158 test/results/test0100-x86-binary
ec64c66b91f38215d493a46e241599355c2dcdad6919340f93981d2a24377197 test/results/test0101-aarch64-binary
0af96fedd2a16696b316d3ca4b37709f65cfdbc231f95c8ee76cd6371e810bb6 test/results/test0101-amd64-binary
3007971adbdf7fd1c44bbd34195bd0d85031c9659f93b1538d7fbde737044a0a test/results/test0101-armv7l-binary
d235e598549df24aea45758e74fa4e03a330c78ad3c3403420ee9d8a6478e6df test/results/test0101-knight-posix-binary
9d86a8d2e3bd202d1d590755e8a6d425287bd9d0001d3061a90374f1167d3628 test/results/test0101-x86-binary
c83feda6f529241e6a25949ce0b68e69021c560280571b44e9c52820e60e0c9e test/results/test0102-aarch64-binary
b75f75a3a7aee46d4064a3cca8690cc7ee90d4b3103c964d3654626a992878d5 test/results/test0102-amd64-binary
96d5500026bea8318f3466f75aa08d0dac7d8d7831452accd9498a78a51ff368 test/results/test0102-armv7l-binary
e17290b73faecf575f385c3c24f85911c069ab124bd6f509a0fd37c560fea5b3 test/results/test0102-knight-posix-binary
560180543bafb33b901e2c73a39ae8c7792ec8c1640db031e49ec083adbf4e41 test/results/test0102-x86-binary
084eaf14dcff2b4e98c69bf2a6dd2998ed8e05b0ca3ae62ac8af1a8f9c2f39ac test/results/test0101-aarch64-binary
121b260aab8a467583f92f39ced5cc2318e13debd3f244a2c73bd39866634fd5 test/results/test0101-amd64-binary
3b0b19768a7591e001e1bf507d5eed51f2221802910c18f0136b59cea00317a4 test/results/test0101-armv7l-binary
5e415e0b2c5482a46627c402da3d4231efe7cb6431b0bc8583ea971846ad3b9f test/results/test0101-knight-posix-binary
2c27aecafa20d23a09fde4b8e17ced7d722eb0d21fd706fac9a645908cda7db3 test/results/test0101-x86-binary
e3ff33d36fc94f612e92f08c4c292498a374f8b32788735567001857ddb252f0 test/results/test0102-aarch64-binary
b05bb60c6ab65c3a38a6b2ee151c0200c0862144c50bf61180468a2e55ea5b8e test/results/test0102-amd64-binary
ae3cbe17abc0c565ea9bb941e1bc0ad68fed3e72ac7843e480ec77218ac34ff9 test/results/test0102-armv7l-binary
b8c7402b751e3da0143177269581bd2094b6e41704cbf1a66247e751b3e525c2 test/results/test0102-knight-posix-binary
b557cf13b3191eb7371b54b51622db775398a17e76ad0d15cb83720559d95498 test/results/test0102-x86-binary
40b27b751443fe3308c795ac387a6ec4f5d6e14ab14bd353a0f9628ccd8e0621 test/results/test0103-aarch64-binary
e6fdb92d35353fb5207ae933dc6638bf9d48aaf5e3d7642de5542783b4bd36ef test/results/test0103-amd64-binary
cc2e451fc4a21f99d3919918ccaa35338dc9d915cdbf20c6c420b31d2c71c8ae test/results/test0103-armv7l-binary
bf7461adbff966eb147f68d49b8522414cac412e5805856d7fe6f38b6d2f383d test/results/test0103-knight-posix-binary
d2c3bcd259d06bbd1799036c0a38ce831d36837fae0c86e5036df37a3b9bd114 test/results/test0103-x86-binary
8a56e8101e7924aee1b052d8541666549d12813fd11225a0dcdae998820b5a6f test/results/test0104-aarch64-binary
c00ede1523cf181605614a16e191c72e6eb6da3841dc1beaf30650b3b98feadb test/results/test0104-amd64-binary
e72b85b91cf435dad66cd56d6acdb422d72c387735e4effa59e4c32e8f13ff58 test/results/test0104-armv7l-binary
e00e1764238ba1bd54d793cf46d02a937b5c2fd157e23ee7451ee22193471ae2 test/results/test0104-x86-binary
fb9ca23cb2523a3401907958291e42813eecdc1bb43d4e0b69048531f718a208 test/results/test0105-aarch64-binary
faf1768ecdae46e684dd76bd8adb342c4fe9906646224f01d85f4c1fbfbdd368 test/results/test0105-amd64-binary
e5ab4f572119c1fc661c94b1d903ce5d70b9282ebf49fe05dcc454bf7313d8bc test/results/test0105-armv7l-binary
39c9064b387defa1ab55e3e7088217b073663e95be7727b00f83961eab824ced test/results/test0105-x86-binary
e03b550cba36414c965e1f62ca5c880f9d1a49ca9ce5a036431c27f9a17d6e9d test/results/test0104-aarch64-binary
0a5beb3c4840a78251a8532ac9dc3a9859dc632b3f20ad406736b69b52e9eb2d test/results/test0104-amd64-binary
a1fae969b8697d118228f45962e1d3fba420e6c1ef9a955ffb9f97f9821f06f7 test/results/test0104-armv7l-binary
32c0e9690aaadc3a99e8c742bbd2316a902531b0ff7fc5be190a522b1d91cb45 test/results/test0104-x86-binary
f999bc35a7ede2de6e0c14b5d2760d2da6c7c7a9fe08b3aa69526c328fc0ed70 test/results/test0105-aarch64-binary
ada42a6fd009718c1341796e4baa219cf47c9f6127a2477eff7fec3e08e87e6a test/results/test0105-amd64-binary
794eae3f0d978820e2f55d377aefa005848ecc7c2e551be72f6590f3a101eb57 test/results/test0105-armv7l-binary
873decbdf250d59dc0d3313a14137584f3b34a84314723fa39ecd1a9e3aeabce test/results/test0105-x86-binary
15081d0f4b57e1fa37c7806b021e6d46b4d134f7b8496e4413f460b52a83ab50 test/results/test0106-aarch64-binary
fc31fc8b2d78bd50a4c89eb0e29149626868a70842a3dcb01ea87bb275a9e3c2 test/results/test0106-amd64-binary
0dfd9118b0ccab36fba948fa1952b4ab7bab28cdd57cf10c7da66240f5dcc598 test/results/test0106-armv7l-binary
965bdf7049179199b9f423250a186c7b64ea55326c3249127d2daf7d42ae53cc test/results/test0106-knight-native-binary
0a929d6990caee3e93b1188a38fd3041c6f8e46d25a386024647c0f05c33bce7 test/results/test0106-knight-posix-binary
331ffb5284bd824494ad61a3b0b2dff5681a63ab604e9a06100af531ae237148 test/results/test0106-x86-binary
7c37ee46b67c400f6ab8740417f59f65fb45ead82e5f9c8872efb92c7a663077 test/results/test1000-aarch64-binary
e70c2d890645766c9c4e648c3e92bfdeaf477c957458ef5d0957c424f6bdc4c0 test/results/test1000-amd64-binary
53ceced359aa2e226c9100dd2cf078b1ba2e72406f76e1bb688dcf14a17b6a12 test/results/test1000-armv7l-binary
99b6e2cb87498493364ecbd6ac9e27e79f510b90fe9560eb07f60011343fcbd2 test/results/test1000-knight-posix-binary
40e0a3e1db4dd6c88f50489280cccf18fa39684e06d6a1683f93c2f99d96715a test/results/test1000-x86-binary
36d7cb9b39048b5c2741c7f1c8ebec57d8536a764f1d0b36e92d0130ab223891 test/results/test1000-aarch64-binary
582774e2d6ceb47983f18e0c7f01709f7302019a64b3a8014e411aa93fbe1af5 test/results/test1000-amd64-binary
a7175eb90a548d0f3874f32903704876cebe6d247ce6cd55e72ab12d8f3050bd test/results/test1000-armv7l-binary
6e5f5f05fe6237697a80d922f11199a77815f7f94046dacd529b27d426e52f65 test/results/test1000-knight-posix-binary
1b2de2224ab3769cc0b69fbc086b46253b1a02ed6e1994244a9474ba719318a6 test/results/test1000-x86-binary

View File

@ -28,7 +28,6 @@ bin/M2-Planet \
-f M2libc/stdlib.c \
-f M2libc/knight/Native/fcntl.h \
-f M2libc/stdio.c \
-f functions/match.c \
-f test/test0018/math.c \
-o ${TMPDIR}/math.M1 \
|| exit 1

View File

@ -16,6 +16,7 @@
*/
#include<stdlib.h>
#include<stdio.h>
char* int2str(int x, int base, int signed_p);
int char2int(char c)
{
@ -35,7 +36,6 @@ void write_string(char* c, FILE* f)
}
}
char* numerate_number(int a);
void sum_file(FILE* input, FILE* output)
{
int c = fgetc(input);
@ -46,7 +46,7 @@ void sum_file(FILE* input, FILE* output)
c = fgetc(input);
}
write_string(numerate_number(sum), output);
write_string(int2str(sum, 10, 0), output);
fputc(10, output);
}

View File

@ -28,9 +28,7 @@ bin/M2-Planet \
-f M2libc/stdlib.c \
-f M2libc/knight/Linux/fcntl.h \
-f M2libc/stdio.c \
-f functions/match.c \
-f functions/in_set.c \
-f functions/numerate_number.c \
-f M2libc/bootstrappable.c \
-f test/test0019/getopt.c \
-o ${TMPDIR}/getopt.M1 \
|| exit 1

View File

@ -31,9 +31,7 @@ bin/M2-Planet \
-f M2libc/stdlib.c \
-f M2libc/${ARCH}/Linux/fcntl.h \
-f M2libc/stdio.c \
-f functions/match.c \
-f functions/in_set.c \
-f functions/numerate_number.c \
-f M2libc/bootstrappable.c \
-f test/test0019/getopt.c \
-o ${TMPDIR}/getopt.M1 \
|| exit 1

View File

@ -23,9 +23,28 @@
#define MAX_STRING 4096
// CONSTANT MAX_STRING 4096
int match(char* a, char* b);
char* get_current_dir_name();
#define FALSE 0
// CONSTANT FALSE 0
#define TRUE 1
// CONSTANT TRUE 1
int match(char* a, char* b)
{
int i = -1;
do
{
i = i + 1;
if(a[i] != b[i])
{
return FALSE;
}
} while((0 != a[i]) && (0 !=b[i]));
return TRUE;
}
char* copy_string(char* target, char* source)
{
while(0 != source[0])

View File

@ -28,7 +28,6 @@ bin/M2-Planet \
-f M2libc/stdlib.c \
-f M2libc/knight/Linux/fcntl.h \
-f M2libc/stdio.c \
-f functions/match.c \
-f test/test0021/chdir.c \
-o ${TMPDIR}/chdir.M1 \
|| exit 1

View File

@ -31,7 +31,6 @@ bin/M2-Planet \
-f M2libc/stdlib.c \
-f M2libc/${ARCH}/Linux/fcntl.h \
-f M2libc/stdio.c \
-f functions/match.c \
-f test/test0021/chdir.c \
--debug \
-o ${TMPDIR}/chdir.M1 \

View File

@ -18,7 +18,7 @@
#include<stdio.h>
#include <stdlib.h>
char* numerate_number(int a);
char* int2str(int x, int base, int signed_p);
int main()
{
@ -26,7 +26,7 @@ int main()
int j;
for(i = 0; i < 10; i = i + 1)
{
fputs(numerate_number(i), stdout);
fputs(int2str(i, 10, 0), stdout);
if(i != 1) continue;
fputc(' ', stdout);
}
@ -38,8 +38,8 @@ int main()
for(j = 0; j < 10; j = j + 1)
{
if(j == 2) continue;
fputs(numerate_number(i), stdout);
fputs(numerate_number(j), stdout);
fputs(int2str(i, 10, 0), stdout);
fputs(int2str(j, 10, 0), stdout);
fputc(' ', stdout);
}
}
@ -50,7 +50,7 @@ int main()
while(i < 9)
{
i = i + 1;
fputs(numerate_number(i), stdout);
fputs(int2str(i, 10, 0), stdout);
if(i != 3) continue;
fputc(' ', stdout);
}
@ -66,8 +66,8 @@ int main()
{
j = j + 1;
if(j == 4) continue;
fputs(numerate_number(i), stdout);
fputs(numerate_number(j), stdout);
fputs(int2str(i, 10, 0), stdout);
fputs(int2str(j, 10, 0), stdout);
fputc(' ', stdout);
}
}
@ -78,7 +78,7 @@ int main()
do
{
i = i + 1;
fputs(numerate_number(i), stdout);
fputs(int2str(i, 10, 0), stdout);
if(i != 5) continue;
fputc(' ', stdout);
}while(i < 9);
@ -94,8 +94,8 @@ int main()
{
j = j + 1;
if(j == 6) continue;
fputs(numerate_number(i), stdout);
fputs(numerate_number(j), stdout);
fputs(int2str(i, 10, 0), stdout);
fputs(int2str(j, 10, 0), stdout);
fputc(' ', stdout);
}while(j < 9);
}while(i < 9);

View File

@ -28,8 +28,7 @@ bin/M2-Planet \
-f M2libc/stdlib.c \
-f M2libc/knight/Linux/fcntl.h \
-f M2libc/stdio.c \
-f functions/in_set.c \
-f functions/numerate_number.c \
-f M2libc/bootstrappable.c \
-f test/test0022/continue.c \
-o ${TMPDIR}/continue.M1 \
|| exit 1

View File

@ -31,8 +31,7 @@ bin/M2-Planet \
-f M2libc/stdlib.c \
-f M2libc/${ARCH}/Linux/fcntl.h \
-f M2libc/stdio.c \
-f functions/in_set.c \
-f functions/numerate_number.c \
-f M2libc/bootstrappable.c \
-f test/test0022/continue.c \
--debug \
-o ${TMPDIR}/continue.M1 \

View File

@ -32,7 +32,24 @@
#define FALSE 0
//CONSTANT FALSE 0
int match(char* a, char* b);
#define FALSE 0
// CONSTANT FALSE 0
#define TRUE 1
// CONSTANT TRUE 1
int match(char* a, char* b)
{
int i = -1;
do
{
i = i + 1;
if(a[i] != b[i])
{
return FALSE;
}
} while((0 != a[i]) && (0 !=b[i]));
return TRUE;
}
struct entry
{

View File

@ -28,7 +28,6 @@ mkdir -p ${TMPDIR}
-f M2libc/stdlib.c \
-f M2libc/knight/Linux/fcntl.h \
-f M2libc/stdio.c \
-f functions/match.c \
-f test/test0100/blood-elf.c \
-o ${TMPDIR}/blood-elf.M1 \
|| exit 1

View File

@ -31,7 +31,6 @@ mkdir -p ${TMPDIR}
-f M2libc/stdlib.c \
-f M2libc/${ARCH}/Linux/fcntl.h \
-f M2libc/stdio.c \
-f functions/match.c \
-f test/test0100/blood-elf.c \
--debug \
-o ${TMPDIR}/blood-elf.M1 \

View File

@ -28,9 +28,7 @@ mkdir -p ${TMPDIR}
-f M2libc/stdlib.c \
-f M2libc/knight/Linux/fcntl.h \
-f M2libc/stdio.c \
-f functions/match.c \
-f functions/in_set.c \
-f functions/numerate_number.c \
-f M2libc/bootstrappable.c\
-f test/test0101/hex2_linker.c \
-o ${TMPDIR}/hex2_linker.M1 \
|| exit 1

View File

@ -31,8 +31,8 @@
//CONSTANT FALSE 0
int match(char* a, char* b);
char* numerate_number(int a);
int numerate_string(char *a);
char* int2str(int x, int base, int signed_p);
int strtoint(char *a);
int in_set(int c, char* s);
struct input_files
@ -65,7 +65,7 @@ void line_error()
{
fputs(filename, stderr);
fputs(":", stderr);
fputs(numerate_number(linenumber), stderr);
fputs(int2str(linenumber, 10, TRUE), stderr);
fputs(" :", stderr);
}
@ -164,7 +164,7 @@ void range_check(int displacement, int number_of_bytes)
if((8388607 < displacement) || (displacement < -8388608))
{
fputs("A displacement of ", stderr);
fputs(numerate_number(displacement), stderr);
fputs(int2str(displacement, 10, TRUE), stderr);
fputs(" does not fit in 3 bytes\n", stderr);
exit(EXIT_FAILURE);
}
@ -175,7 +175,7 @@ void range_check(int displacement, int number_of_bytes)
if((32767 < displacement) || (displacement < -32768))
{
fputs("A displacement of ", stderr);
fputs(numerate_number(displacement), stderr);
fputs(int2str(displacement, 10, TRUE), stderr);
fputs(" does not fit in 2 bytes\n", stderr);
exit(EXIT_FAILURE);
}
@ -186,7 +186,7 @@ void range_check(int displacement, int number_of_bytes)
if((127 < displacement) || (displacement < -128))
{
fputs("A displacement of ", stderr);
fputs(numerate_number(displacement), stderr);
fputs(int2str(displacement, 10, TRUE), stderr);
fputs(" does not fit in 1 byte\n", stderr);
exit(EXIT_FAILURE);
}
@ -592,7 +592,7 @@ int main(int argc, char **argv)
}
else if(match(argv[option_index], "-B") || match(argv[option_index], "--BaseAddress"))
{
Base_Address = numerate_string(argv[option_index + 1]);
Base_Address = strtoint(argv[option_index + 1]);
option_index = option_index + 2;
}
else if(match(argv[option_index], "-h") || match(argv[option_index], "--help"))

View File

@ -31,9 +31,7 @@ mkdir -p ${TMPDIR}
-f M2libc/stdlib.c \
-f M2libc/${ARCH}/Linux/fcntl.h \
-f M2libc/stdio.c \
-f functions/match.c \
-f functions/in_set.c \
-f functions/numerate_number.c \
-f M2libc/bootstrappable.c \
-f test/test0101/hex2_linker.c \
--debug \
-o ${TMPDIR}/hex2_linker.M1 \

View File

@ -56,12 +56,10 @@
/* Imported functions */
char* numerate_number(int a);
int hex2char(int c);
int strtoint(char *a);
char* int2str(int x, int base, int signed_p);
int in_set(int c, char* s);
int match(char* a, char* b);
int numerate_string(char *a);
int string_length(char* a);
void require(int bool, char* error);
struct blob
@ -101,7 +99,7 @@ void line_error(char* filename, int linenumber)
{
fputs(filename, stderr);
fputs(":", stderr);
fputs(numerate_number(linenumber), stderr);
fputs(int2str(linenumber, 10, TRUE), stderr);
fputs(" :", stderr);
}
@ -368,6 +366,15 @@ void line_macro(struct Token* p)
}
}
int string_length(char* a)
{
int i = 0;
while(0 != a[i]) i = i + 1;
return i;
}
void hexify_string(struct blob* p)
{
char* table = "0123456789ABCDEF";
@ -493,7 +500,7 @@ void preserve_other(struct blob* p)
}
else if('<' == c)
{
i->Expression = pad_nulls(numerate_string(i->Text + 1), i->Text);
i->Expression = pad_nulls(strtoint(i->Text + 1), i->Text);
}
}
}
@ -504,9 +511,9 @@ void bound_values(int displacement, int number_of_bytes, int low, int high)
if((high < displacement) || (displacement < low))
{
fputs("A displacement of ", stderr);
fputs(numerate_number(displacement), stderr);
fputs(int2str(displacement, 10, TRUE), stderr);
fputs(" does not fit in ", stderr);
fputs(numerate_number(number_of_bytes), stderr);
fputs(int2str(number_of_bytes, 10, TRUE), stderr);
fputs(" bytes\n", stderr);
exit(EXIT_FAILURE);
}
@ -587,6 +594,15 @@ void LittleEndian(char* start)
if(BigBitEndian) reverseBitOrder(c);
}
int hex2char(int c)
{
if((c >= 0) && (c <= 9)) return (c + 48);
else if((c >= 10) && (c <= 15)) return (c + 55);
else return -1;
}
int stringify(char* s, int digits, int divisor, int value, int shift)
{
int i = value;
@ -630,7 +646,7 @@ char* express_number(int value, char c)
fputs("Given symbol ", stderr);
fputc(c, stderr);
fputs(" to express immediate value ", stderr);
fputs(numerate_number(value), stderr);
fputs(int2str(value, 10, TRUE), stderr);
fputc('\n', stderr);
exit(EXIT_FAILURE);
}
@ -680,7 +696,7 @@ void eval_immediates(struct blob* p)
{
if(in_set(i->Text[0], "%~@!"))
{
value = numerate_string(i->Text + 1);
value = strtoint(i->Text + 1);
if(('0' == i->Text[1]) || (0 != value))
{
@ -690,7 +706,7 @@ void eval_immediates(struct blob* p)
}
else if(KNIGHT == Architecture)
{
value = numerate_string(i->Text);
value = strtoint(i->Text);
if(('0' == i->Text[0]) || (0 != value))
{
i->Expression = express_number(value, '@');

View File

@ -28,11 +28,7 @@ mkdir -p ${TMPDIR}
-f M2libc/stdlib.c \
-f M2libc/knight/Linux/fcntl.h \
-f M2libc/stdio.c \
-f functions/match.c \
-f functions/in_set.c \
-f functions/numerate_number.c \
-f functions/string.c \
-f functions/require.c \
-f M2libc/bootstrappable.c \
-f test/test0102/M1-macro.c \
-o ${TMPDIR}/M1-macro.M1 \
|| exit 1

View File

@ -31,11 +31,7 @@ mkdir -p ${TMPDIR}
-f M2libc/stdlib.c \
-f M2libc/${ARCH}/Linux/fcntl.h \
-f M2libc/stdio.c \
-f functions/match.c \
-f functions/in_set.c \
-f functions/numerate_number.c \
-f functions/string.c \
-f functions/require.c \
-f M2libc/bootstrappable.c \
-f test/test0102/M1-macro.c \
--debug \
-o ${TMPDIR}/M1-macro.M1 \

View File

@ -20,12 +20,25 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/utsname.h>
int match(char* a, char* b);
#define TRUE 1
//CONSTANT TRUE 1
#define FALSE 0
//CONSTANT FALSE 0
// CONSTANT FALSE 0
#define TRUE 1
// CONSTANT TRUE 1
int match(char* a, char* b)
{
int i = -1;
do
{
i = i + 1;
if(a[i] != b[i])
{
return FALSE;
}
} while((0 != a[i]) && (0 !=b[i]));
return TRUE;
}
/* Standard C main program */
int main(int argc, char **argv)

View File

@ -28,7 +28,6 @@ mkdir -p ${TMPDIR}
-f M2libc/stdlib.c \
-f M2libc/knight/Linux/fcntl.h \
-f M2libc/stdio.c \
-f functions/match.c \
-f test/test0103/get_machine.c \
-o ${TMPDIR}/get_machine.M1 \
|| exit 1

View File

@ -31,7 +31,6 @@ mkdir -p ${TMPDIR}
-f M2libc/stdlib.c \
-f M2libc/${ARCH}/Linux/fcntl.h \
-f M2libc/stdio.c \
-f functions/match.c \
-f test/test0103/get_machine.c \
--debug \
-o ${TMPDIR}/get_machine.M1 \

View File

@ -29,7 +29,7 @@
#define max_args 256
//CONSTANT max_args 256
char* numerate_number(int a);
char* int2str(int x, int base, int signed_p);
int match(char* a, char* b);
char** tokens;
@ -364,7 +364,7 @@ void execute_commands(FILE* script, char** envp, int envp_length)
if(STRICT && (0 != status))
{ /* Clearly the script hit an issue that should never have happened */
fputs("Subprocess error ", stderr);
fputs(numerate_number(status), stderr);
fputs(int2str(status,10, FALSE), stderr);
fputs("\nABORTING HARD\n", stderr);
/* stop to prevent damage */
exit(EXIT_FAILURE);

View File

@ -31,9 +31,7 @@ mkdir -p ${TMPDIR}
-f M2libc/stdlib.c \
-f M2libc/${ARCH}/Linux/fcntl.h \
-f M2libc/stdio.c \
-f functions/match.c \
-f functions/in_set.c \
-f functions/numerate_number.c \
-f M2libc/bootstrappable.c \
-f test/test0104/kaem.c \
--debug \
-o ${TMPDIR}/kaem.M1 \

View File

@ -116,7 +116,7 @@ int main(int argc, char **argv)
}
else if(match(argv[i], "-m") || match(argv[i], "--memory"))
{
number_of_cells = numerate_string(argv[i + 1]);
number_of_cells = strtoint(argv[i + 1]);
i = i + 2;
}
else if(match(argv[i], "-o") || match(argv[i], "--output"))

View File

@ -60,8 +60,8 @@ struct cell
/* Common functions */
struct cell* make_cons(struct cell* a, struct cell* b);
int numerate_string(char *a);
char* numerate_number(int a);
int strtoint(char *a);
char* int2str(int x, int base, int signed_p);
int match(char* a, char* b);
/* Global objects */

View File

@ -432,7 +432,7 @@ struct cell* prim_output(struct cell* args, FILE* out)
{
if(INT == args->car->type)
{
fputs(numerate_number(args->car->value), out);
fputs(int2str(args->car->value, 10, TRUE), out);
}
else if(CHAR == args->car->type)
{
@ -480,7 +480,7 @@ struct cell* prim_freecell(struct cell* args)
if(nil == args)
{
fputs("Remaining Cells: ", stdout);
fputs(numerate_number(left_to_take), stdout);
fputs(int2str(left_to_take, 10, TRUE), stdout);
return nil;
}
return make_int(left_to_take);

View File

@ -23,7 +23,7 @@ void writeobj(FILE *output_file, struct cell* op)
if(INT == op->type)
{
fputs(numerate_number(op->value), output_file);
fputs(int2str(op->value, 10, TRUE), output_file);
}
else if(CONS == op->type)
{
@ -70,7 +70,7 @@ void writeobj(FILE *output_file, struct cell* op)
else
{
fputs("Type ", stderr);
fputs(numerate_number(op->type), stderr);
fputs(int2str(op->type, 10, TRUE), stderr);
fputs(" is unknown\nPrint aborting hard\n", stderr);
exit(EXIT_FAILURE);
}

View File

@ -138,7 +138,7 @@ struct cell* atom(struct cell* a)
if(is_integer(a->string))
{
a->type = INT;
a->value = numerate_string(a->string);
a->value = strtoint(a->string);
return a;
}

View File

@ -31,10 +31,8 @@ mkdir -p ${TMPDIR}
-f M2libc/stdlib.c \
-f M2libc/${ARCH}/Linux/fcntl.h \
-f M2libc/stdio.c \
-f M2libc/bootstrappable.c \
-f test/test0105/lisp.h \
-f functions/in_set.c \
-f functions/numerate_number.c \
-f functions/match.c \
-f test/test0105/lisp.c \
-f test/test0105/lisp_cell.c \
-f test/test0105/lisp_eval.c \

View File

@ -25,13 +25,8 @@ mkdir -p ${TMPDIR}
./bin/M2-Planet \
--architecture aarch64 \
-f M2libc/aarch64/Linux/bootstrap.c \
-f functions/match.c \
-f functions/in_set.c \
-f functions/numerate_number.c \
-f functions/number_pack.c \
-f functions/string.c \
-f functions/require.c \
-f cc.h \
-f M2libc/bootstrappable.c \
-f cc_globals.c \
-f cc_reader.c \
-f cc_strings.c \
@ -83,13 +78,8 @@ then
-f M2libc/stdlib.c \
-f M2libc/x86/Linux/fcntl.h \
-f M2libc/stdio.c \
-f functions/match.c \
-f functions/in_set.c \
-f functions/numerate_number.c \
-f functions/number_pack.c \
-f functions/string.c \
-f functions/require.c \
-f cc.h \
-f M2libc/bootstrappable.c \
-f cc_globals.c \
-f cc_reader.c \
-f cc_strings.c \

View File

@ -25,13 +25,8 @@ mkdir -p ${TMPDIR}
./bin/M2-Planet \
--architecture amd64 \
-f M2libc/amd64/Linux/bootstrap.c \
-f functions/match.c \
-f functions/in_set.c \
-f functions/numerate_number.c \
-f functions/number_pack.c \
-f functions/string.c \
-f functions/require.c \
-f cc.h \
-f M2libc/bootstrappable.c \
-f cc_globals.c \
-f cc_reader.c \
-f cc_strings.c \
@ -83,13 +78,8 @@ then
-f M2libc/stdlib.c \
-f M2libc/x86/Linux/fcntl.h \
-f M2libc/stdio.c \
-f functions/match.c \
-f functions/in_set.c \
-f functions/numerate_number.c \
-f functions/number_pack.c \
-f functions/string.c \
-f functions/require.c \
-f cc.h \
-f M2libc/bootstrappable.c \
-f cc_globals.c \
-f cc_reader.c \
-f cc_strings.c \

View File

@ -25,13 +25,8 @@ mkdir -p ${TMPDIR}
./bin/M2-Planet \
--architecture armv7l \
-f M2libc/armv7l/Linux/bootstrap.c \
-f functions/match.c \
-f functions/in_set.c \
-f functions/numerate_number.c \
-f functions/number_pack.c \
-f functions/string.c \
-f functions/require.c \
-f cc.h \
-f M2libc/bootstrappable.c \
-f cc_globals.c \
-f cc_reader.c \
-f cc_strings.c \
@ -82,13 +77,8 @@ then
-f M2libc/stdlib.c \
-f M2libc/x86/Linux/fcntl.h \
-f M2libc/stdio.c \
-f functions/match.c \
-f functions/in_set.c \
-f functions/numerate_number.c \
-f functions/number_pack.c \
-f functions/string.c \
-f functions/require.c \
-f cc.h \
-f M2libc/bootstrappable.c \
-f cc_globals.c \
-f cc_reader.c \
-f cc_strings.c \

View File

@ -25,13 +25,8 @@ mkdir -p ${TMPDIR}
./bin/M2-Planet \
--architecture knight-posix \
-f M2libc/knight/Linux/bootstrap.c \
-f functions/match.c \
-f functions/in_set.c \
-f functions/numerate_number.c \
-f functions/number_pack.c \
-f functions/string.c \
-f functions/require.c \
-f cc.h \
-f M2libc/bootstrappable.c \
-f cc_globals.c \
-f cc_reader.c \
-f cc_strings.c \
@ -75,13 +70,8 @@ then
-f M2libc/stdlib.c \
-f M2libc/x86/Linux/fcntl.h \
-f M2libc/stdio.c \
-f functions/match.c \
-f functions/in_set.c \
-f functions/numerate_number.c \
-f functions/number_pack.c \
-f functions/string.c \
-f functions/require.c \
-f cc.h \
-f M2libc/bootstrappable.c \
-f cc_globals.c \
-f cc_reader.c \
-f cc_strings.c \
@ -111,13 +101,8 @@ then
-f M2libc/stdlib.c \
-f M2libc/x86/Linux/fcntl.h \
-f M2libc/stdio.c \
-f functions/match.c \
-f functions/in_set.c \
-f functions/numerate_number.c \
-f functions/number_pack.c \
-f functions/string.c \
-f functions/require.c \
-f cc.h \
-f M2libc/bootstrappable.c \
-f cc_globals.c \
-f cc_reader.c \
-f cc_strings.c \

View File

@ -25,13 +25,8 @@ mkdir -p ${TMPDIR}
./bin/M2-Planet \
--architecture x86 \
-f M2libc/x86/Linux/bootstrap.c \
-f functions/match.c \
-f functions/in_set.c \
-f functions/numerate_number.c \
-f functions/number_pack.c \
-f functions/string.c \
-f functions/require.c \
-f cc.h \
-f M2libc/bootstrappable.c \
-f cc_globals.c \
-f cc_reader.c \
-f cc_strings.c \
@ -82,13 +77,8 @@ then
-f M2libc/stdlib.c \
-f M2libc/x86/Linux/fcntl.h \
-f M2libc/stdio.c \
-f functions/match.c \
-f functions/in_set.c \
-f functions/numerate_number.c \
-f functions/number_pack.c \
-f functions/string.c \
-f functions/require.c \
-f cc.h \
-f M2libc/bootstrappable.c \
-f cc_globals.c \
-f cc_reader.c \
-f cc_strings.c \

View File

@ -1 +1 @@
c01c25c493655094e8fd89ff7a7e895e89046386ff38733df0a9a70822c22c94 test/test1000/proof
44c1d05a3c1d7545f9f5d5871ea07346421c0312f0c6bf97db46374d10544c71 test/test1000/proof