Skip to content

Commit

Permalink
Merge pull request #4 from kneorain/restructuring
Browse files Browse the repository at this point in the history
Merge Restructuring into main
  • Loading branch information
Ze7111 authored Mar 19, 2024
2 parents 849890d + 2d3a11f commit 46e5f4c
Show file tree
Hide file tree
Showing 62 changed files with 3,766 additions and 1,065 deletions.
39 changes: 24 additions & 15 deletions .helix/cache/build_cache/test_hlx.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# GENERATED FILE
# --------------------------------------------------------------------------------
# Filename: test.hlx
# Generation Date: 2024-03-09 21:43:31
# Generation Date: 2024-03-11 23:27:01
# Generator: Helix Transpiler
# --------------------------------------------------------------------------------
# WARNING: This file is AUTO-GENERATED by the Helix Transpiler. Any modifications
Expand All @@ -29,18 +29,18 @@
import os # type: ignore
import sys # type: ignore
import types # type: ignore
sys.path.append(os.path.dirname(os.path.realpath("c:\\Users\\dhruv\\Documents\\Projects\\helix\\helix.py")) + os.sep + ".helix") # type: ignore
sys.path.append(os.path.dirname(os.path.realpath("c:\\Users\\dhruv\\Documents\\Projects\\helix\\helix.py"))) # type: ignore
sys.path.append(os.path.dirname(os.path.realpath("z:\\devolopment\\helix\\helix-lang\\helix.py")) + os.sep + ".helix") # type: ignore
sys.path.append(os.path.dirname(os.path.realpath("z:\\devolopment\\helix\\helix-lang\\helix.py"))) # type: ignore
sys.path.append(os.path.dirname(os.path.realpath(os.getcwd()))) # type: ignore
# trunk-ignore(ruff/F401)
from include.core import ABC, Any, C_For, Callable, DEFAULT_VALUE, DispatchError, Enum, FastMap, FunctionType, Iterator, Literal, NoReturn, NoneType, Optional, Self, Thread, Type, TypeVar, UnionType, __import_c__, __import_cpp__, __import_py__, __import_rs__, annotations, array, auto, dataclass, double, getcontext, hx__abstract_method, hx__async, hx__multi_method, hx_array, hx_bool, hx_bytes, hx_char, hx_double, hx_float, hx_int, hx_list, hx_map, hx_set, hx_string, hx_tuple, hx_unknown, hx_void, inspect, multimeta, panic, printf, ref, replace_primitives, scanf, sleep, std, string, subtype, unknown, void, wraps # type: ignore
from include.core import ABC, Any, BuiltinFunctionType, C_For, Callable, DEFAULT_VALUE, DispatchError, Enum, FastMap, FunctionType, Iterator, Literal, NoReturn, NoneType, Optional, Self, T, Thread, Type, TypeVar, UnionType, __import_c__, __import_cpp__, __import_py__, __import_rs__, annotations, array, auto, beartype, dataclass, double, getcontext, hx__abstract_method, hx__async, hx__multi_method, hx_array, hx_bool, hx_bytes, hx_char, hx_double, hx_float, hx_int, hx_list, hx_map, hx_set, hx_string, hx_tuple, hx_unknown, hx_void, inspect, multimeta, panic, printf, ref, replace_primitives, scanf, sleep, std, string, subtype, unknown, void, wraps # type: ignore
# trunk-ignore(ruff/F401)
# trunk-ignore(ruff/F811)
from include.core import __import_c__, __import_cpp__, __import_py__, __import_rs__ # type: ignore
import threading # type: ignore
import functools # type: ignore
__lock = threading.Lock()
__file__ = "C:\\Users\\dhruv\\Documents\\Projects\\helix\\syntax\\test.hlx"
__file__ = "Z:\\devolopment\\helix\\helix-lang\\syntax\\test.hlx"
# trunk-ignore(ruff/F821)
def exception_handler(exception_type: type[BaseException] | threading.ExceptHookArgs, exception: Optional[Exception] = None, tb: Optional[types.TracebackType] = None, debug_hook: bool = False, thread_error: bool = False):
import traceback
Expand Down Expand Up @@ -173,7 +173,7 @@ def exception_handler(exception_type: type[BaseException] | threading.ExceptHook
exit(1)
sys.excepthook = exception_handler # type: ignore
threading.excepthook = functools.partial(exception_handler, thread_error=True)
sys.argv = ["C:\\Users\\dhruv\\Documents\\Projects\\helix\\helix.py", "C:\\Users\\dhruv\\Documents\\Projects\\helix\\syntax\\test.hlx"] + list(sys.argv)[2:]
sys.argv = ["Z:\\devolopment\\helix\\helix-lang\\helix.py", "Z:\\devolopment\\helix\\helix-lang\\syntax\\test.hlx"] + list(sys.argv)[2:]
del os, threading, functools
overload_with_type_check = beartype(conf=BeartypeConf(is_color=False)) # type: ignore
class C_cout():
Expand All @@ -184,23 +184,32 @@ def __lshift__(self: Any, a: str | hx_string):
print ( a )
@overload_with_type_check
def main(argv: list[str | hx_string] | hx_list[str | hx_string]):
do_something ( )
a: int | hx_int = int("12")
print ( add ( a , [ "a" , "b" , "c" ] ) )
add ( 123 , 123 )
print ( add . join ( ) )
do_something ( )
for i in C_For(i = int(0)).set_con('i < 10').set_inc('i ++'):
printf ( "doing something else eeeee: %d" , i )
del i
do_something . join ( )
print ( "done" )
return 0
@hx__async
def add(a: int | hx_int, b: int | hx_int) -> int:
printf ( "adding: %d + %d" , a , b )
return a + b
@overload_with_type_check
def subtract(a: int | hx_int, b: int | hx_int) -> int:
return a - b
@overload_with_type_check
def add(a: int | hx_int, b: int | hx_int) -> int:
a: Type = Type(10)
print ( a )
return a - b
@overload_with_type_check
@hx__async
def do_something():
for i in C_For(i = int(0)).set_con('i < 10').set_inc('i ++'):
print ( "doing something: %d" , i )
printf ( "doing something: %d" , i )
del i
@overload_with_type_check
def a_cursed_fucntion(a: int | hx_int) -> FunctionType:
printf ( "new something: %d" , a )
return a_cursed_fucntion
if __name__ == "__main__":
try:
main() # type: ignore
Expand Down
34 changes: 24 additions & 10 deletions .helix/cache/build_cache/test_hlx.py.lines
Original file line number Diff line number Diff line change
Expand Up @@ -185,19 +185,33 @@
85
85
86
87
88
92
89
91
92
93
96
92
95
96
97
98
99
102
102
100
100
101
102
103
104
103
105
105
106
110
110
111
112
111
117
117
117
117
-1
-1
-1
-1
-1
92 changes: 76 additions & 16 deletions .helix/include/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
from functools import wraps
import inspect
from threading import Thread
from types import MappingProxyType as FastMap, NoneType, FunctionType, UnionType
from types import MappingProxyType as FastMap, NoneType, FunctionType, UnionType, BuiltinFunctionType
from beartype.typing import Any, Callable, Literal, NoReturn, Self
from weakref import ref

from multimethod import DispatchError, multimeta
from multimethod import subtype

from typing import Type, TypeVar, Optional
from core.panic import panic, standalone_tokenize_line as _H_tokenize_line__
from src.panic import panic, standalone_tokenize_line as _H_tokenize_line__
from time import sleep
#from include.c_cpp import __import_c__

Expand Down Expand Up @@ -197,6 +197,42 @@ def __void__(self) -> bool:
DEFAULT_VALUE = void()


#class C_For:
# def __init__(self, **kwargs):
# # Initialize loop variables
# self.loop_vars = kwargs
# # Extract condition and increment expressions
# self.condition = "True"
# self.increment = ""
# # Evaluate initial conditions
# [exec(f"{var} = {value}") for var, value in self.loop_vars.items()]
#
# def __iter__(self):
# return self
#
# def __next__(self):
# if not self.loop_condition_met:
# raise StopIteration
# current_values = tuple(self.loop_vars.values())
# exec(self.increment, None, self.loop_vars)
# self.loop_condition_met = eval(self.condition, None, self.loop_vars)
# return current_values if len(current_values) > 1 else current_values[0]
#
# def set_con(self, condition):
# self.condition = condition
# self.loop_condition_met = eval(self.condition, None, self.loop_vars)
# return self
#
# def set_inc(self, increment):
# self.increment = (
# increment.replace("++", "+= 1")
# .replace("--", "-= 1")
# .replace("+*", "*= 1")
# .replace("-*", "*= -1")
# .replace("/-", "/ -1")
# .replace("/*", "*= 1")
# )
# return self
class C_For:
def __init__(self, **kwargs):
# Initialize loop variables
Expand All @@ -206,16 +242,18 @@ def __init__(self, **kwargs):
self.increment = ""
# Evaluate initial conditions
[exec(f"{var} = {value}") for var, value in self.loop_vars.items()]
self.loop_condition_met = eval(self.condition, None, self.loop_vars)

def __iter__(self):
async def __aiter__(self):
return self

def __next__(self):
async def __anext__(self):
if not self.loop_condition_met:
raise StopIteration
raise StopAsyncIteration
current_values = tuple(self.loop_vars.values())
exec(self.increment, None, self.loop_vars)
self.loop_condition_met = eval(self.condition, None, self.loop_vars)
await asyncio.sleep(0) # Yield control to allow other tasks to run
return current_values if len(current_values) > 1 else current_values[0]

def set_con(self, condition):
Expand All @@ -234,10 +272,30 @@ def set_inc(self, increment):
)
return self

def hx__async(func):
def wrapper(*args, **kwargs):
Thread(target=func, args=args, kwargs=kwargs, daemon=True).start()

from beartype import beartype

def hx__async(func: Callable) -> Callable:
def run_thread(func, args, kwargs):
func._result = func(*args, **kwargs)
func._thread_started = False

@wraps(func)
def wrapper(*args, **kwargs):
if not hasattr(func, "_thread_started") or not func._thread_started:
func._thread = Thread(target=run_thread, args=(func, args, kwargs))
func._thread_started = True
func._thread.start()
return func

def join(timeout=None):
if hasattr(func, "_thread"):
func._thread.join(timeout)
return getattr(func, "_result", None)
return None

func.join = join
wrapper.join = join
return wrapper

class hx_void(void): pass
Expand Down Expand Up @@ -710,7 +768,9 @@ def __repr__(self) -> str:
def __bytes__(self) -> bytes:
return self.__value__

class hx_tuple[T](tuple, metaclass=multimeta):
T = TypeVar("T")

class hx_tuple(tuple, metaclass=multimeta):
__value__: tuple | hx_tuple | None = ()
__generic__: subtype = None

Expand Down Expand Up @@ -792,7 +852,7 @@ def last(self) -> T:
return self.__value__[-1]

# Derived Types
class hx_list[T](list, metaclass=multimeta):
class hx_list(list, metaclass=multimeta):
__value__: list = None
__generic__: subtype = None
__initialized__ = False
Expand Down Expand Up @@ -821,7 +881,7 @@ def __type_check__(self, __o: Any) -> None:

def __set_generic__(self, __o: str) -> Self:
exec(
f"self.__generic__ = subtype(list{__o} | {((" | ".join(["list[" + _ + "]" for _ in [replace_primitives[_] for _ in replace_primitives if _ in __o]])) + " | ") if " | ".join(["list[" + _ + "]" for _ in [replace_primitives[_] for _ in replace_primitives if _ in __o] if _]) else ""} void {'| list' if not __o.endswith(']') else ''})"
f"self.__generic__ = subtype(list{__o} | {((' | '.join(['list[' + _ + ']' for _ in [replace_primitives[_] for _ in replace_primitives if _ in __o]])) + ' | ') if ' | '.join(['list[' + _ + ']' for _ in [replace_primitives[_] for _ in replace_primitives if _ in __o] if _]) else ''} void {'| list' if not __o.endswith(']') else ''})"
)
if self.__initialized__:
panic(
Expand Down Expand Up @@ -860,7 +920,7 @@ def length(self) -> int:
self.__check_if_initialed()
return len(self.__value__)

class hx_array[T](array, metaclass=multimeta):
class hx_array(array, metaclass=multimeta):
__value__: list = None
__generic__: subtype = None
__initialized__ = False
Expand Down Expand Up @@ -889,7 +949,7 @@ def __type_check__(self, __o: Any) -> None:

def __set_generic__(self, __o: str) -> Self:
exec(
f"self.__generic__ = subtype(list{__o} | {((" | ".join(["list[" + _ + "]" for _ in [replace_primitives[_] for _ in replace_primitives if _ in __o]])) + " | ") if " | ".join(["array[" + _ + "]" for _ in [replace_primitives[_] for _ in replace_primitives if _ in __o] if _]) else ""} void {'| array' if not __o.endswith(']') else ''})"
f"self.__generic__ = subtype(list{__o} | {((' | '.join(['list[' + _ + ']' for _ in [replace_primitives[_] for _ in replace_primitives if _ in __o]])) + ' | ') if ' | '.join(['array[' + _ + ']' for _ in [replace_primitives[_] for _ in replace_primitives if _ in __o] if _]) else ''} void {'| array' if not __o.endswith(']') else ''})"
)
if self.__initialized__:
panic(
Expand Down Expand Up @@ -927,7 +987,7 @@ def length(self) -> int:
self.__check_if_initialed()
return len(self.__value__)

class hx_set[T](set, metaclass=multimeta):
class hx_set(set, metaclass=multimeta):
__value__: list = None
__generic__: subtype = None
__initialized__ = False
Expand Down Expand Up @@ -956,7 +1016,7 @@ def __type_check__(self, __o: Any) -> None:

def __set_generic__(self, __o: str) -> Self:
exec(
f"self.__generic__ = subtype(set{__o} | {((" | ".join(["set[" + _ + "]" for _ in [replace_primitives[_] for _ in replace_primitives if _ in __o]])) + " | ") if " | ".join(["set[" + _ + "]" for _ in [replace_primitives[_] for _ in replace_primitives if _ in __o] if _]) else ""} void {'| set' if not __o.endswith(']') else ''})"
f"self.__generic__ = subtype(set{__o} | {((' | '.join(['set[' + _ + ']' for _ in [replace_primitives[_] for _ in replace_primitives if _ in __o]])) + ' | ') if ' | '.join(['set[' + _ + ']' for _ in [replace_primitives[_] for _ in replace_primitives if _ in __o] if _]) else ''} void {'| set' if not __o.endswith(']') else ''})"
)
if self.__initialized__:
panic(
Expand Down Expand Up @@ -997,7 +1057,7 @@ def length(self) -> int:



class hx_map[T](dict, metaclass=multimeta):
class hx_map(dict, metaclass=multimeta):
__value__: list = None
__generic__: subtype = None
__initialized__ = False
Expand Down
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Installation

### create a virtual environment
### install the requirements
### run helix.py with a test file

```bash
./init
.venv/bin/python3.12 helix.py
```
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
python helix.py syntax/test.hlx
deactivate # to exit the virtual environment when done
```
Loading

0 comments on commit 46e5f4c

Please sign in to comment.