Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 8 additions & 0 deletions lib/linguist/languages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
40 changes: 40 additions & 0 deletions samples/Verse/events.verse
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/UI }

(Event:event(t) where t:type).Call<public>(Function:type{_(:t):void})<suspends>: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<public>(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<public>(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)

146 changes: 146 additions & 0 deletions samples/Verse/int.verse
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
# CONSTANTES OPTIMISÉES
MAX_INT64 : int = 9223372036854775807
MAX_SAFE_MULTIPLIER : int = 4611686018427387903 # MAX_INT64 / 2

(X:int).IsOdd<public>()<transacts>:logic=if(Mod[X,2]<>0) then true else false
(X:int).IsEven<public>()<transacts>:logic=if(Mod[X,2]=0) then true else false

(InInt:int).Pow<public>(InPower:float)<transacts>:float = Pow(InInt * 1.0,InPower)
(InInt:int).Pow<public>(InPower:int)<transacts>:int = Floor[Pow(InInt * 1.0,InPower * 1.0)] or Err("Integer power calculation failed")

bit_pred := type{_(Left:int, Right:int)<transacts>: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)<transacts>: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)<transacts>: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)<transacts>: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)<transacts>:logic=logic{_Left <> _Right}

# because & operator is not implemented in verse, we need to reproduce it
(InInt:int).And<public>(InInt2:int)<transacts>:int=AllBitsByPredicate(InInt, InInt2, AndPredicate)
# because | operator is not implemented in verse, we need to reproduce it
(InInt:int).Or<public>(InInt2:int)<transacts>:int=AllBitsByPredicate(InInt, InInt2, OrPredicate)
# because ^ operator is not implemented in verse, we need to reproduce it
(InInt:int).Xor<public>(InInt2:int)<transacts>:int=AllBitsByPredicate(InInt, InInt2, XorPredicate)
# because << operator is not implemented in verse, we need to reproduce it
(InInt:int).ShiftLeft<public>(InShift:int)<transacts>:int= InInt * 2.Pow(InShift)
# because >> operator is not implemented in verse, we need to reproduce it
(InInt:int).ShiftRight<public>(InShift:int)<transacts>: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<public>()<transacts>:int = 9223372036854775807 - InInt

# ToFloat is not implemented in verse, we need to reproduce it
(InInt: int).ToFloat<public>()<transacts>:float = InInt * 1.0

# esealy know if a bit is set by index
(InInt: int).HasBit<public>(BitIndex: int)<transacts>:logic=
if(BitIndex < 0 or BitIndex > 63) { return false }
logic{Mod[InInt.ShiftRight(BitIndex), 2] = 1}

# easily set bit by index
(InInt: int).SetBit<public>(BitIndex: int, Value: logic)<transacts>: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<public>():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'+'<public>(I:int, F:float)<computes>:float = I * 1.0 + F
operator'+'<public>(F:float, I:int)<computes>:float = F + I * 1.0
operator'-'<public>(I:int, F:float)<computes>:float = I * 1.0 - F
operator'-'<public>(F:float, I:int)<computes>:float = F - I * 1.0
operator'/'<public>(I:int, F:float)<computes>:float = I * 1.0 / F
operator'/'<public>(F:float, I:int)<computes>:float = F / (I * 1.0)







1 change: 1 addition & 0 deletions vendor/grammars/verse-grammar
Submodule verse-grammar added at c12e4b
31 changes: 31 additions & 0 deletions vendor/licenses/git_submodule/verse-grammar.dep.yml
Original file line number Diff line number Diff line change
@@ -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: []
Loading