WeaponModule::WeaponModule(const FightManager& manager) : Module("Weapon") { for (const auto& w : manager.weapons) { static_field(Util::toupper(w.first), ls::Type::integer(), [&](ls::Compiler& c) { return c.new_integer(w.second->id); }); } field("id", ls::Type::number()); field("cost", ls::Type::number()); field("name", ls::Type::string()); }
void Value::set_immediate_from_static_field(InstanceClass* ic, int offset) { TypeArray::Raw f = ic->fields(); Oop::Raw object; for (int index = 0; index < f().length(); index += 5) { Field static_field(ic, index); if (static_field.offset() == offset) { // Note: there may be a non-static field with the same 'offset' // as the static field we're trying to find. if (static_field.is_final() && static_field.is_static()) { switch (static_field.type()) { case T_BOOLEAN : // fall-through - stored as 32-bit case T_CHAR : // fall-through - stored as 32-bit case T_BYTE : // fall-through - stored as 32-bit case T_SHORT : // fall-through - stored as 32-bit case T_INT : set_int(ic->int_field(offset)); break; case T_ARRAY : // fall-through case T_OBJECT : // Note: if setting immediate for object fields is enabled for cross // generator, this reference will be written to the TEXT block as a // part of relocation information for the compiled method. The // problem is that the referenced object may be put to the HEAP // block and it would be impossible to write its reference // in the TEXT block. At this point we don't know the block type of // the referenced object, so for now we disable setting immediate // for cross generator. if (!USE_AOT_COMPILATION || !GenerateROMImage) { object = ic->obj_field(offset); set_obj(&object); } break; #if ENABLE_FLOAT case T_FLOAT : set_float(ic->float_field(offset)); break; case T_DOUBLE : set_double(ic->double_field(offset)); break; #endif case T_LONG : set_long(ic->long_field(offset)); break; default : SHOULD_NOT_REACH_HERE(); break; } } return; } } // This field is not final and was removed from the fields array // during romization }
ObjectSTD::ObjectSTD() : Module("Object") { LSObject::object_class = clazz; readonly.addField("v", readonly_value); readonly.readonly = true; readonly.native = true; static_field("readonly", Type::object(), [&](Compiler& c) { return c.new_pointer(&ObjectSTD::readonly, Type::object()); }); /* * Operators */ operator_("in", { {Type::object(), Type::any(), Type::boolean(), (void*) &LSObject::in, {}, Method::NATIVE}, {Type::object(), Type::number(), Type::boolean(), (void*) &in_any} }); /* * Methods */ method("copy", { {Type::object(), {Type::object()}, (void*) &ValueSTD::copy} }); Type map_fun_type = Type::fun(Type::any(), {Type::any()}); auto map_fun = &LSObject::ls_map<LSFunction*>; method("map", { {Type::object(), {Type::object(), map_fun_type}, (void*) map_fun, Method::NATIVE} }); method("keys", { {Type::array(Type::string()), {Type::object()}, (void*) &LSObject::ls_get_keys, Method::NATIVE} }); method("values", { {Type::array(Type::any()), {Type::object()}, (void*) &LSObject::ls_get_values, Method::NATIVE} }); }
SystemSTD::SystemSTD() : Module("System") { static_field("version", Type::INTEGER, (void*) &System_version); static_field("operations", Type::INTEGER, (void*) &System_operations); static_field("time", Type::LONG, (void*) &System_time); static_field("milliTime", Type::LONG, (void*) &System_millitime); static_field("microTime", Type::LONG, (void*) &System_microtime); static_field("nanoTime", Type::LONG, (void*) &System_nanotime); static_method("print", { {Type::VOID, {Type::MPZ}, (void*) &System_print_mpz, Method::NATIVE}, {Type::VOID, {Type::MPZ_TMP}, (void*) &System_print_mpz_tmp, Method::NATIVE}, {Type::VOID, {Type::INTEGER}, (void*) &System_print_int, Method::NATIVE}, {Type::VOID, {Type::LONG}, (void*) &System_print_long, Method::NATIVE}, {Type::VOID, {Type::BOOLEAN}, (void*) &System_print_bool, Method::NATIVE}, {Type::VOID, {Type::REAL}, (void*) &System_print_float, Method::NATIVE}, {Type::VOID, {Type::POINTER}, (void*) &System_print, Method::NATIVE} }); }