GithubHelp home page GithubHelp logo

Get imports working. about filbert HOT 4 OPEN

Xavion3 avatar Xavion3 commented on May 26, 2024
Get imports working.

from filbert.

Comments (4)

differentmatt avatar differentmatt commented on May 26, 2024

Cool, looking forward to an example.

from filbert.

Xavion3 avatar Xavion3 commented on May 26, 2024

Alright code stuff, here is what you'd have in pythonRuntime

modules : {
  random : new (function() {
    var self = this;
    self.random = function () { return Math.random(); };
    self.randint = function (a, b) { return self.randrange(a, b+1); };
    etc. etc.
  })(),
  math : new (function() {
    var self = this;
    this.sin = Math.sin;
    etc. etc.
  })()
}

Then the code they'd enter would be something like the following

import math, random as rand
from math import sin as sine

This would be transformed into the following code.

var math = pythonRuntime.modules.math;
var rand = pythonRuntime.modules.random;
var sin = pythonRuntime.modules.math.sine;

Of course you'd modify the vars and so as normal so you only declare once but that's the model I thought of.

from filbert.

differentmatt avatar differentmatt commented on May 26, 2024

I like it! This should work nicely.

Why would you use self instead of this directly in your modules objects?

parseSubscripts has examples of generating AST nodes to reference runtime objects.

createVarDeclFromId will help you create an AST node of the form var math = something;.

from and import keywords are currently skipped over in parseStatement.

We also need to make sure new parsing work is duplicated in filbert_loose.js. There is currently more duplication than necessary between filbert.js and filbert_loose.js.

from filbert.

Xavion3 avatar Xavion3 commented on May 26, 2024

The self instead of this is a habit to make sure scoping doesn't suddenly screw up by giving me the inner functions scope with this so I also get the one I was trying for. I'll look into those and try and get something done.

Also I have been forgetting to update filbert_loose.js, I'll try and remember to do that. I'm going to need to start having multiple branches here or the different goals will start polluting each other.

from filbert.

Related Issues (20)

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.