Added target to compile zephyr against jerryscript.

This patch contains a project in which you can run
a small js test inside the Arduino101.

Follows the Nuttx implementation to replicate a command
line in the Quark SE Lakemont architecture.

Everything is self contained in the targets/arduino_101 folder.
It has only been tested with the arduino 101 at the moment.

Check the README.md for a more detailed explanation of
how to compile and run it.

- Command line javascript run test.

Use test to get a default test.

Write any valid javascript in the shell and get it resolved and executed

- Support for qemu
- Added extra verbose mode on the demo function
- Support to build factory images that can be flashed with dfu-util
- Added a few extra examples on the README about commands that work.

Small fixes to readme and libc_support.c (#1)

- Added a few more instructions to the README.md for arduino_101
- Added the stdint.h include in libc_support.c
- Added parameter to check-vera.sh to check a specific folder
- Cleared the libc function duplication

JerryScript-DCO-1.0-Signed-off-by: Sergio Martinez sergio.martinez.rodriguez@intel.com
This commit is contained in:
Sergio Martinez
2016-05-24 11:08:15 +01:00
parent 308bb3c8e1
commit 7583b63a6e
10 changed files with 629 additions and 1 deletions
+22
View File
@@ -0,0 +1,22 @@
# Copyright © 2016 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
ifdef V
$(info Compiling application)
endif
# Adding path for jerry script APIs
ZEPHYRINCLUDE += -I$(JERRY_INCLUDE)
obj-y += main-zephyr.o
+45
View File
@@ -0,0 +1,45 @@
/* Copyright 2016 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdarg.h>
#include "jerry-port.h"
/**
* Provide log message to filestream implementation for the engine.
*/
int jerry_port_logmsg (FILE *stream, const char *format, ...)
{
va_list args;
int count;
va_start (args, format);
count = vfprintf (stream, format, args);
va_end (args);
return count;
} /* jerry_port_logmsg */
/**
* Provide error message to console implementation for the engine.
*/
int jerry_port_errormsg (const char *format, ...)
{
va_list args;
int count;
va_start (args, format);
count = vfprintf (stderr, format, args);
va_end (args);
return count;
} /* jerry_port_errormsg */
+164
View File
@@ -0,0 +1,164 @@
/* Copyright 2016 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <zephyr.h>
#include <misc/printk.h>
#include <misc/shell.h>
#include "jerry.h"
#if defined (CONFIG_STDOUT_CONSOLE)
#include <stdio.h>
#define PRINT printf
#else
#include <misc/printk.h>
#define PRINT printk
#endif
static char *source_buffer = NULL;
static unsigned char flags = 0;
#define VERBOSE 0x01
/**
* Jerryscript simple test loop
*/
int jerryscript_test ()
{
jerry_completion_code_t ret_code;
const char script[] =
"var test=0; " \
"for (var t=100; t<1000; t++) test+=t; " \
"print ('Hi JS World! '+test);";
printf ("Script [%s]\n",script);
ret_code = jerry_run_simple ((jerry_api_char_t *) script,
strlen (script),
JERRY_FLAG_EMPTY);
return ret_code;
} /* jerryscript_test */
static int shell_cmd_verbose (int argc, char *argv[])
{
printf ("Enable verbose \n");
flags |= VERBOSE;
return 0;
} /* shell_cmd_verbose */
static int shell_cmd_syntax_help (int argc, char *argv[])
{
printf ("version jerryscript & zephyr versions\n");
return 0;
} /* shell_cmd_syntax_help */
static int shell_cmd_version (int argc, char *argv[])
{
uint32_t version = sys_kernel_version_get ();
printf ("Jerryscript %s %s %s\n", jerry_branch_name,
jerry_build_date,
jerry_commit_hash);
printk ("Zephyr version %d.%d.%d\n", SYS_KERNEL_VER_MAJOR (version),
SYS_KERNEL_VER_MINOR (version),
SYS_KERNEL_VER_PATCHLEVEL (version));
return 0;
} /* shell_cmd_version */
static int shell_cmd_test (int argc, char *argv[])
{
return jerryscript_test ();
} /* shell_cmd_test */
static int shell_cmd_handler (int argc, char *argv[])
{
if (argc <= 0)
{
return -1;
}
unsigned int size = 0;
for (int t = 0; t < argc; t++)
{
size += strlen (argv[t]) + 1;
}
source_buffer = (char *) malloc (size);
char *d = source_buffer;
unsigned int len;
for (int t = 0; t < argc; t++)
{
len = strlen (argv[t]);
memcpy (d, argv[t], len);
d += len;
*d = ' ';
d++;
}
* (d - 1) = '\0';
if (flags & VERBOSE)
{
printf ("[%s] %lu\n", source_buffer, strlen (source_buffer));
}
jerry_completion_code_t ret_code;
ret_code = jerry_run_simple ((jerry_api_char_t *) source_buffer,
strlen (source_buffer),
JERRY_FLAG_EMPTY);
free (source_buffer);
if (ret_code != JERRY_COMPLETION_CODE_OK)
{
printf ("Failed to run JS\n");
}
return 0;
} /* shell_cmd_handler */
#define SHELL_COMMAND(name,cmd) { name, cmd }
const struct shell_cmd commands[] =
{
SHELL_COMMAND ("syntax", shell_cmd_syntax_help),
SHELL_COMMAND ("version", shell_cmd_version),
SHELL_COMMAND ("test", shell_cmd_test),
SHELL_COMMAND ("verbose", shell_cmd_verbose),
SHELL_COMMAND (NULL, NULL)
};
void main (void)
{
printf ("Jerry Compilation " __DATE__ " " __TIME__ "\n");
shell_register_app_cmd_handler (shell_cmd_handler);
shell_init ("js> ", commands);
} /* main */