mirror of
https://github.com/aNNiMON/Own-Programming-Language-Tutorial.git
synced 2024-09-20 08:44:20 +03:00
Move classes to separate modules
This commit is contained in:
parent
3aedda0e93
commit
219d654fe5
@ -6,19 +6,12 @@ import java.util.Map;
|
|||||||
|
|
||||||
public final class functional_foreach implements Function {
|
public final class functional_foreach implements Function {
|
||||||
|
|
||||||
private static final int UNKNOWN = -1;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Value execute(Value... args) {
|
public Value execute(Value... args) {
|
||||||
Arguments.check(2, args.length);
|
Arguments.check(2, args.length);
|
||||||
final Value container = args[0];
|
final Value container = args[0];
|
||||||
final Function consumer = ValueUtils.consumeFunction(args[1], 1);
|
final Function consumer = ValueUtils.consumeFunction(args[1], 1);
|
||||||
final int argsCount;
|
final int argsCount = consumer.getArgsCount();
|
||||||
if (consumer instanceof UserDefinedFunction) {
|
|
||||||
argsCount = ((UserDefinedFunction) consumer).getArgsCount();
|
|
||||||
} else {
|
|
||||||
argsCount = UNKNOWN;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (container.type()) {
|
switch (container.type()) {
|
||||||
case Types.STRING:
|
case Types.STRING:
|
@ -1,6 +1,7 @@
|
|||||||
package com.annimon.ownlang.modules.std;
|
package com.annimon.ownlang.modules.std;
|
||||||
|
|
||||||
import com.annimon.ownlang.Main;
|
import com.annimon.ownlang.Shared;
|
||||||
|
import com.annimon.ownlang.Version;
|
||||||
import com.annimon.ownlang.lib.*;
|
import com.annimon.ownlang.lib.*;
|
||||||
import com.annimon.ownlang.modules.Module;
|
import com.annimon.ownlang.modules.Module;
|
||||||
|
|
||||||
@ -13,17 +14,17 @@ public final class std implements Module {
|
|||||||
public static void initConstants() {
|
public static void initConstants() {
|
||||||
MapValue ownlang = new MapValue(5);
|
MapValue ownlang = new MapValue(5);
|
||||||
ownlang.set("PLATFORM", new StringValue("desktop"));
|
ownlang.set("PLATFORM", new StringValue("desktop"));
|
||||||
ownlang.set("VERSION", new StringValue(Main.VERSION));
|
ownlang.set("VERSION", new StringValue(Version.VERSION));
|
||||||
ownlang.set("VERSION_MAJOR", NumberValue.of(Main.VERSION_MAJOR));
|
ownlang.set("VERSION_MAJOR", NumberValue.of(Version.VERSION_MAJOR));
|
||||||
ownlang.set("VERSION_MINOR", NumberValue.of(Main.VERSION_MINOR));
|
ownlang.set("VERSION_MINOR", NumberValue.of(Version.VERSION_MINOR));
|
||||||
ownlang.set("VERSION_PATCH", NumberValue.of(Main.VERSION_PATCH));
|
ownlang.set("VERSION_PATCH", NumberValue.of(Version.VERSION_PATCH));
|
||||||
Variables.define("OwnLang", ownlang);
|
Variables.define("OwnLang", ownlang);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init() {
|
public void init() {
|
||||||
initConstants();
|
initConstants();
|
||||||
Variables.define("ARGS", ArrayValue.of(Main.getOwnlangArgs())); // is not constant
|
Variables.define("ARGS", ArrayValue.of(Shared.getOwnlangArgs())); // is not constant
|
||||||
Functions.set("echo", new std_echo());
|
Functions.set("echo", new std_echo());
|
||||||
Functions.set("readln", new std_readln());
|
Functions.set("readln", new std_readln());
|
||||||
Functions.set("length", new std_length());
|
Functions.set("length", new std_length());
|
@ -22,11 +22,7 @@ public final class std_length implements Function {
|
|||||||
break;
|
break;
|
||||||
case Types.FUNCTION:
|
case Types.FUNCTION:
|
||||||
final Function func = ((FunctionValue) val).getValue();
|
final Function func = ((FunctionValue) val).getValue();
|
||||||
if (func instanceof UserDefinedFunction) {
|
length = func.getArgsCount();
|
||||||
length = ((UserDefinedFunction) func).getArgsCount();
|
|
||||||
} else {
|
|
||||||
length = 0;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
length = 0;
|
length = 0;
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user