Skip to content

Commit a972997

Browse files
committed
Documentation changes
1 parent 40e5186 commit a972997

File tree

1 file changed

+11
-24
lines changed

1 file changed

+11
-24
lines changed

README.md

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
An experimental project to determine whether a full-featured scripting language can be used on larger-memory Arduino boards to control hardware. At the moment only the Giga board with Arduino Display Shield is supported, but future support for Portenta H7 (with USB-C display) may be possible.
66

7-
The [Lox language](https://www.craftinginterpreters.com/) was chosen because of the availability of a ready-made implementation in C ([clox](https://github.com/munificent/craftinginterpreters/tree/master/c)) which is a compact and very quick JIT-compiled interpreter. It is also easy to extend with additional Lox functions, which are mapped to native C/C++ ones defined in the sketch. The construction of the interpreter is described in detail in the book "Crafting Interpreters", however reading the book is not necessarily a prerequisite for using the language or even extending it with new functions.
7+
The [Lox language](https://www.craftinginterpreters.com/appendix-i.html) was chosen because of the availability of a ready-made implementation in C ([clox](https://github.com/munificent/craftinginterpreters/tree/master/c)) which is a compact and very quick JIT-compiled interpreter. It is also easy to extend with additional Lox functions, which are mapped to native C/C++ ones defined in the sketch. The construction of the interpreter is described in detail in the book "Crafting Interpreters", however reading the book is not necessarily a prerequisite for using the language or even extending it with new functions.
88

99
## Getting Started
1010

@@ -13,12 +13,13 @@ The number of supported graphics functions (and other functions from [this page]
1313
Flashing and booting the Giga results in a REPL in the Serial Monitor, enter line(s) of Lox code at `> ` (start) and `. ` (continuation) prompts, and press Enter on a blank line to execute. Error messages are reported in the REPL, and the blue LED turns on for the duration of executing the code fragment just entered. To pulse the blue LED for ten seconds use the following Lox code in the interpreter:
1414

1515
```javascript
16-
pinMode(88, "OUTPUT");
16+
var led = 88;
17+
pinMode(led, "OUTPUT");
1718
for (var i = 1; i <= 10; i = i + 1) {
1819
delay(500);
19-
digitalWrite(88, false);
20+
digitalWrite(led, false);
2021
delay(500);
21-
digitalWrite(88, true);
22+
digitalWrite(led, true);
2223
}
2324
```
2425

@@ -79,6 +80,7 @@ In the style of the book "Crafting Interpreters" by Bob Nystrom, which describes
7980
#ifndef clox_stdio_h
8081
#define clox_stdio_h
8182

83+
#include <stdarg.h>
8284
#include <stdio.h>
8385

8486
#define printf Serial_printf
@@ -95,9 +97,8 @@ int Serial_vfprintf(FILE *dummy, const char *fmt, va_list args);
9597

9698
5. Create a script which defines these two functions, and includes the necessary C headers (as a minimum). Here is a possible outline:
9799

98-
```cpp
100+
```ino
99101
extern "C" {
100-
#include <stdarg.h>
101102
#include "vm.h"
102103
#include "clox_stdio.h"
103104
}
@@ -144,17 +145,10 @@ extern "C" {
144145

145146
int Serial_printf(const char *fmt, ...) {
146147
if (Serial) {
147-
va_list args, args2;
148+
va_list args;
148149
va_start(args, fmt);
149-
va_copy(args2, args);
150-
int nchars = vsnprintf(nullptr, 0, fmt, args2);
151-
va_end(args2);
152-
char *buf = (char *)malloc(nchars + 1);
153-
vsprintf(buf, fmt, args);
150+
int nchars = Serial_vfprintf(stdout, fmt, args);
154151
va_end(args);
155-
Serial.print(buf);
156-
free(buf);
157-
Serial.flush();
158152
return nchars;
159153
}
160154
else {
@@ -164,17 +158,10 @@ int Serial_printf(const char *fmt, ...) {
164158

165159
int Serial_fprintf(FILE *dummy, const char *fmt, ...) {
166160
if (Serial) {
167-
va_list args, args2;
161+
va_list args;
168162
va_start(args, fmt);
169-
va_copy(args2, args);
170-
int nchars = vsnprintf(nullptr, 0, fmt, args2);
171-
va_end(args2);
172-
char *buf = (char *)malloc(nchars + 1);
173-
vsprintf(buf, fmt, args);
163+
int nchars = Serial_vfprintf(dummy, fmt, args);
174164
va_end(args);
175-
Serial.print(buf);
176-
free(buf);
177-
Serial.flush();
178165
return nchars;
179166
}
180167
else {

0 commit comments

Comments
 (0)