Skip to content

Commit

Permalink
Merge pull request #1 from HydroRoll-Team/v1.1.0
Browse files Browse the repository at this point in the history
[feature]: V1.1.0
  • Loading branch information
HsiangNianian authored Nov 2, 2024
2 parents 1ea5780 + f3ef43d commit 6c7f20f
Show file tree
Hide file tree
Showing 43 changed files with 3,954 additions and 378 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "luah"
version = "0.1.0"
version = "1.1.0"
edition = "2021"
description = "An unofficial lua impl by HydroRoll-Team."
description = "Unofficial lua impl by HydroRoll-Team."
license = "AGPL-3.0-or-later"
documentation = "https://luah.hydroroll.team/"
homepage = "https://hydroroll.team/"
Expand Down
50 changes: 50 additions & 0 deletions luah/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import argparse
import sys
from .LibCore import raw_input

class Cli:
def __init__(self):
self.parser = argparse.ArgumentParser(description="luah")
self._setup_arguments()
self.args = self.parser.parse_args()

if self.args.file:
self.process_file(self.args.file)
elif len(sys.argv) > 1 and sys.argv[1].endswith(".lua"):
self.process_file(sys.argv[1])

def _setup_arguments(self):
self.parser.add_argument("--version", action="version", version="luah 0.1.0")
self.parser.add_argument("--verbose", action="store_true", help="verbose mode")
self.parser.add_argument("--debug", action="store_true", help="debug mode")
self.parser.add_argument("--quiet", action="store_true", help="quiet mode")
self.parser.add_argument("--config", help="config file")
self.parser.add_argument("--file", help="file to process")
self.parser.add_argument("--log", help="log file")
self.parser.add_argument("--log-level", help="log level")
self.parser.add_argument("--log-format", help="log format")
self.parser.add_argument("--log-date-format", help="log date format")
self.parser.add_argument("--log-file-max-size", help="log file max size")
self.parser.add_argument("--log-file-backup-count", help="log file backup count")
self.parser.add_argument("--log-file-rotation-count", help="log file rotation count")
self.parser.add_argument("--log-file-rotation-interval", help="log file rotation interval")
self.parser.add_argument("--log-file-rotation-backup-count", help="log file rotation backup count")
self.parser.add_argument("--log-file-rotation-backup-interval", help="log file rotation backup interval")

def process_file(self, file_name):
try:
raw_input(file_name)
except Exception as e:
print(f"Error processing file {file_name}: {e}")

def get_args(self):
return self.args

def get_help(self):
return self.parser.format_help()

if __name__ == "__main__":
cli = Cli()
args = cli.get_args()
if args.verbose:
print("Verbose mode is enabled.")
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ repository = "https://github.com/HydroRoll-Team/luah"
documentation = "https://luah.hydroroll.team/"

[project.scripts]
luah = "luah.cli:main"
luah = "luah.__main__:Cli"

[tool.maturin]
features = ["pyo3/extension-module"]
Expand Down
121 changes: 115 additions & 6 deletions src/bytecode.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,122 @@
#[derive(Debug)]
pub enum ByteCode {
GetGlobal(u8, u8),
SetGlobal(u8, u8),
SetGlobalConst(u8, u8), // TODO u8?
SetGlobalGlobal(u8, u8),
// local variable
LoadConst(u8, u16),
LoadNil(u8),
LoadNil(u8, u8),
LoadBool(u8, bool),
LoadInt(u8, i16),
Move(u8, u8),
Call(u8, u8),

// upvalues
GetUpvalue(u8, u8),
SetUpvalue(u8, u8),
SetUpvalueConst(u8, u8),
Close(u8),

// table
NewTable(u8, u8, u8),
SetTable(u8, u8, u8),
SetField(u8, u8, u8),
SetInt(u8, u8, u8),
SetTableConst(u8, u8, u8),
SetFieldConst(u8, u8, u8),
SetIntConst(u8, u8, u8),
SetList(u8, u8),
GetTable(u8, u8, u8),
GetField(u8, u8, u8),
GetInt(u8, u8, u8),
GetFieldSelf(u8, u8, u8),

// upvalue table, covers global variables
SetUpField(u8, u8, u8),
SetUpFieldConst(u8, u8, u8),
GetUpField(u8, u8, u8),

// condition structures
Jump(i16),
TestAndJump(u8, i16),
TestOrJump(u8, i16),
TestAndSetJump(u8, u8, u8),
TestOrSetJump(u8, u8, u8),

// for-loop
ForPrepare(u8, u16),
ForLoop(u8, u16),
ForCallLoop(u8, u8, u8),

// function call
Closure(u8, u16),
Call(u8, u8, u8),
CallSet(u8, u8, u8),
TailCall(u8, u8),
Return0,
Return(u8, u8),
VarArgs(u8, u8),

// unops
Neg(u8, u8),
Not(u8, u8),
BitNot(u8, u8),
Len(u8, u8),

// binops
Add(u8, u8, u8),
AddConst(u8, u8, u8),
AddInt(u8, u8, u8),
Sub(u8, u8, u8),
SubInt(u8, u8, u8),
SubConst(u8, u8, u8),
Mul(u8, u8, u8),
MulInt(u8, u8, u8),
MulConst(u8, u8, u8),
Mod(u8, u8, u8),
ModInt(u8, u8, u8),
ModConst(u8, u8, u8),
Div(u8, u8, u8),
DivInt(u8, u8, u8),
DivConst(u8, u8, u8),
Idiv(u8, u8, u8),
IdivInt(u8, u8, u8),
IdivConst(u8, u8, u8),
Pow(u8, u8, u8),
PowInt(u8, u8, u8),
PowConst(u8, u8, u8),
BitAnd(u8, u8, u8),
BitAndInt(u8, u8, u8),
BitAndConst(u8, u8, u8),
BitXor(u8, u8, u8),
BitXorInt(u8, u8, u8),
BitXorConst(u8, u8, u8),
BitOr(u8, u8, u8),
BitOrInt(u8, u8, u8),
BitOrConst(u8, u8, u8),
ShiftL(u8, u8, u8),
ShiftLInt(u8, u8, u8),
ShiftLConst(u8, u8, u8),
ShiftR(u8, u8, u8),
ShiftRInt(u8, u8, u8),
ShiftRConst(u8, u8, u8),

Equal(u8, u8, bool),
EqualInt(u8, u8, bool),
EqualConst(u8, u8, bool),
NotEq(u8, u8, bool),
NotEqInt(u8, u8, bool),
NotEqConst(u8, u8, bool),
LesEq(u8, u8, bool),
LesEqInt(u8, u8, bool),
LesEqConst(u8, u8, bool),
GreEq(u8, u8, bool),
GreEqInt(u8, u8, bool),
GreEqConst(u8, u8, bool),
Less(u8, u8, bool),
LessInt(u8, u8, bool),
LessConst(u8, u8, bool),
Greater(u8, u8, bool),
GreaterInt(u8, u8, bool),
GreaterConst(u8, u8, bool),

SetFalseSkip(u8),

Concat(u8, u8, u8),
}
Loading

0 comments on commit 6c7f20f

Please sign in to comment.