-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbitlashMio.h
More file actions
2243 lines (1897 loc) · 54.9 KB
/
bitlashMio.h
File metadata and controls
2243 lines (1897 loc) · 54.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#define NOTRACE
#define NOTRACE1
byte trace=0;
//-------------------nessun trace---------------
String answer, resul;
/***
bitlash.h
Bitlash is a tiny language interpreter that provides a serial port shell environment
for bit banging and hardware hacking.
See the file README for documentation.
Bitlash lives at: http://bitlash.net
The author can be reached at: bill@bitlash.net
Copyright (C) 2008-2013 Bill Roy
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
***/
#ifndef _BITLASH_H
#define _BITLASH_H
#if defined(__x86_64__) || defined(__i386__)
#define UNIX_BUILD 1
#elif defined(__SAM3X8E__)
#define ARM_BUILD 1
#elif (defined(__MK20DX128__) || defined(__MK20DX256__)) && defined (CORE_TEENSY)
// Teensy 3
#define ARM_BUILD 2
#elif defined(PART_LM4F120H5QR) //support Energia.nu - Stellaris Launchpad / Tiva C Series
#define ARM_BUILD 4 //support Energia.nu - Stellaris Launchpad / Tiva C Series
#else
#define AVR_BUILD 1
#endif
#include<Arduino.h>
#ifndef ESP8266
#if defined(AVR_BUILD)
#include "avr/io.h"
#include "avr/pgmspace.h"
#include "avr/interrupt.h"
#endif
#if defined(AVR_BUILD) || defined(ARM_BUILD)
#include "string.h"
#include "ctype.h"
#include "setjmp.h"
#endif
// Unix includes
#if defined(UNIX_BUILD)
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include "ctype.h"
#include "setjmp.h"
#include <time.h>
#include <sys/types.h>
#include <errno.h>
//#include <unistd.h>
#endif
#endif //esp8266
#ifndef byte
#define byte uint8_t
#endif
////////////////////////////////////////////////////
// GLOBAL BUILD OPTIONS
////////////////////////////////////////////////////
//
// Enable LONG_ALIASES to make the parser recognize analogRead(x) as well as ar(x), and so on
// cost: ~200 bytes flash
//#define LONG_ALIASES 1
//
// Enable PARSER_TRACE to make ^T toggle a parser trace debug print stream
// cost: ~400 bytes flash
#define PARSER_TRACE 1
////////////////////////////////////////////////////
//
// ARDUINO BUILD OPTIONS
//
////////////////////////////////////////////////////
//
#if defined(HIGH) || defined(ARDUINO) // this detects the Arduino build environment
#define ARDUINO_BUILD 1
//#define ARDUINO_VERSION 14 // working
//#define ARDUINO_VERSION 15 // working
#define ARDUINO_VERSION 16 // working, released
#include <pgmspace.h>
// the serial support, she is changing all the time
#ifndef ESP8266
#if ARDUINO_VERSION >= 15
#define beginSerial Serial.begin
#define serialAvailable Serial.available
#define serialRead Serial.read
#if defined(ARDUINO) && ARDUINO >= 100
#define serialWrite Serial.write
#else
#define serialWrite Serial.print
#endif
#endif
#endif
// Arduino version: 11 - enable by hand if needed; see bitlash-serial.h
//#define ARDUINO_VERSION 11
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#define prog_char char PROGMEM
#define prog_uchar char PROGMEM
#else
#include "WProgram.h"
#include "WConstants.h"
#endif
// Enable Software Serial tx support for Arduino
// this enables "setbaud(4, 4800); print #4:..."
// at a cost of about 400 bytes (for tx only)
//
#define SOFTWARE_SERIAL_TX 1
#define HARDWARE_SERIAL_TX 1
#define MINIMUM_FREE_RAM 50
#else
#define HIGH 1
#define LOW 0
#endif // HIGH: arduino build
///////////////////////////////////////////////////////
//
// ARDUINO ETHERNET BUILD OPTIONS
//
///////////////////////////////////////////////////////
//
// Enable WIZ_ETHERNET true to build for telnet access to the official Arduino
// WIZ-5100 Ethernet shield
//#define WIZ_ETHERNET 1
//
// Enable AF_ETHERNET to build for telnet access to the Adafruit Ethernet shield
// configured per the pinout below
//
//#define AF_ETHERNET 1
//
///////////////////////////////////////////////////////
// WIZNET ETHERNET CONFIGURATION
//
#ifdef WIZ_ETHERNET
//
// You'll need these two lines in your sketch, as of Arduino-0022:
//
// #include <SPI.h>
// #include <Ethernet.h>
//
byte mac[] = { 'b','i','t','l','s','h' };
byte ip[] = { 192, 168, 1, 27 };
byte gateway[] = { 192, 168, 1, 1 };
byte subnet[] = {255,255,255,0};
#define PORT 8080
Server server = Server(PORT);
#define beginSerial beginEthernet
#define serialAvailable server.available
#define serialRead server.available().read
#define serialWrite server.write
void beginEthernet(unsigned long baud) {
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();
}
#endif // WIZ_ETHERNET
///////////////////////////////////////////////////////
// ADAFRUIT XPORT ETHERNET CONFIGURATION
//
#ifdef AF_ETHERNET
#define NET_TX 2
#define NET_RX 3
#define SOFTWARE_SERIAL_RX 1
#define RXPIN NET_RX
#undef HARDWARE_SERIAL_TX // sorry, no room for pin 0/1 hard uart
#define DEFAULT_OUTPIN NET_TX
#define BAUD_OVERRIDE 9600
#endif // AF_ETHERNET
///////////////////////////////////////////////////////
//
// SANGUINO BUILD
//
///////////////////////////////////////////////////////
//
// SANGUINO is auto-enabled to build for the Sanguino '644
// if the '644 define is present
//
#if defined(__AVR_ATmega644P__)
#define SANGUINO
//void beginSerial(unsigned long baud) { Serial.begin(baud); }
//char serialAvailable(void) { return Serial.available(); }
//char serialRead(void) { return Serial.read(); }
//void serialWrite(char c) { return Serial.print(c); }
#ifndef beginSerial
#define beginSerial Serial.begin
#define serialAvailable Serial.available
#define serialRead Serial.read
#define serialWrite Serial.print
#endif
// Sanguino has 24 digital and 8 analog io pins
#define NUMPINS (24+8)
// Sanguino primary serial tx output is on pin 9 (rx on 8)
// Sanguino alternate hardware serial port tx output is on pin 11 (rx on 10)
#define SANGUINO_DEFAULT_SERIAL 9
#define SANGUINO_ALTERNATE_SERIAL 11
#define DEFAULT_OUTPIN SANGUINO_DEFAULT_SERIAL
#define ALTERNATE_OUTPIN SANGUINO_ALTERNATE_SERIAL
#endif // defined (644)
///////////////////////////////////////////////////////
//
// MEGA BUILD
//
// Note: These are speculative and untested. Feedback welcome.
//
///////////////////////////////////////////////////////
//
// MEGA is auto-enabled to build for the Arduino Mega or Mega2560
// if the '1280/'2560 define is present
//
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
#define MEGA 1
#endif
#if defined(MEGA)
#define beginSerial Serial.begin
#define serialAvailable Serial.available
#define serialRead Serial.read
#define serialWrite Serial.print
// MEGA has 54 digital and 16 analog pins
#define NUMPINS (54+16)
// Mega primary serial tx output is on pin 1 (rx on 0)
// Mega alternate hardware serial port tx output is on pin 18 (rx on 19)
// TODO: Support for hardware serial uart2 and uart3
//
#define MEGA_DEFAULT_SERIAL 1
#define MEGA_ALTERNATE_SERIAL 18
#define DEFAULT_OUTPIN MEGA_DEFAULT_SERIAL
#define ALTERNATE_OUTPIN MEGA_ALTERNATE_SERIAL
#endif // defined (1280)
#if defined(__AVR_ATmega64__)
#define beginSerial Serial1.begin
#define serialAvailable Serial1.available
#define serialRead Serial1.read
#define serialWrite Serial1.print
#define NUMPINS (53)
#endif
#define TINY_BUILD 1
///////////////////////////////////////////////////////
//
// TINY BUILD OPTIONS
//
#if defined(__AVR_ATtiny85__) || defined(__AVR_ATtiny84__)
#define TINY_BUILD 1
#undef MINIMUM_FREE_RAM
#define MINIMUM_FREE_RAM 20
#define NUMPINS 6
//#undef HARDWARE_SERIAL_TX
#undef SOFTWARE_SERIAL_TX
//#define SOFTWARE_SERIAL_TX 1
//#include "usbdrv.h"
#endif // TINY_BUILD
///////////////////////////////////////////////////////
//
// AVROPENDOUS and TEENSY BUILD OPTIONS
//
#if defined(__AVR_AT90USB162__)
//#define AVROPENDOUS_BUILD
#if defined(AVROPENDOUS_BUILD)
#define MINIMUM_FREE_RAM 20
#define NUMPINS 24
#undef HARDWARE_SERIAL_TX
#undef SOFTWARE_SERIAL_TX
void beginSerial(unsigned long baud) { ; }
#define serialAvailable usbAvailable
#define serialRead usbRead
#define serialWrite usbWrite
#include <util/delay.h>
#endif // defined AVRO
#define TEENSY
#ifdef TEENSY
#endif // defined TEENSY
#endif // defined '162
///////////////////////////////////////////////////////
//
// ATMega32U4 BUILD OPTIONS
//
#if defined(__AVR_ATmega32U4__)
//#define AVROPENDOUS_BUILD
#if defined(AVROPENDOUS_BUILD)
#define MINIMUM_FREE_RAM 50
#define NUMPINS 40
#undef HARDWARE_SERIAL_TX
#undef SOFTWARE_SERIAL_TX
void beginSerial(unsigned long baud) { ; }
#define serialAvailable usbAvailable
#define serialRead usbRead
#define serialWrite usbWrite
#include <util/delay.h>
#endif // AVRO
#define TEENSY2
#if defined(TEENSY2)
#endif // TEENSY2
#endif // defined '32U4
///////////////////////////////////////////////////////
//
// SD CARD SUPPORT: Enable the SDFILE define for SD card script-in-file support
//
//#define SDFILE
///////////////////////////////////////////////////////
//
// Unix build options
// (not working)
//
// > gcc bitlash.cpp -D UNIX_BUILD
//
#ifdef UNIX_BUILD
#define MINIMUM_FREE_RAM 200
#define NUMPINS 32
#undef HARDWARE_SERIAL_TX
#undef SOFTWARE_SERIAL_TX
#define beginSerial(x)
#define E2END 2047
#define uint8_t unsigned char
#define uint32_t unsigned long int
#define prog_char char
#define prog_uchar unsigned char
#define strncpy_P strncpy
#define strcmp_P strcmp
#define strlen_P strlen
#define PROGMEM
#define OUTPUT 1
#define pgm_read_byte(addr) (*(char*) (addr))
#define pgm_read_word(addr) (*(int *) (addr))
unsigned long millis(void);
#endif // defined unix_build
////////////////////
//
// ARM BUILD
#if defined(ARM_BUILD)
#define prog_char char
#define prog_uchar byte
#define PROGMEM
#define pgm_read_byte(b) (*(char *)(b))
#define pgm_read_word(b) (*(int *)(b))
#define strncpy_P strncpy
#define strcmp_P strcmp
#define strlen_P strlen
#if ARM_BUILD==1
#define E2END 4096
#else
// Teensy 3
#define E2END 2048
#endif
#endif
// numvar is 32 bits on Arduino and 16 bits elsewhere
//#if (defined(ARDUINO_BUILD)||defined(ESP8266) || defined(UNIX_BUILD)) && !defined(TINY_BUILD)
typedef long int numvar;
typedef unsigned long int unumvar;
#ifdef mai
typedef int numvar;
typedef unsigned int unumvar;
#endif // arduino_build
#ifdef AVROPENDOUS_BUILD
// USB integration
uint8_t usbAvailable(void);
int usbRead(void);
void usbWrite(uint8_t);
void usbMouseOn(void);
void usbMouseOff(void);
void connectBitlash(void);
#endif // avropendous
// Function prototypes
#if !USE_GPIORS
byte sym; // current input symbol
byte inchar; // Current parser character
#endif
/////////////////////////////////////////////
// bitlash-api.c
//
void initBitlash(unsigned long baud); // start up and set baud rate
void runBitlash(void); // call this in loop(), frequently
numvar doCommand(char *); // execute a command from your sketch
void doCharacter(char); // pass an input character to the line editor
//void flash(unsigned int, int);
/////////////////////////////////////////////
// bitlash-arduino.c
//
//#ifndef ARDUINO_BUILD
#if 0
void digitalWrite(uint8_t, uint8_t);
int digitalRead(uint8_t);
int analogRead(uint8_t);
void pinMode(uint8_t, uint8_t);
unsigned long millis(void);
void delay(unsigned long);
void delayMicroseconds(unsigned int);
#define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )
#define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() )
#define INPUT 0
#define OUTPUT 1
#endif
/////////////////////////////////////////////
// bitlash-cmdline.c
//
#ifdef TINY_BUILD
byte putlbuf(char);
//void initlbuf(void);
#endif
// String value buffer size
#ifdef AVR_BUILD
#define STRVALSIZE 120
#else
#define STRVALSIZE 512
#endif
#define STRVALLEN (STRVALSIZE-1)
#define LBUFLEN STRVALSIZE
char *lbufptr;
char lbuf[LBUFLEN];
/////////////////////////////////////////////
// bitlash-eeprom.c
//
int findKey(char *key); // return location of macro keyname in EEPROM or -1
int getValue(char *key); // return location of macro value in EEPROM or -1
int findoccupied(int);
int findend(int);
void eeputs(int);
#define EMPTY ((uint8_t)255)
#define STARTDB 0
#define FAIL ((int)-1)
/////////////////////////////////////////////
// External EEPROM (I2C)
//
//#define EEPROM_MICROCHIP_24XX32A // Uncomment to enable EEPROM via I2C
// Supports a Microchip 24xx32A EEPROM module attached to the I2C bus
// http://ww1.microchip.com/downloads/en/DeviceDoc/21713J.pdf
// Specifically, the DigiX has such a module onboard
// https://digistump.com/wiki/digix/tutorials/eeprom
#define EEPROM_ADDRESS 0x50 // default EEPROM address for DigiX boards
////////////////////////
//
// EEPROM database begin/end offset
//
// Use the predefined constant from the avr-gcc support file
//
#define E2END 2048
#if defined(EEPROM_MICROCHIP_24XX32A)
#define ENDDB 4095
#define ENDEEPROM 4095
#else
#define ENDDB E2END
#define ENDEEPROM E2END
#endif
// Temporary buffer for ids
#define IDLEN 12
//extern char idbuf[IDLEN+1];
// Interpreter globals
byte fetchtype; // current script type
numvar fetchptr; // pointer to current char in script
numvar symval; // value of current numeric expression
// Expression result
byte exptype; // type of expression: s_nval [or s_sval]
numvar expval; // value of numeric expr or length of string
// Temporary buffer for ids
char idbuf[IDLEN + 1];
/////////////////////////////////////////////
// bitlash-error.c
//
#ifndef ESP8266
extern jmp_buf env;
#endif
#define X_EXIT 1
void fatal2(char c, char s) { Serial.println("FATALer"); };
void overflow(byte c) {
Serial.print("OWEF "); Serial.println(c);
};
void underflow(byte c) {
Serial.print("UNDF "); Serial.println(c);
};
void expected(byte c) {
Serial.print("EXP "); Serial.println(c);
};
void expectedchar(byte c) { Serial.print("EXPC "); Serial.println((char)c);
};
void unexpected(byte c) {
if (fetchptr > 1) {
Serial.print("UNEXP ");
if (c == 14 || c == 20 || c == 10)
Serial.print((char)inchar);
else Serial.println(c);
Serial.print(" pos "); Serial.println(fetchptr);
}
};
void missing(byte c) { Serial.print("MISS "); Serial.print(c); };
//void oops(int); // fatal exit
/////////////////////////////////////////////
// bitlash-functions.c
//
typedef numvar (*bitlash_function)(void);
//void show_user_functions(void);
void dofunctioncall(byte);
//numvar func_free(void);
void make_beep(unumvar, unumvar, unumvar);
extern const /*prog_*/char functiondict[]; //PROGMEM; //==============================================
//extern const /*prog_*/char aliasdict[];//PROGMEM; //===========================================
void stir(byte);
/////////////////////////////////////////////
// bitlash-program.c
//
//extern char startup[];
char startup[100];
/////////////////////////////////////////////
// bitlash-serial.c
//
void printIntegerInBase(unumvar, uint8_t, numvar, byte);
void printInteger(numvar num, numvar n, byte b) { Serial.print(num); }
void printHex(unumvar num) { Serial.print(num); }
void printBinary(unumvar);
void spb(char c) { Serial.print(c); }
void sp(const char * c) { Serial.print(c); };
void speol(void) { Serial.println(); };
//numvar func_printf(void) { Serial.printf(arg1, arg2); }
//numvar func_printf_handler(byte,byte);
#ifdef SOFTWARE_SERIAL_TX_MIO
numvar setBaud(numvar, unumvar);
void resetOutput(void);
#endif
// serial override handling
#define SERIAL_OVERRIDE
#ifdef SERIAL_OVERRIDE_MIO
typedef void (*serialOutputFunc)(byte);
byte serialIsOverridden(void);
void setOutputHandler(serialOutputFunc);
void resetOutputHandler(void);
//extern serialOutputFunc serial_override_handler;
#endif
#ifdef ARDUINO_BUILD_MIO
void chkbreak(void);
void cmd_print(void);
#endif
numvar func_printf_handler(byte, byte);
/////////////////////////////////////////////
// bitlash-taskmgr.c
//
#define NUMTASKS 1
int tasklist[NUMTASKS]; // EEPROM address of text of the function
void initTaskList(void) {
memset(tasklist, 0xff, NUMTASKS * sizeof(tasklist[0]));
//+60 bytes
//for (byte slot = 0; (slot < NUMTASKS); slot++) tasklist[slot] = SLOT_FREE;
}
#ifdef MIO
void runBackgroundTasks(void);
void stopTask(byte);
void startTask(int, numvar);
void snooze(unumvar);
void showTaskList(void);
extern byte background;
extern byte curtask;
extern byte suspendBackground;
#endif
/////////////////////////////////////////////
// eeprom.c
// they must live off piste due to aggressive compiler inlining.
//
#ifdef ESP8266
void eewrite(int, byte) {};
byte eeread(int) { return 0; }
#elif defined(AVR_BUILD)
void eewrite(int, byte) __attribute__((noinline));
byte eeread(int) __attribute__((noinline));
#elif defined(ARM_BUILD)
void eewrite(int, byte);
byte eeread(int);
extern char virtual_eeprom[];
void eeinit(void);
#endif
/////////////////////////////////////////////
// bitlash-interpreter.c
//
#ifdef MIO
numvar getstatementlist(void);
void domacrocall(int);
#endif
/////////////////////////////////////////////
// bitlash-parser.c
//
void vinit(void); // init the value stack
void vpush(numvar); // push a numvar on the stack
numvar vpop(void); // pop a numvar
//extern byte vsptr;
#define vsempty() vsptr==0
//extern numvar *arg; // argument frame pointer
numvar getVar(uint8_t id) ; // return value of bitlash variable. id is [0..25] for [a..z]
void assignVar(uint8_t id, numvar value) ; // assign value to variable. id is [0..25] for [a..z]
numvar incVar(uint8_t id) ; // increment variable. id is [0..25] for [a..z]
void fetchc();
void primec();
numvar espressione(char st[]);
// parse context types
#define SCRIPT_NONE 0
#define SCRIPT_RAM 1
#define SCRIPT_PROGMEM 2
#define SCRIPT_EEPROM 3
#define SCRIPT_FILE 4
// bitlash_instrem---------------
byte findscript(char *);
byte scriptfileexists(char *);
numvar execscript(byte, numvar, char *);
void callscriptfunction(byte, numvar);
typedef struct {
numvar fetchptr;
byte fetchtype;
} parsepoint;
void markparsepoint(parsepoint *p) {
#if defined(SDFILE) || defined(UNIX_BUILD)
if (fetchtype == SCRIPT_FILE) {
// the location we wish to return to is the point from which we read inchar,
// which is one byte before the current file pointer since it auto-advances
fetchptr = scriptgetpos() - 1;
}
#endif
p->fetchptr = fetchptr;
p->fetchtype = fetchtype;
#ifdef PARSER_TRACE
if (trace) {
speol();
sp("mark:"); printHex(fetchtype); spb(' '); printHex(fetchptr);
speol();
}
#endif
}
void initparsepoint(byte scripttype, numvar scriptaddress) {
#ifdef PARSER_TRACE
if (trace) {
speol();
sp("init:"); printHex(scripttype); spb(' '); printHex(scriptaddress);
// if (scriptname) { spb(' '); sp(scriptname); }
speol();
}
#endif
fetchtype = scripttype;
fetchptr = scriptaddress;
// if we're restoring to idle, we're done
if (fetchtype == SCRIPT_NONE) return;
#if defined(SDFILE) || defined(UNIX_BUILD)
// handle file transition side effects here, once per transition,
// rather than once per character below in primec()
if (fetchtype == SCRIPT_FILE) {
#if defined(UNIX_BUILD)
// ask the file glue to open and position the file for us
if (!scriptopen(scriptname, scriptaddress, 0)) unexpected(M_oops); // TODO: error message
#else
// ask the file glue to open and position the file for us
if (!scriptopen(scriptname, scriptaddress, O_READ)) unexpected(M_oops); // TODO: error message
#endif
}
#endif
primec(); // re-fetch inchar
}
void returntoparsepoint(parsepoint *p, byte returntoparent) {
// restore parse type and location; for script files, pass name from string pool
initparsepoint(p->fetchtype, p->fetchptr);
}
//void primec(void); //----------used by fetchc only
int stptr = 0;
byte inpStr[200];// = { "5+(1+2)*(4+6)/2;" };
//---------------redefine______________________________________________________
void getsym(void); ////local
void traceback(void);
//numvar func_fprintf(void);
const prog_char *getmsg(byte); //============================================
void parsestring(void (*)(char));
void msgp(byte);
void msgpl(byte);
numvar getnum(void);
#ifdef MIO
void calleeprommacro(int);
#endif
void getexpression(void);
byte hexval(char);
byte is_end(void);
numvar getarg(numvar);
numvar isstring(void);
numvar getstringarg(numvar);
void releaseargblock(void);
void parsearglist(void);
//extern const char reservedwords[];//=============================================
#ifdef MIO
// Interpreter globals
//extern byte fetchtype; // current script type
//extern numvar fetchptr; // pointer to current char in input buffer
//extern numvar symval; // value of current numeric expression
#define USE_GPIORS defined(AVR_BUILD)
#ifndef GPIOR0 || GPIOR1
#undef USE_GPIORS
#endif
#if (defined USE_GPIORS)
#define sym GPIOR0
#define inchar GPIOR1
#else
extern byte sym; // current input symbol
extern byte inchar; // Current parser character
#endif
extern byte trace;
void tb(void);
// Expression result
extern byte exptype; // type of expression: s_nval [or s_sval]
extern numvar expval; // value of numeric expr or length of string
#endif
// Strings live in PROGMEM to save ram
//
#define M_expected 0
#define M_unexpected 1
#define M_missing 2
#define M_string 3
#define M_underflow 4
#define M_overflow 5
#define M_ctrlc 6
#define M_ctrlb 7
#define M_ctrlu 8
#define M_exp 9
#define M_op 10
#define M_pfmts 11
#define M_eof 12
#define M_var 13
#define M_number 14
#define M_rparen 15
#define M_saved 16
#define M_eeprom 17
#define M_defmacro 18
#define M_prompt 19
#define M_char 20
#define M_stack 21
#define M_startup 22
#define M_id 23
#define M_promptid 24
#define M_functions 25
#define M_oops 26
#define M_arg 27
#define M_function 28
// Names for symbols
//
// Each symbol in the grammar is parsed to a unique symval enumerated here
//
// One character symbols take their ascii value as their symval
// Complex symbols have the high bit set so start at 128 (0x80)
//
#define s_eof 0
#define s_undef (0 | 0x80)
#define s_nval (1 | 0x80)
#define s_sval (2 | 0x80)
#define s_nvar (3 | 0x80)
#define s_le (4 | 0x80)
#define s_ge (5 | 0x80)
#define s_logicaland (6 | 0x80)
#define s_logicalor (7 | 0x80)
#define s_logicaleq (8 | 0x80)
#define s_logicalne (9 | 0x80)
#define s_shiftleft (10 | 0x80)
#define s_shiftright (11 | 0x80)
#define s_incr (12 | 0x80)
#define s_decr (13 | 0x80)
#define s_nfunct (14 | 0x80)
#define s_if (15 | 0x80)
#define s_while (16 | 0x80)
#define s_apin (17 | 0x80)
#define s_dpin (18 | 0x80)
#define s_define (19 | 0x80)
#define s_function (20 | 0x80)
#define s_rm (21 | 0x80)
#define s_run (22 | 0x80)
#define s_ps (23 | 0x80)
#define s_stop (24 | 0x80)
#define s_boot (25 | 0x80)
#define s_peep (26 | 0x80)
#define s_help (27 | 0x80)
#define s_ls (28 | 0x80)
#define s_print (29 | 0x80)
#define s_switch (30 | 0x80)
#define s_return (31 | 0x80)
#define s_returning (32 | 0x80)
#define s_arg (33 | 0x80)
#define s_else (34 | 0x80)
#define s_script_eeprom (35 | 0x80)
#define s_script_progmem (36 | 0x80)
#define s_script_file (37 | 0x80)
#define s_comment (38 | 0x80)
// Names for literal symbols: these one-character symbols
// are represented by their 7-bit ascii char code
#define s_semi ';'
#define s_add '+'
#define s_sub '-'
#define s_mul '*'
#define s_div '/'
#define s_mod '%'
#define s_lparen '('
#define s_rparen ')'
#define s_dot '.'
#define s_lt '<'
#define s_gt '>'
#define s_equals '='
#define s_bitand '&'
#define s_bitor '|'
#define s_comma ','
#define s_bitnot '~'
#define s_logicalnot '!'
#define s_xor '^'
#define s_colon ':'
#define s_pound '#'
#define s_quote '"'
#define s_dollars '$'
#define s_lcurly '{'
#define s_rcurly '}'
#endif // defined _BITLASH_H
void skipbyte(char c) { ; }
void skipstatement(void) {
signed char nestlevel = 0;
#ifdef PARSER_TRACE
if (trace) sp("SKP[");
#endif
// Skip a statement list in curly braces: { stmt; stmt; stmt; }
// Eat until the matching s_rcurly