Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
kumir2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
2
Issues
2
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
kumir
kumir2
Commits
e8ccd254
Commit
e8ccd254
authored
Jan 30, 2013
by
Victor Yacovlev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improved runtime performace
parent
88e72355
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
142 additions
and
309 deletions
+142
-309
src/shared/vm/context.hpp
src/shared/vm/context.hpp
+2
-5
src/shared/vm/variant.hpp
src/shared/vm/variant.hpp
+19
-2
src/shared/vm/vm.hpp
src/shared/vm/vm.hpp
+121
-302
No files found.
src/shared/vm/context.hpp
View file @
e8ccd254
...
@@ -29,14 +29,11 @@ typedef std::map<uint32_t, ExternReference> ExternsMap;
...
@@ -29,14 +29,11 @@ typedef std::map<uint32_t, ExternReference> ExternsMap;
// module_id|alg_id -> instructions
// module_id|alg_id -> instructions
typedef
std
::
map
<
uint32_t
,
Bytecode
::
TableElem
>
FunctionMap
;
typedef
std
::
map
<
uint32_t
,
Bytecode
::
TableElem
>
FunctionMap
;
// module_id|global_id
typedef
std
::
pair
<
uint8_t
,
uint16_t
>
GlobalsIndex
;
// module_id|global_id -> global variable
// module_id|global_id -> global variable
typedef
std
::
map
<
GlobalsIndex
,
Variable
>
GlobalsMap
;
typedef
std
::
vector
<
std
::
vector
<
Variable
>
>
GlobalsMap
;
// constant_id -> constant value
// constant_id -> constant value
typedef
std
::
map
<
uint16_t
,
Variable
>
ConstantsMap
;
typedef
std
::
vector
<
Variable
>
ConstantsMap
;
typedef
std
::
vector
<
Variable
>
VariantArray
;
typedef
std
::
vector
<
Variable
>
VariantArray
;
...
...
src/shared/vm/variant.hpp
View file @
e8ccd254
...
@@ -382,8 +382,25 @@ public:
...
@@ -382,8 +382,25 @@ public:
inline
Char
toChar
()
const
{
return
value
().
toChar
();
}
inline
Char
toChar
()
const
{
return
value
().
toChar
();
}
inline
String
toString
()
const
;
inline
String
toString
()
const
;
inline
String
toString
(
int
indeces
[
4
])
const
;
inline
String
toString
(
int
indeces
[
4
])
const
;
inline
const
Record
toRecord
()
const
{
return
value
().
toRecord
();
}
inline
const
Record
toRecord
()
const
{
inline
Record
&
toRecord
()
{
return
value
().
toRecord
();
}
if
(
m_reference
)
{
const
Record
result
=
m_reference
->
toRecord
();
return
result
;
}
else
{
return
m_value
.
toRecord
();
}
}
inline
Record
&
toRecord
()
{
if
(
m_reference
)
{
Record
&
result
=
m_reference
->
toRecord
();
return
result
;
}
else
{
Record
&
result
=
m_value
.
toRecord
();
return
result
;
}
}
inline
Variable
toReference
();
inline
Variable
toReference
();
inline
static
Variable
toConstReference
(
const
AnyValue
&
value
);
inline
static
Variable
toConstReference
(
const
AnyValue
&
value
);
...
...
src/shared/vm/vm.hpp
View file @
e8ccd254
...
@@ -192,6 +192,9 @@ private /*fields*/:
...
@@ -192,6 +192,9 @@ private /*fields*/:
Stack
<
Variable
>
stack_values
;
Stack
<
Variable
>
stack_values
;
Stack
<
Context
>
stack_contexts
;
Stack
<
Context
>
stack_contexts
;
Kumir
::
String
s_programDirectory
;
Kumir
::
String
s_programDirectory
;
std
::
vector
<
Variable
>
*
currentConstants
;
std
::
vector
<
Variable
>
*
currentGlobals
;
std
::
vector
<
Variable
>
*
currentLocals
;
public
/*constructors*/
:
public
/*constructors*/
:
inline
KumirVM
();
inline
KumirVM
();
private
/*methods*/
:
private
/*methods*/
:
...
@@ -208,6 +211,7 @@ private /*methods*/:
...
@@ -208,6 +211,7 @@ private /*methods*/:
inline
static
Record
toRecordValue
(
const
Kumir
::
FileType
&
ft
);
inline
static
Record
toRecordValue
(
const
Kumir
::
FileType
&
ft
);
inline
static
Kumir
::
FileType
fromRecordValue
(
const
Record
&
record
);
inline
static
Kumir
::
FileType
fromRecordValue
(
const
Record
&
record
);
inline
Variable
&
findVariable
(
uint8_t
scope
,
uint16_t
id
);
private
/*instruction methods*/
:
private
/*instruction methods*/
:
inline
void
do_call
(
uint8_t
,
uint16_t
);
inline
void
do_call
(
uint8_t
,
uint16_t
);
...
@@ -260,6 +264,19 @@ private /*instruction methods*/:
...
@@ -260,6 +264,19 @@ private /*instruction methods*/:
/**** IMPLEMENTATION ******/
/**** IMPLEMENTATION ******/
Variable
&
KumirVM
::
findVariable
(
uint8_t
scope
,
uint16_t
id
)
{
if
(
VariableScope
(
scope
)
==
Bytecode
::
CONSTT
)
{
return
currentConstants
->
at
(
id
);
}
else
if
(
VariableScope
(
scope
)
==
Bytecode
::
LOCAL
)
{
return
currentLocals
->
at
(
id
);
}
else
{
return
currentGlobals
->
at
(
id
);
}
}
void
KumirVM
::
setProgram
(
const
Bytecode
::
Data
&
program
,
bool
isMain
,
const
String
&
filename
)
void
KumirVM
::
setProgram
(
const
Bytecode
::
Data
&
program
,
bool
isMain
,
const
String
&
filename
)
{
{
if
(
isMain
)
{
if
(
isMain
)
{
...
@@ -271,13 +288,30 @@ void KumirVM::setProgram(const Bytecode::Data &program, bool isMain, const Strin
...
@@ -271,13 +288,30 @@ void KumirVM::setProgram(const Bytecode::Data &program, bool isMain, const Strin
moduleContexts
.
push_back
(
ModuleContext
());
moduleContexts
.
push_back
(
ModuleContext
());
moduleContexts
.
back
().
filename
=
filename
;
moduleContexts
.
back
().
filename
=
filename
;
int
currentModuleContext
=
moduleContexts
.
size
()
-
1
;
int
currentModuleContext
=
moduleContexts
.
size
()
-
1
;
moduleContexts
.
back
().
globals
.
clear
();
moduleContexts
.
back
().
constants
.
clear
();
moduleContexts
.
back
().
globals
.
reserve
(
16
);
for
(
int
i
=
0
;
i
<
moduleContexts
.
back
().
globals
.
size
();
i
++
)
{
moduleContexts
.
back
().
globals
.
at
(
i
).
clear
();
moduleContexts
.
back
().
globals
.
at
(
i
).
reserve
(
256
);
}
moduleContexts
.
back
().
constants
.
reserve
(
256
);
LocalsMap
locals
;
LocalsMap
locals
;
for
(
int
i
=
0
;
i
<
program
.
d
.
size
();
i
++
)
{
for
(
int
i
=
0
;
i
<
program
.
d
.
size
();
i
++
)
{
const
TableElem
e
=
program
.
d
[
i
];
const
TableElem
e
=
program
.
d
[
i
];
if
(
e
.
type
==
EL_GLOBAL
)
{
if
(
e
.
type
==
EL_GLOBAL
)
{
moduleContexts
[
currentModuleContext
].
globals
[
std
::
pair
<
uint8_t
,
uint16_t
>
(
e
.
module
,
e
.
id
)]
=
fromTableElem
(
e
);
if
(
moduleContexts
[
currentModuleContext
].
globals
.
size
()
<=
e
.
module
)
{
moduleContexts
[
currentModuleContext
].
globals
.
resize
(
e
.
module
+
1
);
moduleContexts
[
currentModuleContext
].
globals
[
e
.
module
].
reserve
(
256
);
}
if
(
moduleContexts
[
currentModuleContext
].
globals
[
e
.
module
].
size
()
<=
e
.
id
)
{
moduleContexts
[
currentModuleContext
].
globals
[
e
.
module
].
resize
(
e
.
id
+
1
);
}
moduleContexts
[
currentModuleContext
].
globals
[
e
.
module
][
e
.
id
]
=
fromTableElem
(
e
);
}
}
else
if
(
e
.
type
==
EL_CONST
)
{
else
if
(
e
.
type
==
EL_CONST
)
{
if
(
moduleContexts
[
currentModuleContext
].
constants
.
size
()
<=
e
.
id
)
moduleContexts
[
currentModuleContext
].
constants
.
resize
(
e
.
id
+
1
);
moduleContexts
[
currentModuleContext
].
constants
[
e
.
id
]
=
fromTableElem
(
e
);
moduleContexts
[
currentModuleContext
].
constants
[
e
.
id
]
=
fromTableElem
(
e
);
}
}
...
@@ -436,6 +470,9 @@ void KumirVM::setProgram(const Bytecode::Data &program, bool isMain, const Strin
...
@@ -436,6 +470,9 @@ void KumirVM::setProgram(const Bytecode::Data &program, bool isMain, const Strin
const
VariantArray
&
arr
=
(
*
it
).
second
;
const
VariantArray
&
arr
=
(
*
it
).
second
;
moduleContexts
[
currentModuleContext
].
cleanLocalTables
[
key
]
=
arr
;
moduleContexts
[
currentModuleContext
].
cleanLocalTables
[
key
]
=
arr
;
}
}
currentLocals
=
0
;
currentGlobals
=
0
;
currentConstants
=
0
;
}
}
KumirVM
::
KumirVM
()
{
KumirVM
::
KumirVM
()
{
...
@@ -469,6 +506,9 @@ void KumirVM::reset()
...
@@ -469,6 +506,9 @@ void KumirVM::reset()
stack_contexts
.
reset
();
stack_contexts
.
reset
();
mainProgram
.
instructions
.
clear
();
mainProgram
.
instructions
.
clear
();
testingProgram
.
instructions
.
clear
();
testingProgram
.
instructions
.
clear
();
currentLocals
=
0
;
currentGlobals
=
0
;
currentConstants
=
0
;
// Find testing and main algorithms
// Find testing and main algorithms
for
(
FunctionMap
::
iterator
it
=
moduleContexts
.
front
().
functions
.
begin
();
for
(
FunctionMap
::
iterator
it
=
moduleContexts
.
front
().
functions
.
begin
();
...
@@ -532,9 +572,16 @@ void KumirVM::reset()
...
@@ -532,9 +572,16 @@ void KumirVM::reset()
}
}
c
.
IP
=
0
;
c
.
IP
=
0
;
currentGlobals
=
&
(
moduleContexts
[
0
].
globals
.
back
());
currentConstants
=
&
(
moduleContexts
[
0
].
constants
);
// Push startup context to stack (if non empty)
// Push startup context to stack (if non empty)
if
(
c
.
program
)
if
(
c
.
program
)
{
stack_contexts
.
push
(
c
);
stack_contexts
.
push
(
c
);
currentLocals
=
&
(
stack_contexts
.
top
().
locals
);
currentGlobals
=
&
(
moduleContexts
[
0
].
globals
[
c
.
moduleId
]);
}
// Each kumir module have 'initialization' section,
// Each kumir module have 'initialization' section,
// so push all these sections (if any) into stack
// so push all these sections (if any) into stack
...
@@ -558,6 +605,8 @@ void KumirVM::reset()
...
@@ -558,6 +605,8 @@ void KumirVM::reset()
initContext
.
IP
=
-
1
;
initContext
.
IP
=
-
1
;
initContext
.
moduleContextNo
=
moduleContextNo
;
initContext
.
moduleContextNo
=
moduleContextNo
;
stack_contexts
.
push
(
initContext
);
stack_contexts
.
push
(
initContext
);
currentConstants
=
&
(
moduleContexts
[
moduleContextNo
].
constants
);
currentGlobals
=
&
(
moduleContexts
[
moduleContextNo
].
globals
[
e
.
module
]);
}
}
}
}
}
}
...
@@ -770,6 +819,9 @@ void KumirVM::do_call(uint8_t mod, uint16_t alg)
...
@@ -770,6 +819,9 @@ void KumirVM::do_call(uint8_t mod, uint16_t alg)
stack_contexts
.
push
(
c
);
stack_contexts
.
push
(
c
);
b_nextCallInto
=
false
;
b_nextCallInto
=
false
;
stack_values
.
pop
();
// current implementation doesn't requere args count
stack_values
.
pop
();
// current implementation doesn't requere args count
currentLocals
=
&
(
stack_contexts
.
top
().
locals
);
currentGlobals
=
&
(
moduleContexts
[
c
.
moduleContextNo
].
globals
[
c
.
moduleId
]);
currentConstants
=
&
(
moduleContexts
[
c
.
moduleContextNo
].
constants
);
if
(
m_dontTouchMe
)
if
(
m_dontTouchMe
)
m_dontTouchMe
->
unlock
();
m_dontTouchMe
->
unlock
();
}
}
...
@@ -1894,15 +1946,7 @@ void KumirVM::do_specialcall(uint16_t alg)
...
@@ -1894,15 +1946,7 @@ void KumirVM::do_specialcall(uint16_t alg)
void
KumirVM
::
do_init
(
uint8_t
s
,
uint16_t
id
)
void
KumirVM
::
do_init
(
uint8_t
s
,
uint16_t
id
)
{
{
if
(
m_dontTouchMe
)
m_dontTouchMe
->
lock
();
if
(
m_dontTouchMe
)
m_dontTouchMe
->
lock
();
if
(
VariableScope
(
s
)
==
LOCAL
)
{
findVariable
(
s
,
id
).
init
();
stack_contexts
.
top
().
locals
[
id
].
init
();
}
else
if
(
VariableScope
(
s
)
==
GLOBAL
)
{
moduleContexts
[
stack_contexts
.
top
().
moduleContextNo
].
globals
[
GlobalsIndex
(
stack_contexts
.
top
().
moduleId
,
id
)].
init
();
}
else
{
s_error
=
Kumir
::
Core
::
fromAscii
(
"Internal error"
);
}
nextIP
();
nextIP
();
if
(
m_dontTouchMe
)
m_dontTouchMe
->
unlock
();
if
(
m_dontTouchMe
)
m_dontTouchMe
->
unlock
();
}
}
...
@@ -1910,31 +1954,18 @@ void KumirVM::do_init(uint8_t s, uint16_t id)
...
@@ -1910,31 +1954,18 @@ void KumirVM::do_init(uint8_t s, uint16_t id)
void
KumirVM
::
do_setarr
(
uint8_t
s
,
uint16_t
id
)
void
KumirVM
::
do_setarr
(
uint8_t
s
,
uint16_t
id
)
{
{
if
(
m_dontTouchMe
)
m_dontTouchMe
->
lock
();
if
(
m_dontTouchMe
)
m_dontTouchMe
->
lock
();
int
dim
=
0
;
Variable
&
var
=
findVariable
(
s
,
id
);
int
bounds
[
7
];
const
int
dim
=
var
.
dimension
();
if
(
VariableScope
(
s
)
==
LOCAL
)
{
int
bounds
[
7
];
dim
=
stack_contexts
.
top
().
locals
[
id
].
dimension
();
}
else
if
(
VariableScope
(
s
)
==
GLOBAL
)
{
dim
=
moduleContexts
[
stack_contexts
.
top
().
moduleContextNo
].
globals
[
GlobalsIndex
(
stack_contexts
.
top
().
moduleId
,
id
)].
dimension
();
}
else
{
s_error
=
Kumir
::
Core
::
fromAscii
(
"Internal error"
);
}
if
(
dim
>
0
)
{
if
(
dim
>
0
)
{
String
name
;
String
name
;
bounds
[
6
]
=
dim
*
2
;
bounds
[
6
]
=
dim
*
2
;
for
(
int
i
=
0
;
i
<
dim
*
2
;
i
++
)
{
for
(
int
i
=
0
;
i
<
dim
*
2
;
i
++
)
{
bounds
[
i
]
=
stack_values
.
pop
().
toInt
();
bounds
[
i
]
=
stack_values
.
pop
().
toInt
();
}
}
if
(
VariableScope
(
s
)
==
LOCAL
)
{
var
.
setBounds
(
bounds
);
stack_contexts
.
top
().
locals
[
id
].
setBounds
(
bounds
);
if
(
!
b_blindMode
)
name
=
stack_contexts
.
top
().
locals
[
id
].
name
();
name
=
var
.
name
();
}
else
if
(
VariableScope
(
s
)
==
GLOBAL
)
{
moduleContexts
[
stack_contexts
.
top
().
moduleContextNo
].
globals
[
GlobalsIndex
(
stack_contexts
.
top
().
moduleId
,
id
)].
setBounds
(
bounds
);
name
=
moduleContexts
[
stack_contexts
.
top
().
moduleContextNo
].
globals
[
GlobalsIndex
(
stack_contexts
.
top
().
moduleId
,
id
)].
name
();
}
s_error
=
Kumir
::
Core
::
getError
();
s_error
=
Kumir
::
Core
::
getError
();
const
int
lineNo
=
stack_contexts
.
top
().
lineNo
;
const
int
lineNo
=
stack_contexts
.
top
().
lineNo
;
if
(
lineNo
!=-
1
&&
if
(
lineNo
!=-
1
&&
...
@@ -1963,17 +1994,9 @@ void KumirVM::do_setarr(uint8_t s, uint16_t id)
...
@@ -1963,17 +1994,9 @@ void KumirVM::do_setarr(uint8_t s, uint16_t id)
void
KumirVM
::
do_updarr
(
uint8_t
s
,
uint16_t
id
)
void
KumirVM
::
do_updarr
(
uint8_t
s
,
uint16_t
id
)
{
{
if
(
m_dontTouchMe
)
m_dontTouchMe
->
lock
();
if
(
m_dontTouchMe
)
m_dontTouchMe
->
lock
();
int
dim
=
0
;
Variable
&
var
=
findVariable
(
s
,
id
);
const
int
dim
=
var
.
dimension
();
int
bounds
[
7
];
int
bounds
[
7
];
if
(
VariableScope
(
s
)
==
LOCAL
)
{
dim
=
stack_contexts
.
top
().
locals
[
id
].
dimension
();
}
else
if
(
VariableScope
(
s
)
==
GLOBAL
)
{
dim
=
moduleContexts
[
stack_contexts
.
top
().
moduleContextNo
].
globals
[
GlobalsIndex
(
stack_contexts
.
top
().
moduleId
,
id
)].
dimension
();
}
else
{
s_error
=
Kumir
::
Core
::
fromAscii
(
"Internal error"
);
}
if
(
dim
>
0
)
{
if
(
dim
>
0
)
{
String
name
;
String
name
;
int
effectiveBounds
[
7
];
int
effectiveBounds
[
7
];
...
@@ -1981,16 +2004,10 @@ void KumirVM::do_updarr(uint8_t s, uint16_t id)
...
@@ -1981,16 +2004,10 @@ void KumirVM::do_updarr(uint8_t s, uint16_t id)
for
(
int
i
=
0
;
i
<
dim
*
2
;
i
++
)
{
for
(
int
i
=
0
;
i
<
dim
*
2
;
i
++
)
{
bounds
[
i
]
=
stack_values
.
pop
().
toInt
();
bounds
[
i
]
=
stack_values
.
pop
().
toInt
();
}
}
if
(
VariableScope
(
s
)
==
LOCAL
)
{
var
.
updateBounds
(
bounds
);
stack_contexts
.
top
().
locals
[
id
].
updateBounds
(
bounds
);
var
.
getEffectiveBounds
(
effectiveBounds
);
name
=
stack_contexts
.
top
().
locals
[
id
].
myName
();
if
(
!
b_blindMode
)
stack_contexts
.
top
().
locals
[
id
].
getEffectiveBounds
(
effectiveBounds
);
name
=
var
.
myName
();
}
else
if
(
VariableScope
(
s
)
==
GLOBAL
)
{
moduleContexts
[
stack_contexts
.
top
().
moduleContextNo
].
globals
[
GlobalsIndex
(
stack_contexts
.
top
().
moduleId
,
id
)].
updateBounds
(
bounds
);
name
=
moduleContexts
[
stack_contexts
.
top
().
moduleContextNo
].
globals
[
GlobalsIndex
(
stack_contexts
.
top
().
moduleId
,
id
)].
myName
();
moduleContexts
[
stack_contexts
.
top
().
moduleContextNo
].
globals
[
GlobalsIndex
(
stack_contexts
.
top
().
moduleId
,
id
)].
getEffectiveBounds
(
effectiveBounds
);
}
s_error
=
Kumir
::
Core
::
getError
();
s_error
=
Kumir
::
Core
::
getError
();
const
int
lineNo
=
stack_contexts
.
top
().
lineNo
;
const
int
lineNo
=
stack_contexts
.
top
().
lineNo
;
if
(
lineNo
!=-
1
&&
if
(
lineNo
!=-
1
&&
...
@@ -1999,7 +2016,6 @@ void KumirVM::do_updarr(uint8_t s, uint16_t id)
...
@@ -1999,7 +2016,6 @@ void KumirVM::do_updarr(uint8_t s, uint16_t id)
)
)
{
{
String
boundsText
;
String
boundsText
;
for
(
int
i
=
0
;
i
<
dim
;
i
++
)
{
for
(
int
i
=
0
;
i
<
dim
;
i
++
)
{
boundsText
+=
Kumir
::
Converter
::
sprintfInt
(
bounds
[
i
*
2
],
10
,
0
,
0
);
boundsText
+=
Kumir
::
Converter
::
sprintfInt
(
bounds
[
i
*
2
],
10
,
0
,
0
);
boundsText
.
push_back
(
Char
(
':'
));
boundsText
.
push_back
(
Char
(
':'
));
...
@@ -2020,55 +2036,30 @@ void KumirVM::do_updarr(uint8_t s, uint16_t id)
...
@@ -2020,55 +2036,30 @@ void KumirVM::do_updarr(uint8_t s, uint16_t id)
void
KumirVM
::
do_store
(
uint8_t
s
,
uint16_t
id
)
void
KumirVM
::
do_store
(
uint8_t
s
,
uint16_t
id
)
{
{
if
(
m_dontTouchMe
)
m_dontTouchMe
->
lock
();
if
(
m_dontTouchMe
)
m_dontTouchMe
->
lock
();
const
Variable
&
val
=
stack_values
.
top
();
const
Variable
&
val
ue
=
stack_values
.
top
();
String
name
;
String
name
;
String
svalue
;
String
svalue
;
const
int
lineNo
=
stack_contexts
.
top
().
lineNo
;
const
int
lineNo
=
stack_contexts
.
top
().
lineNo
;
ValueType
t
=
VT_void
;
Variable
&
variable
=
findVariable
(
s
,
id
);
Variable
*
reference
=
0
;
ValueType
t
=
variable
.
baseType
();
Variable
*
reference
=
variable
.
reference
();
int
bounds
[
7
];
int
bounds
[
7
];
val
.
getBounds
(
bounds
);
value
.
getBounds
(
bounds
);
if
(
VariableScope
(
s
)
==
LOCAL
)
{
if
(
value
.
isConstant
())
if
(
stack_contexts
.
top
().
locals
[
id
].
isReference
())
variable
.
setConstValue
(
value
);
reference
=
stack_contexts
.
top
().
locals
[
id
].
reference
();
if
(
val
.
isConstant
())
{
stack_contexts
.
top
().
locals
[
id
].
setConstValue
(
val
);
}
else
{
stack_contexts
.
top
().
locals
[
id
].
setBounds
(
bounds
);
stack_contexts
.
top
().
locals
[
id
].
setValue
(
val
.
value
());
stack_contexts
.
top
().
locals
[
id
].
setDimension
(
val
.
dimension
());
}
if
(
lineNo
!=-
1
&&
!
b_blindMode
)
{
name
=
stack_contexts
.
top
().
locals
[
id
].
myName
();
svalue
=
stack_contexts
.
top
().
locals
[
id
].
toString
();
}
t
=
stack_contexts
.
top
().
locals
[
id
].
baseType
();
}
else
if
(
VariableScope
(
s
)
==
GLOBAL
)
{
// if (globals[GlobalsIndex(stack_contexts.top().moduleId,id)].isReference())
reference
=
moduleContexts
[
stack_contexts
.
top
().
moduleContextNo
].
globals
[
GlobalsIndex
(
stack_contexts
.
top
().
moduleId
,
id
)].
reference
();
if
(
val
.
isConstant
())
{
moduleContexts
[
stack_contexts
.
top
().
moduleContextNo
].
globals
[
GlobalsIndex
(
stack_contexts
.
top
().
moduleId
,
id
)].
setConstValue
(
val
);
}
else
{
moduleContexts
[
stack_contexts
.
top
().
moduleContextNo
].
globals
[
GlobalsIndex
(
stack_contexts
.
top
().
moduleId
,
id
)].
setDimension
(
val
.
dimension
());
moduleContexts
[
stack_contexts
.
top
().
moduleContextNo
].
globals
[
GlobalsIndex
(
stack_contexts
.
top
().
moduleId
,
id
)].
setBounds
(
bounds
);
moduleContexts
[
stack_contexts
.
top
().
moduleContextNo
].
globals
[
GlobalsIndex
(
stack_contexts
.
top
().
moduleId
,
id
)].
setValue
(
val
.
value
());
}
if
(
lineNo
!=-
1
&&
!
b_blindMode
)
{
name
=
moduleContexts
[
stack_contexts
.
top
().
moduleContextNo
].
globals
[
GlobalsIndex
(
stack_contexts
.
top
().
moduleId
,
id
)].
myName
();
svalue
=
moduleContexts
[
stack_contexts
.
top
().
moduleContextNo
].
globals
[
GlobalsIndex
(
stack_contexts
.
top
().
moduleId
,
id
)].
toString
();
}
t
=
moduleContexts
[
stack_contexts
.
top
().
moduleContextNo
].
globals
[
GlobalsIndex
(
stack_contexts
.
top
().
moduleId
,
id
)].
baseType
();
}
else
{
else
{
s_error
=
Kumir
::
Core
::
fromAscii
(
"Internal error"
);
variable
.
setBounds
(
bounds
);
variable
.
setValue
(
value
.
value
());
variable
.
setDimension
(
value
.
dimension
());
}
if
(
lineNo
!=-
1
&&
!
b_blindMode
)
{
name
=
variable
.
myName
();
svalue
=
variable
.
toString
();
}
}
if
(
lineNo
!=-
1
&&
if
(
lineNo
!=-
1
&&
!
b_blindMode
&&
!
b_blindMode
&&
stack_contexts
.
top
().
type
!=
EL_BELOWMAIN
&&
stack_contexts
.
top
().
type
!=
EL_BELOWMAIN
&&
val
.
dimension
()
==
0
val
ue
.
dimension
()
==
0
)
)
{
{
if
(
t
==
VT_string
)
{
if
(
t
==
VT_string
)
{
...
@@ -2104,36 +2095,24 @@ void KumirVM::do_load(uint8_t s, uint16_t id)
...
@@ -2104,36 +2095,24 @@ void KumirVM::do_load(uint8_t s, uint16_t id)
{
{
if
(
m_dontTouchMe
)
m_dontTouchMe
->
lock
();
if
(
m_dontTouchMe
)
m_dontTouchMe
->
lock
();
Variable
val
;
Variable
val
;
Variable
&
variable
=
findVariable
(
s
,
id
);
int
bounds
[
7
];
int
bounds
[
7
];
if
(
VariableScope
(
s
)
==
LOCAL
)
{
val
.
setBaseType
(
variable
.
baseType
());
val
.
setBaseType
(
stack_contexts
.
top
().
locals
[
id
].
baseType
());
variable
.
getBounds
(
bounds
);
stack_contexts
.
top
().
locals
[
id
].
getBounds
(
bounds
);
val
.
setDimension
(
variable
.
dimension
());
val
.
setDimension
(
stack_contexts
.
top
().
locals
[
id
].
dimension
());
val
.
setBounds
(
bounds
);
val
.
setBounds
(
bounds
);
if
(
VariableScope
(
s
)
==
CONSTT
)
{
val
.
setValue
(
stack_contexts
.
top
().
locals
[
id
].
value
());
}
else
if
(
VariableScope
(
s
)
==
GLOBAL
)
{
val
.
setBaseType
(
moduleContexts
[
stack_contexts
.
top
().
moduleContextNo
].
globals
[
GlobalsIndex
(
stack_contexts
.
top
().
moduleId
,
id
)].
baseType
());
moduleContexts
[
stack_contexts
.
top
().
moduleContextNo
].
globals
[
GlobalsIndex
(
stack_contexts
.
top
().
moduleId
,
id
)].
getBounds
(
bounds
);
val
.
setDimension
(
moduleContexts
[
stack_contexts
.
top
().
moduleContextNo
].
globals
[
GlobalsIndex
(
stack_contexts
.
top
().
moduleId
,
id
)].
dimension
());
val
.
setBounds
(
bounds
);
val
.
setValue
(
moduleContexts
[
stack_contexts
.
top
().
moduleContextNo
].
globals
[
GlobalsIndex
(
stack_contexts
.
top
().
moduleId
,
id
)].
value
());
}
else
if
(
VariableScope
(
s
)
==
CONSTT
)
{
val
.
setBaseType
(
moduleContexts
[
stack_contexts
.
top
().
moduleContextNo
].
constants
[
id
].
baseType
());
val
.
setDimension
(
moduleContexts
[
stack_contexts
.
top
().
moduleContextNo
].
constants
[
id
].
dimension
());
moduleContexts
[
stack_contexts
.
top
().
moduleContextNo
].
constants
[
id
].
getBounds
(
bounds
);
val
.
setBounds
(
bounds
);
bool
wasError
=
Kumir
::
Core
::
getError
().
length
()
>
0
;
bool
wasError
=
Kumir
::
Core
::
getError
().
length
()
>
0
;
AnyValue
v
=
moduleContexts
[
stack_contexts
.
top
().
moduleContextNo
].
constants
[
id
]
.
value
();
AnyValue
v
=
variable
.
value
();
if
(
!
wasError
)
if
(
!
wasError
)
Variable
::
unsetError
();
Variable
::
unsetError
();
val
.
setValue
(
v
);
val
.
setValue
(
v
);
val
.
setConstantFlag
(
true
);
val
.
setConstantFlag
(
true
);
}
}
else
{
else
{
s_error
=
Kumir
::
Core
::
fromAscii
(
"Internal error"
);
val
.
setValue
(
variable
.
value
()
);
}
}
bool
isRetVal
=
VariableScope
(
s
)
==
LOCAL
bool
isRetVal
=
VariableScope
(
s
)
==
LOCAL
&&
stack_contexts
.
top
().
locals
[
id
].
algorhitmName
()
==
stack_contexts
.
top
().
locals
[
id
].
name
();
&&
stack_contexts
.
top
().
locals
[
id
].
algorhitmName
()
==
stack_contexts
.
top
().
locals
[
id
].
name
();
if
(
isRetVal
&&
stack_contexts
.
top
().
type
==
Bytecode
::
EL_MAIN
)
if
(
isRetVal
&&
stack_contexts
.
top
().
type
==
Bytecode
::
EL_MAIN
)
...
@@ -2153,21 +2132,14 @@ void KumirVM::do_load(uint8_t s, uint16_t id)
...
@@ -2153,21 +2132,14 @@ void KumirVM::do_load(uint8_t s, uint16_t id)
void
KumirVM
::
do_storearr
(
uint8_t
s
,
uint16_t
id
)
void
KumirVM
::
do_storearr
(
uint8_t
s
,
uint16_t
id
)
{
{
if
(
m_dontTouchMe
)
m_dontTouchMe
->
lock
();
if
(
m_dontTouchMe
)
m_dontTouchMe
->
lock
();
int
dim
=
0
;
String
name
;
String
name
;
String
svalue
;
String
svalue
;
const
int
lineNo
=
stack_contexts
.
top
().
lineNo
;
const
int
lineNo
=
stack_contexts
.
top
().
lineNo
;
String
sindeces
;
String
sindeces
;
if
(
VariableScope
(
s
)
==
LOCAL
)
{
Variable
&
variable
=
findVariable
(
s
,
id
);
dim
=
stack_contexts
.
top
().
locals
[
id
].
dimension
();
const
int
dim
=
variable
.
dimension
();
name
=
stack_contexts
.
top
().
locals
[
id
].
name
();
if
(
!
b_blindMode
)
{
}
name
=
variable
.
name
();
else
if
(
VariableScope
(
s
)
==
GLOBAL
)
{
dim
=
moduleContexts
[
stack_contexts
.
top
().
moduleContextNo
].
globals
[
GlobalsIndex
(
stack_contexts
.
top
().
moduleId
,
id
)].
dimension
();
name
=
moduleContexts
[
stack_contexts
.
top
().
moduleContextNo
].
globals
[
GlobalsIndex
(
stack_contexts
.
top
().
moduleId
,
id
)].
name
();
}
else
{
s_error
=
Kumir
::
Core
::
fromAscii
(
"Internal error"
);
}
}
if
(
dim
>
0
)
{
if
(
dim
>
0
)
{
int
indeces
[
4
];
int
indeces
[
4
];
...
@@ -2178,21 +2150,12 @@ void KumirVM::do_storearr(uint8_t s, uint16_t id)
...
@@ -2178,21 +2150,12 @@ void KumirVM::do_storearr(uint8_t s, uint16_t id)
sindeces
.
push_back
(
','
);
sindeces
.
push_back
(
','
);
sindeces
+=
Kumir
::
Converter
::
sprintfInt
(
indeces
[
i
],
10
,
0
,
0
);
sindeces
+=
Kumir
::
Converter
::
sprintfInt
(
indeces
[
i
],
10
,
0
,
0
);
}
}
const
Variable
&
val
=
stack_values
.
top
();
const
Variable
&
val
ue
=
stack_values
.
top
();
ValueType
t
=
VT_void
;
ValueType
t
=
VT_void
;
svalue
=
val
.
toString
();
if
(
!
b_blindMode
)
if
(
VariableScope
(
s
)
==
LOCAL
)
{
svalue
=
value
.
toString
();
stack_contexts
.
top
().
locals
[
id
].
setValue
(
indeces
,
val
.
value
());
variable
.
setValue
(
indeces
,
value
.
value
());
t
=
stack_contexts
.
top
().
locals
[
id
].
baseType
();
t
=
variable
.
baseType
();
if
(
lineNo
!=-
1
&&
!
b_blindMode
)
svalue
=
stack_contexts
.
top
().
locals
[
id
].
toString
(
indeces
);
}
else
if
(
VariableScope
(
s
)
==
GLOBAL
)
{
moduleContexts
[
stack_contexts
.
top
().
moduleContextNo
].
globals
[
GlobalsIndex
(
stack_contexts
.
top
().
moduleId
,
id
)].
setValue
(
indeces
,
val
.
value
());
t
=
moduleContexts
[
stack_contexts
.
top
().
moduleContextNo
].
globals
[
GlobalsIndex
(
stack_contexts
.
top
().
moduleId
,
id
)].
baseType
();
if
(
lineNo
!=-
1
&&
!
b_blindMode
)
svalue
=
moduleContexts
[
stack_contexts
.
top
().
moduleContextNo
].
globals
[
GlobalsIndex
(
stack_contexts
.
top
().
moduleId
,
id
)].
toString
(
indeces
);
}
if
(
t
==
VT_string
)
if
(
t
==
VT_string
)
if
(
lineNo
!=-
1
&&
!
b_blindMode
)
{
if
(
lineNo
!=-
1
&&
!
b_blindMode
)
{
svalue
.
insert
(
0
,
1
,
Char
(
'"'
));
svalue
.
insert
(
0
,
1
,
Char
(
'"'
));
...
@@ -2224,23 +2187,9 @@ void KumirVM::do_storearr(uint8_t s, uint16_t id)
...
@@ -2224,23 +2187,9 @@ void KumirVM::do_storearr(uint8_t s, uint16_t id)
void
KumirVM
::
do_loadarr
(
uint8_t
s
,
uint16_t
id
)
void
KumirVM
::
do_loadarr
(
uint8_t
s
,
uint16_t
id
)
{
{
if
(
m_dontTouchMe
)
m_dontTouchMe
->
lock
();
if
(
m_dontTouchMe
)
m_dontTouchMe
->
lock
();
int
dim
=
0
;
Variable
&
variable
=
findVariable
(
s
,
id
);
ValueType
vt
=
VT_void
;
const
int
dim
=
variable
.
dimension
();
if
(
VariableScope
(
s
)
==
LOCAL
)
{
const
ValueType
vt
=
variable
.
baseType
();
dim
=
stack_contexts
.
top
().
locals
[
id
].
dimension
();
vt
=
stack_contexts
.
top
().
locals
[
id
].
baseType
();
}
else
if
(
VariableScope
(
s
)
==
GLOBAL
)
{
dim
=
moduleContexts
[
stack_contexts
.
top
().
moduleContextNo
].
globals
[
GlobalsIndex
(
stack_contexts
.
top
().
moduleId
,
id
)].
dimension
();
vt
=
moduleContexts
[
stack_contexts
.
top
().
moduleContextNo
].
globals
[
GlobalsIndex
(
stack_contexts
.
top
().
moduleId
,
id
)].
baseType
();
}
else
if
(
VariableScope
(
s
)
==
CONSTT
)
{
dim
=
moduleContexts
[
stack_contexts
.
top
().
moduleContextNo
].
constants
[
id
].
dimension
();
vt
=
moduleContexts
[
stack_contexts
.
top
().
moduleContextNo
].
constants
[
id
].
baseType
();
}
else
{
s_error
=
Kumir
::
Core
::
fromAscii
(
"Internal error"
);
}
if
(
dim
>
0
||
vt
==
VT_string
)
{
if
(
dim
>
0
||
vt
==
VT_string
)
{
int
indeces
[
4
];
int
indeces
[
4
];
...
@@ -2250,18 +2199,8 @@ void KumirVM::do_loadarr(uint8_t s, uint16_t id)
...
@@ -2250,18 +2199,8 @@ void KumirVM::do_loadarr(uint8_t s, uint16_t id)
}