Skip to content

Commit

Permalink
Add a luau library with support for parsing. (aatxe#32)
Browse files Browse the repository at this point in the history
* add infra for queijo luau library

* initial cut of parsing expressions

* added an example to test the expression parsing

* clean up setupState a bit

* add missing source files, i got got by the gitignore

* clean up somewhat

* partial statement support

* the rest of statements

* little fixups

* AstName is 1 entry.

Co-authored-by: vegorov-rbx <75688451+vegorov-rbx@users.noreply.github.com>

* move pretty print script to std

* clean up pp a bit more

* fix horrible formatting

* rename tableRef to seen

* oops

* spaces, not tabs

* more, ick

* some serialization for function AST nodes

* de-indent sorting function

---------

Co-authored-by: vegorov-rbx <75688451+vegorov-rbx@users.noreply.github.com>
  • Loading branch information
aatxe and vegorov-rbx authored Dec 20, 2024
1 parent f152df2 commit 41d2431
Show file tree
Hide file tree
Showing 9 changed files with 1,381 additions and 8 deletions.
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
/crash-*
/default.prof*
/fuzz-*
/luau
/luau-tests
/luau-analyze
/luau-compile
__pycache__
.cache
.clangd
Expand Down
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ project(Queijo LANGUAGES CXX C)

add_library(Queijo.Runtime STATIC)
add_library(Queijo.Fs STATIC)
add_library(Queijo.Luau STATIC)
add_library(Queijo.Net STATIC)
add_library(Queijo.Task STATIC)

Expand Down Expand Up @@ -57,21 +58,25 @@ include(Sources.cmake)

target_compile_features(Queijo.Runtime PUBLIC cxx_std_17)
target_compile_features(Queijo.Fs PUBLIC cxx_std_17)
target_compile_features(Queijo.Luau PUBLIC cxx_std_17)
target_compile_features(Queijo.Net PUBLIC cxx_std_17)
target_compile_features(Queijo.Task PUBLIC cxx_std_17)
target_include_directories(Queijo.Runtime PUBLIC runtime/include ${LIBUV_INCLUDE_DIR})
target_include_directories(Queijo.Fs PUBLIC fs/include ${LIBUV_INCLUDE_DIR})
target_include_directories(Queijo.Luau PUBLIC luau/include ${LIBUV_INCLUDE_DIR})
target_include_directories(Queijo.Net PUBLIC net/include ${LIBUV_INCLUDE_DIR})
target_include_directories(Queijo.Task PUBLIC task/include ${LIBUV_INCLUDE_DIR})

target_link_libraries(Queijo.Runtime PRIVATE Luau.VM uv_a)
target_link_libraries(Queijo.Fs PRIVATE Queijo.Runtime Luau.VM uv_a)
target_link_libraries(Queijo.Luau PRIVATE Queijo.Runtime Luau.VM uv_a Luau.Analysis Luau.Ast)
target_link_libraries(Queijo.Net PRIVATE Queijo.Runtime Luau.VM uv_a ${WOLFSSL_LIBRARY} libcurl)
target_link_libraries(Queijo.Task PRIVATE Queijo.Runtime Luau.VM uv_a)
target_link_libraries(Queijo.CLI PRIVATE Luau.CLI.lib Luau.Compiler Luau.Config Luau.CodeGen Luau.Analysis Luau.VM Queijo.Runtime Queijo.Fs Queijo.Net Queijo.Task)
target_link_libraries(Queijo.CLI PRIVATE Luau.CLI.lib Luau.Compiler Luau.Config Luau.CodeGen Luau.Analysis Luau.VM Queijo.Runtime Queijo.Fs Queijo.Luau Queijo.Net Queijo.Task)

target_compile_options(Queijo.Runtime PRIVATE ${QUEIJO_OPTIONS})
target_compile_options(Queijo.Fs PRIVATE ${QUEIJO_OPTIONS})
target_compile_options(Queijo.Luau PRIVATE ${QUEIJO_OPTIONS})
target_compile_options(Queijo.Net PRIVATE ${QUEIJO_OPTIONS})
target_compile_options(Queijo.Task PRIVATE ${QUEIJO_OPTIONS})
target_compile_options(Queijo.CLI PRIVATE ${QUEIJO_OPTIONS})
Expand Down
6 changes: 6 additions & 0 deletions Sources.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ target_sources(Queijo.Fs PRIVATE
fs/src/fs.cpp
)

target_sources(Queijo.Luau PRIVATE
luau/include/queijo/luau.h

luau/src/luau.cpp
)

target_sources(Queijo.Net PRIVATE
net/include/queijo/net.h

Expand Down
8 changes: 6 additions & 2 deletions cli/queijo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
#include "lua.h"
#include "lualib.h"

#include "queijo/net.h"
#include "queijo/fs.h"
#include "queijo/net.h"
#include "queijo/luau.h"
#include "queijo/ref.h"
#include "queijo/runtime.h"

Expand Down Expand Up @@ -57,10 +58,13 @@ lua_State* setupState(Runtime& runtime)
// register the builtin tables
luaL_openlibs(L);

luaopen_fs(L);
lua_pop(L, 1);

luaopen_net(L);
lua_pop(L, 1);

luaopen_fs(L);
luaopen_luau(L);
lua_pop(L, 1);

static const luaL_Reg funcs[] = {
Expand Down
3 changes: 3 additions & 0 deletions examples/parsing.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
local pretty = require("@std/pp")
local foo = luau.parseexpr("{} + 2")
print(pretty(foo))
3 changes: 2 additions & 1 deletion extern/luau/Ast/include/Luau/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ class Parser
ParseOptions options = ParseOptions()
);

private:
// FIXME(queijo): temporary change, we should expose a few more methods here ultimately
//private:
struct Name;
struct Binding;

Expand Down
5 changes: 5 additions & 0 deletions luau/include/queijo/luau.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

struct lua_State;

int luaopen_luau(lua_State* L);
Loading

0 comments on commit 41d2431

Please sign in to comment.