-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathjava-api-core.k
More file actions
165 lines (136 loc) · 4.33 KB
/
java-api-core.k
File metadata and controls
165 lines (136 loc) · 4.33 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
require "java-core.k"
require "java-classes.k"
module JAVA-API-CORE
imports JAVA-CORE
imports JAVA-CLASSES
// This module contains the minimal part of java API required to perform
// console read/write operations.
syntax KResult ::= "rtSystem"
| "rtSystemOut"
| "rtSystemOutPrint"
// | "rtSystemOutPrintln" was moved to JAVA-CORE
| "rtSystemConsole"
| "rtSystemConsoleReadLine"
| "rtInteger"
| "rtIntegerParseInt"
| "rtSystemIn"
| "rtScannerNextInt"
| "methodGetClass" "(" K ")"
| "classObject" "(" Id ")"
| "methodClassGetName" "(" K ")"
syntax RawVal ::= "rtSymbolicConsoleLine"
| "rtScanner"
rule [NameSystem]:
'ExprName(X:Id) => rtSystem
when
Id2String(X) ==String "System"
rule [NameSystemConsole]:
'MethodName(rtSystem,, X:Id) => rtSystemConsole
when
Id2String(X) ==String "console"
rule [InvokeSystemConsole]:
'Invoke(rtSystemConsole,, 'ListWrap(.List{K})) => rtSystemConsole
rule [NameSystemConsoleReadLine]:
'MethodName(rtSystemConsole,, X:Id) => rtSystemConsoleReadLine
when
Id2String(X) ==String "readLine"
rule [InvokeSystemConsoleReadLine]:
'Invoke(rtSystemConsoleReadLine,, 'ListWrap(.List{K}))
=> rtSymbolicConsoleLine :: rtString
rule [NameInteger]:
'ExprName(X:Id) => rtInteger
when
Id2String(X) ==String "Integer"
rule [NameIntegerParseInt]:
'MethodName(rtInteger,, X:Id) => rtIntegerParseInt
when
Id2String(X) ==String "parseInt"
rule [consoleReadInt]:
<k>
'Invoke(rtIntegerParseInt,, 'ListWrap(rtSymbolicConsoleLine :: rtString))
=> I:Int :: int
...
</k>
<in> ListItem(I) => . ...</in>
[transition]
//@ For integers and strings, print their value. For classes, print class type.
rule [NameSystemOut]:
'ExprName(rtSystem,, X:Id) => rtSystemOut
when
Id2String(X) ==String "out"
rule [NameSystemOutPrint]:
'MethodName(rtSystemOut,, X:Id) => rtSystemOutPrint
when
Id2String(X) ==String "print"
rule [NameSystemOutPrintln]:
'MethodName(rtSystemOut,, X:Id) => rtSystemOutPrintln
when
Id2String(X) ==String "println"
rule [printlnDesugar]:
'Invoke(rtSystemOutPrintln,, 'ListWrap(KR:KResult))
=> 'Invoke(rtSystemOutPrint,, 'ListWrap('Plus(KR:KResult,,"\n"::rtString)))
rule [printlnEmptyDesugar]:
'Invoke(rtSystemOutPrintln,, 'ListWrap(.List{K}))
=> 'Invoke(rtSystemOutPrint,, 'ListWrap("\n"::rtString))
rule [consolePrintArgConvert]:
'Invoke(rtSystemOutPrint,, 'ListWrap(KR:KResult => toString(KR)))
when
typeOf(KR) =/=K rtString
rule [consolePrint]:
<k>
'Invoke(rtSystemOutPrint,, 'ListWrap(Str:String :: rtString))
=> nothing::void
...
</k>
<out>... .=> ListItem(Str) </out>
[transition]
rule [NameSystemIn]:
'ExprName(rtSystem,, X:Id) => rtSystemIn
when
Id2String(X) ==String "in"
rule [NewInstanceScanner]:
'NewInstance('None(.List{K}),,
'ClassOrInterfaceType(
'TypeName(X:Id),,
'None(.List{K})
),,
'ListWrap(rtSystemIn),,
'None(.List{K})
)
=> rtScanner :: class X
when
Id2String(X) ==String "Scanner"
rule [ScannerNextInt]:
'MethodName(rtScanner::_,, X:Id) => rtScannerNextInt
when
Id2String(X) ==String "nextInt"
rule [InvokeScannerNextInt]:
<k>
'Invoke(rtScannerNextInt,, 'ListWrap(.List{K}))
=> I:Int :: int
...
</k>
<in> ListItem(I) => . ...</in>
[transition]
rule [NameGetClass]:
'MethodName(KR:KResult,, X:Id) => methodGetClass(KR)
when
Id2String(X) ==String "getClass"
rule [InvokeGetClass]:
'Invoke(
methodGetClass(
objectClosure((_ <envStack>ListItem((Class:Id, _))...</envStack>))::_
),,
'ListWrap(.List{K})
) => classObject(Class)
rule [NameClassGetName]:
'MethodName(classObject(Class:Id),, X:Id)
=> methodClassGetName(classObject(Class))
when
Id2String(X) ==String "getName"
rule [InvokeClassGetName]:
'Invoke(
methodClassGetName(classObject(Class:Id)),,
'ListWrap(.List{K})
) => toString(class Class)
endmodule