Coder Social home page Coder Social logo

gmh5225 / wrench Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jingoro2112/wrench

0.0 1.0 0.0 1.37 MB

practical embedded script interpreter

License: MIT License

JavaScript 0.69% C++ 78.05% Python 0.01% Perl 0.02% C 6.38% Lua 0.15% CSS 11.04% Squirrel 0.13% Makefile 0.16% HTML 3.13% CWeb 0.23%

wrench's Introduction

http://northarc.com/wrench/www/

A full-featured compiler+interpreter that uses a bare minimum of ram and program space.

How little? The wrench Virtual Machine compiles to ~26k on an Arduino, and
uses less than 700 Bytes of RAM to operate, it is fully functional on an Uno Mini.

Highlights:

- Weakly typed, supporting native 32-bit int, float and string.
  Code is easy to write and intuitive.

- Optimizing compiler and very fast VM

- Produces very compact endian-neutral bytecode: compile-anywhere-run-anywhere.

- Executes from ROM, no local copy of the code is made

- Multiple concurrent contexts supported

- Code is easy to write, imagine c with the typenames removed; that's pretty much it.

- Supports everything a good interpreter should: if/then/else/do/while/for/switch/functions/operators/etc..

- Yes structs too

- Can operate directly on native data without thunking

- Can call back and forth to native code with minimal overhead

- API is designed to be extended, that's the whole point

- Memory is garbage-collected but only for dynamic arrays. Unless
  you are allocating/de-allocating arrays the gc _never_ runs.

- MIT licence

- Includes a handy command-line tool

- Easy to integrate, here is a complete example:


----- Step 1: The entire source tree is included, but is wrapped up in two 
              files, src/wrench.h and src/wrench.cpp simply include these in 
              your build and you have everything.

----- Step 2: Here is a complete source-code example:

#include <wrench.h>
#include <string.h>
#include <stdio.h>

void print( WRState* w, const WRValue* argv, const int argn, WRValue& retVal, void* usr )
{
	char buf[1024];
	for( int i=0; i<argn; ++i )
	{
		printf( "%s", argv[i].asString(buf,1024) );
	}
}


const char* wrenchCode = 
                         "print( \"Hello World!\\n\" );"
                         "for( i=0; i<10; i++ )        "
                         "{                            "
                         "    print( i );              "
                         "}                            "
                         "print(\"\\n\");              ";



int main( int argn, char** argv )
{
	WRState* w = wr_newState(); // create the state

	wr_registerFunction( w, "print", print ); // bind a function

	unsigned char* outBytes; // compiled code is alloc'ed
	int outLen;

	int err = wr_compile( wrenchCode, strlen(wrenchCode), &outBytes, &outLen ); // compile it
	if ( err == 0 )
	{
		wr_run( w, outBytes, outLen ); // load and run the code!
		delete[] outBytes; // clean up 
	}

	wr_destroyState( w );

	return 0;
}


---- Step 3: compile the above with something like: 

            g++ -o example example.c wrench.cpp

---- Step 4: done!

wrench's People

Contributors

jingoro2112 avatar diegovsky avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.