Skip to content

Programming the turtle #11

@HybridDog

Description

@HybridDog

I've made a custom primitive programming language and successfully used it for maidroids: https://github.com/HybridDog/maidroid
https://github.com/hybriddog/pdisc
I tried to make it resemble assembler, you can use mov to assign/copy values to variables, there are neither if statements, nor loops, you need to do it manually using jmp (conditional jump).
If statements and while and for loops don't represent the basic possibilities of programming, they're changed to conditional jumps when compiling.
A visual editor should be easy to implement for this simple language.
Here's an example program for maidroids:

call init
mainloop:
	call make_frames
	mov target.z, buildpos.z
	sub target.z, 3
	call walkz
jmp mainloop

; changes the "maidpos" and "buildpos" fields
init:
	setyaw 0
	getpos $maidpos
	copytable $buildpos, $maidpos
	add buildpos.x, 0.5
	floor buildpos.x
	add buildpos.y, 0.5
	floor buildpos.y
	add buildpos.z, 0.5
	floor buildpos.z
ret

; uses "target.z"
; changes "maidpos.z"
; taints "stop_walk" and the "vel" fields
walkz:
	setwalk 2
	walkz_loop:
	getpos $maidpos
	mov stop_walk, target.z
	sub stop_walk, maidpos.z
	less stop_walk, 0
	jmp finished_walk, stop_walk
		sleep 0.5
		getvelocity $vel
		equal vel.z, 2
		jmp walkz_loop, vel.z
		print $don't stop me
		flush
		setwalk 3
		jmp walkz_loop
	finished_walk:
	setwalk
ret

; uses the "buildpos" and "maidpos" fields
; changes buildpos.z
; taints "near_enough", "dist" and the "pos" fields
make_frames:
	mov dist, buildpos.z
	sub dist, maidpos.z

	jump; demo

	make_frames_loop:
	mov near_enough, dist
	less near_enough, 5
	jmp one_more_frame, near_enough
	ret
	one_more_frame:
		copytable $pos, $buildpos
		call make_frame
		inc buildpos.z
		inc dist
	jmp make_frames_loop


; uses the "pos" fields
; taints the "pos" fields
make_frame:
	mov hole, pos.z
	mod hole, 2
	equal hole, 0

	; floor
	dec pos.y
	call place_if_needed

	; right wall
	inc pos.x
	inc pos.y
	call place_if_needed
	inc pos.y
	jmp frame_no_wallright, hole
		call place_if_needed
	frame_no_wallright:

	; ceiling
	inc pos.y
	dec pos.x
	call place_if_needed

	; left wall
	dec pos.x
	sub pos.y, 2
	call place_if_needed
	jmp frame_no_wallleft, hole
		inc pos.y
		call place_if_needed
	frame_no_wallleft:
ret

; uses "nodename"
; changes "walkable"
; taints the "def" fields
is_walkable:
	get_nodedef nodename, $def
	jmp node_known, nodename
	jmp unknown_node
	node_known:
	mov walkable, def.walkable
ret

; uses the "pos" fields
; taints "nodename", "placing_problem" and a few "pos" fields
place_if_needed:
	get_node $pos
	mov nodename, pos.name
	call is_walkable
	jmp no_placement_required, walkable
		mov placing_problem, $pos
		place placing_problem, errormsg
		sleep 0.03; for demonstration purpose
		neg placing_problem
		jmp placing_error, placing_problem
	no_placement_required:
ret

; jumped to on error
unknown_node:
	print $unknown node detected at, pos.x, pos.y, pos.z
	jmp end

placing_error:
	print errormsg
	jmp end

end:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions