-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
7 changed files
with
60 additions
and
10 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
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,21 @@ | ||
package dev.tenfont.cpmm.lang; | ||
|
||
import dev.tenfont.cpmm.lang.components.Function; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class FunctionRegistry { | ||
private final Map<String, Function> map = new HashMap<>(); | ||
|
||
public boolean declareFunction(String name, Function function) { | ||
if (map.containsKey(name)) | ||
return false; | ||
map.put(name, function); | ||
return true; | ||
} | ||
|
||
public boolean functionExists(String name) { | ||
return map.containsKey(name); | ||
} | ||
} |
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,5 @@ | ||
package dev.tenfont.cpmm.lang.components; | ||
|
||
public interface Function { | ||
void execute(Object[] arguments); | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/dev/tenfont/cpmm/lang/components/ScriptFunction.java
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 @@ | ||
package dev.tenfont.cpmm.lang.components; | ||
|
||
import dev.tenfont.cpmm.lang.Interpreter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import java.util.LinkedList; | ||
|
||
@RequiredArgsConstructor | ||
public class ScriptFunction implements Function { | ||
private final LinkedList<Statement> statements; | ||
|
||
@Override | ||
public void execute(Object[] arguments) { | ||
new Interpreter(statements).execute(); | ||
} | ||
} |