Code Monkey home page Code Monkey logo

laux-compiler's Introduction

Hi ๐Ÿ‘‹! My name is Matteo and I'm a Software Developer, from Sweden.

stats graph languages graph

javascript logo typescript logo react logo html5 logo css3 logo python logo csharp logo svelte logo lua logo tailwindcss logo figma logo github logo php logo trello logo vscode logo


Snake animation

laux-compiler's People

Contributors

8char avatar avivi55 avatar semantic-release-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

avivi55

laux-compiler's Issues

Type checking messing things up.

I was testing compilation with the exemple.lua file.

I changed it to just use the native laux compiler:

class Test
  public constructor()
    self:receive()
  end

  private receive()
    local a = { 2, 3 }
    local b = { 1, ...a, 4 }
    print(b) -- { 1, 2, 3, 4 }
  end

  greetPerson(yes: string)
    return `yes : ${yes}`
  end
end


local t = Test()

print(t.greetPerson("test"))

and it compiles well, the problematic part is the greetPerson() method

    greetPerson = function(self, yes)
      local __laux_type = (istable(yes) and yes.__type and yes:__type()) or type(yes)
      assert(__laux_type == "string", "Expected parameter `yes` to be type `string` instead of `" .. __laux_type .. "`")
      return "yes : " .. tostring(yes)
    end,
    __type = function(self)
      return self.__name
    end

The type checking part uses the istable() function, which is a GLua function and isn't a lua native function.
It made it unable to run the script in the command line.

parameter number mismatch in native lua

Related to #3

When removing the istable function, I am prompted with

table: 0x55a3aaa48770
lua: tt.lua.lua:35: attempt to index a nil value (local 'yes')
stack traceback:
	tt.lua.lua:35: in field 'greetPerson'
	tt.lua.lua:63: in main chunk
	[C]: in ?

when looking at line 35 :

greetPerson = function(self, yes)

and the call (63) :

print(t.greetPerson("test"))

As seen in the definition the function takes two parameters and putting anything as a first parameter fixes the output.

print(t.greetPerson(0, "test"))
table: 0x559080175770
yes : test

The cause is probably that it works in gmod as a lot of gmod functions have a self argument as first parameter.

Linux : compile doesn't work unless file changes

This issue was supposed to concern Atals but, trying it on a single file didn't change anything.

The Problem: (trying to transpile AtlasFramework)

When running > ./transpile.sh for the first few time I kept getting

LAUX BUILT atlasui/libs/configurator/ui/entities/row.lua 55.211ms
LAUX BUILT atlasui/libs/configurator/ui/entities/row_settings.lua 42.739ms
LAUX BUILT atlasui/libs/configurator/ui/entities/settings_base.lua 37.655ms
LAUX BUILT atlasui/libs/players/ui/notifications/hud.lua 1.659ms
LAUX BUILT atlasui/libs/players/ui/notifications/main.lua 89.654ms
LAUX BUILT atlasui/libs/players/ui/notifications/row.lua 68.266ms
/usr/lib/node_modules/laux-compiler/dist/codegenerator.js:609
        throw new Error("Tried to print invalid node type '" + type + "'");
              ^
Error: Tried to print invalid node type 'TableSpreadExpression'
    at CodeGenerator.print (/usr/lib/node_modules/laux-compiler/dist/codegenerator.js:609:15)
    at CodeGenerator.printJoin (/usr/lib/node_modules/laux-compiler/dist/codegenerator.js:643:14)
    at CodeGenerator.printSequence (/usr/lib/node_modules/laux-compiler/dist/codegenerator.js:661:19)
    at CodeGenerator.TableConstructorExpression (/usr/lib/node_modules/laux-compiler/dist/codegenerator.js:508:16)
    at CodeGenerator.print (/usr/lib/node_modules/laux-compiler/dist/codegenerator.js:607:46)
    at CodeGenerator.printJoin (/usr/lib/node_modules/laux-compiler/dist/codegenerator.js:643:14)
    at CodeGenerator.printList (/usr/lib/node_modules/laux-compiler/dist/codegenerator.js:621:19)
    at CodeGenerator.CallExpression (/usr/lib/node_modules/laux-compiler/dist/codegenerator.js:418:14)
    at CodeGenerator.print (/usr/lib/node_modules/laux-compiler/dist/codegenerator.js:607:46)
    at CodeGenerator.CallStatement (/usr/lib/node_modules/laux-compiler/dist/codegenerator.js:113:14)
    at CodeGenerator.print (/usr/lib/node_modules/laux-compiler/dist/codegenerator.js:607:46)
    at CodeGenerator.printJoin (/usr/lib/node_modules/laux-compiler/dist/codegenerator.js:643:14)
    at CodeGenerator.printSequence (/usr/lib/node_modules/laux-compiler/dist/codegenerator.js:661:19)
    at CodeGenerator.FunctionExpression (/usr/lib/node_modules/laux-compiler/dist/codegenerator.js:462:16)
    at CodeGenerator.print (/usr/lib/node_modules/laux-compiler/dist/codegenerator.js:607:46)
    at CodeGenerator.TableKeyString (/usr/lib/node_modules/laux-compiler/dist/codegenerator.js:539:14)

Node.js v19.8.1

And after miraculously fixing it, an other problem came up.

Problem 2

When running lauxc ... the build runs but gets stuck
exemple :

LAUX COPIED atlasui/libs/configurator/ui/inputs/toggle.lua
LAUX COPIED atlasui/libs/configurator/ui/entities/entity.lua
LAUX COPIED atlasui/libs/configurator/ui/entities/entity_grid.lua
LAUX COPIED atlasui/libs/configurator/ui/entities/entity_list.lua
LAUX COPIED atlasui/libs/configurator/ui/entities/entity_list_row.lua
LAUX COPIED atlasui/libs/configurator/ui/entities/row.lua
LAUX COPIED atlasui/libs/configurator/ui/entities/row_settings.lua
LAUX COPIED atlasui/libs/configurator/ui/entities/settings_base.lua

and generates the correct files but they are empty, the file tree is good but not the content.
ecept that for each .laux file 2 .lua files are generated one in the same directory as the .laux and one in the new lua/ folder.

Note

When saving a .laux file :

LAUX CHANGE atlasui/core/ui/main.lua 287.334ms
LAUX CHANGE atlasui/core/ui/tab.lua 483.888ms

the related file in the lua/ folder. is updated and filled up with the compiled code ๐Ÿ‘ but the rest are still empty.

PS:
I run Manjaro (based on Arch) if it can help troubleshoot

[Question] Why does the compiler parse a throw statement, if you can't use it ?

It is defined as a statement here :

defineType("ThrowStatement", {
visitors: ["expression"],
builder: ["expression"],
aliases: ["Statement"],
});

And it has a parsing function:

laux-compiler/src/parser.js

Lines 559 to 577 in 40cd306

function parseThrowStatement() {
const expressions = [];
if (token.value !== "end") {
let expression = parseExpression();
if (expression != null) expressions.push(expression);
while (consume(",")) {
expression = parseExpectedExpression();
expressions.push(expression);
}
consume(";"); // grammar tells us ; is optional here.
}
return finishNode(b.throwStatement(expressions));
}
function parseThrowExpression() {
return parseThrowStatement();
}

But I can't see where it is used or how to use it, is it an old leftover from the fork ?

When I try to use it, it throws an invalid node type and not a SyntaxError

LAUX ERROR test.laux:
LAUX ERROR Error: Tried to print invalid node type 'ThrowStatement'

I was just wondering.

Thank you.

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.