-
-
Save swayf/a0ca4f26d889cce8559f to your computer and use it in GitHub Desktop.
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
(function () { "use strict"; | |
var RegTest = function() { | |
this.ram = new Uint8Array(65536); | |
}; | |
RegTest.main = function() { | |
var foo = new RegTest(); | |
foo.whatIsR0(); | |
}; | |
RegTest.prototype = { | |
whatIsR0: function() { | |
console.log("r0 is " + this.ram[123]); | |
} | |
,get_r0: function() { | |
return this.ram[123]; | |
} | |
,set_r0: function(value) { | |
return this.ram[123] = value; | |
} | |
}; | |
RegTest.main(); | |
})(); |
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
package ; | |
import haxe.macro.Context; | |
import haxe.macro.Expr; | |
class RegisterMacro | |
{ | |
macro static public function memoryMappedRegister(fieldName:String,index :Int):Array<Field> { | |
var fields = Context.getBuildFields(); | |
var getterName = "get_" + fieldName; | |
var setterName = "set_" + fieldName; | |
var propertyFromMacro = macro : { | |
var $fieldName(get, set) : Int; | |
inline function $getterName() : Int { | |
return ram[ $v{index} ]; | |
} | |
inline function $setterName(value:Int) : Int { | |
return ram[$v{index}]=value; | |
} | |
}; | |
switch (propertyFromMacro) { | |
case TAnonymous(getterFields): | |
fields=fields.concat(getterFields); | |
default: | |
throw 'unreachable'; | |
} | |
return fields; | |
} | |
} |
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
import js.html.Uint8Array; | |
@:build( RegisterMacro.memoryMappedRegister("r0",123) ) | |
class RegTest | |
{ | |
var ram : Uint8Array; | |
public function new() { | |
ram = new Uint8Array(65536); | |
} | |
public function whatIsR0() { | |
trace("r0 is "+r0); | |
} | |
static function main() { | |
var foo = new RegTest(); | |
foo.whatIsR0(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment