-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJavaLang.dart
More file actions
112 lines (96 loc) · 3.58 KB
/
Copy pathJavaLang.dart
File metadata and controls
112 lines (96 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
library JdkLib;
import '../Runner.dart';
import '../types.dart';
import '../ast.dart' show Identifier, MethodDecl, Variable, MethodType, TypeNode;
//const Package javaPkg = const Package.fixed(PkgIds.java, const {"lang": javaLangPkg});
//const Package javaLangPkg = const Package.fixed(PkgIds.lang, const {"String": bla});
//
//const bla = "";
//class LibraryClass {
// final Map<Identifier, Value> variables = new Map<Identifier, Value>();
//
// lookup(Identifier name) => variables[name];
//}
//class PkgIds {
// static const Identifier java = const Identifier.fixed("java");
// static const Identifier lang = const Identifier.fixed("lang");
//}
//class LibraryMethodDecl implements MethodDecl {
// const int startPos = -1;
// const int endPos = -1;
// const int nodeId = -1;
//
// List<EvalTree> _body;
// List<EvalTree> get body => _body;
// bool isStatic() => modifiers.contains("static");
// bool isConstructor;
// String name;
// String publicName;
// MethodType type;
// List<Variable> parameters;
// List<String> modifiers;
//}
class LibraryMethodDecl implements MethodDecl {
final List<String> modifiers;
final List<Variable> parameters;
final MethodType type;
final List<EvalTree> body;
final bool isConstructor;
final bool isStatic;
final String name;
final String publicName;
const LibraryMethodDecl({this.modifiers, this.parameters, this.type, this.body, this.isConstructor, this.isStatic,
this.name, this.publicName});
}
//class LibMethodBody implements EvalTree {
// const int startPos = -1;
// const int endPos = -1;
// const int nodeId = -1;
// const bool isStatic = false;
// const List modifiers = const [];
//
// final method;
// const LibMethodBody(this.method);
//
// dynamic execute() => method();
//}
class JDKString implements ClassInstance {
final Map<Identifier, dynamic> variables = new Map();
StaticClass lookupClass(Identifier name) => null;
dynamic lookup(Identifier name) => null;
final Identifier name = const Identifier.fixed("String");
final List<LibraryMethodDecl> methods = new List<LibraryMethodDecl>();
final String value;
String val() => value;
JDKString(String this.value) {
// methods.add(new LibraryMethodDecl(modifiers: const ["public"],
// parameters: const [const Variable("index", TypeNode.INT, null)],
// type: const MethodType(TypeNode.CHAR, const [TypeNode.INT]),
// body: [new LibMethodBody((List args){
// print(args);
// print(val().codeUnits);
// return val().codeUnits[args[0]];})],
// isConstructor: false,
// isStatic: false,
// name: "charAt", publicName: "charAt"));
}
void newVariable(Identifier name, [dynamic value]){
if(name.name != "value")
throw "Cannot declare field $name in object ${this.name}";
if(value != null)
throw "Cannot assign value to an immutable object ${this.name}";
}
bool assign(Identifier name, dynamic value){
throw "Cannot assign value to an immutable object ${this.name}";
}
CharValue charAt(IntegerValue index) => new CharValue(value.codeUnitAt(index.value));
String toString() => "\"$value\"";
//Methods
// LibraryMethodDecl charAt = new LibraryMethodDecl(modifiers: const ["public"],
// parameters: const [const Variable("index", TypeNode.INT, null)],
// type: const MethodType(TypeNode.CHAR, const [TypeNode.INT]),
// body: [new LibMethodBody((List args) => this.val().codeUnits[args[0]])],
// isConstructor: false,
// isStatic: false,
// name: "charAt", publicName: "charAt");
}