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
5e7f92ce
Commit
5e7f92ce
authored
May 10, 2015
by
daarond
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more debugging
parent
da2e0710
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
23 additions
and
25 deletions
+23
-25
generators/php.js
generators/php.js
+9
-0
generators/php/loops.js
generators/php/loops.js
+3
-14
generators/php/math.js
generators/php/math.js
+6
-6
generators/php/procedures.js
generators/php/procedures.js
+4
-4
generators/php/text.js
generators/php/text.js
+1
-1
No files found.
generators/php.js
View file @
5e7f92ce
...
@@ -120,6 +120,15 @@ Blockly.PHP.getDistinctName = function(name, type) {
...
@@ -120,6 +120,15 @@ Blockly.PHP.getDistinctName = function(name, type) {
return
'
$
'
+
safeName
;
return
'
$
'
+
safeName
;
};
};
Blockly
.
PHP
.
getName
=
function
(
name
,
type
)
{
var
normalized
=
name
.
toLowerCase
()
+
'
_
'
+
type
;
if
(
normalized
in
this
.
variableDB_
.
db_
)
{
return
this
.
variableDB_
.
db_
[
normalized
];
}
var
safeName
=
this
.
getDistinctName
(
name
,
type
);
this
.
variableDB_
[
normalized
]
=
safeName
;
return
safeName
;
};
/**
/**
* Prepend the generated code with the variable definitions.
* Prepend the generated code with the variable definitions.
...
...
generators/php/loops.js
View file @
5e7f92ce
...
@@ -81,7 +81,7 @@ Blockly.PHP['controls_whileUntil'] = function(block) {
...
@@ -81,7 +81,7 @@ Blockly.PHP['controls_whileUntil'] = function(block) {
Blockly
.
PHP
[
'
controls_for
'
]
=
function
(
block
)
{
Blockly
.
PHP
[
'
controls_for
'
]
=
function
(
block
)
{
// For loop.
// For loop.
var
variable0
=
Blockly
.
PHP
.
variableDB_
.
getName
(
var
variable0
=
Blockly
.
PHP
.
getName
(
block
.
getFieldValue
(
'
VAR
'
),
Blockly
.
Variables
.
NAME_TYPE
);
block
.
getFieldValue
(
'
VAR
'
),
Blockly
.
Variables
.
NAME_TYPE
);
var
argument0
=
Blockly
.
PHP
.
valueToCode
(
block
,
'
FROM
'
,
var
argument0
=
Blockly
.
PHP
.
valueToCode
(
block
,
'
FROM
'
,
Blockly
.
PHP
.
ORDER_ASSIGNMENT
)
||
'
0
'
;
Blockly
.
PHP
.
ORDER_ASSIGNMENT
)
||
'
0
'
;
...
@@ -146,25 +146,14 @@ Blockly.PHP['controls_for'] = function(block) {
...
@@ -146,25 +146,14 @@ Blockly.PHP['controls_for'] = function(block) {
Blockly
.
PHP
[
'
controls_forEach
'
]
=
function
(
block
)
{
Blockly
.
PHP
[
'
controls_forEach
'
]
=
function
(
block
)
{
// For each loop.
// For each loop.
var
variable0
=
Blockly
.
PHP
.
variableDB_
.
getName
(
var
variable0
=
Blockly
.
PHP
.
getName
(
block
.
getFieldValue
(
'
VAR
'
),
Blockly
.
Variables
.
NAME_TYPE
);
block
.
getFieldValue
(
'
VAR
'
),
Blockly
.
Variables
.
NAME_TYPE
);
var
argument0
=
Blockly
.
PHP
.
valueToCode
(
block
,
'
LIST
'
,
var
argument0
=
Blockly
.
PHP
.
valueToCode
(
block
,
'
LIST
'
,
Blockly
.
PHP
.
ORDER_ASSIGNMENT
)
||
'
[]
'
;
Blockly
.
PHP
.
ORDER_ASSIGNMENT
)
||
'
[]
'
;
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
=
''
;
// Cache non-trivial values to variables to prevent repeated look-ups.
code
+=
'
foreach (
'
+
argument0
+
'
as
'
+
variable0
+
'
) {
\n
'
+
branch
+
'
}
\n
'
;
var
listVar
=
argument0
;
if
(
!
argument0
.
match
(
/^
\w
+$/
))
{
listVar
=
Blockly
.
PHP
.
getDistinctName
(
variable0
+
'
_list
'
,
Blockly
.
Variables
.
NAME_TYPE
);
code
+=
listVar
+
'
=
'
+
argument0
+
'
;
\n
'
;
}
var
indexVar
=
Blockly
.
PHP
.
getDistinctName
(
variable0
+
'
_index
'
,
Blockly
.
Variables
.
NAME_TYPE
);
branch
=
Blockly
.
PHP
.
INDENT
+
variable0
+
'
=
'
+
listVar
+
'
[
'
+
indexVar
+
'
];
\n
'
+
branch
;
code
+=
'
foreach (
'
+
listVar
+
'
as
'
+
indexVar
+
'
) {
\n
'
+
branch
+
'
}
\n
'
;
return
code
;
return
code
;
};
};
...
...
generators/php/math.js
View file @
5e7f92ce
...
@@ -146,13 +146,13 @@ Blockly.PHP['math_single'] = function(block) {
...
@@ -146,13 +146,13 @@ Blockly.PHP['math_single'] = function(block) {
Blockly
.
PHP
[
'
math_constant
'
]
=
function
(
block
)
{
Blockly
.
PHP
[
'
math_constant
'
]
=
function
(
block
)
{
// Constants: PI, E, the Golden Ratio, sqrt(2), 1/sqrt(2), INFINITY.
// Constants: PI, E, the Golden Ratio, sqrt(2), 1/sqrt(2), INFINITY.
var
CONSTANTS
=
{
var
CONSTANTS
=
{
'
PI
'
:
[
'
pi()
'
,
Blockly
.
PHP
.
ORDER_
MEMBER
],
'
PI
'
:
[
'
pi()
'
,
Blockly
.
PHP
.
ORDER_
FUNCTION_CALL
],
'
E
'
:
[
'
exp
'
,
Blockly
.
PHP
.
ORDER_FUNCTION_CALL
],
'
E
'
:
[
'
exp
()
'
,
Blockly
.
PHP
.
ORDER_FUNCTION_CALL
],
'
GOLDEN_RATIO
'
:
'
GOLDEN_RATIO
'
:
[
'
(1 + sqrt(5)) / 2
'
,
Blockly
.
PHP
.
ORDER_DIVISION
],
[
'
(1 + sqrt(5)) / 2
'
,
Blockly
.
PHP
.
ORDER_DIVISION
],
'
SQRT2
'
:
[
'
sqrt
'
,
Blockly
.
PHP
.
ORDER_MEMBER
],
'
SQRT2
'
:
[
'
M_SQRT2
'
,
Blockly
.
PHP
.
ORDER_ATOMIC
],
'
SQRT1_2
'
:
[
'
sqrt
'
,
Blockly
.
PHP
.
ORDER_MEMBER
],
'
SQRT1_2
'
:
[
'
M_SQRT1_2
'
,
Blockly
.
PHP
.
ORDER_ATOMIC
],
'
INFINITY
'
:
[
'
I
nfinity
'
,
Blockly
.
PHP
.
ORDER_ATOMIC
]
'
INFINITY
'
:
[
'
I
NF
'
,
Blockly
.
PHP
.
ORDER_ATOMIC
]
};
};
return
CONSTANTS
[
block
.
getFieldValue
(
'
CONSTANT
'
)];
return
CONSTANTS
[
block
.
getFieldValue
(
'
CONSTANT
'
)];
};
};
...
@@ -197,7 +197,7 @@ Blockly.PHP['math_change'] = function(block) {
...
@@ -197,7 +197,7 @@ Blockly.PHP['math_change'] = function(block) {
// Add to a variable in place.
// Add to a variable in place.
var
argument0
=
Blockly
.
PHP
.
valueToCode
(
block
,
'
DELTA
'
,
var
argument0
=
Blockly
.
PHP
.
valueToCode
(
block
,
'
DELTA
'
,
Blockly
.
PHP
.
ORDER_ADDITION
)
||
'
0
'
;
Blockly
.
PHP
.
ORDER_ADDITION
)
||
'
0
'
;
var
varName
=
Blockly
.
PHP
.
variableDB_
.
getName
(
var
varName
=
Blockly
.
PHP
.
getName
(
block
.
getFieldValue
(
'
VAR
'
),
Blockly
.
Variables
.
NAME_TYPE
);
block
.
getFieldValue
(
'
VAR
'
),
Blockly
.
Variables
.
NAME_TYPE
);
return
varName
+
'
= (typeof
'
+
varName
+
'
==
\'
number
\'
?
'
+
varName
+
return
varName
+
'
= (typeof
'
+
varName
+
'
==
\'
number
\'
?
'
+
varName
+
'
: 0) +
'
+
argument0
+
'
;
\n
'
;
'
: 0) +
'
+
argument0
+
'
;
\n
'
;
...
...
generators/php/procedures.js
View file @
5e7f92ce
...
@@ -31,7 +31,7 @@ goog.require('Blockly.PHP');
...
@@ -31,7 +31,7 @@ goog.require('Blockly.PHP');
Blockly
.
PHP
[
'
procedures_defreturn
'
]
=
function
(
block
)
{
Blockly
.
PHP
[
'
procedures_defreturn
'
]
=
function
(
block
)
{
// Define a procedure with a return value.
// Define a procedure with a return value.
var
funcName
=
Blockly
.
PHP
.
variableDB_
.
getName
(
var
funcName
=
Blockly
.
PHP
.
getName
(
block
.
getFieldValue
(
'
NAME
'
),
Blockly
.
Procedures
.
NAME_TYPE
);
block
.
getFieldValue
(
'
NAME
'
),
Blockly
.
Procedures
.
NAME_TYPE
);
var
branch
=
Blockly
.
PHP
.
statementToCode
(
block
,
'
STACK
'
);
var
branch
=
Blockly
.
PHP
.
statementToCode
(
block
,
'
STACK
'
);
if
(
Blockly
.
PHP
.
STATEMENT_PREFIX
)
{
if
(
Blockly
.
PHP
.
STATEMENT_PREFIX
)
{
...
@@ -50,7 +50,7 @@ Blockly.PHP['procedures_defreturn'] = function(block) {
...
@@ -50,7 +50,7 @@ Blockly.PHP['procedures_defreturn'] = function(block) {
}
}
var
args
=
[];
var
args
=
[];
for
(
var
x
=
0
;
x
<
block
.
arguments_
.
length
;
x
++
)
{
for
(
var
x
=
0
;
x
<
block
.
arguments_
.
length
;
x
++
)
{
args
[
x
]
=
Blockly
.
PHP
.
variableDB_
.
getName
(
block
.
arguments_
[
x
],
args
[
x
]
=
Blockly
.
PHP
.
getName
(
block
.
arguments_
[
x
],
Blockly
.
Variables
.
NAME_TYPE
);
Blockly
.
Variables
.
NAME_TYPE
);
}
}
var
code
=
'
function
'
+
funcName
+
'
(
'
+
args
.
join
(
'
,
'
)
+
'
) {
\n
'
+
var
code
=
'
function
'
+
funcName
+
'
(
'
+
args
.
join
(
'
,
'
)
+
'
) {
\n
'
+
...
@@ -67,7 +67,7 @@ Blockly.PHP['procedures_defnoreturn'] =
...
@@ -67,7 +67,7 @@ Blockly.PHP['procedures_defnoreturn'] =
Blockly
.
PHP
[
'
procedures_callreturn
'
]
=
function
(
block
)
{
Blockly
.
PHP
[
'
procedures_callreturn
'
]
=
function
(
block
)
{
// Call a procedure with a return value.
// Call a procedure with a return value.
var
funcName
=
Blockly
.
PHP
.
variableDB_
.
getName
(
var
funcName
=
Blockly
.
PHP
.
getName
(
block
.
getFieldValue
(
'
NAME
'
),
Blockly
.
Procedures
.
NAME_TYPE
);
block
.
getFieldValue
(
'
NAME
'
),
Blockly
.
Procedures
.
NAME_TYPE
);
var
args
=
[];
var
args
=
[];
for
(
var
x
=
0
;
x
<
block
.
arguments_
.
length
;
x
++
)
{
for
(
var
x
=
0
;
x
<
block
.
arguments_
.
length
;
x
++
)
{
...
@@ -80,7 +80,7 @@ Blockly.PHP['procedures_callreturn'] = function(block) {
...
@@ -80,7 +80,7 @@ Blockly.PHP['procedures_callreturn'] = function(block) {
Blockly
.
PHP
[
'
procedures_callnoreturn
'
]
=
function
(
block
)
{
Blockly
.
PHP
[
'
procedures_callnoreturn
'
]
=
function
(
block
)
{
// Call a procedure with no return value.
// Call a procedure with no return value.
var
funcName
=
Blockly
.
PHP
.
variableDB_
.
getName
(
var
funcName
=
Blockly
.
PHP
.
getName
(
block
.
getFieldValue
(
'
NAME
'
),
Blockly
.
Procedures
.
NAME_TYPE
);
block
.
getFieldValue
(
'
NAME
'
),
Blockly
.
Procedures
.
NAME_TYPE
);
var
args
=
[];
var
args
=
[];
for
(
var
x
=
0
;
x
<
block
.
arguments_
.
length
;
x
++
)
{
for
(
var
x
=
0
;
x
<
block
.
arguments_
.
length
;
x
++
)
{
...
...
generators/php/text.js
View file @
5e7f92ce
...
@@ -65,7 +65,7 @@ Blockly.PHP['text_join'] = function(block) {
...
@@ -65,7 +65,7 @@ Blockly.PHP['text_join'] = function(block) {
Blockly
.
PHP
[
'
text_append
'
]
=
function
(
block
)
{
Blockly
.
PHP
[
'
text_append
'
]
=
function
(
block
)
{
// Append to a variable in place.
// Append to a variable in place.
var
varName
=
Blockly
.
PHP
.
variableDB_
.
getName
(
var
varName
=
Blockly
.
PHP
.
getName
(
block
.
getFieldValue
(
'
VAR
'
),
Blockly
.
Variables
.
NAME_TYPE
);
block
.
getFieldValue
(
'
VAR
'
),
Blockly
.
Variables
.
NAME_TYPE
);
var
argument0
=
Blockly
.
PHP
.
valueToCode
(
block
,
'
TEXT
'
,
var
argument0
=
Blockly
.
PHP
.
valueToCode
(
block
,
'
TEXT
'
,
Blockly
.
PHP
.
ORDER_NONE
)
||
'
\'\'
'
;
Blockly
.
PHP
.
ORDER_NONE
)
||
'
\'\'
'
;
...
...
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