Skip to content

Commit

Permalink
refac
Browse files Browse the repository at this point in the history
  • Loading branch information
zeroflag committed Dec 15, 2017
1 parent 134bdd1 commit 9e3ca57
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 35 deletions.
10 changes: 2 additions & 8 deletions arch/esp8266/forth/examples/example-dht22-data-logger.forth
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@ variable: server

: measure ( -- temperature humidity | throws:EGAVEUP )
10 0 do
['] dht-measure catch ?dup 0<>
if
ex-type cr
5000 ms
else
unloop exit
then
['] dht-measure catch ?dup if ex-type cr 5000 ms else unloop exit then
loop
EGAVEUP throw ;

Expand All @@ -19,7 +13,7 @@ variable: server
: dispose ( -- ) server @ netcon-dispose ;
: send ( -- ) server @ data 4 netcon-write-buf ;
: log ( temperature humidity -- ) data! connect ['] send catch dispose throw ;
: log-measurement ( -- ) { measure log } catch ?dup 0<> if ex-type cr then ;
: log-measurement ( -- ) { measure log } catch ?dup if ex-type cr then ;
: main ( -- ) log-measurement 50 ms 120000000 deep-sleep ;

' boot is: main
Expand Down
4 changes: 1 addition & 3 deletions arch/esp8266/forth/examples/example-stock-price.forth
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,7 @@ variable: idx
begin
last-refresh @ 0= expired? or if
ms@ last-refresh !
{ show } catch ?dup 0<> if
error-draw
then
{ show } catch ?dup if error-draw then
then
pause
again ;
Expand Down
20 changes: 5 additions & 15 deletions arch/esp8266/forth/tasks.forth
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,8 @@ INTERPRETER init-variable: var-current-task
: current-task ( -- task ) var-current-task @ ;
: current-task! ( task -- ) var-current-task ! ;

: alloc-data-stack ( -- a )
var-task-stack-size @ allot here ;

: alloc-return-stack ( -- a )
var-task-rstack-size @ allot here ;
: alloc-data-stack ( -- a ) var-task-stack-size @ allot here ;
: alloc-return-stack ( -- a ) var-task-rstack-size @ allot here ;

: task: ( user-space-size "name" ) ( -- task )
create:
Expand All @@ -48,12 +45,7 @@ INTERPRETER init-variable: var-current-task
dup .rp @ over .r0 ! \ init r0 = top of rstack address
last-task! ; \ last-task = this

: task-choose-next ( -- )
current-task
begin
.next @ dup
.status @ PAUSED =
until ;
: task-choose-next ( -- ) current-task begin .next @ dup .status @ PAUSED = until ;

: task-save-context ( sp ip rp -- ) \ XXX temporal coupling
current-task .rp !
Expand All @@ -72,8 +64,7 @@ INTERPRETER init-variable: var-current-task

: task-user-space ( task -- a ) Task + ;

: user-space ( -- a )
current-task task-user-space ;
: user-space ( -- a ) current-task task-user-space ;

defer: pause

Expand All @@ -100,8 +91,7 @@ defer: pause
SKIPPED swap .status !
task-choose-next task-run ;

: deactivate ( -- )
current-task stop ;
: deactivate ( -- ) current-task stop ;

: task-find ( task -- link )
lastword
Expand Down
6 changes: 1 addition & 5 deletions arch/esp8266/forth/turnkey.forth
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ defer: boot

: dst ( -- n ) 16r51000 SIZE + ;
: heap-size ( -- n ) usedmem align ;
: check ( code -- | ETURNKEY )
?dup 0<> if
print: 'SPI FLASH ERROR: ' . cr
ETURNKEY throw
then ;
: check ( code -- | ETURNKEY ) ?dup if print: 'SPI FLASH ERROR: ' . cr ETURNKEY throw then ;

: n, ( addr n -- addr+strlen ) over >r >str r> dup strlen + ;
: s, ( str-dst str-src -- str-dst+strlen ) tuck strlen 2dup + { cmove } dip ;
Expand Down
6 changes: 2 additions & 4 deletions generic/forth/punit.forth
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,9 @@ marker: -punit
test-reset
lastword
begin
dup 0<>
dup
while
dup test? if
dup test-run
then
dup test? if dup test-run then
@
repeat
drop
Expand Down

0 comments on commit 9e3ca57

Please sign in to comment.