forked from LinuxCNC/linuxcnc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
interp/oword: enable optional return values on 'return' and 'endsub'
See nc_files/retval.ngc for an example. there's a single global value '#<_value>' which holds the last returned value Default for #<_value> is 0. Document in gcode/main and gcode/overview. Add test case in tests/interp/return-value. Conflicts: src/emc/rs274ngc/rs274ngc_pre.cc
- Loading branch information
Michael Haberler
committed
Oct 28, 2011
1 parent
1620409
commit 6905295
Showing
10 changed files
with
176 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
; demonstrate optional return values from endsub and return | ||
|
||
o1000 sub | ||
o1010 if [#1 GT 0] | ||
o1010 return [123*[#1]] | ||
o1010 endif | ||
|
||
o1020 if [#1 LT 0] | ||
o1020 return | ||
o1020 endif | ||
|
||
o1000 endsub [4712] | ||
|
||
o1000 call [0] | ||
(debug,call with arg1=0 return #<_value>) | ||
|
||
; #<_value> is 4712.0 | ||
|
||
o1000 call [2] | ||
(debug,call with arg1=2 return #<_value>) | ||
|
||
; #<_value> is 246.0 | ||
|
||
o1000 call [-1] | ||
(debug,call with arg1=-1 return #<_value>) | ||
|
||
; #<_value> is 0.0 | ||
|
||
m2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
N..... USE_LENGTH_UNITS(CANON_UNITS_MM) | ||
N..... SET_G5X_OFFSET(1, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000) | ||
N..... SET_G92_OFFSET(0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000) | ||
N..... SET_XY_ROTATION(0.0000) | ||
N..... SET_FEED_REFERENCE(CANON_XYZ) | ||
N..... MESSAGE("line 6.000000: _value: - expected 0.000000, got 0.000000") | ||
N..... MESSAGE("line 28.000000: call with arg1=2.000000 expect 246.000000, got 246.000000") | ||
N..... MESSAGE("line 37.000000: call with arg1=-1.000000 expect 0.000000, got 0.000000") | ||
N..... MESSAGE("line 47.000000: call with arg1=0.000000 expect 4712.000000, got 4712.000000") | ||
N..... MESSAGE("line 53.000000: _value=4712.000000 - expected 4712.000000") | ||
N..... SET_G5X_OFFSET(1, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000) | ||
N..... SET_XY_ROTATION(0.0000) | ||
N..... SET_FEED_MODE(0) | ||
N..... SET_FEED_RATE(0.0000) | ||
N..... STOP_SPINDLE_TURNING() | ||
N..... SET_SPINDLE_MODE(0.0000) | ||
N..... PROGRAM_END() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
; test that #<_value> is accessible and is 0 | ||
|
||
; test for proper initialization of #<_value> if program is re-run | ||
; see note at end of program | ||
#<expect> = 0 | ||
(debug,line #<_line>: _value: - expected #<expect>, got #<_value>) | ||
o200 if [#<_value> NE 0] | ||
(debug, fail: _value=#<_value> - expecting 0) | ||
o200 endif | ||
|
||
|
||
o1000 sub | ||
o1010 if [#1 GT 0] | ||
o1010 return [123*[#1]] | ||
o1010 endif | ||
|
||
o1020 if [#1 LT 0] | ||
o1020 return | ||
o1020 endif | ||
|
||
o1000 endsub [4712] | ||
|
||
|
||
; test returning value via 'return' | ||
#<arg> = 2 | ||
#<expect> = 246 | ||
o1000 call [#<arg>] | ||
(debug,line #<_line>: call with arg1=#<arg> expect #<expect>, got #<_value>) | ||
o3000 if [#<_value> NE #<expect>] | ||
(debug,line #<_line>: 'return' return value=#<_value> - expected #<expect>) | ||
o3000 endif | ||
|
||
; test returning no value at all - plain old style 'return' | ||
#<arg> = -1 | ||
#<expect> = 0 | ||
o1000 call [#<arg>] | ||
(debug,line #<_line>: call with arg1=#<arg> expect #<expect>, got #<_value>) | ||
o4000 if [#<_value> NE #<expect>] | ||
(debug,line #<_line>: 'plain return' return value=#<_value> - expected #<expect>) | ||
o4000 endif | ||
|
||
|
||
; test returning value via 'endsub' | ||
#<arg> = 0 | ||
#<expect> = 4712 | ||
o1000 call [#<arg>] | ||
(debug,line #<_line>: call with arg1=#<arg> expect #<expect>, got #<_value>) | ||
o2000 if [#<_value> NE #<expect>] | ||
(debug,line #<_line>: 'endsub' return value=#<_value> - expected #<expect>) | ||
o2000 endif | ||
|
||
; note #<_value> is 4712 at this point. | ||
(debug,line #<_line>: _value=#<_value> - expected #<expect>) | ||
|
||
m2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
rs274 -g test.ngc | awk '{$1=""; print}' | ||
exit ${PIPESTATUS[0]} |