From 14843efa5ed13372b1ec32a76d19f27b3febab91 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sun, 19 Nov 2017 09:52:14 +0100 Subject: [PATCH 1/2] Make hex.c more mescc friendly to simplify bootstrapping --- Linux Bootstrap/hex.c | 54 +++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/Linux Bootstrap/hex.c b/Linux Bootstrap/hex.c index ce4461d..92f07fa 100644 --- a/Linux Bootstrap/hex.c +++ b/Linux Bootstrap/hex.c @@ -35,21 +35,25 @@ void purge_line_comments() int hex(char c) { - switch(c) + if (c >= '0' && c <= '9') { - case '0' ... '9': return (c - 48); - case 'a' ... 'f': return (c - 87); - case 'A' ... 'F': return (c - 55); - default: break; + return (c - 48); } - - printf("You managed to call a hex function without a hex value!!!\n"); - exit(EXIT_FAILURE); + else if (c >= 'a' && c <= 'z') + { + return (c - 87); + } + else if (c >= 'A' && c <= 'Z') + { + return (c - 55); + } + printf("You managed to call a hex function without a hex value!!!\n"); + exit(EXIT_FAILURE); } int main(int argc, char *argv[]) { - char c; + int c; int sum; bool toggle; toggle = false; @@ -57,27 +61,23 @@ int main(int argc, char *argv[]) do { c = getchar(); - switch(c) + if (c == '#') + purge_line_comments(); + else if ((c >= '0' && c <= '9') + || (c >= 'a' && c <= 'z') + || (c >= 'A' && c <= 'Z')) { - case '0' ... '9': - case 'a' ... 'f': - case 'A' ... 'F': + if(!toggle) { - if(!toggle) - { - sum = hex(c); - toggle = true; - } - else - { - sum = (sum * 16) + hex(c); - toggle = false; - putc(sum, stdout); - } - break; + sum = hex(c); + toggle = true; + } + else + { + sum = (sum * 16) + hex(c); + toggle = false; + fputc(sum, stdout); } - case '#': purge_line_comments(); - default: break; } }while(c != EOF); From 137e8b7139f146befc556b29b781caba1d29b7e4 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sun, 19 Nov 2017 09:53:50 +0100 Subject: [PATCH 2/2] makefile: use $(CC) --- makefile | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/makefile b/makefile index a2c4d1f..1104640 100644 --- a/makefile +++ b/makefile @@ -26,16 +26,16 @@ development: vm libvm.so asm dis ALL-ROMS # VM Builds vm-minimal: vm.h vm_minimal.c vm_instructions.c vm_decode.c | bin - gcc vm.h vm_minimal.c vm_instructions.c vm_decode.c -o bin/vm-minimal + $(CC) vm.h vm_minimal.c vm_instructions.c vm_decode.c -o bin/vm-minimal vm: vm.h vm.c vm_instructions.c vm_decode.c tty.c | bin - gcc -ggdb -Dtty_lib=true vm.h vm.c vm_instructions.c vm_decode.c tty.c -o bin/vm + $(CC) -ggdb -Dtty_lib=true vm.h vm.c vm_instructions.c vm_decode.c tty.c -o bin/vm vm-production: vm.h vm.c vm_instructions.c vm_decode.c | bin - gcc vm.h vm.c vm_instructions.c vm_decode.c -o bin/vm-production + $(CC) vm.h vm.c vm_instructions.c vm_decode.c -o bin/vm-production vm-trace: vm.h vm.c vm_instructions.c vm_decode.c tty.c dynamic_execution_trace.c | bin - gcc -ggdb -Dtty_lib=true -DTRACE=true vm.h vm.c vm_instructions.c vm_decode.c tty.c dynamic_execution_trace.c -o bin/vm + $(CC) -ggdb -Dtty_lib=true -DTRACE=true vm.h vm.c vm_instructions.c vm_decode.c tty.c dynamic_execution_trace.c -o bin/vm # Build the roms ALL-ROMS: stage0_monitor stage1_assembler-0 SET DEHEX stage1_assembler-1 stage1_assembler-2 M0 CAT lisp forth @@ -81,23 +81,23 @@ forth: M0 stage1_assembler-2 vm High_level_prototypes/defs stage2/forth.s | roms # Primitive development tools, not required but it was handy asm: High_level_prototypes/asm.c | bin - gcc -ggdb High_level_prototypes/asm.c -o bin/asm + $(CC) -ggdb High_level_prototypes/asm.c -o bin/asm dis: High_level_prototypes/disasm.c | bin - gcc -ggdb High_level_prototypes/disasm.c -o bin/dis + $(CC) -ggdb High_level_prototypes/disasm.c -o bin/dis hex: Linux\ Bootstrap/hex.c | bin - gcc Linux\ Bootstrap/hex.c -o bin/hex + $(CC) Linux\ Bootstrap/hex.c -o bin/hex xeh: Linux\ Bootstrap/xeh.c | bin - gcc Linux\ Bootstrap/xeh.c -o bin/xeh + $(CC) Linux\ Bootstrap/xeh.c -o bin/xeh # libVM Builds for Development tools libvm.so: wrapper.c vm_instructions.c vm_decode.c vm.h tty.c - gcc -ggdb -Dtty_lib=true -shared -Wl,-soname,libvm.so -o libvm.so -fPIC wrapper.c vm_instructions.c vm_decode.c vm.h tty.c + $(CC) -ggdb -Dtty_lib=true -shared -Wl,-soname,libvm.so -o libvm.so -fPIC wrapper.c vm_instructions.c vm_decode.c vm.h tty.c libvm-production.so: wrapper.c vm_instructions.c vm_decode.c vm.h - gcc -shared -Wl,-soname,libvm.so -o libvm-production.so -fPIC wrapper.c vm_instructions.c vm_decode.c vm.h + $(CC) -shared -Wl,-soname,libvm.so -o libvm-production.so -fPIC wrapper.c vm_instructions.c vm_decode.c vm.h # Tests Generate-rom-test: ALL-ROMS @@ -111,25 +111,25 @@ test: ALL-ROMS test/SHA256SUMS ALL-PROTOTYPES: prototype_dehex prototype_M0 prototype_more prototype_SET prototype_stage1_assembler-1 prototype_stage1_assembler-2 prototype_lisp prototype_dehex: dehex.c | prototypes - gcc stage1/High_level_prototypes/dehex.c -o prototypes/prototype_dehex + $(CC) stage1/High_level_prototypes/dehex.c -o prototypes/prototype_dehex prototype_M0: M0-macro.c | prototypes - gcc stage1/High_level_prototypes/M0-macro.c -o prototypes/prototype_M0 + $(CC) stage1/High_level_prototypes/M0-macro.c -o prototypes/prototype_M0 prototype_more: more.c tty.c | prototypes - gcc stage1/High_level_prototypes/more.c tty.c -o prototypes/prototype_more + $(CC) stage1/High_level_prototypes/more.c tty.c -o prototypes/prototype_more prototype_SET: SET.c tty.c | prototypes - gcc stage1/High_level_prototypes/SET.c tty.c -o prototypes/prototype_SET + $(CC) stage1/High_level_prototypes/SET.c tty.c -o prototypes/prototype_SET prototype_stage1_assembler-1: stage1_assembler-1.c | prototypes - gcc stage1/High_level_prototypes/stage1_assembler-1.c -o prototypes/prototype_stage1_assembler-1 + $(CC) stage1/High_level_prototypes/stage1_assembler-1.c -o prototypes/prototype_stage1_assembler-1 prototype_stage1_assembler-2: stage1_assembler-2.c | prototypes - gcc stage1/High_level_prototypes/stage1_assembler-2.c -o prototypes/prototype_stage1_assembler-2 + $(CC) stage1/High_level_prototypes/stage1_assembler-2.c -o prototypes/prototype_stage1_assembler-2 prototype_lisp: lisp.c lisp.h lisp_cell.c lisp_eval.c lisp_print.c lisp_read.c | prototypes - gcc -O2 stage2/High_level_prototypes/lisp.h \ + $(CC) -O2 stage2/High_level_prototypes/lisp.h \ stage2/High_level_prototypes/lisp.c \ stage2/High_level_prototypes/lisp_cell.c \ stage2/High_level_prototypes/lisp_eval.c \