forked from vsmenon/start
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:vsmenon/start into vsmenon-master
Conflicts: .gitignore
- Loading branch information
Showing
18 changed files
with
2,039 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
examples/*.dot | ||
examples/*.txt | ||
examples/*.pdf | ||
packages | ||
pubspec.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
library renum; | ||
|
||
import 'dart:io'; | ||
|
||
void _check(bool flag, String message) { | ||
if (!flag) { | ||
print(message); | ||
throw new Exception(message); | ||
} | ||
} | ||
|
||
Map _parse(String bytecode) { | ||
final instMap = new Map<num, int>(); | ||
int count = 0; | ||
// Read in the program from stdin | ||
for (final line in bytecode.split('\n')) { | ||
var words = line.trim().split(" "); | ||
if (line.trim() == "") { | ||
// print('$line\n'); | ||
continue; | ||
} | ||
if (words[0] != "instr") { | ||
// print('$line\n'); | ||
continue; | ||
} | ||
count += 1; | ||
num pc = double.parse(words[1].replaceFirst(':', '')); | ||
instMap[pc] = count; | ||
} | ||
return instMap; | ||
} | ||
|
||
void _renum(String bytecode, Map<num, int> instMap) { | ||
int count = 0; | ||
// Read in the program from stdin | ||
for (final line in bytecode.split('\n')) { | ||
var words = line.trim().split(" "); | ||
if (line.trim() == "") { | ||
print(line); | ||
continue; | ||
} | ||
if (words[0] != "instr") { | ||
print(line); | ||
continue; | ||
} | ||
count += 1; | ||
String newInst = ' instr $count:'; | ||
// _check(index == (instructions.length + 1), "Invalid index $index"); | ||
for (int i = 2; i < words.length; ++i) { | ||
var word = words[i]; | ||
if (word[0] == '(') { | ||
final pc = double.parse(word.substring(1, word.length - 1)); | ||
word = '(${instMap[pc]})'; | ||
} else if (word[0] == '[') { | ||
final pc = double.parse(word.substring(1, word.length - 1)); | ||
word = '[${instMap[pc]}]'; | ||
} | ||
newInst += ' $word'; | ||
} | ||
print(newInst); | ||
} | ||
} | ||
|
||
void main() | ||
{ | ||
final args = (new Options()).arguments; | ||
|
||
final filename = args[0]; | ||
|
||
final file = new File(filename); | ||
final input = file.readAsStringSync(); | ||
|
||
final map = _parse(input); | ||
_renum(input, map); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import 'stdio.dart'; | ||
|
||
int data0; | ||
int data1; | ||
int data2; | ||
|
||
void cproptest1() { | ||
int j; | ||
j = 1 + 2 * 4; | ||
data0 = j; | ||
} | ||
|
||
void cproptest9() { | ||
int i; | ||
int stop; | ||
int j; | ||
|
||
stop = data0; | ||
j = 21; | ||
i = 1; | ||
while (i < stop) { | ||
j = (j - 20) * 21; | ||
i = i + 1; | ||
} | ||
data1 = j; | ||
data2 = i; | ||
} | ||
|
||
void main() { | ||
data0 = 0; | ||
|
||
cproptest1(); | ||
WriteLong(data0); | ||
WriteLine(); | ||
|
||
data1 = 0; | ||
data2 = 0; | ||
cproptest9(); | ||
WriteLong(data1); | ||
WriteLong(data2); | ||
WriteLine(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
//test array and struct | ||
import 'stdio.dart'; | ||
|
||
class Rational { | ||
int numerator; | ||
int denominator; | ||
} | ||
|
||
// Return value for functions. | ||
var retVal; | ||
|
||
void gcd(int a, int b) | ||
{ | ||
int c; | ||
|
||
while (b != 0) { | ||
c = a; | ||
a = b; | ||
b = c % b; | ||
} | ||
retVal = a; | ||
} | ||
|
||
void makeRational(int n, int d) { | ||
int common; | ||
|
||
gcd(n, d); | ||
common = retVal; | ||
retVal = new Rational(); | ||
retVal.numerator = n ~/ common; | ||
retVal.denominator = d ~/ common; | ||
} | ||
|
||
void add(var a, var b) { | ||
if (a is int) { | ||
if (b is int) { | ||
retVal = a + b; | ||
} else { | ||
makeRational(a * b.denominator + b.numerator, b.denominator); | ||
} | ||
} else { | ||
// a is Rational | ||
if (b is int) { | ||
makeRational(b * a.denominator + a.numerator, a.denominator); | ||
} else { | ||
makeRational(a.numerator * b.denominator + b.numerator * a.denominator, a.denominator * b.denominator); | ||
} | ||
} | ||
} | ||
|
||
void write(var a) { | ||
if (a is Rational) { | ||
WriteLong(a.numerator); | ||
WriteLong(a.denominator); | ||
WriteLine(); | ||
} else { | ||
// a is int | ||
WriteLong(a); | ||
WriteLine(); | ||
} | ||
} | ||
|
||
void main() { | ||
int a, b; | ||
Rational x, y; | ||
|
||
a = 2; | ||
b = 5; | ||
|
||
makeRational(1, 2); | ||
x = retVal; | ||
makeRational(2, 3); | ||
y = retVal; | ||
|
||
write(a); | ||
write(x); | ||
add(a, x); | ||
write(retVal); | ||
add(y, y); | ||
write(retVal); | ||
add(a, b); | ||
write(retVal); | ||
} | ||
|
||
/* | ||
2 | ||
1 2 | ||
5 2 | ||
4 3 | ||
7 | ||
*/ |
Oops, something went wrong.