start 04
This commit is contained in:
parent
31c9f4ca2a
commit
b48712f9c9
6 changed files with 190 additions and 0 deletions
7
04a/Makefile
Normal file
7
04a/Makefile
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
all: out03
|
||||||
|
out03: in03 ../03/out02
|
||||||
|
../03/out02
|
||||||
|
%.html: %.md ../markdown
|
||||||
|
../markdown $<
|
||||||
|
clean:
|
||||||
|
rm -f out* README.html
|
74
04a/in03
Normal file
74
04a/in03
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
I=8S
|
||||||
|
A=d3
|
||||||
|
?I!A:usage_error
|
||||||
|
; open input file
|
||||||
|
J=S
|
||||||
|
; argv[1] is at *(rsp+16)
|
||||||
|
J+=d16
|
||||||
|
J=8J
|
||||||
|
I=d0
|
||||||
|
syscall x2
|
||||||
|
J=A
|
||||||
|
?J<0:input_file_error
|
||||||
|
; open output file
|
||||||
|
J=S
|
||||||
|
; argv[2] is at *(rsp+24)
|
||||||
|
J+=d24
|
||||||
|
J=8J
|
||||||
|
I=x241
|
||||||
|
D=x1ed
|
||||||
|
syscall x2
|
||||||
|
J=A
|
||||||
|
?J<0:output_file_error
|
||||||
|
J=d0
|
||||||
|
syscall x3c
|
||||||
|
|
||||||
|
:usage_error
|
||||||
|
B=:usage_error_message
|
||||||
|
call :error
|
||||||
|
|
||||||
|
:usage_error_message
|
||||||
|
str Please provide an input and an output file.
|
||||||
|
xa
|
||||||
|
x0
|
||||||
|
|
||||||
|
:input_file_error
|
||||||
|
B=:input_file_error_message
|
||||||
|
!:error
|
||||||
|
|
||||||
|
:input_file_error_message
|
||||||
|
str Couldn't open input file.
|
||||||
|
xa
|
||||||
|
x0
|
||||||
|
|
||||||
|
:output_file_error
|
||||||
|
B=:output_file_error_message
|
||||||
|
!:error
|
||||||
|
|
||||||
|
:output_file_error_message
|
||||||
|
str Couldn't open output file.
|
||||||
|
xa
|
||||||
|
x0
|
||||||
|
|
||||||
|
:error
|
||||||
|
J=B
|
||||||
|
call :strlen
|
||||||
|
D=A
|
||||||
|
I=J
|
||||||
|
J=d2
|
||||||
|
syscall x1
|
||||||
|
J=d1
|
||||||
|
syscall x3c
|
||||||
|
|
||||||
|
:strlen
|
||||||
|
I=B
|
||||||
|
D=B
|
||||||
|
:strlen_loop
|
||||||
|
C=1I
|
||||||
|
?C=0:strlen_ret
|
||||||
|
I+=d1
|
||||||
|
!:strlen_loop
|
||||||
|
:strlen_ret
|
||||||
|
I-=D
|
||||||
|
A=I
|
||||||
|
return
|
3
04a/in04a
Normal file
3
04a/in04a
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
#define A 777
|
||||||
|
#define B 226
|
||||||
|
A+B
|
7
04b/Makefile
Normal file
7
04b/Makefile
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
all: out03
|
||||||
|
out03: in03 ../03/out02
|
||||||
|
../03/out02
|
||||||
|
%.html: %.md ../markdown
|
||||||
|
../markdown $<
|
||||||
|
clean:
|
||||||
|
rm -f out* README.html
|
95
04b/in04
Normal file
95
04b/in04
Normal file
|
@ -0,0 +1,95 @@
|
||||||
|
// types: char, uchar, short, ushort, int, uint, long, ulong, *type
|
||||||
|
// declaration:
|
||||||
|
// static <type> <name>;
|
||||||
|
// local <type> <name>;
|
||||||
|
// :<label>
|
||||||
|
// statement:
|
||||||
|
// <declaration>
|
||||||
|
// if <term> <==/</>/>=/<=/!=> <term> goto <label>
|
||||||
|
// goto <label>
|
||||||
|
// <lvalue> = <rvalue>
|
||||||
|
// <lvalue> += <rvalue>
|
||||||
|
// <lvalue> -= <rvalue>
|
||||||
|
// <function>(<term>, <term>, ...)
|
||||||
|
// syscall(<term>, <term>, ...)
|
||||||
|
// return <rvalue>;
|
||||||
|
// term:
|
||||||
|
// <var>
|
||||||
|
// <number>
|
||||||
|
// number:
|
||||||
|
// 'c
|
||||||
|
// 12345
|
||||||
|
// 0xabc
|
||||||
|
// lvalue:
|
||||||
|
// <var>
|
||||||
|
// *<var>
|
||||||
|
// <var>[<term>]
|
||||||
|
// rvalue:
|
||||||
|
// `<string>`
|
||||||
|
// <var>
|
||||||
|
// &<var>
|
||||||
|
// *<var>
|
||||||
|
// <var>[<term>]
|
||||||
|
// ~<var>
|
||||||
|
// <function>(<term>, <term>, ...)
|
||||||
|
// syscall(<term>, <term>, ...)
|
||||||
|
// <term> + <term>
|
||||||
|
// <term> - <term>
|
||||||
|
// <term> * <term>
|
||||||
|
// <term> / <term>
|
||||||
|
// <term> % <term>
|
||||||
|
// <term> & <term>
|
||||||
|
// <term> | <term>
|
||||||
|
// <term> ^ <term>
|
||||||
|
// <term> < <term> (left shift)
|
||||||
|
// <term> > <term> (right shift)
|
||||||
|
// (<term> ] <term>)
|
||||||
|
|
||||||
|
main();
|
||||||
|
|
||||||
|
static char x;
|
||||||
|
static uchar y;
|
||||||
|
static long z;
|
||||||
|
|
||||||
|
function strlen(*char s)
|
||||||
|
local ulong len;
|
||||||
|
local char c;
|
||||||
|
len = 0;
|
||||||
|
:strlen.loop
|
||||||
|
c = s[len];
|
||||||
|
if c == 0 goto strlen.loop_end;
|
||||||
|
len += 1;
|
||||||
|
goto strlen.loop
|
||||||
|
:strlen.loop_end
|
||||||
|
return len;
|
||||||
|
|
||||||
|
function putc(char c)
|
||||||
|
local char *p;
|
||||||
|
p = &c;
|
||||||
|
syscall(1, 1, p, 1, 0, 0, 0, 0);
|
||||||
|
return;
|
||||||
|
|
||||||
|
function puts(*char s)
|
||||||
|
local ulong len;
|
||||||
|
len = strlen(s);
|
||||||
|
syscall(1, 1, s, len, 0, 0, 0, 0);
|
||||||
|
return;
|
||||||
|
|
||||||
|
function main()
|
||||||
|
local *char hello;
|
||||||
|
hello = `Hello, world!
|
||||||
|
`;
|
||||||
|
puts(hello);
|
||||||
|
syscall(0x3c, 0, 0, 0, 0, 0, 0, 0);
|
||||||
|
|
||||||
|
function f(*long x, **long y)
|
||||||
|
local long v;
|
||||||
|
local *long p;
|
||||||
|
v = *x;
|
||||||
|
p = *y;
|
||||||
|
*p = v;
|
||||||
|
if v == 0 goto something;
|
||||||
|
p[1] = v + 1;
|
||||||
|
return p[2];
|
||||||
|
:something
|
||||||
|
return p[1];
|
4
Makefile
4
Makefile
|
@ -3,11 +3,15 @@ all: markdown README.html
|
||||||
$(MAKE) -C 01
|
$(MAKE) -C 01
|
||||||
$(MAKE) -C 02
|
$(MAKE) -C 02
|
||||||
$(MAKE) -C 03
|
$(MAKE) -C 03
|
||||||
|
$(MAKE) -C 04a
|
||||||
|
$(MAKE) -C 04b
|
||||||
clean:
|
clean:
|
||||||
$(MAKE) -C 00 clean
|
$(MAKE) -C 00 clean
|
||||||
$(MAKE) -C 01 clean
|
$(MAKE) -C 01 clean
|
||||||
$(MAKE) -C 02 clean
|
$(MAKE) -C 02 clean
|
||||||
$(MAKE) -C 03 clean
|
$(MAKE) -C 03 clean
|
||||||
|
$(MAKE) -C 04a clean
|
||||||
|
$(MAKE) -C 04b clean
|
||||||
rm -f markdown
|
rm -f markdown
|
||||||
rm -f README.html
|
rm -f README.html
|
||||||
markdown: markdown.c
|
markdown: markdown.c
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue