Coder Social home page Coder Social logo

jspicl's Introduction

jspicl is a Javascript to PICO-8 Lua transpiler. It creates an AST out of the JavaScript code and then transpiles it down to the LUA subset of which PICO-8 supports.

Visit jspicl.github.io for docs, guides, API and more!


npm version License

jspicl's People

Contributors

agronkabashi avatar dependabot[bot] avatar m-lindstrom avatar marols avatar mlusiak avatar morkalork avatar nathanchere avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

jspicl's Issues

Error: There is no handler for ThrowStatement

const { output, polyfills } = jspicl(src);
Thrown:
Error: There is no handler for ThrowStatement
at filter.map.node (/home/zaoqi/src/temp/node_modules/trastpiler/lib/trastpiler.js:39:15)
at Array.map ()
at transpile (/home/zaoqi/src/temp/node_modules/trastpiler/lib/trastpiler.js:35:6)
at BlockStatement (/home/zaoqi/src/temp/node_modules/jspicl/lib/jspicl.js:582:53)
at filter.map.node (/home/zaoqi/src/temp/node_modules/trastpiler/lib/trastpiler.js:42:22)
at Array.map ()
at transpile (/home/zaoqi/src/temp/node_modules/trastpiler/lib/trastpiler.js:35:6)
at FunctionDeclaration (/home/zaoqi/src/temp/node_modules/jspicl/lib/jspicl.js:356:27)
at filter.map.node (/home/zaoqi/src/temp/node_modules/trastpiler/lib/trastpiler.js:42:22)
at Array.map ()

Create CLI

A CLI would make jspicl more accessible and eliminate the need to setup your own build pipeline using rollup-plugin-jspicl.

The CLI should accept the same input parameters as rollup-plugin-jspicl in addition to the following parameters:

  • path to entry source file [mandatory]
  • path to output final cartridge [mandatory]
  • prettify output
  • path to file exporting custom handlers
  • path to file exporting custom polyfills

function() end()

(function(){...})() => function() ... end()
`> function() end
function: 0x55bdfbe64b10

function() end()
stdin:1: expected near '('
`

Ternary conditional is not supported

Writing a ternary conditional in your code results in an error:

[!] Error: Error transforming bundle: Conditional expressions such as 'a ? b : c;' are not supported.

"use strict"

error loading module 'a' from file './a.lua':
./a.lua:1: unexpected symbol near '"use strict"'

assert(true,????

WARNING #LANG en_CN.UTF-8

ThrowStatement: ({ argument }, { transpile }) =>
assert(true, ${transpile(argument)}),

assert(true,????
Why it is not assert(false,...

Add polyfill: Math.random

Math.random should be transpiled into a polyfilled function random

function random()
  return rnd(0, 1000) / 1000 -- 1000 determines the precision, i.e. 3 decimals
end

-=

error loading module 'a' from file './a.lua':
./a.lua:309: syntax error near '-'

Include referenced polyfills only

Currenty all polyfills are always included in the generated lua code.
Only include them if they are used by the code.

Collect usage during traversal of the AST tree?

Move code from rollup-plugin-jspicl to this repo

Polyfills for various javascript functions that are handled by rollup-plugin-jspicl should be handled by jspicl instead.

jspicl(source)
      .replace(/\$/g, "_")
      .replace(/Math\.max\(/g, "max(")
      .replace(/Math\.floor\(/g, "flr(")
      .replace(/Object\.assign\(/g, "merge(")
      .replace(/(\w+)\.forEach\(/g, "foreach($1, ")
      .replace(/(\w+)\.push\(/g, "add($1, ")
      .replace(/(\w+)\.join\(/g, "join($1, ");

Includes: https://github.com/AgronKabashi/rollup-plugin-jspicl/blob/master/src/utilities.js

Undefined and nulls are not transpiled.

const a = null; // local a = null
const b = undefined; // local b = undefined

Expected

const a = null; // local a = nil
const b = undefined; // local b = nil

Add support for Switch & Break statements

http://esprima.readthedocs.io/en/latest/syntax-tree-format.html#switch-statement

http://esprima.readthedocs.io/en/latest/syntax-tree-format.html#break-statement

Example output

switch (choice) {
  case "option1":
    break;
  
  case "optionN":
    break;

  default: break;
}

Possible Lua alternatives:

-- Using lookup table: faster ( O(1) ) but requires more tokens
local switch =
{
  ["option1"] = function () ${option1-case-contents} end,
  ["optionN"] = ...,
  ["default"] = ...
}

(switch[choice] or switch["default"] or noop)()
-- Regular if/else statements: slower ( O(n) ) but requires fewer tokens
-- Potential problem: need to make sure that default case is last if available
if (choice == "option1") then
  ${option1-case-contents}
elseif (choice == "optionN") then
  ${option2-case-contents}
else
  ${default-case-contents}
end

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.