diff --git a/.gitmodules b/.gitmodules index 6947977ff2..ee23ed1988 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1584,3 +1584,6 @@ [submodule "vendor/grammars/zephir-sublime"] path = vendor/grammars/zephir-sublime url = https://github.com/phalcon/zephir-sublime +[submodule "vendor/grammars/verse-grammar"] + path = vendor/grammars/verse-grammar + url = https://github.com/simnjs/verse-grammar.git diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 108105d56e..10895698c7 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -8242,6 +8242,14 @@ Verilog: codemirror_mode: verilog codemirror_mime_type: text/x-verilog language_id: 387 +Verse: + type: programming + color: "#518ef8" + extensions: + - ".verse" + tm_scope: source.verse + ace_mode: text + language_id: 180832205 Vim Help File: type: prose color: "#199f4b" diff --git a/samples/Verse/events.verse b/samples/Verse/events.verse new file mode 100644 index 0000000000..5f95989af8 --- /dev/null +++ b/samples/Verse/events.verse @@ -0,0 +1,40 @@ +using { /Verse.org/Simulation } +using { /UnrealEngine.com/Temporary/UI } + +(Event:event(t) where t:type).Call(Function:type{_(:t):void}):void= + loop: + EventData := Event.Await() + Function(EventData) + + +wrapper_agent(t : type) := class(): + ExtraData : t + OutputFunc : tuple(agent, t) -> void + InputFunc(Agent : agent): void = OutputFunc(Agent, ExtraData) + + + +(Listenable : listenable(agent)).SubscribeAgent(OutputFunc : tuple(agent, t)->void, ExtraData : t where t:type) : cancelable = + Wrapper := wrapper_agent(t){ExtraData := ExtraData, OutputFunc := OutputFunc} + Listenable.Subscribe(Wrapper.InputFunc) + + + +#Wrapper widget_message +wrapper_widget(t : type) := class(): + ExtraData : t + OutputFunc : tuple(widget_message, t) -> void + InputFunc(Widget : widget_message): void = OutputFunc(Widget, ExtraData) + + +(Listenable : listenable(widget_message)).SubscribeWidget(OutputFunc : tuple(widget_message, t)->void, ExtraData : t where t:type) : cancelable = + Wrapper := wrapper_widget(t){ExtraData := ExtraData, OutputFunc := OutputFunc} + Listenable.Subscribe(Wrapper.InputFunc) + + + +wrapper(t : type ) := class(): + ExtraData : t + OutputFunc : t -> void + InputFunc(): void = OutputFunc(ExtraData) + diff --git a/samples/Verse/int.verse b/samples/Verse/int.verse new file mode 100644 index 0000000000..55ea5b3da4 --- /dev/null +++ b/samples/Verse/int.verse @@ -0,0 +1,146 @@ +# CONSTANTES OPTIMISÉES +MAX_INT64 : int = 9223372036854775807 +MAX_SAFE_MULTIPLIER : int = 4611686018427387903 # MAX_INT64 / 2 + +(X:int).IsOdd():logic=if(Mod[X,2]<>0) then true else false +(X:int).IsEven():logic=if(Mod[X,2]=0) then true else false + +(InInt:int).Pow(InPower:float):float = Pow(InInt * 1.0,InPower) +(InInt:int).Pow(InPower:int):int = Floor[Pow(InInt * 1.0,InPower * 1.0)] or Err("Integer power calculation failed") + +bit_pred := type{_(Left:int, Right:int):logic} + +# this function will return the result of applying the predicate to each bit of the input numbers +# used to implement the And, Or and Xor operators +AllBitsByPredicate(_Left:int, _Right:int, Predicate:bit_pred):int= + var Left :int = _Left + var Right :int = _Right + var Result :int = 0 + var Multiplier :int = 1 + + loop: + # find LSB + if(Predicate(Mod[Left, 2], Mod[Right, 2])?) { set Result += Multiplier } + + # shift right + set Left = Floor(Left / 2) or Err("Left bit shift calculation failed") + set Right = Floor(Right / 2) or Err("Right bit shift calculation failed") + + if(Left <= 0 and Right <= 0) { break } + # Protection overflow améliorée + if(Multiplier >= 4611686018427387903) { break } + + set Multiplier *= 2 + Result + +<#> + trueth table + a b r + 0 0 0 + 0 1 1 + 1 0 1 + 1 1 1 +<#> +OrPredicate(_Left:int, _Right:int):logic=logic{_Left = 1 or _Right = 1} + +<#> + trueth table + a b r + 0 0 0 + 0 1 0 + 1 0 0 + 1 1 1 +<#> + +AndPredicate(_Left:int, _Right:int):logic=logic{_Left = 1 and _Right = 1} + +<#> + trueth table + a b r + 0 0 0 + 0 1 1 + 1 0 1 + 1 1 0 +<#> +XorPredicate(_Left:int, _Right:int):logic=logic{_Left <> _Right} + +# because & operator is not implemented in verse, we need to reproduce it +(InInt:int).And(InInt2:int):int=AllBitsByPredicate(InInt, InInt2, AndPredicate) +# because | operator is not implemented in verse, we need to reproduce it +(InInt:int).Or(InInt2:int):int=AllBitsByPredicate(InInt, InInt2, OrPredicate) +# because ^ operator is not implemented in verse, we need to reproduce it +(InInt:int).Xor(InInt2:int):int=AllBitsByPredicate(InInt, InInt2, XorPredicate) +# because << operator is not implemented in verse, we need to reproduce it +(InInt:int).ShiftLeft(InShift:int):int= InInt * 2.Pow(InShift) +# because >> operator is not implemented in verse, we need to reproduce it +(InInt:int).ShiftRight(InShift:int):int= Floor(InInt / 2.Pow(InShift)) or Err("Right shift calculation failed") +# because ~ operator is not implemented in verse, we need to reproduce it +(InInt: int).Not():int = 9223372036854775807 - InInt + +# ToFloat is not implemented in verse, we need to reproduce it +(InInt: int).ToFloat():float = InInt * 1.0 + +# esealy know if a bit is set by index +(InInt: int).HasBit(BitIndex: int):logic= + if(BitIndex < 0 or BitIndex > 63) { return false } + logic{Mod[InInt.ShiftRight(BitIndex), 2] = 1} + +# easily set bit by index +(InInt: int).SetBit(BitIndex: int, Value: logic):int= + Mask := 1.ShiftLeft(BitIndex) + if(Value?) then InInt.Or(Mask) else InInt.And(Mask.Not()) + +LOOKUP :[int]string = map: + 1 => "" + 1000 => "k" + 1000000 => "M" + 1000000000 => "B" + 1000000000000 => "T" + 1000000000000000 => "P" + 1000000000000000000 => "E" + +(InInt:int).Compactize():string= + # Gestion des cas négatifs + if(InInt < 0): + return "0" + + if(InInt < 1000): + return "{InInt}" + + for(k -> v : LOOKUP): + if(InInt < k * 1000): + if(k = 1): + return "{InInt}" + else: + FloatValue := InInt.ToFloat() + FloatK := k.ToFloat() + + if(InInt < k * 10): + New := FloatValue / FloatK + return New.StrRounded(2) + v + else if(InInt < k * 100): + New := FloatValue / FloatK + return New.StrRounded(1) + v + else: + New := FloatValue / FloatK + return New.StrRounded(0) + v + + return "{InInt}" + + + + + +operator'+'(I:int, F:float):float = I * 1.0 + F +operator'+'(F:float, I:int):float = F + I * 1.0 +operator'-'(I:int, F:float):float = I * 1.0 - F +operator'-'(F:float, I:int):float = F - I * 1.0 +operator'/'(I:int, F:float):float = I * 1.0 / F +operator'/'(F:float, I:int):float = F / (I * 1.0) + + + + + + + diff --git a/vendor/grammars/verse-grammar b/vendor/grammars/verse-grammar new file mode 160000 index 0000000000..c12e4b7b58 --- /dev/null +++ b/vendor/grammars/verse-grammar @@ -0,0 +1 @@ +Subproject commit c12e4b7b5819e201d55808f5c1306b7b84655fa6 diff --git a/vendor/licenses/git_submodule/verse-grammar.dep.yml b/vendor/licenses/git_submodule/verse-grammar.dep.yml new file mode 100644 index 0000000000..8e8edf3a02 --- /dev/null +++ b/vendor/licenses/git_submodule/verse-grammar.dep.yml @@ -0,0 +1,31 @@ +--- +name: verse-grammar +version: 27d99dba87f755d66e408e09986ac376fe78b92b +type: git_submodule +homepage: https://github.com/simnjs/verse-grammar +license: mit +licenses: + - sources: LICENSE + text: | + MIT License + + Copyright (c) 2025 GAY Simon + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +notices: []