These determine the assumed/default size of instruction operands, and restricts which opcodes are available, and how they are used.
Modern operating systems, booted inside Real mode,
| {-| Exercise: | |
| - Step 1: | |
| Write a program simulating an iterating machine: we for example feed a range | |
| @[0..4]@ and an action @print@ and it must execute this action on all the | |
| elements of the range. | |
| Writing @iterate1 [4..9] print@ must output: | |
| > 4 |
| from dataclasses import dataclass | |
| from typing import List, Tuple, Union, Dict, Iterator, Optional | |
| import sys | |
| import itertools | |
| Id = int | |
| class UnionFind: | |
| parents: List[Id] |
| #r "nuget: FParsec, 1.1.1" | |
| open FParsec | |
| let ws = skipMany (pchar ' ' <|> pchar '\t') | |
| let ws1 = skipMany1 (pchar ' ' <|> pchar '\t') | |
| let parseComment = | |
| pstring "#" >>. skipRestOfLine true >>% [] |
| type term = | |
| | Lam of (term -> term) | |
| | Pi of term * (term -> term) | |
| | Appl of term * term | |
| | Ann of term * term | |
| | FreeVar of int | |
| | Star | |
| | Box | |
| let unfurl lvl f = f (FreeVar lvl) |
Note: this was originally several Reddit posts, chained and linked. But now that Reddit is dying I've finally moved them out. Sorry about the mess.
URL: https://www.reddit.com/r/ProgrammingLanguages/comments/up206c/stack_machines_for_compilers/i8ikupw/ Summary: stack-based vs register-based in general.
There are a wide variety of machines that can be described as "stack-based" or "register-based", but not all of them are practical. And there are a lot of other decisions that affect that practicality (do variables have names or only address/indexes? fixed-width or variable-width instructions? are you interpreting the bytecode (and if so, are you using machine stack frames?) or turning it into machine code? how many registers are there, and how many are special? how do you represent multiple types of variable? how many scopes are there(various kinds of global, local, member, ...)? how much effort/complexity can you afford to put into your machine? etc.)
| ######################### Preamble ########################################### | |
| SHELL := bash | |
| .ONESHELL: | |
| .SHELLFLAGS := -eu -o pipefail -c | |
| .DELETE_ON_ERROR: | |
| .SECONDEXPANSION: | |
| .EXTRA_PREREQS := $(MAKEFILE_LIST) | |
| MAKEFLAGS += --warn-undefined-variables | |
| MAKEFLAGS += --no-builtin-rules | |
| MAKEFLAGS += -j$(shell nproc) |
| /// This module implements a generic [union-find](https://en.wikipedia.org/wiki/Disjoint-set_data_structure) data structure. | |
| /// This structure is used to manage disjoint sets, often used in partitioning or clustering problems. | |
| /// | |
| /// Here is a summary of the features and members of this data structure: | |
| /// | |
| /// 1. **Constructor**: The `UnionFind` constructor initializes a new instance of the Union-Find data structure with | |
| /// default elements of the original set specified as a sequence. This set can be extended. | |
| /// | |
| /// 2. **Public Members** : | |
| /// - `UnionFind.AddElement` Adds a new element to the set. |
| """ | |
| The most atomic way to train and run inference for a GPT in pure, dependency-free Python. | |
| This file is the complete algorithm. | |
| Everything else is just efficiency. | |
| @karpathy | |
| """ | |
| import os # os.path.exists | |
| import math # math.log, math.exp |
| #!/usr/bin/dotnet fsi | |
| open System | |
| open System.Collections.Generic | |
| open System.Globalization | |
| open System.IO | |
| open System.Net.Http | |
| open System.Numerics | |
| open System.Text |