-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8f1bb16
commit ff2e141
Showing
13 changed files
with
177 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
.git/ | ||
.vs/ | ||
venv/ | ||
.idea/ | ||
__pycache__/ | ||
**/__pycache__/ | ||
build/ | ||
dist/ | ||
*.bat | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import "std/types/events/exceptionevent.para"; | ||
|
||
print(EventHandler.handlers); | ||
let handler = EventHandler.new(); | ||
print(EventHandler.handlers); | ||
print(handler.handled_events); | ||
func m(handled_event, event) { print("EVENT TRIGGERED: " + handled_event.to_str() + " " + event.to_str()); } | ||
handler.handle(ExceptionEvent, m); | ||
print(handler.handled_events); | ||
|
||
let a = []; | ||
print(a[1]); // Will trigger an out-of-bounds error. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
let FailedAssertionError = Exception.extend({ | ||
name = 'FailedAssertionError' | ||
|
||
instance = { | ||
func raise(self) { | ||
// TODO: Add the line number | ||
return raise(self, "Assertion Failed"); | ||
} | ||
} | ||
|
||
func __construct__(self, _message) { | ||
self.message = _message; | ||
} | ||
}); | ||
|
||
// TODO: Integrate into ParaCode so the condition and line number will be accessible and printable directly | ||
func assert(condition, message) { | ||
if !condition { | ||
FailedAssertionError.new(message).raise(); | ||
} | ||
return condition; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
let Test = Type.extend({ | ||
name = 'Test' | ||
|
||
instance = { | ||
statement, | ||
expected_result | ||
|
||
func test(self) { | ||
import "std/experimental/assert.para"; | ||
|
||
assert(self.is_truthy(), "Test Failed!"); | ||
} | ||
|
||
func is_truthy(self) { | ||
return self.statement == self.expected_result; | ||
} | ||
|
||
func __bool__(self) { | ||
return self.is_truthy(); | ||
} | ||
} | ||
|
||
func __construct__(self, statement, expected_result) { | ||
self.statement = statement; | ||
self.expected_result = expected_result; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
let Event = Type.extend({ | ||
name = 'Event' | ||
|
||
instance = { | ||
func trigger(self) { | ||
return EventHandler.trigger(self); | ||
} | ||
} | ||
|
||
func __construct__(self) { | ||
} | ||
|
||
func handle(self, handler, method) { | ||
return handler.handle(self, method); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
let EventHandler = Type.extend({ | ||
name = 'EventHandler' | ||
|
||
handlers = [] | ||
|
||
instance = { | ||
handled_events = [] | ||
|
||
func handle(self, event, method=null) { | ||
if method == null && event.type() == HandledEvent { | ||
self.handled_events.append(event); | ||
return event; | ||
} | ||
else { | ||
let handled = HandledEvent.new(event, method); | ||
self.handled_events.append(handled); | ||
return handled; | ||
} | ||
} | ||
} | ||
|
||
func __construct__(self) { | ||
EventHandler.handlers.append(self); | ||
return self; | ||
} | ||
|
||
func trigger(self, event) { | ||
for handler in EventHandler.handlers { | ||
for handled in handler.handled_events { | ||
handled.method(event); | ||
} | ||
} | ||
} | ||
}); | ||
|
||
let HandledEvent = Type.extend({ | ||
name = 'HandledEvent' | ||
|
||
instance = { | ||
event_type | ||
method | ||
} | ||
|
||
func __construct__(self, event_type, method) { | ||
self.event_type = event_type; | ||
self.method = method; | ||
|
||
return self; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
let ExceptionEvent = Event.extend({ | ||
name = 'ExceptionEvent' | ||
|
||
instance = { | ||
name | ||
exception | ||
|
||
func trigger(self) { | ||
return EventHandler.trigger(self); | ||
} | ||
} | ||
|
||
func __construct__(self, name, exception) { | ||
self.name = name; | ||
self.exception = exception; | ||
} | ||
|
||
func handle(self, handler, method) { | ||
return handler.handle(self, method); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
let LangInfo = Type.extend({ | ||
name = "LangInfo" | ||
|
||
func get_version() { | ||
return "2.1.0"; | ||
} | ||
|
||
func get_extension_language() { | ||
return "Python"; | ||
} | ||
}); |