lang-bootstrap/05/main.b

105 lines
1.9 KiB
Brainfuck
Raw Normal View History

2022-01-07 23:32:27 -05:00
; add 24 + 16 = 40 to the stack pointer to put argc, argv in the right place
byte 0x48
byte 0x81
byte 0xc4
byte 40
byte 0
byte 0
byte 0
goto main
2022-01-08 14:37:39 -05:00
global object_macros_size
global function_macros_size
; these are allocated in main()
global object_macros
global function_macros
2022-01-08 12:15:17 -05:00
function compile_error
argument file
argument line
argument message
fputs(2, file)
fputc(2, ':)
fputn(2, line)
2022-01-08 14:37:39 -05:00
fputs(2, .str_error_prefix)
2022-01-08 12:15:17 -05:00
fputs(2, message)
fputc(2, 10)
exit(1)
2022-01-09 22:33:33 -05:00
function compile_warning
argument file
argument line
argument message
fputs(2, file)
fputc(2, ':)
fputn(2, line)
fputs(2, .str_warning_prefix)
fputs(2, message)
fputc(2, 10)
return
2022-01-08 12:15:17 -05:00
2022-01-08 14:37:39 -05:00
:str_error_prefix
2022-01-08 12:15:17 -05:00
string : Error:
byte 32
byte 0
2022-01-09 22:33:33 -05:00
:str_warning_prefix
string : Warning:
byte 32
byte 0
2022-01-07 23:32:27 -05:00
#include util.b
#include constants.b
#include preprocess.b
function main
argument argv2
argument argv1
argument argv0
argument argc
local input_filename
local output_filename
2022-01-08 12:15:17 -05:00
local pptokens
2022-01-10 15:12:24 -05:00
local processed_pptokens
2022-01-07 23:32:27 -05:00
2022-01-09 12:31:35 -05:00
dat_banned_objmacros = 255
dat_banned_fmacros = 255
2022-01-09 00:08:29 -05:00
2022-01-08 14:37:39 -05:00
object_macros = malloc(4000000)
function_macros = malloc(4000000)
2022-01-07 23:32:27 -05:00
input_filename = .str_default_input_filename
output_filename = .str_default_output_filename
if argc == 1 goto have_filenames
if argc != 3 goto usage_error
input_filename = argv1
output_filename = argv2
:have_filenames
2022-01-08 12:15:17 -05:00
pptokens = split_into_preprocessing_tokens(input_filename)
print_pptokens(pptokens)
2022-01-08 14:37:39 -05:00
print_separator()
2022-01-10 15:12:24 -05:00
processed_pptokens = malloc(16000000)
translation_phase_4(input_filename, pptokens, processed_pptokens)
free(pptokens)
pptokens = processed_pptokens
2022-01-09 00:08:29 -05:00
print_pptokens(pptokens)
2022-01-08 14:37:39 -05:00
print_object_macros()
2022-01-08 18:13:48 -05:00
print_function_macros()
2022-01-07 23:32:27 -05:00
exit(0)
:usage_error
fputs(2, .str_usage_error)
exit(1)
:str_usage_error
string Please either specify no arguments or an input and output file.
:str_default_input_filename
string main.c
byte 0
:str_default_output_filename
string a.out
byte 0