Skip to content

Commit

Permalink
Merge branch 'pr/5'
Browse files Browse the repository at this point in the history
  • Loading branch information
sfranzyshen committed Aug 28, 2019
2 parents faa718a + d3b867a commit 8bb7e3a
Show file tree
Hide file tree
Showing 6 changed files with 1,049 additions and 754 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
language: c
sudo: false
after_success: bash <(curl -s https://codecov.io/bash)
os:
- linux
- osx
Expand Down
25 changes: 16 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,32 +1,39 @@
PROG = mjs
PROG = elk
DBG ?=
#MFLAGS += -DMJS_DEBUG
TFLAGS += -DMJS_PROP_POOL_SIZE=30 -DMJS_STRING_POOL_SIZE=512
#MFLAGS += -DJS_DEBUG
TFLAGS += -DJS_STRING_POOL_SIZE=512
CFLAGS += -W -Wall -Werror -Wstrict-overflow -fno-strict-aliasing -Os -g
GCOV ?= true

ifeq ($(CC),clang)
CFLAGS += -coverage
GCOV = gcov
endif

all: $(PROG) test cpptest vc98 test98
.PHONY: test $(PROG)

$(PROG): mjs.c example.c
$(PROG): elk.c example.c
$(CC) -o $@ example.c -DNDEBUG $(CFLAGS) $(MFLAGS)

test: unit_test.c mjs.c
test: clean unit_test.c elk.c
$(CC) -o $@ unit_test.c $(CFLAGS) $(MFLAGS) $(TFLAGS)
$(DBG) ./$@
@$(DBG) ./$@
-@$(GCOV) unit_test.c

cpptest:
$(CXX) -x c++ -o $@ unit_test.c $(CFLAGS) $(MFLAGS) $(TFLAGS)
$(DBG) ./$@

VC98 = docker run -v $(CURDIR):$(CURDIR) -w $(CURDIR) docker.io/mgos/vc98
VCFLAGS = /nologo /W4 /O1
vc98: mjs.c example.c
vc98: elk.c example.c
$(VC98) wine cl example.c $(VCFLAGS) /DNDEBUG $(MFLAGS) /Fe$(PROG).exe

test98: unit_test.c mjs.c
test98: unit_test.c elk.c
$(VC98) wine cl unit_test.c $(VCFLAGS) $(MFLAGS) $(TFLAGS) /Fe$@.exe
$(VC98) wine $@.exe


clean:
rm -rf $(PROG) *test *.exe *.obj *.dSYM example
rm -rf $(PROG) *test *.exe *.obj *.dSYM example *.gc*
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# mJS - a JS engine for embedded systems
# Elk - a restricted JS engine for embedded systems

[![License: GPL v2](https://img.shields.io/badge/License-GPL%20v2-blue.svg)](https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html)
[![Build Status](https://travis-ci.org/cpq/mjs3.svg?branch=master)](https://travis-ci.org/cpq/mjs3)
[![Build Status](https://travis-ci.org/cpq/elk.svg?branch=master)](https://travis-ci.org/cpq/elk)
[![Code Coverage](https://codecov.io/gh/cpq/elk/branch/master/graph/badge.svg)](https://codecov.io/gh/cpq/elk)

mJS is a single-source JavaScript engine for microcontrollers.

Elk is a single-file JavaScript engine for microcontrollers.

## Features

Expand All @@ -27,17 +29,16 @@ mJS is a single-source JavaScript engine for microcontrollers.

```c++
#define MJS_STRING_POOL_SIZE 200 // Buffer for all strings
#include "mjs.c" // Sketch -> Add File -> mjs.c
#include "elk.c" // Sketch -> Add File -> elk.c

extern "C" void myDelay(int x) { delay(x); }
extern "C" void myDigitalWrite(int x, int y) { digitalWrite(x, y); }

void setup() {
pinMode(13, OUTPUT);
struct mjs *vm = mjs_create(); // Create JS instance
mjs_ffi(vm, "delay", (cfn_t) myDelay, "vi"); // Import delay()
mjs_ffi(vm, "write", (cfn_t) myDigitalWrite, "vii"); // Import write()
mjs_eval(vm, "while (1) { write(13, 0); delay(100); write(13, 1); delay(100); }", -1);
struct vm *vm = js_create(); // Create JS instance
js_ffi(vm, "delay", (cfn_t) myDelay, "vi"); // Import delay()
js_ffi(vm, "write", (cfn_t) myDigitalWrite, "vii"); // Import write()
js_eval(vm, "while (1) { write(13, 0); delay(100); write(13, 1); delay(100); }", -1);
}

void loop() { delay(1000); }
Expand All @@ -60,13 +61,13 @@ Global variables use 955 bytes (46%) of dynamic memory, leaving 1093 bytes for l
| Simple types | `let a = null, b = undefined, c = false, d = true;` |
| Functions | `let f = function(x, y) { return x + y; }; ` |
| Objects | `let obj = {a: 1, f: function(x) { return x * 2}}; obj.f();` |
| Arrays | `let arr = [1, 2, 'hi there']` |
## Unsupported standard operations and constructs
| Name | Operation |
| ----------------- | ----------------------------------------- |
| Arrays | `let arr = [1, 2, 'hi there']` |
| Loops/switch | `for (...) { ... }`,`for (let k in obj) { ... }`, `do { ... } while (...)`, `switch (...) {...}` |
| Equality | `==`, `!=` (note: use strict equality `===`, `!==`) |
| var | `var ...` (note: use `let ...`) |
Expand Down
Loading

0 comments on commit 8bb7e3a

Please sign in to comment.