-
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.
Implemented bitwise operations, began drafting object memory model
- Loading branch information
1 parent
5a3cd96
commit cb6265d
Showing
9 changed files
with
339 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright (C) 2024 MyWorld, LLC | ||
* All rights reserved. | ||
* | ||
* This file is part of Chipmunk. | ||
* | ||
* Chipmunk is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Chipmunk is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Chipmunk. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package chipmunk.runtime.hvm; | ||
|
||
public class CClass { | ||
|
||
protected CField[] fields; | ||
protected CField[] shared; | ||
protected CMethod[] methods; | ||
protected long storagePtr; | ||
|
||
} |
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,29 @@ | ||
/* | ||
* Copyright (C) 2024 MyWorld, LLC | ||
* All rights reserved. | ||
* | ||
* This file is part of Chipmunk. | ||
* | ||
* Chipmunk is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Chipmunk is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Chipmunk. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package chipmunk.runtime.hvm; | ||
|
||
public record CField(int offset, int flags, CType pType, String name) { | ||
|
||
public int calculateAddress(long pointer){ | ||
return (int) pointer + offset; | ||
} | ||
|
||
} |
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,40 @@ | ||
/* | ||
* Copyright (C) 2024 MyWorld, LLC | ||
* All rights reserved. | ||
* | ||
* This file is part of Chipmunk. | ||
* | ||
* Chipmunk is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Chipmunk is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Chipmunk. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package chipmunk.runtime.hvm; | ||
|
||
public class CFlags { | ||
|
||
public static final int SHARED = 0b001; | ||
public static final int FINAL = 0b010; | ||
public static final int TRAIT = 0b100; | ||
|
||
public static int combine(int... flags){ | ||
var combined = 0; | ||
for(var f : flags){ | ||
combined |= f; | ||
} | ||
return combined; | ||
} | ||
|
||
public static boolean isSet(int flags, int flag){ | ||
return (flags & flag) != 0; | ||
} | ||
} |
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,23 @@ | ||
/* | ||
* Copyright (C) 2024 MyWorld, LLC | ||
* All rights reserved. | ||
* | ||
* This file is part of Chipmunk. | ||
* | ||
* Chipmunk is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Chipmunk is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Chipmunk. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package chipmunk.runtime.hvm; | ||
|
||
public record CMethod(int address, int flags, String name /* TODO - signature*/) {} |
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,34 @@ | ||
/* | ||
* Copyright (C) 2024 MyWorld, LLC | ||
* All rights reserved. | ||
* | ||
* This file is part of Chipmunk. | ||
* | ||
* Chipmunk is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Chipmunk is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Chipmunk. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package chipmunk.runtime.hvm; | ||
|
||
public enum CType { | ||
INT(32), LONG(64), FLOAT(32), DOUBLE(64); | ||
private final int width; | ||
|
||
CType(int width){ | ||
this.width = width; | ||
} | ||
|
||
public int bitWidth(){ | ||
return width; | ||
} | ||
} |
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,54 @@ | ||
/* | ||
* Copyright (C) 2024 MyWorld, LLC | ||
* All rights reserved. | ||
* | ||
* This file is part of Chipmunk. | ||
* | ||
* Chipmunk is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Chipmunk is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Chipmunk. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package chipmunk.runtime.hvm; | ||
|
||
import myworld.hummingbird.HummingbirdVM; | ||
|
||
public class Memory { | ||
|
||
public static long read(long pointer, CType type, HummingbirdVM vm){ | ||
return switch (type){ | ||
case INT, FLOAT -> vm.memory.getInt((int)pointer); | ||
case LONG, DOUBLE -> vm.memory.getLong((int)pointer); | ||
}; | ||
} | ||
|
||
public static void write(long pointer, long value, CType type, HummingbirdVM vm){ | ||
switch (type){ | ||
case INT, FLOAT -> vm.memory.putInt((int) pointer, (int) value); | ||
case LONG, DOUBLE -> vm.memory.putLong((int) pointer, value); | ||
} | ||
} | ||
|
||
public static long readField(long pointer, int field, CClass type, HummingbirdVM vm){ | ||
var f = type.fields[field]; | ||
return read(f.calculateAddress(pointer), f.pType(), vm); | ||
} | ||
|
||
public static void writeField(long pointer, long value, int field, CClass type, HummingbirdVM vm){ | ||
var f = type.fields[field]; | ||
var addr = f.calculateAddress(pointer); | ||
write(f.calculateAddress(addr), value, f.pType(), vm); | ||
} | ||
|
||
// TODO - support shared fields in memory model | ||
|
||
} |
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,23 @@ | ||
/* | ||
* Copyright (C) 2024 MyWorld, LLC | ||
* All rights reserved. | ||
* | ||
* This file is part of Chipmunk. | ||
* | ||
* Chipmunk is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Chipmunk is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Chipmunk. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package chipmunk.runtime.hvm; | ||
|
||
public record TypeName(String module, String 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