GithubHelp home page GithubHelp logo

plumpmath / tracing-js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from heylu/tracing-js

0.0 0.0 0.0 260 KB

Tracing JavaScript for fun and understanding.

Home Page: http://papill0n.org/trace

License: MIT License

Haskell 20.20% Makefile 4.37% JavaScript 53.12% Ruby 0.76% HTML 21.55%

tracing-js's Introduction

tracing-js - Tracing JavaScript for fun and understanding.

Tracing the step a JavaScript program takes to understand what it does.

The current main motivation is understanding different string search algorithms. They look quite simple, but what they do isn't easy to explain. I hope that by looking at their behaviour it will be easier to understand what they do and why they do it.

There's a version of this available at http://papill0n.org/trace.

Quickstart

You need the Haskell platform installed.

$ make run-server

Then open trace.html in your browser. (And of course write some code.)

Implementation

  • a library that transforms given code into a traced version of it (written in Haskell)

    For example, the following code:

      var sum = 0;
    
      for (var i = 0; i < 10; i++) {
          sum += i;
      }
    

    Will be transformed into the following:

      traceLine(1);
      var sum = traceWrite("sum",0,true,{line: 1,col: 19});
      traceLine(2);
      traceLine(3);
      for (var i = traceWrite("i",0,true,{line: 3,col: 24});
           traceLine(3), traceValue("i < 10",traceRead("i",i,{line: 3,col: 31}) < 10,{line: 3,col: 33});
           traceLine(3), traceWrite("i++",i++,false,{line: 3,col: 39})) {
        traceLine(4);
        sum += traceWrite("sum += i",traceRead("i",i,{line: 4,col: 24}),false,{line: 4,col: 17});
        traceLine(5);
      }
    
  • a frontend that allows you to write some code, send it to the server, execute it and then look at the trace

Known imitations

  • it only traces reads and writes

  • some statements aren't traced yet (e.g. try/catch, labels; but easy to add, I just didn't need them yet. for now they're ignored.)

  • assignments are displayed quite weird

    E.g. with i = 0, i++ will display as i++ := 0 even though it probably should display i++ := 1 or i := 1.

    i += 3 displays as i += 3 := 3.

    (This might get fixed if I find (or need) a better way to display variables, preferrably inline, not in comments as done now. Ideas & suggestions welcome.)

tracing-js's People

Contributors

heylu 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.