Skip to content

Commit 41e573c

Browse files
author
aixiangfei
committed
update
1 parent 3908501 commit 41e573c

38 files changed

+3261
-35
lines changed

Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jackc/jackc.o: jackc/jackc.cpp
88

99
jackc/Scanner.o: jackc/Scanner.cpp
1010
g++ -c -o jackc/Scanner.o jackc/Scanner.cpp -std=c++11
11-
11+
1212
jackc/Parser.o: jackc/Parser.cpp
1313
g++ -c -o jackc/Parser.o jackc/Parser.cpp -std=c++11
1414

@@ -35,7 +35,7 @@ jack/VirtualMachion.o: jack/VirtualMachion.cpp
3535

3636

3737
clean:
38-
rm jackc/*.o
39-
rm jack/*.o
40-
rm jackc.exe
41-
rm jack.exe
38+
rm -rf jackc/*.o
39+
rm -rf jack/*.o
40+
rm -rf jackc.exe
41+
rm -rf jack.exe

api/Array.jack

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class Array
1+
class Array
22
{
33
/** 构造大小为size的新数组 */
44
function Array new(int size)

api/Math.jack

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
class Math
22
{
3-
/** 仅供内部使用 */
3+
/** �����ڲ�ʹ�� */
44
function void init()
55
{
66
return;
77
}
88

9-
/** 返回x的绝对值 */
9+
/** ����x�ľ���ֵ */
1010
function int abs(int x)
1111
{
1212
int absNum;
@@ -21,7 +21,7 @@ class Math
2121
return absNum;
2222
}
2323

24-
/** 返回x和y的乘积 */
24+
/** ����x��y�ij˻� */
2525
function int multiply(int x, int y)
2626
{
2727
int sum;
@@ -56,7 +56,7 @@ class Math
5656
return sum;
5757
}
5858

59-
/** 返回x/y的整数部分(x>0, y>0) */
59+
/** ����x/y����������(x>0, y>0) */
6060
function int div(int x, int y) {
6161
int q, qy;
6262
if((y < 0) | (y > x))
@@ -75,7 +75,7 @@ class Math
7575
}
7676
}
7777

78-
/** 返回x/y的整数值 */
78+
/** ����x/y������ֵ */
7979
function int divide(int x, int y)
8080
{
8181
int answer;
@@ -96,7 +96,7 @@ class Math
9696
return answer;
9797
}
9898

99-
/** 返回x <= 2^n中指数n的值 */
99+
/** ����x <= 2^n��ָ��n��ֵ */
100100
function int logTwo(int x)
101101
{
102102
int powerTwo,flag;
@@ -114,7 +114,7 @@ class Math
114114
return flag;
115115
}
116116

117-
/** 返回x的y次方 */
117+
/** ����x��y�η� */
118118
function int power(int x, int y)
119119
{
120120
int flag;
@@ -135,7 +135,7 @@ class Math
135135
return result;
136136
}
137137

138-
/** 返回x的平方根的整数部分 */
138+
/** ����x��ƽ�������������� */
139139
function int sqrt(int x)
140140
{
141141
int y, j, flag, powerJ;
@@ -163,7 +163,7 @@ class Math
163163
return y;
164164
}
165165

166-
/** 返回x和y中的较大值 */
166+
/** ����x��y�еĽϴ�ֵ */
167167
function int max(int a, int b)
168168
{
169169
if (a > b)
@@ -176,7 +176,7 @@ class Math
176176
}
177177
}
178178

179-
/** 返回x和y中的较小值 */
179+
/** ����x��y�еĽ�Сֵ */
180180
function int min(int a, int b)
181181
{
182182
if (a < b)

api/String.jack

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
class String
22
{
3-
field Array a; // 字符串本身是一个数组, a是这个数组的引用
4-
field int stringLength; // 当前字符串的长度
5-
field boolean negFlag; // 判断是否为负数
6-
field int allocLength; // 最大字符串长度
3+
field Array a; // �ַ���������һ������, a��������������
4+
field int stringLength; // ��ǰ�ַ����ij���
5+
field boolean negFlag; // �ж��Ƿ�Ϊ����
6+
field int allocLength; // ����ַ�������
77

8-
/** 构造一个长度为maxLength的字符串 */
8+
/** ����һ������ΪmaxLength���ַ��� */
99
constructor String new(int maxLength)
1010
{
1111
if (maxLength < 1)
@@ -19,7 +19,7 @@ class String
1919
return this;
2020
}
2121

22-
/** 销毁字符串并释放内存 */
22+
/** �����ַ������ͷ��ڴ� */
2323
method void dispose()
2424
{
2525
a.dispose();
@@ -31,22 +31,22 @@ class String
3131
return stringLength;
3232
}
3333

34-
/** 返回字符串第j个位置上的字符 */
34+
/** �����ַ�����j��λ���ϵ��ַ� */
3535
method char charAt(int j)
3636
{
3737
char c;
3838
c = a[j];
3939
return c;
4040
}
4141

42-
/** 将字符串中第j个元素置为字符c */
42+
/** ���ַ����е�j��Ԫ����Ϊ�ַ�c */
4343
method void setCharAt(int j, char c)
4444
{
4545
a[j] = c;
4646
return;
4747
}
4848

49-
/** 在字符串末尾追加字符c并返回整个字符串 */
49+
/** ���ַ���ĩβ׷���ַ�c�����������ַ��� */
5050
method String appendChar(char c)
5151
{
5252
int length;
@@ -60,7 +60,7 @@ class String
6060
return this;
6161
}
6262

63-
/** 删除字符串中的最后一个字符 */
63+
/** ɾ���ַ����е����һ���ַ� */
6464
method void eraseLastChar()
6565
{
6666
int length;
@@ -69,12 +69,12 @@ class String
6969
return;
7070
}
7171

72-
/** 从最左边开始直到遇到非数字字符为止的字串的整数值 */
72+
/** ������߿�ʼֱ�������������ַ�Ϊֹ���ִ�������ֵ */
7373
method int intValue()
7474
{
7575
int length, i, result;
7676
int temp;
77-
boolean flag; // 判断是否为负数
77+
boolean flag; // �ж��Ƿ�Ϊ����
7878

7979
flag = false;
8080
i = 0;
@@ -109,7 +109,7 @@ class String
109109
return result;
110110
}
111111

112-
/** 以字符串形式保存number所代表的整数 */
112+
/** ���ַ�����ʽ����number������������ */
113113
method void setInt(int number)
114114
{
115115
int lastDigit;
@@ -143,12 +143,12 @@ class String
143143
return;
144144
}
145145

146-
/** 返回换行符 */
146+
/** ���ػ��з� */
147147
function char newLine() {
148148
return 10;
149149
}
150150

151-
/** 返回双引号字符 */
151+
/** ����˫�����ַ� */
152152
function char doubleQuote() {
153153
return 34;
154154
}

api/Sys.jack

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class Sys
22
{
3-
/** 调用其他OS类的init函数, 进而调用Main.main()函数. */
3+
/** ��������OS���init����, ��������Main.main()����. */
44
function void init()
55
{
66
Memory.init();
@@ -16,14 +16,14 @@ class Sys
1616
return;
1717
}
1818

19-
/** 中止程序执行 */
19+
/** ��ֹ����ִ�� */
2020
function void halt()
2121
{
2222
Output.printString("Program ended!");
2323
return;
2424
}
2525

26-
/** 等待大约duration毫秒后返回 */
26+
/** �ȴ���Լduration����󷵻� */
2727
function void wait(int duration)
2828
{
2929
int temp;
@@ -43,7 +43,7 @@ class Sys
4343
return;
4444
}
4545

46-
/** 在屏幕上打印错误代码, 并中止程序执行 */
46+
/** ����Ļ�ϴ�ӡ�������, ����ֹ����ִ�� */
4747
function void error(int errorCode)
4848
{
4949
String s;

jack/api/Array.jack

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Array
2+
{
3+
/** 构造大小为size的新数组 */
4+
function Array new(int size)
5+
{
6+
Array a;
7+
a = Memory.alloc(size);
8+
return a;
9+
}
10+
11+
/** 清除数组 */
12+
method void dispose()
13+
{
14+
Memory.deAlloc(this);
15+
return;
16+
}
17+
}

jack/api/Array.vm

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
function Array.new 1
2+
push argument 0
3+
call Memory.alloc 1
4+
pop local 0
5+
push local 0
6+
return
7+
function Array.dispose 0
8+
push argument 0
9+
pop pointer 0
10+
push pointer 0
11+
call Memory.deAlloc 1
12+
pop temp 0
13+
push constant 0
14+
return

jack/api/IO.jack

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class IO
2+
{
3+
function void putchar(char ch)
4+
{
5+
return;
6+
}
7+
function char getchar()
8+
{
9+
return '0';
10+
}
11+
}

jack/api/IO.vm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
function IO.putchar 0
2+
push constant 0
3+
return
4+
function IO.getchar 0
5+
return

jack/api/Input.jack

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
class Input
2+
{
3+
function char readChar()
4+
{
5+
char ch;
6+
ch = IO.getchar();
7+
return ch;
8+
}
9+
10+
function String readLine()
11+
{
12+
char ch;
13+
String s;
14+
s = String.new(100);
15+
while (true)
16+
{
17+
ch = IO.getchar();
18+
if (ch == 10)
19+
{
20+
return s;
21+
}
22+
s = s.appendChar(ch);
23+
}
24+
return s;
25+
}
26+
}

jack/api/Input.vm

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
function Input.readChar 1
2+
call IO.getchar 0
3+
pop local 0
4+
push local 0
5+
return
6+
function Input.readLine 2
7+
push constant 100
8+
call String.new 1
9+
pop local 1
10+
label WHILE_EXP9
11+
push constant 0
12+
not
13+
not
14+
if-goto WHILE_END9
15+
call IO.getchar 0
16+
pop local 0
17+
push local 0
18+
push constant 10
19+
eq
20+
if-goto IF_TRUE31
21+
goto IF_FALSE31
22+
label IF_TRUE31
23+
push local 1
24+
return
25+
label IF_FALSE31
26+
push local 1
27+
push local 0
28+
call String.appendChar 2
29+
pop local 1
30+
goto WHILE_EXP9
31+
label WHILE_END9
32+
push local 1
33+
return

0 commit comments

Comments
 (0)