Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
ardublockly
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
ardublockly
Commits
da2e0710
Commit
da2e0710
authored
May 09, 2015
by
daarond
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixing some items
parent
f0c837bb
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
44 additions
and
40 deletions
+44
-40
generators/php.js
generators/php.js
+12
-7
generators/php/lists.js
generators/php/lists.js
+3
-3
generators/php/loops.js
generators/php/loops.js
+26
-26
generators/php/text.js
generators/php/text.js
+2
-2
generators/php/variables.js
generators/php/variables.js
+1
-2
No files found.
generators/php.js
View file @
da2e0710
...
@@ -105,17 +105,22 @@ Blockly.PHP.init = function(workspace) {
...
@@ -105,17 +105,22 @@ Blockly.PHP.init = function(workspace) {
}
else
{
}
else
{
Blockly
.
PHP
.
variableDB_
.
reset
();
Blockly
.
PHP
.
variableDB_
.
reset
();
}
}
};
var
defvars
=
[];
Blockly
.
PHP
.
getDistinctName
=
function
(
name
,
type
)
{
var
variables
=
Blockly
.
Variables
.
allVariables
(
workspace
);
var
safeName
=
this
.
variableDB_
.
safeName_
(
name
);
for
(
var
x
=
0
;
x
<
variables
.
length
;
x
++
)
{
var
i
=
''
;
defvars
[
x
]
=
'
var
'
+
while
(
this
.
variableDB_
.
dbReverse_
[
safeName
+
i
]
||
Blockly
.
PHP
.
variableDB_
.
getName
(
variables
[
x
],
(
safeName
+
i
)
in
this
.
variableDB_
.
reservedDict_
)
{
Blockly
.
Variables
.
NAME_TYPE
)
+
'
;
'
;
// Collision with existing name. Create a unique name.
i
=
i
?
i
+
1
:
2
;
}
}
Blockly
.
PHP
.
definitions_
[
'
variables
'
]
=
defvars
.
join
(
'
\n
'
);
safeName
+=
i
;
this
.
variableDB_
.
dbReverse_
[
safeName
]
=
true
;
return
'
$
'
+
safeName
;
};
};
/**
/**
* Prepend the generated code with the variable definitions.
* Prepend the generated code with the variable definitions.
* @param {string} code Generated code.
* @param {string} code Generated code.
...
...
generators/php/lists.js
View file @
da2e0710
...
@@ -61,7 +61,7 @@ Blockly.PHP['lists_repeat'] = function(block) {
...
@@ -61,7 +61,7 @@ Blockly.PHP['lists_repeat'] = function(block) {
Blockly
.
PHP
.
ORDER_COMMA
)
||
'
null
'
;
Blockly
.
PHP
.
ORDER_COMMA
)
||
'
null
'
;
var
argument1
=
Blockly
.
PHP
.
valueToCode
(
block
,
'
NUM
'
,
var
argument1
=
Blockly
.
PHP
.
valueToCode
(
block
,
'
NUM
'
,
Blockly
.
PHP
.
ORDER_COMMA
)
||
'
0
'
;
Blockly
.
PHP
.
ORDER_COMMA
)
||
'
0
'
;
var
code
=
functionName
+
'
(
$
'
+
argument0
+
'
, $
'
+
argument1
+
'
)
'
;
var
code
=
functionName
+
'
(
'
+
argument0
+
'
,
'
+
argument1
+
'
)
'
;
return
[
code
,
Blockly
.
PHP
.
ORDER_FUNCTION_CALL
];
return
[
code
,
Blockly
.
PHP
.
ORDER_FUNCTION_CALL
];
};
};
...
@@ -197,7 +197,7 @@ Blockly.PHP['lists_setIndex'] = function(block) {
...
@@ -197,7 +197,7 @@ Blockly.PHP['lists_setIndex'] = function(block) {
if
(
list
.
match
(
/^
\w
+$/
))
{
if
(
list
.
match
(
/^
\w
+$/
))
{
return
''
;
return
''
;
}
}
var
listVar
=
Blockly
.
PHP
.
variableDB_
.
getDistinctName
(
var
listVar
=
Blockly
.
PHP
.
getDistinctName
(
'
tmp_list
'
,
Blockly
.
Variables
.
NAME_TYPE
);
'
tmp_list
'
,
Blockly
.
Variables
.
NAME_TYPE
);
var
code
=
'
var
'
+
listVar
+
'
=
'
+
list
+
'
;
\n
'
;
var
code
=
'
var
'
+
listVar
+
'
=
'
+
list
+
'
;
\n
'
;
list
=
listVar
;
list
=
listVar
;
...
@@ -243,7 +243,7 @@ Blockly.PHP['lists_setIndex'] = function(block) {
...
@@ -243,7 +243,7 @@ Blockly.PHP['lists_setIndex'] = function(block) {
}
}
}
else
if
(
where
==
'
RANDOM
'
)
{
}
else
if
(
where
==
'
RANDOM
'
)
{
var
code
=
cacheList
();
var
code
=
cacheList
();
var
xVar
=
Blockly
.
PHP
.
variableDB_
.
getDistinctName
(
var
xVar
=
Blockly
.
PHP
.
getDistinctName
(
'
tmp_x
'
,
Blockly
.
Variables
.
NAME_TYPE
);
'
tmp_x
'
,
Blockly
.
Variables
.
NAME_TYPE
);
code
+=
'
var
'
+
xVar
+
'
= Math.floor(Math.random() *
'
+
list
+
code
+=
'
var
'
+
xVar
+
'
= Math.floor(Math.random() *
'
+
list
+
'
.length);
\n
'
;
'
.length);
\n
'
;
...
...
generators/php/loops.js
View file @
da2e0710
...
@@ -34,10 +34,10 @@ Blockly.PHP['controls_repeat'] = function(block) {
...
@@ -34,10 +34,10 @@ Blockly.PHP['controls_repeat'] = function(block) {
var
repeats
=
Number
(
block
.
getFieldValue
(
'
TIMES
'
));
var
repeats
=
Number
(
block
.
getFieldValue
(
'
TIMES
'
));
var
branch
=
Blockly
.
PHP
.
statementToCode
(
block
,
'
DO
'
);
var
branch
=
Blockly
.
PHP
.
statementToCode
(
block
,
'
DO
'
);
branch
=
Blockly
.
PHP
.
addLoopTrap
(
branch
,
block
.
id
);
branch
=
Blockly
.
PHP
.
addLoopTrap
(
branch
,
block
.
id
);
var
loopVar
=
Blockly
.
PHP
.
variableDB_
.
getDistinctName
(
var
loopVar
=
Blockly
.
PHP
.
getDistinctName
(
'
count
'
,
Blockly
.
Variables
.
NAME_TYPE
);
'
count
'
,
Blockly
.
Variables
.
NAME_TYPE
);
var
code
=
'
for (
$
'
+
loopVar
+
'
= 0; $
'
+
var
code
=
'
for (
'
+
loopVar
+
'
= 0;
'
+
loopVar
+
'
<
'
+
repeats
+
'
;
$
'
+
loopVar
+
'
<
'
+
repeats
+
'
;
'
+
loopVar
+
'
++) {
\n
'
+
loopVar
+
'
++) {
\n
'
+
branch
+
'
}
\n
'
;
branch
+
'
}
\n
'
;
return
code
;
return
code
;
...
@@ -50,16 +50,16 @@ Blockly.PHP['controls_repeat_ext'] = function(block) {
...
@@ -50,16 +50,16 @@ Blockly.PHP['controls_repeat_ext'] = function(block) {
var
branch
=
Blockly
.
PHP
.
statementToCode
(
block
,
'
DO
'
);
var
branch
=
Blockly
.
PHP
.
statementToCode
(
block
,
'
DO
'
);
branch
=
Blockly
.
PHP
.
addLoopTrap
(
branch
,
block
.
id
);
branch
=
Blockly
.
PHP
.
addLoopTrap
(
branch
,
block
.
id
);
var
code
=
''
;
var
code
=
''
;
var
loopVar
=
Blockly
.
PHP
.
variableDB_
.
getDistinctName
(
var
loopVar
=
Blockly
.
PHP
.
getDistinctName
(
'
count
'
,
Blockly
.
Variables
.
NAME_TYPE
);
'
count
'
,
Blockly
.
Variables
.
NAME_TYPE
);
var
endVar
=
repeats
;
var
endVar
=
repeats
;
if
(
!
repeats
.
match
(
/^
\w
+$/
)
&&
!
Blockly
.
isNumber
(
repeats
))
{
if
(
!
repeats
.
match
(
/^
\w
+$/
)
&&
!
Blockly
.
isNumber
(
repeats
))
{
var
endVar
=
Blockly
.
PHP
.
variableDB_
.
getDistinctName
(
var
endVar
=
Blockly
.
PHP
.
getDistinctName
(
'
repeat_end
'
,
Blockly
.
Variables
.
NAME_TYPE
);
'
repeat_end
'
,
Blockly
.
Variables
.
NAME_TYPE
);
code
+=
'
var
'
+
endVar
+
'
=
'
+
repeats
+
'
;
\n
'
;
code
+=
endVar
+
'
=
'
+
repeats
+
'
;
\n
'
;
}
}
code
+=
'
for (
$
'
+
loopVar
+
'
= 0; $
'
+
code
+=
'
for (
'
+
loopVar
+
'
= 0;
'
+
loopVar
+
'
<
$
'
+
endVar
+
'
; $
'
+
loopVar
+
'
<
'
+
endVar
+
'
;
'
+
loopVar
+
'
++) {
\n
'
+
loopVar
+
'
++) {
\n
'
+
branch
+
'
}
\n
'
;
branch
+
'
}
\n
'
;
return
code
;
return
code
;
...
@@ -96,8 +96,8 @@ Blockly.PHP['controls_for'] = function(block) {
...
@@ -96,8 +96,8 @@ Blockly.PHP['controls_for'] = function(block) {
Blockly
.
isNumber
(
increment
))
{
Blockly
.
isNumber
(
increment
))
{
// All arguments are simple numbers.
// All arguments are simple numbers.
var
up
=
parseFloat
(
argument0
)
<=
parseFloat
(
argument1
);
var
up
=
parseFloat
(
argument0
)
<=
parseFloat
(
argument1
);
code
=
'
for (
$
'
+
variable0
+
'
=
'
+
argument0
+
'
; $
'
+
code
=
'
for (
'
+
variable0
+
'
=
'
+
argument0
+
'
;
'
+
variable0
+
(
up
?
'
<=
'
:
'
>=
'
)
+
argument1
+
'
;
$
'
+
variable0
+
(
up
?
'
<=
'
:
'
>=
'
)
+
argument1
+
'
;
'
+
variable0
;
variable0
;
var
step
=
Math
.
abs
(
parseFloat
(
increment
));
var
step
=
Math
.
abs
(
parseFloat
(
increment
));
if
(
step
==
1
)
{
if
(
step
==
1
)
{
...
@@ -111,34 +111,34 @@ Blockly.PHP['controls_for'] = function(block) {
...
@@ -111,34 +111,34 @@ Blockly.PHP['controls_for'] = function(block) {
// Cache non-trivial values to variables to prevent repeated look-ups.
// Cache non-trivial values to variables to prevent repeated look-ups.
var
startVar
=
argument0
;
var
startVar
=
argument0
;
if
(
!
argument0
.
match
(
/^
\w
+$/
)
&&
!
Blockly
.
isNumber
(
argument0
))
{
if
(
!
argument0
.
match
(
/^
\w
+$/
)
&&
!
Blockly
.
isNumber
(
argument0
))
{
startVar
=
Blockly
.
PHP
.
variableDB_
.
getDistinctName
(
startVar
=
Blockly
.
PHP
.
getDistinctName
(
variable0
+
'
_start
'
,
Blockly
.
Variables
.
NAME_TYPE
);
variable0
+
'
_start
'
,
Blockly
.
Variables
.
NAME_TYPE
);
code
+=
'
$
'
+
startVar
+
'
=
'
+
argument0
+
'
;
\n
'
;
code
+=
startVar
+
'
=
'
+
argument0
+
'
;
\n
'
;
}
}
var
endVar
=
argument1
;
var
endVar
=
argument1
;
if
(
!
argument1
.
match
(
/^
\w
+$/
)
&&
!
Blockly
.
isNumber
(
argument1
))
{
if
(
!
argument1
.
match
(
/^
\w
+$/
)
&&
!
Blockly
.
isNumber
(
argument1
))
{
var
endVar
=
Blockly
.
PHP
.
variableDB_
.
getDistinctName
(
var
endVar
=
Blockly
.
PHP
.
getDistinctName
(
variable0
+
'
_end
'
,
Blockly
.
Variables
.
NAME_TYPE
);
variable0
+
'
_end
'
,
Blockly
.
Variables
.
NAME_TYPE
);
code
+=
'
$
'
+
endVar
+
'
=
'
+
argument1
+
'
;
\n
'
;
code
+=
endVar
+
'
=
'
+
argument1
+
'
;
\n
'
;
}
}
// Determine loop direction at start, in case one of the bounds
// Determine loop direction at start, in case one of the bounds
// changes during loop execution.
// changes during loop execution.
var
incVar
=
Blockly
.
PHP
.
variableDB_
.
getDistinctName
(
var
incVar
=
Blockly
.
PHP
.
getDistinctName
(
variable0
+
'
_inc
'
,
Blockly
.
Variables
.
NAME_TYPE
);
variable0
+
'
_inc
'
,
Blockly
.
Variables
.
NAME_TYPE
);
code
+=
'
$
'
+
incVar
+
'
=
'
;
code
+=
incVar
+
'
=
'
;
if
(
Blockly
.
isNumber
(
increment
))
{
if
(
Blockly
.
isNumber
(
increment
))
{
code
+=
Math
.
abs
(
increment
)
+
'
;
\n
'
;
code
+=
Math
.
abs
(
increment
)
+
'
;
\n
'
;
}
else
{
}
else
{
code
+=
'
abs(
'
+
increment
+
'
);
\n
'
;
code
+=
'
abs(
'
+
increment
+
'
);
\n
'
;
}
}
code
+=
'
if (
$
'
+
startVar
+
'
> $
'
+
endVar
+
'
) {
\n
'
;
code
+=
'
if (
'
+
startVar
+
'
>
'
+
endVar
+
'
) {
\n
'
;
code
+=
Blockly
.
PHP
.
INDENT
+
'
$
'
+
incVar
+
'
= -$
'
+
incVar
+
'
;
\n
'
;
code
+=
Blockly
.
PHP
.
INDENT
+
incVar
+
'
= -
'
+
incVar
+
'
;
\n
'
;
code
+=
'
}
\n
'
;
code
+=
'
}
\n
'
;
code
+=
'
for (
'
+
variable0
+
'
=
$
'
+
startVar
+
'
;
\n
'
+
code
+=
'
for (
'
+
variable0
+
'
=
'
+
startVar
+
'
;
\n
'
+
'
'
+
incVar
+
'
>= 0 ?
$
'
+
'
'
+
incVar
+
'
>= 0 ?
'
+
variable0
+
'
<=
'
+
endVar
+
'
:
$
'
+
variable0
+
'
<=
'
+
endVar
+
'
:
'
+
variable0
+
'
>=
'
+
endVar
+
'
;
\n
'
+
variable0
+
'
>=
'
+
endVar
+
'
;
\n
'
+
'
'
+
variable0
+
'
+=
$
'
+
incVar
+
'
) {
\n
'
+
'
'
+
variable0
+
'
+=
'
+
incVar
+
'
) {
\n
'
+
branch
+
'
}
\n
'
;
branch
+
'
}
\n
'
;
}
}
return
code
;
return
code
;
...
@@ -156,15 +156,15 @@ Blockly.PHP['controls_forEach'] = function(block) {
...
@@ -156,15 +156,15 @@ Blockly.PHP['controls_forEach'] = function(block) {
// Cache non-trivial values to variables to prevent repeated look-ups.
// Cache non-trivial values to variables to prevent repeated look-ups.
var
listVar
=
argument0
;
var
listVar
=
argument0
;
if
(
!
argument0
.
match
(
/^
\w
+$/
))
{
if
(
!
argument0
.
match
(
/^
\w
+$/
))
{
listVar
=
Blockly
.
PHP
.
variableDB_
.
getDistinctName
(
listVar
=
Blockly
.
PHP
.
getDistinctName
(
variable0
+
'
_list
'
,
Blockly
.
Variables
.
NAME_TYPE
);
variable0
+
'
_list
'
,
Blockly
.
Variables
.
NAME_TYPE
);
code
+=
'
$
'
+
listVar
+
'
=
'
+
argument0
+
'
;
\n
'
;
code
+=
listVar
+
'
=
'
+
argument0
+
'
;
\n
'
;
}
}
var
indexVar
=
Blockly
.
PHP
.
variableDB_
.
getDistinctName
(
var
indexVar
=
Blockly
.
PHP
.
getDistinctName
(
variable0
+
'
_index
'
,
Blockly
.
Variables
.
NAME_TYPE
);
variable0
+
'
_index
'
,
Blockly
.
Variables
.
NAME_TYPE
);
branch
=
Blockly
.
PHP
.
INDENT
+
variable0
+
'
=
'
+
branch
=
Blockly
.
PHP
.
INDENT
+
variable0
+
'
=
'
+
listVar
+
'
[
'
+
indexVar
+
'
];
\n
'
+
branch
;
listVar
+
'
[
'
+
indexVar
+
'
];
\n
'
+
branch
;
code
+=
'
foreach (
$
'
+
listVar
+
'
as $
'
+
indexVar
+
'
) {
\n
'
+
branch
+
'
}
\n
'
;
code
+=
'
foreach (
'
+
listVar
+
'
as
'
+
indexVar
+
'
) {
\n
'
+
branch
+
'
}
\n
'
;
return
code
;
return
code
;
};
};
...
...
generators/php/text.js
View file @
da2e0710
...
@@ -76,14 +76,14 @@ Blockly.PHP['text_length'] = function(block) {
...
@@ -76,14 +76,14 @@ Blockly.PHP['text_length'] = function(block) {
// String length.
// String length.
var
argument0
=
Blockly
.
PHP
.
valueToCode
(
block
,
'
VALUE
'
,
var
argument0
=
Blockly
.
PHP
.
valueToCode
(
block
,
'
VALUE
'
,
Blockly
.
PHP
.
ORDER_FUNCTION_CALL
)
||
'
\'\'
'
;
Blockly
.
PHP
.
ORDER_FUNCTION_CALL
)
||
'
\'\'
'
;
return
[
'
strlen(
'
+
argument0
+
'
)
'
,
Blockly
.
PHP
.
ORDER_
MEMBER
];
return
[
'
strlen(
'
+
argument0
+
'
)
'
,
Blockly
.
PHP
.
ORDER_
FUNCTION_CALL
];
};
};
Blockly
.
PHP
[
'
text_isEmpty
'
]
=
function
(
block
)
{
Blockly
.
PHP
[
'
text_isEmpty
'
]
=
function
(
block
)
{
// Is the string null?
// Is the string null?
var
argument0
=
Blockly
.
PHP
.
valueToCode
(
block
,
'
VALUE
'
,
var
argument0
=
Blockly
.
PHP
.
valueToCode
(
block
,
'
VALUE
'
,
Blockly
.
PHP
.
ORDER_MEMBER
)
||
'
\'\'
'
;
Blockly
.
PHP
.
ORDER_MEMBER
)
||
'
\'\'
'
;
return
[
'
empty(
'
+
argument0
+
'
)
'
,
Blockly
.
PHP
.
ORDER_
LOGICAL_NOT
];
return
[
'
empty(
'
+
argument0
+
'
)
'
,
Blockly
.
PHP
.
ORDER_
FUNCTION_CALL
];
};
};
Blockly
.
PHP
[
'
text_indexOf
'
]
=
function
(
block
)
{
Blockly
.
PHP
[
'
text_indexOf
'
]
=
function
(
block
)
{
...
...
generators/php/variables.js
View file @
da2e0710
...
@@ -31,8 +31,7 @@ goog.require('Blockly.PHP');
...
@@ -31,8 +31,7 @@ goog.require('Blockly.PHP');
Blockly
.
PHP
[
'
variables_get
'
]
=
function
(
block
)
{
Blockly
.
PHP
[
'
variables_get
'
]
=
function
(
block
)
{
// Variable getter.
// Variable getter.
var
code
=
Blockly
.
PHP
.
variableDB_
.
getName
(
block
.
getFieldValue
(
'
VAR
'
),
var
code
=
'
$
'
+
block
.
getFieldValue
(
'
VAR
'
);
Blockly
.
Variables
.
NAME_TYPE
);
return
[
code
,
Blockly
.
PHP
.
ORDER_ATOMIC
];
return
[
code
,
Blockly
.
PHP
.
ORDER_ATOMIC
];
};
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment