Skip to content

Commit c19318b

Browse files
author
Zsolt Borbély
committed
Update the webpage and add Port API documentation
JerryScript-DCO-1.0-Signed-off-by: Zsolt Borbély zsborbely.u-szeged@partner.samsung.com
1 parent 622f42e commit c19318b

File tree

3 files changed

+230
-9
lines changed

3 files changed

+230
-9
lines changed

01.GETTING-STARTED.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,20 @@ permalink: /getting-started/
1111

1212
Currently, only Ubuntu 14.04+ is officially supported as primary development environment.
1313

14-
There are several dependencies, that should be installed manually. The following list is required for building:
14+
There are several dependencies, that should be installed manually. The following list is the absolute minimum for building:
1515

16-
- `gcc` or any C99-compliant compiler
17-
- native
18-
- arm-none-eabi
16+
- `gcc` or any C99-compliant compiler (native or cross, e.g., arm-none-eabi)
1917
- `cmake` >= `2.8.12.2`
18+
19+
Several scripts and tools help the building and development process, thus it is recommended to have the following installed as well:
20+
2021
- `bash` >= `4.3.11`
2122
- `cppcheck` >= `1.61`
2223
- `vera++` >= `1.2.1`
2324
- `python` >= `2.7.6`
2425

2526
```bash
26-
sudo apt-get install gcc g++ gcc-arm-none-eabi cmake cppcheck vera++ python
27+
sudo apt-get install gcc gcc-arm-none-eabi cmake cppcheck vera++ python
2728
```
2829

2930
To make our scripts run correctly, several shell utilities should be available on the system:

04.INTERNALS.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,11 @@ Compressed pointers were introduced to save heap space.
248248

249249
![Compressed Pointer]({{ site.baseurl }}/img/ecma_compressed.png){: class="thumbnail center-block img-responsive" }
250250

251-
These pointers are 8 byte aligned 16 bit long pointers which can address 512 Kb of memory which is also the maximum size of the JerryScript heap.
252-
253-
ECMA data elements are allocated in pools (pools are allocated on heap)
254-
Chunk size of the pool is 8 bytes (reduces fragmentation).
251+
These pointers are 8 byte aligned 16 bit long pointers which can address 512 Kb of
252+
memory which is also the maximum size of the JerryScript heap. To support even more
253+
memory the size of compressed pointers can be extended to 32 bit to cover the entire
254+
address space of a 32 bit system by passing "--cpointer_32_bit on" to the build
255+
system. These "uncompressed pointers" increases the memory consumption by around 20%.
255256

256257
### Number
257258

05.PORT-API.md

Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
---
2+
layout: page
3+
title: Port API
4+
permalink: /port-api/
5+
---
6+
7+
* toc
8+
{:toc}
9+
10+
# Reference
11+
12+
## Termination
13+
14+
It is questionable whether a library should be able to terminate an application. Any API function can signal an error (ex.: cannot allocate memory), so the engine use the termination approach with this port function.
15+
16+
```c
17+
/**
18+
* Signal the port that jerry experienced a fatal failure from which it cannot
19+
* recover.
20+
*
21+
* @param code gives the cause of the error.
22+
*
23+
* Note: jerry expects the function not to return.
24+
*
25+
* Example: a libc-based port may implement this with exit() or abort(), or both.
26+
*/
27+
void jerry_port_fatal (jerry_fatal_code_t code);
28+
```
29+
30+
Error codes
31+
32+
```c
33+
typedef enum
34+
{
35+
ERR_OUT_OF_MEMORY = 10,
36+
ERR_SYSCALL = 11,
37+
ERR_REF_COUNT_LIMIT = 12,
38+
ERR_FAILED_INTERNAL_ASSERTION = 120
39+
} jerry_fatal_code_t;
40+
```
41+
42+
## I/O
43+
44+
These are the only I/O functions jerry calls.
45+
46+
```c
47+
/**
48+
* Print a string to the console. The function should implement a printf-like
49+
* interface, where the first argument specifies a format string on how to
50+
* stringify the rest of the parameter list.
51+
*
52+
* This function is only called with strings coming from the executed ECMAScript
53+
* wanting to print something as the result of its normal operation.
54+
*
55+
* It should be the port that decides what a "console" is.
56+
*
57+
* Example: a libc-based port may implement this with vprintf().
58+
*/
59+
void jerry_port_console (const char *fmt, ...);
60+
61+
/**
62+
* Jerry log levels. The levels are in severity order
63+
* where the most serious levels come first.
64+
*/
65+
typedef enum
66+
{
67+
JERRY_LOG_LEVEL_ERROR, /**< the engine will terminate after the message is printed */
68+
JERRY_LOG_LEVEL_WARNING, /**< a request is aborted, but the engine continues its operation */
69+
JERRY_LOG_LEVEL_DEBUG, /**< debug messages from the engine, low volume */
70+
JERRY_LOG_LEVEL_TRACE /**< detailed info about engine internals, potentially high volume */
71+
} jerry_log_level_t;
72+
73+
/**
74+
* Display or log a debug/error message. The function should implement a printf-like
75+
* interface, where the first argument specifies the log level
76+
* and the second argument specifies a format string on how to stringify the rest
77+
* of the parameter list.
78+
*
79+
* This function is only called with messages coming from the jerry engine as
80+
* the result of some abnormal operation or describing its internal operations
81+
* (e.g., data structure dumps or tracing info).
82+
*
83+
* It should be the port that decides whether error and debug messages are logged to
84+
* the console, or saved to a database or to a file.
85+
*
86+
* Example: a libc-based port may implement this with vfprintf(stderr) or
87+
* vfprintf(logfile), or both, depending on log level.
88+
*/
89+
void jerry_port_log (jerry_log_level_t level, const char *fmt, ...);
90+
```
91+
92+
## Date
93+
94+
```c
95+
/**
96+
* Jerry time zone structure
97+
*/
98+
typedef struct
99+
{
100+
int offset; /**< minutes from west */
101+
int daylight_saving_time; /**< daylight saving time (1 - DST applies, 0 - not on DST) */
102+
} jerry_time_zone_t;
103+
104+
/**
105+
* Get timezone and daylight saving data
106+
*
107+
* @return true - if success
108+
* false - otherwise
109+
*/
110+
bool jerry_port_get_time_zone (jerry_time_zone_t *);
111+
112+
/**
113+
* Get system time
114+
*
115+
* @return milliseconds since Unix epoch
116+
*/
117+
double jerry_port_get_current_time (void);
118+
```
119+
120+
# How to port JerryScript
121+
122+
This section describes a basic port implementation which was created for Unix based systems.
123+
124+
## Termination
125+
126+
```c
127+
#include <stdlib.h>
128+
#include "jerry-port.h"
129+
130+
/**
131+
* Default implementation of jerry_port_fatal.
132+
*/
133+
void jerry_port_fatal (jerry_fatal_code_t code)
134+
{
135+
exit (code);
136+
} /* jerry_port_fatal */
137+
```
138+
139+
## I/O
140+
141+
```c
142+
#include <stdarg.h>
143+
#include "jerry-port.h"
144+
145+
/**
146+
* Provide console message implementation for the engine.
147+
*/
148+
void
149+
jerry_port_console (const char *format, /**< format string */
150+
...) /**< parameters */
151+
{
152+
va_list args;
153+
va_start (args, format);
154+
vfprintf (stdout, format, args);
155+
va_end (args);
156+
} /* jerry_port_console */
157+
158+
/**
159+
* Provide log message implementation for the engine.
160+
*
161+
* Note:
162+
* This example ignores the log level.
163+
*/
164+
void
165+
jerry_port_log (jerry_log_level_t level, /**< log level */
166+
const char *format, /**< format string */
167+
...) /**< parameters */
168+
{
169+
va_list args;
170+
va_start (args, format);
171+
vfprintf (stderr, format, args);
172+
va_end (args);
173+
} /* jerry_port_log */
174+
```
175+
176+
## Date
177+
178+
```c
179+
#include <sys/time.h>
180+
#include "jerry-port.h"
181+
182+
/**
183+
* Default implementation of jerry_port_get_time_zone.
184+
*/
185+
bool jerry_port_get_time_zone (jerry_time_zone_t *tz_p)
186+
{
187+
struct timeval tv;
188+
struct timezone tz;
189+
190+
/* gettimeofday may not fill tz, so zero-initializing */
191+
tz.tz_minuteswest = 0;
192+
tz.tz_dsttime = 0;
193+
194+
if (gettimeofday (&tv, &tz) != 0)
195+
{
196+
return false;
197+
}
198+
199+
tz_p->offset = tz.tz_minuteswest;
200+
tz_p->daylight_saving_time = tz.tz_dsttime > 0 ? 1 : 0;
201+
202+
return true;
203+
} /* jerry_port_get_time_zone */
204+
205+
/**
206+
* Default implementation of jerry_port_get_current_time.
207+
*/
208+
double jerry_port_get_current_time ()
209+
{
210+
struct timeval tv;
211+
212+
if (gettimeofday (&tv, NULL) != 0)
213+
{
214+
return 0;
215+
}
216+
217+
return ((double) tv.tv_sec) * 1000.0 + ((double) tv.tv_usec) / 1000.0;
218+
} /* jerry_port_get_current_time */
219+
```

0 commit comments

Comments
 (0)